@codefast/cli 0.8.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/CHANGELOG.md +596 -0
  2. package/LICENSE +1 -1
  3. package/README.md +335 -129
  4. package/dist/arrange/analyze.d.ts +10 -0
  5. package/dist/arrange/cli-schema.d.ts +50 -0
  6. package/dist/arrange/command.d.ts +7 -0
  7. package/dist/arrange/domain/analyze-service.d.ts +18 -0
  8. package/dist/arrange/domain/ast/ast-node.d.ts +394 -0
  9. package/dist/arrange/domain/ast/collectors-cn.d.ts +26 -0
  10. package/dist/arrange/domain/ast/collectors-jsx.d.ts +8 -0
  11. package/dist/arrange/domain/ast/collectors-tv.d.ts +34 -0
  12. package/dist/arrange/domain/ast/helpers.d.ts +36 -0
  13. package/dist/arrange/domain/ast/helpers.js +1 -0
  14. package/dist/arrange/domain/ast/simplify-targets.d.ts +22 -0
  15. package/dist/arrange/domain/ast/targets.d.ts +20 -0
  16. package/dist/arrange/domain/constants.d.ts +111 -0
  17. package/dist/arrange/domain/grouping-service.d.ts +100 -0
  18. package/dist/arrange/domain/grouping.d.ts +21 -0
  19. package/dist/arrange/domain/imports.d.ts +14 -0
  20. package/dist/arrange/domain/source-text-formatters.d.ts +33 -0
  21. package/dist/arrange/domain/tailwind-token.d.ts +24 -0
  22. package/dist/arrange/domain/token-classifier.d.ts +47 -0
  23. package/dist/arrange/domain/types.d.ts +208 -0
  24. package/dist/arrange/output.d.ts +26 -0
  25. package/dist/arrange/process-file.d.ts +11 -0
  26. package/dist/arrange/resolve-target.d.ts +10 -0
  27. package/dist/arrange/resolve-target.js +3 -16
  28. package/dist/arrange/scan-target.d.ts +7 -0
  29. package/dist/arrange/simplify-process-file.d.ts +11 -0
  30. package/dist/arrange/simplify-sync.d.ts +13 -0
  31. package/dist/arrange/source-parse.d.ts +7 -0
  32. package/dist/arrange/suggest.d.ts +8 -0
  33. package/dist/arrange/sync.d.ts +11 -0
  34. package/dist/arrange/typescript-ast-translator.d.ts +31 -0
  35. package/dist/arrange/workspace.d.ts +13 -0
  36. package/dist/arrange/workspace.js +2 -2
  37. package/dist/audit/cli-schema.d.ts +93 -0
  38. package/dist/audit/cli-schema.js +14 -3
  39. package/dist/audit/command.d.ts +8 -0
  40. package/dist/audit/command.js +52 -12
  41. package/dist/audit/domain/audit-file.d.ts +7 -0
  42. package/dist/audit/domain/comment-content.d.ts +26 -0
  43. package/dist/audit/domain/comment-dividers.d.ts +62 -0
  44. package/dist/audit/domain/comment-dividers.js +48 -20
  45. package/dist/audit/domain/display-names.d.ts +11 -0
  46. package/dist/audit/domain/display-names.js +71 -0
  47. package/dist/audit/domain/import-policy.d.ts +34 -0
  48. package/dist/audit/domain/import-policy.js +147 -0
  49. package/dist/audit/domain/link-references.d.ts +40 -0
  50. package/dist/audit/domain/mappings.d.ts +45 -0
  51. package/dist/audit/domain/markdown-links.d.ts +44 -0
  52. package/dist/audit/domain/since-versions.d.ts +26 -0
  53. package/dist/audit/domain/tokenize.d.ts +14 -0
  54. package/dist/audit/domain/tsdoc-syntax.d.ts +20 -0
  55. package/dist/audit/domain/types.d.ts +171 -0
  56. package/dist/audit/output.d.ts +91 -0
  57. package/dist/audit/output.js +52 -11
  58. package/dist/audit/prepare.d.ts +70 -0
  59. package/dist/audit/prepare.js +41 -10
  60. package/dist/audit/run-comments.d.ts +17 -0
  61. package/dist/audit/run-comments.js +22 -18
  62. package/dist/audit/run-display-names.d.ts +14 -0
  63. package/dist/audit/run-display-names.js +60 -0
  64. package/dist/audit/run-imports.d.ts +14 -0
  65. package/dist/audit/{run-react.js → run-imports.js} +15 -5
  66. package/dist/audit/run-links.d.ts +14 -0
  67. package/dist/audit/run.d.ts +14 -0
  68. package/dist/bin.d.ts +2 -0
  69. package/dist/cli.d.ts +6 -0
  70. package/dist/core/cli/format-error.d.ts +7 -0
  71. package/dist/core/cli/global-options.d.ts +15 -0
  72. package/dist/core/cli/positional.d.ts +6 -0
  73. package/dist/core/cli/result-handle.d.ts +19 -0
  74. package/dist/core/config/define-config.d.ts +7 -0
  75. package/dist/core/config/define-config.js +8 -0
  76. package/dist/core/config/loader.d.ts +18 -0
  77. package/dist/core/config/loader.js +2 -7
  78. package/dist/core/config/schema.d.ts +99 -0
  79. package/dist/core/config/schema.js +7 -75
  80. package/dist/core/config/warnings.d.ts +6 -0
  81. package/dist/core/config.d.ts +12 -0
  82. package/dist/core/errors.d.ts +25 -0
  83. package/dist/core/exit-codes.d.ts +18 -0
  84. package/dist/core/filesystem/node.d.ts +7 -0
  85. package/dist/core/filesystem/node.js +1 -0
  86. package/dist/core/filesystem/port.d.ts +44 -0
  87. package/dist/core/glob.d.ts +19 -0
  88. package/dist/core/logger.d.ts +9 -0
  89. package/dist/core/result.d.ts +30 -0
  90. package/dist/core/schema-parse.d.ts +9 -0
  91. package/dist/core/source-text-edit.d.ts +33 -0
  92. package/dist/core/verbose-diagnostics.d.ts +6 -0
  93. package/dist/core/workspace/ancestor-directories.d.ts +12 -0
  94. package/dist/core/workspace/ancestor-directories.js +30 -0
  95. package/dist/core/workspace/markdown-walk.d.ts +7 -0
  96. package/dist/core/workspace/markdown-walk.js +2 -20
  97. package/dist/core/workspace/package-version.d.ts +9 -0
  98. package/dist/core/workspace/package-version.js +8 -12
  99. package/dist/core/workspace/resolver.d.ts +39 -0
  100. package/dist/core/workspace/resolver.js +58 -75
  101. package/dist/core/workspace/skip-directories.d.ts +6 -0
  102. package/dist/core/workspace/source-walk.d.ts +16 -0
  103. package/dist/core/workspace/source-walk.js +14 -20
  104. package/dist/core/workspace/typescript-walk.d.ts +7 -0
  105. package/dist/core/workspace/typescript-walk.js +2 -23
  106. package/dist/core/workspace/walk-files.d.ts +7 -0
  107. package/dist/core/workspace/walk-files.js +27 -0
  108. package/dist/core/workspace/well-known-files.d.ts +18 -0
  109. package/dist/core/workspace/well-known-files.js +18 -0
  110. package/dist/index.d.ts +6 -0
  111. package/dist/index.js +5 -0
  112. package/dist/mirror/cli-result.d.ts +13 -0
  113. package/dist/mirror/cli-schema.d.ts +8 -0
  114. package/dist/mirror/command.d.ts +7 -0
  115. package/dist/mirror/dist-filesystem-impl.d.ts +8 -0
  116. package/dist/mirror/domain/constants.d.ts +18 -0
  117. package/dist/mirror/domain/constants.js +0 -12
  118. package/dist/mirror/domain/dirent-guard.d.ts +10 -0
  119. package/dist/mirror/domain/dist-filesystem.d.ts +9 -0
  120. package/dist/mirror/domain/errors.d.ts +24 -0
  121. package/dist/mirror/domain/exports.d.ts +36 -0
  122. package/dist/mirror/domain/package-display-name.d.ts +8 -0
  123. package/dist/mirror/domain/path-normalizer.d.ts +6 -0
  124. package/dist/mirror/domain/types.d.ts +131 -0
  125. package/dist/mirror/output.d.ts +23 -0
  126. package/dist/mirror/package-path.d.ts +19 -0
  127. package/dist/mirror/prepare.d.ts +15 -0
  128. package/dist/mirror/prepare.js +2 -2
  129. package/dist/mirror/supplement-exports.d.ts +27 -0
  130. package/dist/mirror/supplement-exports.js +2 -2
  131. package/dist/mirror/sync-reporter.d.ts +60 -0
  132. package/dist/mirror/sync-reporter.js +4 -0
  133. package/dist/mirror/sync-types.d.ts +43 -0
  134. package/dist/mirror/sync-workspace-package.d.ts +9 -0
  135. package/dist/mirror/sync-workspace-package.js +3 -3
  136. package/dist/mirror/sync.d.ts +12 -0
  137. package/dist/mirror/sync.js +5 -3
  138. package/dist/mirror/write-exports.d.ts +15 -0
  139. package/dist/pack-slim/cli-result.d.ts +13 -0
  140. package/dist/pack-slim/cli-schema.d.ts +17 -0
  141. package/dist/pack-slim/command.d.ts +7 -0
  142. package/dist/pack-slim/command.js +5 -4
  143. package/dist/pack-slim/domain/transform.d.ts +69 -0
  144. package/dist/pack-slim/domain/transform.js +141 -15
  145. package/dist/pack-slim/domain/types.d.ts +46 -0
  146. package/dist/pack-slim/output.d.ts +15 -0
  147. package/dist/pack-slim/output.js +10 -1
  148. package/dist/pack-slim/sync.d.ts +23 -0
  149. package/dist/pack-slim/sync.js +14 -8
  150. package/dist/pack-slim/working-tree.d.ts +20 -0
  151. package/dist/tag/cli-result.d.ts +7 -0
  152. package/dist/tag/cli-schema.d.ts +8 -0
  153. package/dist/tag/command.d.ts +7 -0
  154. package/dist/tag/domain/types.d.ts +111 -0
  155. package/dist/tag/output.d.ts +17 -0
  156. package/dist/tag/prepare.d.ts +13 -0
  157. package/dist/tag/prepare.js +2 -2
  158. package/dist/tag/resolve-target-path.d.ts +10 -0
  159. package/dist/tag/since-writer.d.ts +32 -0
  160. package/dist/tag/sync.d.ts +42 -0
  161. package/dist/tag/target-candidates.d.ts +8 -0
  162. package/dist/tag/target-candidates.js +1 -1
  163. package/dist/tag/target-runner.d.ts +8 -0
  164. package/dist/tag/version-resolver.d.ts +7 -0
  165. package/package.json +16 -33
  166. package/dist/audit/domain/react-imports.js +0 -91
