@codefast/cli 0.9.0 → 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 (159) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +329 -149
  3. package/dist/arrange/analyze.d.ts +10 -0
  4. package/dist/arrange/cli-schema.d.ts +50 -0
  5. package/dist/arrange/command.d.ts +7 -0
  6. package/dist/arrange/domain/analyze-service.d.ts +18 -0
  7. package/dist/arrange/domain/ast/ast-node.d.ts +394 -0
  8. package/dist/arrange/domain/ast/collectors-cn.d.ts +26 -0
  9. package/dist/arrange/domain/ast/collectors-jsx.d.ts +8 -0
  10. package/dist/arrange/domain/ast/collectors-tv.d.ts +34 -0
  11. package/dist/arrange/domain/ast/helpers.d.ts +36 -0
  12. package/dist/arrange/domain/ast/helpers.js +1 -0
  13. package/dist/arrange/domain/ast/simplify-targets.d.ts +22 -0
  14. package/dist/arrange/domain/ast/targets.d.ts +20 -0
  15. package/dist/arrange/domain/constants.d.ts +111 -0
  16. package/dist/arrange/domain/grouping-service.d.ts +100 -0
  17. package/dist/arrange/domain/grouping.d.ts +21 -0
  18. package/dist/arrange/domain/imports.d.ts +14 -0
  19. package/dist/arrange/domain/source-text-formatters.d.ts +33 -0
  20. package/dist/arrange/domain/tailwind-token.d.ts +24 -0
  21. package/dist/arrange/domain/token-classifier.d.ts +47 -0
  22. package/dist/arrange/domain/types.d.ts +208 -0
  23. package/dist/arrange/output.d.ts +26 -0
  24. package/dist/arrange/process-file.d.ts +11 -0
  25. package/dist/arrange/resolve-target.d.ts +10 -0
  26. package/dist/arrange/resolve-target.js +3 -16
  27. package/dist/arrange/scan-target.d.ts +7 -0
  28. package/dist/arrange/simplify-process-file.d.ts +11 -0
  29. package/dist/arrange/simplify-sync.d.ts +13 -0
  30. package/dist/arrange/source-parse.d.ts +7 -0
  31. package/dist/arrange/suggest.d.ts +8 -0
  32. package/dist/arrange/sync.d.ts +11 -0
  33. package/dist/arrange/typescript-ast-translator.d.ts +31 -0
  34. package/dist/arrange/workspace.d.ts +13 -0
  35. package/dist/arrange/workspace.js +2 -2
  36. package/dist/audit/cli-schema.d.ts +93 -0
  37. package/dist/audit/cli-schema.js +3 -3
  38. package/dist/audit/command.d.ts +8 -0
  39. package/dist/audit/command.js +12 -12
  40. package/dist/audit/domain/audit-file.d.ts +7 -0
  41. package/dist/audit/domain/comment-content.d.ts +26 -0
  42. package/dist/audit/domain/comment-dividers.d.ts +62 -0
  43. package/dist/audit/domain/display-names.d.ts +11 -0
  44. package/dist/audit/domain/import-policy.d.ts +34 -0
  45. package/dist/audit/domain/import-policy.js +147 -0
  46. package/dist/audit/domain/link-references.d.ts +40 -0
  47. package/dist/audit/domain/mappings.d.ts +45 -0
  48. package/dist/audit/domain/markdown-links.d.ts +44 -0
  49. package/dist/audit/domain/since-versions.d.ts +26 -0
  50. package/dist/audit/domain/tokenize.d.ts +14 -0
  51. package/dist/audit/domain/tsdoc-syntax.d.ts +20 -0
  52. package/dist/audit/domain/types.d.ts +171 -0
  53. package/dist/audit/output.d.ts +91 -0
  54. package/dist/audit/output.js +11 -11
  55. package/dist/audit/prepare.d.ts +70 -0
  56. package/dist/audit/prepare.js +11 -11
  57. package/dist/audit/run-comments.d.ts +17 -0
  58. package/dist/audit/run-display-names.d.ts +14 -0
  59. package/dist/audit/run-imports.d.ts +14 -0
  60. package/dist/audit/{run-react.js → run-imports.js} +15 -5
  61. package/dist/audit/run-links.d.ts +14 -0
  62. package/dist/audit/run.d.ts +14 -0
  63. package/dist/bin.d.ts +2 -0
  64. package/dist/cli.d.ts +6 -0
  65. package/dist/core/cli/format-error.d.ts +7 -0
  66. package/dist/core/cli/global-options.d.ts +15 -0
  67. package/dist/core/cli/positional.d.ts +6 -0
  68. package/dist/core/cli/result-handle.d.ts +19 -0
  69. package/dist/core/config/define-config.d.ts +7 -0
  70. package/dist/core/config/define-config.js +8 -0
  71. package/dist/core/config/loader.d.ts +18 -0
  72. package/dist/core/config/loader.js +2 -7
  73. package/dist/core/config/schema.d.ts +99 -0
  74. package/dist/core/config/schema.js +7 -85
  75. package/dist/core/config/warnings.d.ts +6 -0
  76. package/dist/core/config.d.ts +12 -0
  77. package/dist/core/errors.d.ts +25 -0
  78. package/dist/core/exit-codes.d.ts +18 -0
  79. package/dist/core/filesystem/node.d.ts +7 -0
  80. package/dist/core/filesystem/node.js +1 -0
  81. package/dist/core/filesystem/port.d.ts +44 -0
  82. package/dist/core/glob.d.ts +19 -0
  83. package/dist/core/logger.d.ts +9 -0
  84. package/dist/core/result.d.ts +30 -0
  85. package/dist/core/schema-parse.d.ts +9 -0
  86. package/dist/core/source-text-edit.d.ts +33 -0
  87. package/dist/core/verbose-diagnostics.d.ts +6 -0
  88. package/dist/core/workspace/ancestor-directories.d.ts +12 -0
  89. package/dist/core/workspace/ancestor-directories.js +30 -0
  90. package/dist/core/workspace/markdown-walk.d.ts +7 -0
  91. package/dist/core/workspace/markdown-walk.js +2 -20
  92. package/dist/core/workspace/package-version.d.ts +9 -0
  93. package/dist/core/workspace/package-version.js +8 -12
  94. package/dist/core/workspace/resolver.d.ts +39 -0
  95. package/dist/core/workspace/resolver.js +58 -75
  96. package/dist/core/workspace/skip-directories.d.ts +6 -0
  97. package/dist/core/workspace/source-walk.d.ts +16 -0
  98. package/dist/core/workspace/source-walk.js +2 -19
  99. package/dist/core/workspace/typescript-walk.d.ts +7 -0
  100. package/dist/core/workspace/typescript-walk.js +2 -23
  101. package/dist/core/workspace/walk-files.d.ts +7 -0
  102. package/dist/core/workspace/walk-files.js +27 -0
  103. package/dist/core/workspace/well-known-files.d.ts +18 -0
  104. package/dist/core/workspace/well-known-files.js +18 -0
  105. package/dist/index.d.ts +6 -0
  106. package/dist/index.js +5 -0
  107. package/dist/mirror/cli-result.d.ts +13 -0
  108. package/dist/mirror/cli-schema.d.ts +8 -0
  109. package/dist/mirror/command.d.ts +7 -0
  110. package/dist/mirror/dist-filesystem-impl.d.ts +8 -0
  111. package/dist/mirror/domain/constants.d.ts +18 -0
  112. package/dist/mirror/domain/constants.js +0 -12
  113. package/dist/mirror/domain/dirent-guard.d.ts +10 -0
  114. package/dist/mirror/domain/dist-filesystem.d.ts +9 -0
  115. package/dist/mirror/domain/errors.d.ts +24 -0
  116. package/dist/mirror/domain/exports.d.ts +36 -0
  117. package/dist/mirror/domain/package-display-name.d.ts +8 -0
  118. package/dist/mirror/domain/path-normalizer.d.ts +6 -0
  119. package/dist/mirror/domain/types.d.ts +131 -0
  120. package/dist/mirror/output.d.ts +23 -0
  121. package/dist/mirror/package-path.d.ts +19 -0
  122. package/dist/mirror/prepare.d.ts +15 -0
  123. package/dist/mirror/prepare.js +2 -2
  124. package/dist/mirror/supplement-exports.d.ts +27 -0
  125. package/dist/mirror/supplement-exports.js +2 -2
  126. package/dist/mirror/sync-reporter.d.ts +60 -0
  127. package/dist/mirror/sync-reporter.js +4 -0
  128. package/dist/mirror/sync-types.d.ts +43 -0
  129. package/dist/mirror/sync-workspace-package.d.ts +9 -0
  130. package/dist/mirror/sync-workspace-package.js +3 -3
  131. package/dist/mirror/sync.d.ts +12 -0
  132. package/dist/mirror/sync.js +5 -3
  133. package/dist/mirror/write-exports.d.ts +15 -0
  134. package/dist/pack-slim/cli-result.d.ts +13 -0
  135. package/dist/pack-slim/cli-schema.d.ts +17 -0
  136. package/dist/pack-slim/command.d.ts +7 -0
  137. package/dist/pack-slim/command.js +2 -2
  138. package/dist/pack-slim/domain/transform.d.ts +69 -0
  139. package/dist/pack-slim/domain/types.d.ts +46 -0
  140. package/dist/pack-slim/output.d.ts +15 -0
  141. package/dist/pack-slim/sync.d.ts +23 -0
  142. package/dist/pack-slim/sync.js +4 -4
  143. package/dist/pack-slim/working-tree.d.ts +20 -0
  144. package/dist/tag/cli-result.d.ts +7 -0
  145. package/dist/tag/cli-schema.d.ts +8 -0
  146. package/dist/tag/command.d.ts +7 -0
  147. package/dist/tag/domain/types.d.ts +111 -0
  148. package/dist/tag/output.d.ts +17 -0
  149. package/dist/tag/prepare.d.ts +13 -0
  150. package/dist/tag/prepare.js +2 -2
  151. package/dist/tag/resolve-target-path.d.ts +10 -0
  152. package/dist/tag/since-writer.d.ts +32 -0
  153. package/dist/tag/sync.d.ts +42 -0
  154. package/dist/tag/target-candidates.d.ts +8 -0
  155. package/dist/tag/target-candidates.js +1 -1
  156. package/dist/tag/target-runner.d.ts +8 -0
  157. package/dist/tag/version-resolver.d.ts +7 -0
  158. package/package.json +12 -1
  159. package/dist/audit/domain/react-imports.js +0 -91