@@ -1,8 +1,23 @@
1
- /** Pure transforms that strip a package's source lane from a publish artifact. */
1
+ /** Pure transforms that slim a package's manifest and dist for publish. */
2
2
  /**
3
3
  * The emitted-file extensions that may carry a `sourceMappingURL` directive.
4
4
  */
5
5
  const MAP_ANNOTATED_EXTENSIONS = new Set([".js", ".mjs", ".cjs", ".d.ts", ".d.mts", ".d.cts"]);
6
+ /**
7
+ * The script names npm and pnpm run on their own, on a consumer's install or on this package's publish.
8
+ */
9
+ const LIFECYCLE_SCRIPT_STEMS = new Set([
10
+ "install",
11
+ "prepare",
12
+ "prepublish",
13
+ "prepublishOnly",
14
+ "pack",
15
+ "publish",
16
+ ]);
17
+ /**
18
+ * The characters that make a `files` entry a glob rather than a path.
19
+ */
20
+ const GLOB_CHARACTERS = /[*?[\]{}]/;
6
21
  /**
7
22
  * Whether a dist entry is a source-map sidecar (`*.map`).
8
23
  *
@@ -25,11 +40,26 @@ export function isMapAnnotatedFile(fileName) {
25
40
  return false;
26
41
  }
27
42
  /**
28
- * Produces a publish manifest with `src` dropped from `files` and every `source` export/import condition removed.
43
+ * Whether a script name is an install or publish lifecycle hook, with or without its `pre`/`post` prefix.
44
+ *
45
+ * @remarks Publish hooks stay because `pnpm publish` runs them right after pack-slim; install hooks stay because a
46
+ * consumer's package manager runs them.
47
+ *
48
+ * @since 0.9.0
49
+ */
50
+ export function isLifecycleScript(name) {
51
+ if (LIFECYCLE_SCRIPT_STEMS.has(name)) {
52
+ return true;
53
+ }
54
+ const stem = name.replace(/^(?:pre|post)/, "");
55
+ return stem !== name && LIFECYCLE_SCRIPT_STEMS.has(stem);
56
+ }
57
+ /**
58
+ * Produces a publish manifest carrying only what a consumer's `tsc` and Node read.
29
59
  *
30
- * @remarks Operates on a structural clone, so the caller's manifest is left intact. A consumer never enables the
31
- * `source` condition and resolves `#/` through `types`/`default` to `dist`, so dropping the source lane and the shipped
32
- * sources it points at leaves the published surface whole.
60
+ * @remarks Operates on a structural clone, so the caller's manifest is left intact. A consumer never enables `source`
61
+ * and resolves `#/` through `types`/`default` to `dist`, so dropping the source lane, the `imports` left pointing
62
+ * outside `files`, the scripts that are not lifecycle hooks, and `devDependencies` leaves the published surface whole.
33
63
  *
34
64
  * @since 0.8.1
35
65
  */
@@ -38,10 +68,21 @@ export function slimPublishManifest(manifest) {
38
68
  const filesSrcRemoved = removeSrcFromFiles(draft);
39
69
  const exportsSourceRemoved = deleteSourceConditions(draft.exports);
40
70
  const importsSourceRemoved = deleteSourceConditions(draft.imports);
41
- const changed = filesSrcRemoved || exportsSourceRemoved > 0 || importsSourceRemoved > 0;
71
+ const importsUnshippedRemoved = deleteUnshippedImports(draft);
72
+ const scriptsRemoved = deleteDevOnlyScripts(draft);
73
+ const devDependenciesRemoved = deleteDevDependencies(draft);
74
+ const changed = JSON.stringify(draft) !== JSON.stringify(manifest);
42
75
  return {
43
76
  manifest: draft,
44
- report: { filesSrcRemoved, exportsSourceRemoved, importsSourceRemoved, changed },
77
+ report: {
78
+ filesSrcRemoved,
79
+ exportsSourceRemoved,
80
+ importsSourceRemoved,
81
+ importsUnshippedRemoved,
82
+ scriptsRemoved,
83
+ devDependenciesRemoved,
84
+ changed,
85
+ },
45
86
  };
46
87
  }
47
88
  /**
@@ -69,8 +110,8 @@ function removeSrcFromFiles(manifest) {
69
110
  manifest.files = next;
70
111
  return true;
71
112
  }
72
- // Walks a conditions tree deleting every `source` key. A subpath key always starts with ".", so only real
73
- // condition objects match, and a source-only entry never occurs here, so no node is left empty.
113
+ // Walks a conditions tree deleting every `source` key. A subpath key always starts with ".", so only real condition
114
+ // objects match; an `imports` entry this leaves empty is what the unshipped pass removes.
74
115
  function deleteSourceConditions(node) {
75
116
  if (Array.isArray(node)) {
76
117
  let removed = 0;
@@ -79,17 +120,102 @@ function deleteSourceConditions(node) {
79
120
  }
80
121
  return removed;
81
122
  }
82
- if (node === null || typeof node !== "object") {
123
+ if (!isRecord(node)) {
83
124
  return 0;
84
125
  }
85
- const record = node;
86
126
  let removed = 0;
87
- if ("source" in record) {
88
- delete record.source;
127
+ if ("source" in node) {
128
+ delete node.source;
89
129
  removed += 1;
90
130
  }
91
- for (const key of Object.keys(record)) {
92
- removed += deleteSourceConditions(record[key]);
131
+ for (const key of Object.keys(node)) {
132
+ removed += deleteSourceConditions(node[key]);
93
133
  }
94
134
  return removed;
135
+ }
136
+ // Keeps an `imports` entry only while one of its targets lands inside a path `files` ships. `files` is read after the
137
+ // `src` drop, so a lane still pointing at `./src/*` counts as unshipped; with no `files` at all npm ships everything.
138
+ function deleteUnshippedImports(manifest) {
139
+ const imports = manifest.imports;
140
+ const files = manifest.files;
141
+ if (!isRecord(imports) || !Array.isArray(files)) {
142
+ return 0;
143
+ }
144
+ const shippedEntries = files.filter((entry) => typeof entry === "string");
145
+ let removed = 0;
146
+ for (const specifier of Object.keys(imports)) {
147
+ const targets = collectTargets(imports[specifier]);
148
+ if (targets.some((target) => isShippedTarget(target, shippedEntries))) {
149
+ continue;
150
+ }
151
+ delete imports[specifier];
152
+ removed += 1;
153
+ }
154
+ if (Object.keys(imports).length === 0) {
155
+ delete manifest.imports;
156
+ }
157
+ return removed;
158
+ }
159
+ function collectTargets(node, into = []) {
160
+ if (typeof node === "string") {
161
+ into.push(node);
162
+ }
163
+ else if (Array.isArray(node)) {
164
+ for (const item of node) {
165
+ collectTargets(item, into);
166
+ }
167
+ }
168
+ else if (isRecord(node)) {
169
+ for (const value of Object.values(node)) {
170
+ collectTargets(value, into);
171
+ }
172
+ }
173
+ return into;
174
+ }
175
+ // A glob entry is left to npm, so any target counts as shipped under it; a negated entry ships nothing.
176
+ function isShippedTarget(target, shippedEntries) {
177
+ const relativeTarget = stripDotSlash(target);
178
+ return shippedEntries.some((entry) => {
179
+ if (entry.startsWith("!")) {
180
+ return false;
181
+ }
182
+ if (GLOB_CHARACTERS.test(entry)) {
183
+ return true;
184
+ }
185
+ const shipped = stripDotSlash(entry).replace(/\/+$/, "");
186
+ return relativeTarget === shipped || relativeTarget.startsWith(`${shipped}/`);
187
+ });
188
+ }
189
+ function stripDotSlash(filePath) {
190
+ return filePath.startsWith("./") ? filePath.slice(2) : filePath;
191
+ }
192
+ // Drops every script that is not a lifecycle hook, and the field itself once nothing is left in it.
193
+ function deleteDevOnlyScripts(manifest) {
194
+ const scripts = manifest.scripts;
195
+ if (!isRecord(scripts)) {
196
+ return 0;
197
+ }
198
+ let removed = 0;
199
+ for (const name of Object.keys(scripts)) {
200
+ if (isLifecycleScript(name)) {
201
+ continue;
202
+ }
203
+ delete scripts[name];
204
+ removed += 1;
205
+ }
206
+ if (Object.keys(scripts).length === 0) {
207
+ delete manifest.scripts;
208
+ }
209
+ return removed;
210
+ }
211
+ function deleteDevDependencies(manifest) {
212
+ const devDependencies = manifest.devDependencies;
213
+ if (!isRecord(devDependencies)) {
214
+ return 0;
215
+ }
216
+ delete manifest.devDependencies;
217
+ return Object.keys(devDependencies).length;
218
+ }
219
+ function isRecord(value) {
220
+ return value !== null && typeof value === "object" && !Array.isArray(value);
95
221
  }
@@ -0,0 +1,46 @@
1
+ /** Stats and progress types for a pack-slim run. */
2
+ /**
3
+ * The outcome of slimming one workspace package.
4
+ *
5
+ * @since 0.8.1
6
+ */
7
+ export interface PackSlimPackageStats {
8
+ name: string;
9
+ path: string;
10
+ skipped: boolean;
11
+ skipReason: string;
12
+ error: string | null;
13
+ filesSrcRemoved: boolean;
14
+ exportsSourceRemoved: number;
15
+ importsSourceRemoved: number;
16
+ importsUnshippedRemoved: number;
17
+ scriptsRemoved: number;
18
+ devDependenciesRemoved: number;
19
+ mapFilesDeleted: number;
20
+ sourceCommentsStripped: number;
21
+ changed: boolean;
22
+ }
23
+ /**
24
+ * The aggregate stats of a pack-slim run across every targeted package.
25
+ *
26
+ * @since 0.8.1
27
+ */
28
+ export interface PackSlimRunStats {
29
+ packagesFound: number;
30
+ packagesProcessed: number;
31
+ packagesSkipped: number;
32
+ packagesErrored: number;
33
+ packagesChanged: number;
34
+ totalMapFilesDeleted: number;
35
+ packageDetails: Array<PackSlimPackageStats>;
36
+ }
37
+ /**
38
+ * The progress events a pack-slim run emits as it works through the packages.
39
+ *
40
+ * @since 0.8.1
41
+ */
42
+ export interface PackSlimProgressListener {
43
+ onBanner?(): void;
44
+ onPackageComplete?(stats: PackSlimPackageStats, ordinal: number, total: number): void;
45
+ onComplete?(stats: PackSlimRunStats, elapsedSeconds: number): void;
46
+ }
@@ -0,0 +1,15 @@
1
+ import type { PackSlimPackageStats, PackSlimProgressListener, PackSlimRunStats } from "#/pack-slim/domain/types";
2
+ /**
3
+ * A progress listener that renders pack-slim run events as human-readable CLI lines.
4
+ *
5
+ * @since 0.8.1
6
+ */
7
+ export declare class PackSlimProgressPresenter implements PackSlimProgressListener {
8
+ private dryRun;
9
+ configure(options: {
10
+ readonly dryRun: boolean;
11
+ }): void;
12
+ onBanner(): void;
13
+ onPackageComplete(stats: PackSlimPackageStats, ordinal: number, total: number): void;
14
+ onComplete(stats: PackSlimRunStats, elapsedSeconds: number): void;
15
+ }
@@ -10,7 +10,7 @@ export class PackSlimProgressPresenter {
10
10
  this.dryRun = options.dryRun;
11
11
  }