@@ -0,0 +1,10 @@
1
+ import type { DirectoryEntry } from "#/core/filesystem/port";
2
+ /**
3
+ * Narrow `fs.promises.readdir` overload result to `Dirent[]` when `withFileTypes: true`.
4
+ * Accepts both historical checks (`isFile` / `isDirectory`) in one guard.
5
+ * Returning `true` for an empty array is intentional: callers treat empty lists
6
+ * the same regardless of the element type, so `[]` is safely accepted as `Dirent[]`.
7
+ *
8
+ * @since 0.3.16-canary.0
9
+ */
10
+ export declare function isDirentList(x: Array<string> | Array<DirectoryEntry>): x is Array<DirectoryEntry>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Filesystem surface used by mirror export generation (relative paths under `dist/`).
3
+ *
4
+ * @since 0.3.16-canary.0
5
+ */
6
+ export interface DistFilesystem {
7
+ listRelativeFilesRecursively(dirPath: string): Promise<Array<string>>;
8
+ isDirectoryCssOnly(distDir: string, dirPath: string): Promise<boolean>;
9
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The error codes a mirror run can fail with.
3
+ *
4
+ * @since 0.3.16-canary.0
5
+ */
6
+ export declare const MirrorErrorCode: {
7
+ readonly FATAL: "FATAL";
8
+ readonly PACKAGE_WRITE: "PACKAGE_WRITE";
9
+ };
10
+ /**
11
+ * The union of `MirrorErrorCode` values.
12
+ *
13
+ * @since 0.3.16-canary.0
14
+ */
15
+ export type MirrorErrorCode = (typeof MirrorErrorCode)[keyof typeof MirrorErrorCode];
16
+ /**
17
+ * An `Error` carrying a `MirrorErrorCode` for mirror-specific failures.
18
+ *
19
+ * @since 0.3.16-canary.0
20
+ */
21
+ export declare class MirrorError extends Error {
22
+ readonly code: MirrorErrorCode;
23
+ constructor(code: MirrorErrorCode, message: string, options?: ErrorOptions);
24
+ }
@@ -0,0 +1,36 @@
1
+ import type { DistFilesystem } from "#/mirror/domain/dist-filesystem";
2
+ import type { GenerateExportsResult } from "#/mirror/domain/types";
3
+ /**
4
+ * Creates a transform that strips a configured prefix from export paths, or `null` when none is set.
5
+ *
6
+ * @since 0.3.16-canary.0
7
+ */
8
+ export declare function createPathTransform(strip: string | undefined): ((pathString: string) => string) | null;
9
+ /**
10
+ * Options shaping the conditions and specifiers of a generated exports map.
11
+ *
12
+ * @since 0.3.16-canary.3
13
+ */
14
+ export interface GenerateExportsOptions {
15
+ /** Include a `source` condition pointing to the original source file. Pass `true` to
16
+ * auto-derive via `resolveSourcePath`, or a string to set an explicit path for the
17
+ * root export (`.`) only. */
18
+ source?: boolean | string;
19
+ /** Include the `types` condition when a `.d.ts` file exists (default `true`). */
20
+ types?: boolean;
21
+ /** Include the `import` condition (default `true`). */
22
+ import?: boolean;
23
+ /** Specifiers to leave out of the generated map — see `mirror.<pkg>.exclude`. Matched against
24
+ * the post-`strip` specifier; a trailing `/*` excludes the whole subtree. */
25
+ exclude?: ReadonlyArray<string>;
26
+ /** Override the default source path derivation. Receives the module path relative to
27
+ * `dist/` (e.g. `"components/button"`) and returns the full source specifier
28
+ * (e.g. `"./src/components/button.tsx"`). When omitted, falls back to `./src/<path>.ts`. */
29
+ resolveSourcePath?: (modulePath: string) => string;
30
+ }
31
+ /**
32
+ * Generates a package's `package.json#exports` map from its `dist/` contents.
33
+ *
34
+ * @since 0.5.0-canary.8
35
+ */
36
+ export declare function generateExports(fileSystemService: DistFilesystem, distDir: string, pathTransform: ((pathString: string) => string) | null, cssConfig: Record<string, unknown> | boolean | undefined, extraExports: Record<string, string>, options?: GenerateExportsOptions): Promise<GenerateExportsResult>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Domain rule: prefer `package.json#name` when it is present, otherwise use folder basename.
3
+ *
4
+ * @since 0.3.16-canary.0
5
+ */
6
+ export declare function resolvePackageDisplayName(packageJson: {
7
+ name?: unknown;
8
+ }, folderBasename: string): string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a path's separators to forward slashes.
3
+ *
4
+ * @since 0.3.16-canary.0
5
+ */
6
+ export declare function normalizePath(pathString: string): string;
@@ -0,0 +1,131 @@
1
+ import type { GlobalCliOptions } from "#/core/cli/global-options";
2
+ import type { CodefastConfig } from "#/core/config/schema";
3
+ /**
4
+ * One conditional exports entry, keyed by resolution condition.
5
+ *
6
+ * @since 0.3.16-canary.0
7
+ */
8
+ export interface ExportEntry {
9
+ source?: string;
10
+ types?: string;
11
+ import?: string;
12
+ require?: string;
13
+ }
14
+ /**
15
+ * Final `package.json#exports` map (conditional exports + string shims + `./package.json`).
16
+ *
17
+ * @since 0.3.16-canary.0
18
+ */
19
+ export type ExportMapData = Record<string, ExportEntry | string>;
20
+ /**
21
+ * The pre-transform `dist/` path for each generated export specifier.
22
+ *
23
+ * @since 0.3.16-canary.0
24
+ */
25
+ export type ExportOriginalPathBySpecifier = Record<string, string>;
26
+ interface DistModuleFiles {
27
+ js: string | null;
28
+ mjs: string | null;
29
+ cjs: string | null;
30
+ dts: string | null;
31
+ }
32
+ /**
33
+ * A `dist/` module path together with the build files found for it.
34
+ *
35
+ * @since 0.3.16-canary.0
36
+ */
37
+ export interface DistModule {
38
+ path: string;
39
+ files: DistModuleFiles;
40
+ }
41
+ /**
42
+ * Parsed `package.json` — only fields mirror reads/writes are typed strictly.
43
+ *
44
+ * @since 0.3.16-canary.0
45
+ */
46
+ export type PackageJsonShape = {
47
+ name?: unknown;
48
+ exports?: unknown;
49
+ [key: string]: unknown;
50
+ };
51
+ /**
52
+ * A generated exports map with its specifier origins and asset counts.
53
+ *
54
+ * @since 0.3.16-canary.0
55
+ */
56
+ export interface GenerateExportsResult {
57
+ exports: ExportMapData;
58
+ originalPathBySpecifier: ExportOriginalPathBySpecifier;
59
+ jsCount: number;
60
+ cssCount: number;
61
+ }
62
+ /**
63
+ * Per-package outcome of a mirror run, as reported in progress and JSON output.
64
+ *
65
+ * @since 0.3.16-canary.0
66
+ */
67
+ export interface PackageStats {
68
+ name: string;
69
+ path: string;
70
+ jsModules: number;
71
+ cssExports: number;
72
+ extraExports: number;
73
+ totalExports: number;
74
+ hasTransform: boolean;
75
+ cssConfigStatus: "disabled" | "configured" | "";
76
+ skipped: boolean;
77
+ skipReason: string;
78
+ error: string | null;
79
+ prunedExportKeys: Array<string>;
80
+ }
81
+ /**
82
+ * Built dist assets tallied for one package (reporter / progress output).
83
+ *
84
+ * @since 0.3.16-canary.0
85
+ */
86
+ export interface MirrorDistAssetCounts {
87
+ jsCount: number;
88
+ cssCount: number;
89
+ }
90
+ /**
91
+ * Aggregate totals across every package in a mirror run.
92
+ *
93
+ * @since 0.3.16-canary.0
94
+ */
95
+ export interface GlobalStats {
96
+ packagesFound: number;
97
+ packagesProcessed: number;
98
+ packagesSkipped: number;
99
+ packagesErrored: number;
100
+ totalExports: number;
101
+ totalJsModules: number;
102
+ totalCssExports: number;
103
+ packageDetails: Array<PackageStats>;
104
+ }
105
+ /**
106
+ * How workspace packages were resolved when scanning the repo (for logging / UX).
107
+ *
108
+ * @since 0.3.16-canary.0
109
+ */
110
+ export type WorkspaceMultiDiscoverySource = "default-patterns" | "pnpm-workspace-yaml" | "declared-empty" | "single-package";
111
+ /**
112
+ * The workspace package paths found for a mirror run and how they were discovered.
113
+ *
114
+ * @since 0.3.16-canary.0
115
+ */
116
+ export type FindWorkspacePackagesResult = {
117
+ relPaths: Array<string>;
118
+ multiSource: WorkspaceMultiDiscoverySource;
119
+ };
120
+ /**
121
+ * Everything the `mirror` action needs resolved before a run: globals, root, config, and filter.
122
+ *
123
+ * @since 0.3.16-canary.0
124
+ */
125
+ export interface MirrorSyncCommandPrelude {
126
+ readonly globals: GlobalCliOptions;
127
+ readonly rootDir: string;
128
+ readonly config: CodefastConfig;
129
+ readonly packageFilter: string | undefined;
130
+ }
131
+ export {};
@@ -0,0 +1,23 @@
1
+ import type { GlobalStats, PackageStats } from "#/mirror/domain/types";
2
+ import type { MirrorProcessingModeInput } from "#/mirror/sync-reporter";
3
+ import type { MirrorSyncProgressListener } from "#/mirror/sync-types";
4
+ /**
5
+ * A progress listener that renders mirror run events through the CLI reporter.
6
+ *
7
+ * @since 0.3.16-canary.0
8
+ */
9
+ export declare class MirrorSyncProgressPresenter implements MirrorSyncProgressListener {
10
+ private readonly reporter;
11
+ private verbose;
12
+ private dryRun;
13
+ configure(options: {
14
+ readonly noColor: boolean;
15
+ readonly verbose: boolean;
16
+ readonly dryRun: boolean;
17
+ }): void;
18
+ onBanner(): void;
19
+ onProcessingMode(mode: MirrorProcessingModeInput): void;
20
+ onNoPackages(): void;
21
+ onPackageComplete(pkgStats: PackageStats, ordinal: number, total: number): void;
22
+ onComplete(stats: GlobalStats, elapsedSeconds: number): void;
23
+ }
@@ -0,0 +1,19 @@
1
+ import { AppError } from "#/core/errors";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { Result } from "#/core/result";
4
+ /**
5
+ * Resolves the optional positional package argument to a root-relative path, or `undefined` when absent.
6
+ *
7
+ * @since 0.3.16-canary.0
8
+ */
9
+ export declare function resolveMirrorPackageFromCliArg(fs: FilesystemPort, args: {
10
+ readonly rootDir: string;
11
+ readonly packageArg: string | undefined;
12
+ readonly currentWorkingDirectory: string;
13
+ }): Result<string | undefined, AppError>;
14
+ /**
15
+ * Resolves a package filter to a root-relative path, rejecting anything outside the monorepo root.
16
+ *
17
+ * @since 0.3.16-canary.0
18
+ */
19
+ export declare function resolvePackageFilterUnderRoot(fs: FilesystemPort, rootDir: string, packageFilter: string): Result<string, AppError>;
@@ -0,0 +1,15 @@
1
+ import type { GlobalCliOptions } from "#/core/cli/global-options";
2
+ import { AppError } from "#/core/errors";
3
+ import type { FilesystemPort } from "#/core/filesystem/port";
4
+ import type { Result } from "#/core/result";
5
+ import type { MirrorSyncCommandPrelude } from "#/mirror/domain/types";
6
+ /**
7
+ * Resolves the repo root, config, and package filter into the prelude a mirror run starts from.
8
+ *
9
+ * @since 0.3.16-canary.0
10
+ */
11
+ export declare function prepareMirrorSync(fs: FilesystemPort, args: {
12
+ readonly currentWorkingDirectory: string;
13
+ readonly packageArg: string | undefined;
14
+ readonly globals: GlobalCliOptions;
15
+ }): Promise<Result<MirrorSyncCommandPrelude, AppError>>;
@@ -2,7 +2,7 @@ import { loadCodefastConfig } from "#/core/config";
2
2
  import { AppError } from "#/core/errors";
3
3
  import { messageFrom } from "#/core/errors";
4
4
  import { err, ok } from "#/core/result";
5
- import { findRepoRoot } from "#/core/workspace/resolver";
5
+ import { resolveProjectRoot } from "#/core/workspace/resolver";
6
6
  import { resolveMirrorPackageFromCliArg } from "#/mirror/package-path";
7
7
  /**
8
8
  * Resolves the repo root, config, and package filter into the prelude a mirror run starts from.
@@ -12,7 +12,7 @@ import { resolveMirrorPackageFromCliArg } from "#/mirror/package-path";
12
12
  export async function prepareMirrorSync(fs, args) {
13
13
  let rootDir;
14
14
  try {
15
- rootDir = findRepoRoot(args.currentWorkingDirectory, fs);
15
+ rootDir = resolveProjectRoot(args.currentWorkingDirectory, fs).rootDir;
16
16
  }
17
17
  catch (caughtError) {
18
18
  return err(new AppError("INFRA_FAILURE", messageFrom(caughtError), caughtError));
@@ -0,0 +1,27 @@
1
+ import type { FilesystemPort } from "#/core/filesystem/port";
2
+ /**
3
+ * The export specifiers a preserve-mode run added conditions to.
4
+ *
5
+ * @since 0.3.16-canary.3
6
+ */
7
+ export type SupplementResult = {
8
+ supplementedSpecifiers: Array<string>;
9
+ };
10
+ /**
11
+ * Adds missing conditions to a package's existing exports map and returns the specifiers it touched.
12
+ *
13
+ * @since 0.3.16-canary.0
14
+ */
15
+ export declare function supplementExportsInPackageJson(fs: FilesystemPort, packageJsonPath: string, packageDir: string, options: {
16
+ source: boolean | string;
17
+ types: boolean;
18
+ import: boolean;
19
+ resolveSourcePath: (modulePath: string) => string;
20
+ }, write?: boolean): Promise<SupplementResult>;
21
+ /**
22
+ * Builds a `resolveSourcePath` closure that checks the filesystem for `.tsx` before
23
+ * falling back to `.ts`. Mirrors the logic used in normal (non-custom) mode.
24
+ *
25
+ * @since 0.3.16-canary.0
26
+ */
27
+ export declare function buildSourcePathResolver(fs: FilesystemPort, packageDir: string): (modulePath: string) => string;
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { DIST_DIR } from "#/mirror/domain/constants";
2
+ import { distDirName } from "#/core/workspace/well-known-files";
3
3
  import { writePackageJsonExportsAtomic } from "#/mirror/write-exports";
4
4
  const DTS_EXTENSIONS = [".d.mts", ".d.ts", ".d.cts"];
5
5
  const JS_EXTENSIONS = [".mjs", ".js"];
@@ -116,7 +116,7 @@ export async function supplementExportsInPackageJson(fs, packageJsonPath, packag
116
116
  if (!existingExports || typeof existingExports !== "object" || Array.isArray(existingExports)) {
117
117
  return { supplementedSpecifiers: [] };
118
118
  }
119
- const distDir = path.join(packageDir, DIST_DIR);
119
+ const distDir = path.join(packageDir, distDirName);
120
120
  const supplementedSpecifiers = [];
121
121
  const supplementedExports = {};
122
122
  const originalPathBySpecifier = {};
@@ -0,0 +1,60 @@
1
+ import type { GlobalStats, MirrorDistAssetCounts, PackageStats, WorkspaceMultiDiscoverySource } from "#/mirror/domain/types";
2
+ /**
3
+ * Whether a run targets a single package or the discovered workspace set.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export type MirrorProcessingModeInput = {
8
+ kind: "single";
9
+ } | {
10
+ kind: "multi";
11
+ source: WorkspaceMultiDiscoverySource;
12
+ };
13
+ /**
14
+ * The stdout/stderr line-writer shape the reporter prints through.
15
+ *
16
+ * @since 0.3.16-canary.0
17
+ */
18
+ export type CliLoggerLike = {
19
+ out(line: string): void;
20
+ err(line: string): void;
21
+ };
22
+ /**
23
+ * The rendering surface for every message a mirror run prints.
24
+ *
25
+ * @since 0.3.16-canary.0
26
+ */
27
+ interface MirrorSyncReporterPort {
28
+ configureMirrorColors(noColor: boolean): void;
29
+ mirrorBanner(logger: CliLoggerLike): void;
30
+ mirrorDryRunNotice(logger: CliLoggerLike): void;
31
+ mirrorProcessingMode(logger: CliLoggerLike, mode: MirrorProcessingModeInput): void;
32
+ mirrorNoPackages(logger: CliLoggerLike): void;
33
+ logSkippedWorkspacePackage(logger: CliLoggerLike, index: number, total: number, displayName: string, reason: string): void;
34
+ logPackageSuccess(logger: CliLoggerLike, index: number, total: number, pkgStats: PackageStats, generatedDistAssetCounts: MirrorDistAssetCounts, verbose: boolean): void;
35
+ logPrunedStaleExport(logger: CliLoggerLike, exportSpecifier: string): void;
36
+ logPackageError(logger: CliLoggerLike, index: number, total: number, displayName: string, errorValue: unknown, verbose: boolean): void;
37
+ mirrorSummarySeparator(logger: CliLoggerLike): void;
38
+ mirrorSummary(logger: CliLoggerLike, stats: GlobalStats, elapsedSeconds: number): void;
39
+ }
40
+ /**
41
+ * Console implementation: ANSI styling and layout for the mirror command.
42
+ *
43
+ * @since 0.3.16-canary.0
44
+ */
45
+ export declare class MirrorSyncReporter implements MirrorSyncReporterPort {
46
+ private colorsAreEnabled;
47
+ configureMirrorColors(noColor: boolean): void;
48
+ mirrorBanner(logger: CliLoggerLike): void;
49
+ mirrorDryRunNotice(logger: CliLoggerLike): void;
50
+ mirrorProcessingMode(logger: CliLoggerLike, mode: MirrorProcessingModeInput): void;
51
+ mirrorNoPackages(logger: CliLoggerLike): void;
52
+ logSkippedWorkspacePackage(logger: CliLoggerLike, index: number, total: number, displayName: string, reason: string): void;
53
+ logPackageSuccess(logger: CliLoggerLike, index: number, total: number, pkgStats: PackageStats, generatedDistAssetCounts: MirrorDistAssetCounts, verbose: boolean): void;
54
+ logPrunedStaleExport(logger: CliLoggerLike, exportSpecifier: string): void;
55
+ logPackageError(logger: CliLoggerLike, index: number, total: number, displayName: string, errorValue: unknown, verbose: boolean): void;
56
+ mirrorSummarySeparator(logger: CliLoggerLike): void;
57
+ mirrorSummary(logger: CliLoggerLike, stats: GlobalStats, elapsedSeconds: number): void;
58
+ private paint;
59
+ }
60
+ export {};
@@ -42,6 +42,10 @@ export class MirrorSyncReporter {
42
42
  logger.out(`${this.paint("Discovering workspace packages from pnpm-workspace.yaml…", ANSI.dim)}\n`);
43
43
  return;
44
44
  }
45
+ if (mode.source === "single-package") {
46
+ logger.out(`${this.paint("No pnpm-workspace.yaml — processing the single package at the project root…", ANSI.dim)}\n`);
47
+ return;
48
+ }
45
49
  logger.out(`${this.paint("pnpm-workspace.yaml declares an empty workspace package list.", ANSI.dim)}\n`);
46
50
  }
47
51
  mirrorNoPackages(logger) {
@@ -0,0 +1,43 @@
1
+ import type { GlobalStats, PackageStats, WorkspaceMultiDiscoverySource } from "#/mirror/domain/types";
2
+ /**
3
+ * The inputs a mirror run is invoked with.
4
+ *
5
+ * @since 0.3.16-canary.0
6
+ */
7
+ export type MirrorSyncRunRequest = {
8
+ rootDir: string;
9
+ packageFilter?: string | undefined;
10
+ config?: unknown;
11
+ /** When false, compute and report changes without writing package.json. Defaults to true. */
12
+ write?: boolean | undefined;
13
+ };
14
+ /**
15
+ * Callbacks a mirror run invokes as it progresses through packages.
16
+ *
17
+ * @since 0.3.16-canary.0
18
+ */
19
+ export type MirrorSyncProgressListener = {
20
+ configure(options: {
21
+ readonly noColor: boolean;
22
+ readonly verbose: boolean;
23
+ readonly dryRun: boolean;
24
+ }): void;
25
+ onBanner(): void;
26
+ onProcessingMode(mode: {
27
+ readonly kind: "single";
28
+ } | {
29
+ readonly kind: "multi";
30
+ readonly source: WorkspaceMultiDiscoverySource;
31
+ }): void;
32
+ onNoPackages(): void;
33
+ onPackageComplete(pkgStats: PackageStats, ordinal: number, total: number): void;
34
+ onComplete(stats: GlobalStats, elapsedSeconds: number): void;
35
+ };
36
+ /**
37
+ * A run request paired with an optional progress listener.
38
+ *
39
+ * @since 0.3.16-canary.0
40
+ */
41
+ export type MirrorSyncExecutionInput = MirrorSyncRunRequest & {
42
+ readonly listener?: MirrorSyncProgressListener | undefined;
43
+ };
@@ -0,0 +1,9 @@
1
+ import type { MirrorConfig } from "#/core/config/schema";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { PackageStats } from "#/mirror/domain/types";
4
+ /**
5
+ * Regenerates one package's `package.json#exports` from its `dist/` and returns the package's stats.
6
+ *
7
+ * @since 0.3.16-canary.0
8
+ */
9
+ export declare function syncExportsForWorkspacePackage(fs: FilesystemPort, rootDir: string, packagePathStr: string, config: MirrorConfig, write?: boolean): Promise<PackageStats>;
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import { messageFrom } from "#/core/errors";
3
+ import { distDirName, packageJsonFileName } from "#/core/workspace/well-known-files";
3
4
  import { createMirrorDistFilesystem } from "#/mirror/dist-filesystem-impl";
4
- import { DIST_DIR, PACKAGE_JSON } from "#/mirror/domain/constants";
5
5
  import { createPathTransform, generateExports } from "#/mirror/domain/exports";
6
6
  import { resolvePackageDisplayName } from "#/mirror/domain/package-display-name";
7
7
  import { buildSourcePathResolver, supplementExportsInPackageJson } from "#/mirror/supplement-exports";
@@ -16,8 +16,8 @@ export async function syncExportsForWorkspacePackage(fs, rootDir, packagePathStr
16
16
  const pathResolve = path.resolve;
17
17
  const pathBasename = path.basename;
18
18
  const packageDir = pathResolve(rootDir, packagePathStr);
19
- const distDir = pathJoin(packageDir, DIST_DIR);
20
- const packageJsonPath = pathJoin(packageDir, PACKAGE_JSON);
19
+ const distDir = pathJoin(packageDir, distDirName);
20
+ const packageJsonPath = pathJoin(packageDir, packageJsonFileName);
21
21
  const folderBasename = pathBasename(packageDir);
22
22
  const distFilesystem = createMirrorDistFilesystem(fs);
23
23
  const pkgStats = {
@@ -0,0 +1,12 @@
1
+ import { AppError } from "#/core/errors";
2
+ import type { FilesystemPort } from "#/core/filesystem/port";
3
+ import type { Result } from "#/core/result";
4
+ import type { GlobalStats } from "#/mirror/domain/types";
5
+ import type { MirrorSyncExecutionInput } from "#/mirror/sync-types";
6
+ export type { MirrorSyncExecutionInput } from "#/mirror/sync-types";
7
+ /**
8
+ * Runs the mirror sync across the targeted packages and returns the aggregate stats.
9
+ *
10
+ * @since 0.3.16-canary.0
11
+ */
12
+ export declare function runMirrorSync(fs: FilesystemPort, input: MirrorSyncExecutionInput): Promise<Result<GlobalStats, AppError>>;
@@ -83,9 +83,11 @@ function mirrorTargetsFromWorkspaceLayout(rootDir, layoutOutcome) {
83
83
  return { relPaths: [], multiSource: "declared-empty" };
84
84
  }
85
85
  const multiSource = layoutOutcome.layoutSource;
86
- const relPaths = layoutOutcome.packageDirectoryPathsAbsolute
87
- .map((absolutePath) => normalizePath(path.relative(rootDir, absolutePath)))
88
- .filter((relativePath) => relativePath.length > 0);
86
+ // A single-package root maps to "." (path.relative to itself is empty); a workspace maps to subpaths.
87
+ const relPaths = layoutOutcome.packageDirectoryPathsAbsolute.map((absolutePath) => {
88
+ const relativePath = normalizePath(path.relative(rootDir, absolutePath));
89
+ return relativePath.length > 0 ? relativePath : ".";
90
+ });
89
91
  relPaths.sort((left, right) => left.localeCompare(right));
90
92
  return { relPaths, multiSource };
91
93
  }
@@ -0,0 +1,15 @@
1
+ import type { FilesystemPort } from "#/core/filesystem/port";
2
+ import type { ExportMapData, ExportOriginalPathBySpecifier } from "#/mirror/domain/types";
3
+ /**
4
+ * Writes `exports` into `package.json` via a temp file + rename (atomic on same volume).
5
+ * Preserves a trailing newline after JSON.
6
+ *
7
+ * @since 0.3.16-canary.0
8
+ */
9
+ export declare function writePackageJsonExportsAtomic(fs: FilesystemPort, packageJsonPath: string, mergeInput: {
10
+ generatedExports: ExportMapData;
11
+ managedExportSpecifiers: Array<string>;
12
+ originalPathBySpecifier: ExportOriginalPathBySpecifier;
13
+ }, write?: boolean): Promise<{
14
+ prunedKeys: Array<string>;
15
+ }>;
@@ -0,0 +1,13 @@
1
+ import type { PackSlimRunStats } from "#/pack-slim/domain/types";
2
+ /**
3
+ * Maps a pack-slim run's stats to the process exit code.
4
+ *
5
+ * @since 0.8.1
6
+ */
7
+ export declare function exitCodeForPackSlimResult(stats: PackSlimRunStats): number;
8
+ /**
9
+ * Serializes a pack-slim run's stats as the single-line JSON summary printed under `--json`.
10
+ *
11
+ * @since 0.8.1
12
+ */
13
+ export declare function formatPackSlimJsonOutput(stats: PackSlimRunStats, elapsedSeconds: number, write?: boolean): string;
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The validated serializable inputs of a pack-slim run.
4
+ *
5
+ * @since 0.8.1
6
+ */
7
+ export interface PackSlimRunRequest {
8
+ rootDir: string;
9
+ packageFilter?: string | undefined;
10
+ write?: boolean | undefined;
11
+ }
12
+ /**
13
+ * Zod schema validating the serializable inputs of a pack-slim run.
14
+ *
15
+ * @since 0.8.1
16
+ */
17
+ export declare const packSlimRunRequestSchema: z.ZodType<PackSlimRunRequest>;
@@ -0,0 +1,7 @@
1
+ import { Command } from "commander";
2
+ /**
3
+ * Creates the `pack-slim` subcommand, which slims published packages down to what a consumer reads before publish.
4
+ *
5
+ * @since 0.8.1
6
+ */
7
+ export declare function createPackSlimCommand(): Command;
@@ -8,7 +8,7 @@ import { nodeFilesystem } from "#/core/filesystem/node";
8
8
  import { logger } from "#/core/logger";
9
9
  import { err } from "#/core/result";
10
10
  import { parseWithSchema } from "#/core/schema-parse";
11
- import { findRepoRoot } from "#/core/workspace/resolver";
11
+ import { resolveProjectRoot } from "#/core/workspace/resolver";
12
12
  import { exitCodeForPackSlimResult, formatPackSlimJsonOutput } from "#/pack-slim/cli-result";
13
13
  import { packSlimRunRequestSchema } from "#/pack-slim/cli-schema";
14
14
  import { PackSlimProgressPresenter } from "#/pack-slim/output";
@@ -36,7 +36,7 @@ export function createPackSlimCommand() {
36
36
  }
37
37
  let rootDir;
38
38
  try {
39
- rootDir = findRepoRoot(process.cwd(), nodeFilesystem);
39
+ rootDir = resolveProjectRoot(process.cwd(), nodeFilesystem).rootDir;
40
40
  }
41
41
  catch (caughtError) {
42
42
  consumeCliAppError(err(new AppError("INFRA_FAILURE", messageFrom(caughtError), caughtError)));