12
12
  onBanner() {
13
- logger.out(this.dryRun ? "pack-slim (dry run) — no files will change" : "pack-slim — stripping source lane");
13
+ logger.out(this.dryRun ? "pack-slim (dry run) — no files will change" : "pack-slim — slimming publish artifacts");
14
14
  }
15
15
  onPackageComplete(stats, ordinal, total) {
16
16
  const position = `[${ordinal}/${total}]`;
@@ -37,6 +37,15 @@ export class PackSlimProgressPresenter {
37
37
  if (stats.importsSourceRemoved > 0) {
38
38
  parts.push(`imports:source×${stats.importsSourceRemoved}`);
39
39
  }
40
+ if (stats.importsUnshippedRemoved > 0) {
41
+ parts.push(`imports:unshipped×${stats.importsUnshippedRemoved}`);
42
+ }
43
+ if (stats.scriptsRemoved > 0) {
44
+ parts.push(`scripts×${stats.scriptsRemoved}`);
45
+ }
46
+ if (stats.devDependenciesRemoved > 0) {
47
+ parts.push(`devDependencies×${stats.devDependenciesRemoved}`);
48
+ }
40
49
  if (stats.mapFilesDeleted > 0) {
41
50
  parts.push(`maps×${stats.mapFilesDeleted}`);
42
51
  }
@@ -0,0 +1,23 @@
1
+ import { AppError } from "#/core/errors";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { Result } from "#/core/result";
4
+ import type { PackSlimRunRequest } from "#/pack-slim/cli-schema";
5
+ import type { PackSlimProgressListener, PackSlimRunStats } from "#/pack-slim/domain/types";
6
+ /**
7
+ * A pack-slim run request paired with an optional progress listener.
8
+ *
9
+ * @since 0.8.1
10
+ */
11
+ export type PackSlimRunInput = PackSlimRunRequest & {
12
+ readonly listener?: PackSlimProgressListener | undefined;
13
+ };
14
+ /**
15
+ * Slims every published package's manifest and build output for publish and returns the aggregate stats.
16
+ *
17
+ * @remarks Meant to run on an ephemeral CI checkout right before `changeset publish`: it rewrites `package.json` down to
18
+ * what a consumer reads, drops `dist` source maps, and clears their now-dangling `sourceMappingURL` directives, so the
19
+ * tarball ships only `dist` runtime and types. Private packages are skipped because `changeset publish` never publishes them.
20
+ *
21
+ * @since 0.8.1
22
+ */
23
+ export declare function runPackSlim(fs: FilesystemPort, input: PackSlimRunInput): Promise<Result<PackSlimRunStats, AppError>>;
@@ -2,14 +2,14 @@ import path from "node:path";
2
2
  import { AppError, messageFrom } from "#/core/errors";
3
3
  import { err, ok } from "#/core/result";
4
4
  import { listWorkspacePackageDirectories } from "#/core/workspace/resolver";
5
- import { DIST_DIR, PACKAGE_JSON } from "#/mirror/domain/constants";
5
+ import { distDirName, packageJsonFileName } from "#/core/workspace/well-known-files";
6
6
  import { isMapAnnotatedFile, isSourceMapFile, slimPublishManifest, stripSourceMappingComment, } from "#/pack-slim/domain/transform";
7
7
  /**
8
- * Strips the source lane from every published package's build output and returns the aggregate stats.
8
+ * Slims every published package's manifest and build output for publish and returns the aggregate stats.
9
9
  *
10
- * @remarks Meant to run on an ephemeral CI checkout right before `changeset publish`: it rewrites `package.json`, drops
11
- * `dist` source maps, and clears their now-dangling `sourceMappingURL` directives, so the tarball ships only `dist`
12
- * runtime and types. Private packages are skipped because `changeset publish` never publishes them.
10
+ * @remarks Meant to run on an ephemeral CI checkout right before `changeset publish`: it rewrites `package.json` down to
11
+ * what a consumer reads, drops `dist` source maps, and clears their now-dangling `sourceMappingURL` directives, so the
12
+ * tarball ships only `dist` runtime and types. Private packages are skipped because `changeset publish` never publishes them.
13
13
  *
14
14
  * @since 0.8.1
15
15
  */
@@ -47,7 +47,7 @@ export async function runPackSlim(fs, input) {
47
47
  async function resolveTargets(fs, rootDir, packageFilter) {
48
48
  if (packageFilter !== undefined) {
49
49
  const packageDir = path.resolve(rootDir, packageFilter);
50
- if (!fs.existsSync(path.join(packageDir, PACKAGE_JSON))) {
50
+ if (!fs.existsSync(path.join(packageDir, packageJsonFileName))) {
51
51
  throw new Error(`No package.json under "${packageFilter}"`);
52
52
  }
53
53
  return [packageDir];
@@ -56,7 +56,7 @@ async function resolveTargets(fs, rootDir, packageFilter) {
56
56
  return [...layout.packageDirectoryPathsAbsolute].sort((left, right) => left.localeCompare(right));
57
57
  }
58
58
  async function slimWorkspacePackage(fs, packageDir, write) {
59
- const packageJsonPath = path.join(packageDir, PACKAGE_JSON);
59
+ const packageJsonPath = path.join(packageDir, packageJsonFileName);
60
60
  const pkgStats = {
61
61
  name: path.basename(packageDir),
62
62
  path: packageDir,
@@ -66,6 +66,9 @@ async function slimWorkspacePackage(fs, packageDir, write) {
66
66
  filesSrcRemoved: false,
67
67
  exportsSourceRemoved: 0,
68
68
  importsSourceRemoved: 0,
69
+ importsUnshippedRemoved: 0,
70
+ scriptsRemoved: 0,
71
+ devDependenciesRemoved: 0,
69
72
  mapFilesDeleted: 0,
70
73
  sourceCommentsStripped: 0,
71
74
  changed: false,
@@ -94,10 +97,13 @@ async function slimWorkspacePackage(fs, packageDir, write) {
94
97
  pkgStats.filesSrcRemoved = report.filesSrcRemoved;
95
98
  pkgStats.exportsSourceRemoved = report.exportsSourceRemoved;
96
99
  pkgStats.importsSourceRemoved = report.importsSourceRemoved;
100
+ pkgStats.importsUnshippedRemoved = report.importsUnshippedRemoved;
101
+ pkgStats.scriptsRemoved = report.scriptsRemoved;
102
+ pkgStats.devDependenciesRemoved = report.devDependenciesRemoved;
97
103
  if (report.changed && write) {
98
104
  await fs.writeFile(packageJsonPath, `${JSON.stringify(slimmed, null, 2)}\n`, "utf8");
99
105
  }
100
- await pruneDist(fs, path.join(packageDir, DIST_DIR), write, pkgStats);
106
+ await pruneDist(fs, path.join(packageDir, distDirName), write, pkgStats);
101
107
  pkgStats.changed = report.changed || pkgStats.mapFilesDeleted > 0 || pkgStats.sourceCommentsStripped > 0;
102
108
  }
103
109
  catch (caughtError) {
@@ -0,0 +1,20 @@
1
+ import { AppError } from "#/core/errors";
2
+ import type { Result } from "#/core/result";
3
+ /**
4
+ * Whether git's tracked-only porcelain output reports any uncommitted change.
5
+ *
6
+ * @remarks The output is read with `--untracked-files=no`, so untracked and gitignored paths (like the freshly built
7
+ * `dist`) never appear — any non-blank line is a staged or unstaged change to a tracked file.
8
+ *
9
+ * @since 0.8.1
10
+ */
11
+ export declare function hasUncommittedTrackedChanges(porcelainOutput: string): boolean;
12
+ /**
13
+ * Refuses when the git working tree carries uncommitted tracked changes, so a destructive slim never lands on real work.
14
+ *
15
+ * @remarks pack-slim rewrites tracked `package.json` files and deletes build output; its result must never be committed.
16
+ * A caller passing `--force` skips this, and `--dry-run` never reaches it because it writes nothing.
17
+ *
18
+ * @since 0.8.1
19
+ */
20
+ export declare function ensureWorkingTreeClean(rootDir: string): Result<void, AppError>;
@@ -0,0 +1,7 @@
1
+ import type { TagSyncResult } from "#/tag/domain/types";
2
+ /**
3
+ * Maps a tag run's result to the process exit code.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export declare function exitCodeForTagSyncResult(result: TagSyncResult): number;
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ import type { TagSyncRunRequest } from "#/tag/sync";
3
+ /**
4
+ * Zod schema validating a `TagSyncRunRequest`.
5
+ *
6
+ * @since 0.3.16-canary.0
7
+ */
8
+ export declare const tagSyncRunRequestSchema: z.ZodType<TagSyncRunRequest>;
@@ -0,0 +1,7 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Creates the `tag` subcommand, which stamps `@since` tags on exported declarations.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export declare function createTagCommand(): Command;
@@ -0,0 +1,111 @@
1
+ import type { CodefastConfig } from "#/core/config/schema";
2
+ /**
3
+ * Per-file outcome of a tag run.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export type TagFileResult = {
8
+ filePath: string;
9
+ taggedDeclarations: number;
10
+ changed: boolean;
11
+ };
12
+ /**
13
+ * Outcome of tagging one target: the version stamped and the per-file tallies.
14
+ *
15
+ * @since 0.3.16-canary.0
16
+ */
17
+ export type TagRunResult = {
18
+ version: string;
19
+ filesScanned: number;
20
+ filesChanged: number;
21
+ taggedDeclarations: number;
22
+ fileResults: Array<TagFileResult>;
23
+ };
24
+ /**
25
+ * Options for one target's tag run.
26
+ *
27
+ * @since 0.3.16-canary.0
28
+ */
29
+ export type TagRunOptions = {
30
+ write: boolean;
31
+ };
32
+ type TagTargetCandidateSource = "explicit-target" | "workspace-package" | "repo-src-fallback";
33
+ /**
34
+ * How a resolved tag target was chosen.
35
+ *
36
+ * @since 0.3.16-canary.0
37
+ */
38
+ type TagTargetSource = "explicit-target" | "workspace-package-selected-src" | "workspace-package-selected-root" | "repo-src-fallback";
39
+ /**
40
+ * A candidate path a tag run may resolve into a target.
41
+ *
42
+ * @since 0.3.16-canary.0
43
+ */
44
+ export type TagTargetCandidate = {
45
+ candidatePath: string;
46
+ rootRelativeCandidatePath: string;
47
+ source: TagTargetCandidateSource;
48
+ packageDir: string | null;
49
+ packageName: string | null;
50
+ };
51
+ /**
52
+ * A directory or file a tag run will stamp, with its owning package when known.
53
+ *
54
+ * @since 0.3.16-canary.0
55
+ */
56
+ export type TagResolvedTarget = {
57
+ targetPath: string;
58
+ rootRelativeTargetPath: string;
59
+ source: TagTargetSource;
60
+ packageDir: string | null;
61
+ packageName: string | null;
62
+ };
63
+ /**
64
+ * One target's execution outcome, carrying either its run result or its error.
65
+ *
66
+ * @since 0.3.16-canary.0
67
+ */
68
+ export type TagTargetExecutionResult = {
69
+ target: TagResolvedTarget;
70
+ targetExists: boolean;
71
+ runError: string | null;
72
+ result: TagRunResult | null;
73
+ };
74
+ /**
75
+ * Callbacks a tag run invokes as each target starts and completes.
76
+ *
77
+ * @since 0.3.16-canary.0
78
+ */
79
+ export interface TagProgressListener {
80
+ onTargetStarted: (target: TagResolvedTarget) => void;
81
+ onTargetCompleted: (target: TagResolvedTarget, result: TagTargetExecutionResult) => void;
82
+ }
83
+ /**
84
+ * Aggregate outcome of a tag run across every selected target.
85
+ *
86
+ * @since 0.3.16-canary.0
87
+ */
88
+ export type TagSyncResult = {
89
+ mode: "applied" | "dry-run";
90
+ selectedTargets: Array<TagResolvedTarget>;
91
+ skippedPackages: Array<string>;
92
+ targetResults: Array<TagTargetExecutionResult>;
93
+ filesScanned: number;
94
+ filesChanged: number;
95
+ taggedDeclarations: number;
96
+ versionSummary: string;
97
+ distinctVersions: Array<string>;
98
+ modifiedFiles: Array<string>;
99
+ hookError: string | null;
100
+ };
101
+ /**
102
+ * Everything the `tag` action needs resolved before a run: root, config, and target path.
103
+ *
104
+ * @since 0.3.16-canary.0
105
+ */
106
+ export interface TagCommandPrelude {
107
+ readonly rootDir: string;
108
+ readonly config: CodefastConfig;
109
+ readonly resolvedTargetPath: string | undefined;
110
+ }
111
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { TagProgressListener, TagResolvedTarget, TagSyncResult, TagTargetExecutionResult } from "#/tag/domain/types";
2
+ /**
3
+ * A progress listener that prints a line as each tag target starts and completes.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export declare class TagSyncProgressPresenter implements TagProgressListener {
8
+ onTargetStarted(target: TagResolvedTarget): void;
9
+ onTargetCompleted(target: TagResolvedTarget, result: TagTargetExecutionResult): void;
10
+ private static formatProgress;
11
+ }
12
+ /**
13
+ * Prints a tag run's target table, warnings, and summary, and returns the exit code.
14
+ *
15
+ * @since 0.3.16-canary.0
16
+ */
17
+ export declare function presentTagSyncResult(result: TagSyncResult, rootDir: string): number;
@@ -0,0 +1,13 @@
1
+ import type { AppError } from "#/core/errors";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { Result } from "#/core/result";
4
+ import type { TagCommandPrelude } from "#/tag/domain/types";
5
+ /**
6
+ * Resolves the repo root, config, and optional target path into the prelude a tag run starts from.
7
+ *
8
+ * @since 0.3.16-canary.0
9
+ */
10
+ export declare function prepareTagSync(fs: FilesystemPort, args: {
11
+ readonly currentWorkingDirectory: string;
12
+ readonly rawTarget: string | undefined;
13
+ }): Promise<Result<TagCommandPrelude, AppError>>;
@@ -1,6 +1,6 @@
1
1
  import { loadCodefastConfig } from "#/core/config";
2
2
  import { ok } from "#/core/result";
3
- import { findRepoRoot } from "#/core/workspace/resolver";
3
+ import { resolveProjectRoot } from "#/core/workspace/resolver";
4
4
  import { resolveProvidedTagTargetPath } from "#/tag/resolve-target-path";
5
5
  /**
6
6
  * Resolves the repo root, config, and optional target path into the prelude a tag run starts from.
@@ -10,7 +10,7 @@ import { resolveProvidedTagTargetPath } from "#/tag/resolve-target-path";
10
10
  export async function prepareTagSync(fs, args) {
11
11
  let rootDir;
12
12
  try {
13
- rootDir = findRepoRoot(args.currentWorkingDirectory, fs);
13
+ rootDir = resolveProjectRoot(args.currentWorkingDirectory, fs).rootDir;
14
14
  }
15
15
  catch {
16
16
  rootDir = args.currentWorkingDirectory;
@@ -0,0 +1,10 @@
1
+ import type { FilesystemPort } from "#/core/filesystem/port";
2
+ /**
3
+ * Canonicalizes the user-provided target path, or returns `undefined` when none was given.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export declare function resolveProvidedTagTargetPath(fs: FilesystemPort, args: {
8
+ readonly currentWorkingDirectory: string;
9
+ readonly rawTarget: string | undefined;
10
+ }): string | undefined;
@@ -0,0 +1,32 @@
1
+ import type { FilesystemPort } from "#/core/filesystem/port";
2
+ import type { TagFileResult } from "#/tag/domain/types";
3
+ /**
4
+ * The writer that adds missing `@since` tags to a file's exported declarations.
5
+ *
6
+ * @since 0.3.16-canary.0
7
+ */
8
+ export declare class TagSinceWriter {
9
+ private readonly fs;
10
+ private readonly sinceDocumentationTag;
11
+ constructor(fs: FilesystemPort);
12
+ applySinceTagsToFile(filePath: string, version: string, write: boolean): TagFileResult;
13
+ /**
14
+ * The taggable declaration a top-level statement introduces, resolving the
15
+ * `export … <decl>` wrapper to the wrapper node — its `start` sits at `export`,
16
+ * matching `ts.getStart` on a modifier-bearing declaration.
17
+ */
18
+ private taggableDeclarationOf;
19
+ private declarationNames;
20
+ private addDeclarationName;
21
+ private collectLocalNamedDeclarations;
22
+ private collectExportedDeclarations;
23
+ /**
24
+ * The JSDoc block documenting `anchor`: the nearest preceding `/** … *\/` whose
25
+ * gap to the declaration is whitespace only, mirroring TS comment attachment.
26
+ */
27
+ private associatedJsDoc;
28
+ private jsDocHasSinceTag;
29
+ private makeJSDocSinceLine;
30
+ private makeSinceOnlyJSDocBlock;
31
+ private makeDeclarationSinceLine;
32
+ }
@@ -0,0 +1,42 @@
1
+ import { AppError } from "#/core/errors";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { Result } from "#/core/result";
4
+ import type { TagProgressListener, TagSyncResult, TagTargetCandidate } from "#/tag/domain/types";
5
+ /**
6
+ * The inputs a tag run is invoked with.
7
+ *
8
+ * @since 0.3.16-canary.0
9
+ */
10
+ export type TagSyncRunRequest = {
11
+ rootDir: string;
12
+ write: boolean;
13
+ json?: boolean | undefined;
14
+ targetPath?: string | undefined;
15
+ skipPackages?: Array<string> | undefined;
16
+ config?: unknown;
17
+ };
18
+ /**
19
+ * A run request paired with an optional progress listener.
20
+ *
21
+ * @since 0.3.16-canary.0
22
+ */
23
+ export type TagSyncExecutionInput = TagSyncRunRequest & {
24
+ readonly listener?: TagProgressListener | undefined;
25
+ };
26
+ /**
27
+ * Runs the tag sync across the selected targets and returns the aggregate result.
28
+ *
29
+ * @since 0.3.16-canary.0
30
+ */
31
+ export declare function runTagSync(fs: FilesystemPort, input: TagSyncExecutionInput): Promise<Result<TagSyncResult, AppError>>;
32
+ /**
33
+ * Partition tag target candidates into those to tag and those to skip, matching
34
+ * each candidate's package name against `skipPackages` as glob patterns.
35
+ * Candidates without a package name (e.g. an explicit-target path) are never skipped.
36
+ *
37
+ * @since 0.5.0-canary.0
38
+ */
39
+ export declare function filterSkippedCandidates(targetCandidates: Array<TagTargetCandidate>, skipPackages: ReadonlyArray<string> | undefined): {
40
+ includedCandidates: Array<TagTargetCandidate>;
41
+ skippedPackages: Array<string>;
42
+ };