@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.
- package/CHANGELOG.md +596 -0
- package/LICENSE +1 -1
- package/README.md +335 -129
- package/dist/arrange/analyze.d.ts +10 -0
- package/dist/arrange/cli-schema.d.ts +50 -0
- package/dist/arrange/command.d.ts +7 -0
- package/dist/arrange/domain/analyze-service.d.ts +18 -0
- package/dist/arrange/domain/ast/ast-node.d.ts +394 -0
- package/dist/arrange/domain/ast/collectors-cn.d.ts +26 -0
- package/dist/arrange/domain/ast/collectors-jsx.d.ts +8 -0
- package/dist/arrange/domain/ast/collectors-tv.d.ts +34 -0
- package/dist/arrange/domain/ast/helpers.d.ts +36 -0
- package/dist/arrange/domain/ast/helpers.js +1 -0
- package/dist/arrange/domain/ast/simplify-targets.d.ts +22 -0
- package/dist/arrange/domain/ast/targets.d.ts +20 -0
- package/dist/arrange/domain/constants.d.ts +111 -0
- package/dist/arrange/domain/grouping-service.d.ts +100 -0
- package/dist/arrange/domain/grouping.d.ts +21 -0
- package/dist/arrange/domain/imports.d.ts +14 -0
- package/dist/arrange/domain/source-text-formatters.d.ts +33 -0
- package/dist/arrange/domain/tailwind-token.d.ts +24 -0
- package/dist/arrange/domain/token-classifier.d.ts +47 -0
- package/dist/arrange/domain/types.d.ts +208 -0
- package/dist/arrange/output.d.ts +26 -0
- package/dist/arrange/process-file.d.ts +11 -0
- package/dist/arrange/resolve-target.d.ts +10 -0
- package/dist/arrange/resolve-target.js +3 -16
- package/dist/arrange/scan-target.d.ts +7 -0
- package/dist/arrange/simplify-process-file.d.ts +11 -0
- package/dist/arrange/simplify-sync.d.ts +13 -0
- package/dist/arrange/source-parse.d.ts +7 -0
- package/dist/arrange/suggest.d.ts +8 -0
- package/dist/arrange/sync.d.ts +11 -0
- package/dist/arrange/typescript-ast-translator.d.ts +31 -0
- package/dist/arrange/workspace.d.ts +13 -0
- package/dist/arrange/workspace.js +2 -2
- package/dist/audit/cli-schema.d.ts +93 -0
- package/dist/audit/cli-schema.js +14 -3
- package/dist/audit/command.d.ts +8 -0
- package/dist/audit/command.js +52 -12
- package/dist/audit/domain/audit-file.d.ts +7 -0
- package/dist/audit/domain/comment-content.d.ts +26 -0
- package/dist/audit/domain/comment-dividers.d.ts +62 -0
- package/dist/audit/domain/comment-dividers.js +48 -20
- package/dist/audit/domain/display-names.d.ts +11 -0
- package/dist/audit/domain/display-names.js +71 -0
- package/dist/audit/domain/import-policy.d.ts +34 -0
- package/dist/audit/domain/import-policy.js +147 -0
- package/dist/audit/domain/link-references.d.ts +40 -0
- package/dist/audit/domain/mappings.d.ts +45 -0
- package/dist/audit/domain/markdown-links.d.ts +44 -0
- package/dist/audit/domain/since-versions.d.ts +26 -0
- package/dist/audit/domain/tokenize.d.ts +14 -0
- package/dist/audit/domain/tsdoc-syntax.d.ts +20 -0
- package/dist/audit/domain/types.d.ts +171 -0
- package/dist/audit/output.d.ts +91 -0
- package/dist/audit/output.js +52 -11
- package/dist/audit/prepare.d.ts +70 -0
- package/dist/audit/prepare.js +41 -10
- package/dist/audit/run-comments.d.ts +17 -0
- package/dist/audit/run-comments.js +22 -18
- package/dist/audit/run-display-names.d.ts +14 -0
- package/dist/audit/run-display-names.js +60 -0
- package/dist/audit/run-imports.d.ts +14 -0
- package/dist/audit/{run-react.js → run-imports.js} +15 -5
- package/dist/audit/run-links.d.ts +14 -0
- package/dist/audit/run.d.ts +14 -0
- package/dist/bin.d.ts +2 -0
- package/dist/cli.d.ts +6 -0
- package/dist/core/cli/format-error.d.ts +7 -0
- package/dist/core/cli/global-options.d.ts +15 -0
- package/dist/core/cli/positional.d.ts +6 -0
- package/dist/core/cli/result-handle.d.ts +19 -0
- package/dist/core/config/define-config.d.ts +7 -0
- package/dist/core/config/define-config.js +8 -0
- package/dist/core/config/loader.d.ts +18 -0
- package/dist/core/config/loader.js +2 -7
- package/dist/core/config/schema.d.ts +99 -0
- package/dist/core/config/schema.js +7 -75
- package/dist/core/config/warnings.d.ts +6 -0
- package/dist/core/config.d.ts +12 -0
- package/dist/core/errors.d.ts +25 -0
- package/dist/core/exit-codes.d.ts +18 -0
- package/dist/core/filesystem/node.d.ts +7 -0
- package/dist/core/filesystem/node.js +1 -0
- package/dist/core/filesystem/port.d.ts +44 -0
- package/dist/core/glob.d.ts +19 -0
- package/dist/core/logger.d.ts +9 -0
- package/dist/core/result.d.ts +30 -0
- package/dist/core/schema-parse.d.ts +9 -0
- package/dist/core/source-text-edit.d.ts +33 -0
- package/dist/core/verbose-diagnostics.d.ts +6 -0
- package/dist/core/workspace/ancestor-directories.d.ts +12 -0
- package/dist/core/workspace/ancestor-directories.js +30 -0
- package/dist/core/workspace/markdown-walk.d.ts +7 -0
- package/dist/core/workspace/markdown-walk.js +2 -20
- package/dist/core/workspace/package-version.d.ts +9 -0
- package/dist/core/workspace/package-version.js +8 -12
- package/dist/core/workspace/resolver.d.ts +39 -0
- package/dist/core/workspace/resolver.js +58 -75
- package/dist/core/workspace/skip-directories.d.ts +6 -0
- package/dist/core/workspace/source-walk.d.ts +16 -0
- package/dist/core/workspace/source-walk.js +14 -20
- package/dist/core/workspace/typescript-walk.d.ts +7 -0
- package/dist/core/workspace/typescript-walk.js +2 -23
- package/dist/core/workspace/walk-files.d.ts +7 -0
- package/dist/core/workspace/walk-files.js +27 -0
- package/dist/core/workspace/well-known-files.d.ts +18 -0
- package/dist/core/workspace/well-known-files.js +18 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/mirror/cli-result.d.ts +13 -0
- package/dist/mirror/cli-schema.d.ts +8 -0
- package/dist/mirror/command.d.ts +7 -0
- package/dist/mirror/dist-filesystem-impl.d.ts +8 -0
- package/dist/mirror/domain/constants.d.ts +18 -0
- package/dist/mirror/domain/constants.js +0 -12
- package/dist/mirror/domain/dirent-guard.d.ts +10 -0
- package/dist/mirror/domain/dist-filesystem.d.ts +9 -0
- package/dist/mirror/domain/errors.d.ts +24 -0
- package/dist/mirror/domain/exports.d.ts +36 -0
- package/dist/mirror/domain/package-display-name.d.ts +8 -0
- package/dist/mirror/domain/path-normalizer.d.ts +6 -0
- package/dist/mirror/domain/types.d.ts +131 -0
- package/dist/mirror/output.d.ts +23 -0
- package/dist/mirror/package-path.d.ts +19 -0
- package/dist/mirror/prepare.d.ts +15 -0
- package/dist/mirror/prepare.js +2 -2
- package/dist/mirror/supplement-exports.d.ts +27 -0
- package/dist/mirror/supplement-exports.js +2 -2
- package/dist/mirror/sync-reporter.d.ts +60 -0
- package/dist/mirror/sync-reporter.js +4 -0
- package/dist/mirror/sync-types.d.ts +43 -0
- package/dist/mirror/sync-workspace-package.d.ts +9 -0
- package/dist/mirror/sync-workspace-package.js +3 -3
- package/dist/mirror/sync.d.ts +12 -0
- package/dist/mirror/sync.js +5 -3
- package/dist/mirror/write-exports.d.ts +15 -0
- package/dist/pack-slim/cli-result.d.ts +13 -0
- package/dist/pack-slim/cli-schema.d.ts +17 -0
- package/dist/pack-slim/command.d.ts +7 -0
- package/dist/pack-slim/command.js +5 -4
- package/dist/pack-slim/domain/transform.d.ts +69 -0
- package/dist/pack-slim/domain/transform.js +141 -15
- package/dist/pack-slim/domain/types.d.ts +46 -0
- package/dist/pack-slim/output.d.ts +15 -0
- package/dist/pack-slim/output.js +10 -1
- package/dist/pack-slim/sync.d.ts +23 -0
- package/dist/pack-slim/sync.js +14 -8
- package/dist/pack-slim/working-tree.d.ts +20 -0
- package/dist/tag/cli-result.d.ts +7 -0
- package/dist/tag/cli-schema.d.ts +8 -0
- package/dist/tag/command.d.ts +7 -0
- package/dist/tag/domain/types.d.ts +111 -0
- package/dist/tag/output.d.ts +17 -0
- package/dist/tag/prepare.d.ts +13 -0
- package/dist/tag/prepare.js +2 -2
- package/dist/tag/resolve-target-path.d.ts +10 -0
- package/dist/tag/since-writer.d.ts +32 -0
- package/dist/tag/sync.d.ts +42 -0
- package/dist/tag/target-candidates.d.ts +8 -0
- package/dist/tag/target-candidates.js +1 -1
- package/dist/tag/target-runner.d.ts +8 -0
- package/dist/tag/version-resolver.d.ts +7 -0
- package/package.json +16 -33
- package/dist/audit/domain/react-imports.js +0 -91
|
@@ -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>>;
|
package/dist/mirror/prepare.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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 {
|
|
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,
|
|
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,
|
|
20
|
-
const packageJsonPath = pathJoin(packageDir,
|
|
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>>;
|
package/dist/mirror/sync.js
CHANGED
|
@@ -83,9 +83,11 @@ function mirrorTargetsFromWorkspaceLayout(rootDir, layoutOutcome) {
|
|
|
83
83
|
return { relPaths: [], multiSource: "declared-empty" };
|
|
84
84
|
}
|
|
85
85
|
const multiSource = layoutOutcome.layoutSource;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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>;
|
|
@@ -8,20 +8,21 @@ 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 {
|
|
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";
|
|
15
15
|
import { runPackSlim } from "#/pack-slim/sync";
|
|
16
16
|
import { ensureWorkingTreeClean } from "#/pack-slim/working-tree";
|
|
17
17
|
/**
|
|
18
|
-
* Creates the `pack-slim` subcommand, which
|
|
18
|
+
* Creates the `pack-slim` subcommand, which slims published packages down to what a consumer reads before publish.
|
|
19
19
|
*
|
|
20
20
|
* @since 0.8.1
|
|
21
21
|
*/
|
|
22
22
|
export function createPackSlimCommand() {
|
|
23
23
|
const cmd = new Command("pack-slim")
|
|
24
|
-
.description("Strip src, source conditions, and dist source maps from
|
|
24
|
+
.description("Strip src, source conditions, unshipped imports, dev-only scripts, devDependencies, and dist source maps from " +
|
|
25
|
+
"published packages before publish")
|
|
25
26
|
.argument("[package]", "Optional package path relative to repo root (e.g. packages/ui)")
|
|
26
27
|
.option("--dry-run", "Report what would change without touching any file", false)
|
|
27
28
|
.option("--force", "Run even if the git working tree has uncommitted tracked changes", false)
|
|
@@ -35,7 +36,7 @@ export function createPackSlimCommand() {
|
|
|
35
36
|
}
|
|
36
37
|
let rootDir;
|
|
37
38
|
try {
|
|
38
|
-
rootDir =
|
|
39
|
+
rootDir = resolveProjectRoot(process.cwd(), nodeFilesystem).rootDir;
|
|
39
40
|
}
|
|
40
41
|
catch (caughtError) {
|
|
41
42
|
consumeCliAppError(err(new AppError("INFRA_FAILURE", messageFrom(caughtError), caughtError)));
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** Pure transforms that slim a package's manifest and dist for publish. */
|
|
2
|
+
/**
|
|
3
|
+
* What slimming one manifest removed.
|
|
4
|
+
*/
|
|
5
|
+
interface ManifestSlimReport {
|
|
6
|
+
readonly filesSrcRemoved: boolean;
|
|
7
|
+
readonly exportsSourceRemoved: number;
|
|
8
|
+
readonly importsSourceRemoved: number;
|
|
9
|
+
readonly importsUnshippedRemoved: number;
|
|
10
|
+
readonly scriptsRemoved: number;
|
|
11
|
+
readonly devDependenciesRemoved: number;
|
|
12
|
+
readonly changed: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The slimmed manifest paired with the report of what it dropped.
|
|
16
|
+
*
|
|
17
|
+
* @since 0.8.1
|
|
18
|
+
*/
|
|
19
|
+
export interface SlimManifestResult {
|
|
20
|
+
readonly manifest: Record<string, unknown>;
|
|
21
|
+
readonly report: ManifestSlimReport;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The result of stripping the `sourceMappingURL` directive from an emitted file's text.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.8.1
|
|
27
|
+
*/
|
|
28
|
+
export interface StripCommentResult {
|
|
29
|
+
readonly text: string;
|
|
30
|
+
readonly stripped: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether a dist entry is a source-map sidecar (`*.map`).
|
|
34
|
+
*
|
|
35
|
+
* @since 0.8.1
|
|
36
|
+
*/
|
|
37
|
+
export declare function isSourceMapFile(fileName: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether a dist entry is an emitted file that may carry a `sourceMappingURL` directive.
|
|
40
|
+
*
|
|
41
|
+
* @since 0.8.1
|
|
42
|
+
*/
|
|
43
|
+
export declare function isMapAnnotatedFile(fileName: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether a script name is an install or publish lifecycle hook, with or without its `pre`/`post` prefix.
|
|
46
|
+
*
|
|
47
|
+
* @remarks Publish hooks stay because `pnpm publish` runs them right after pack-slim; install hooks stay because a
|
|
48
|
+
* consumer's package manager runs them.
|
|
49
|
+
*
|
|
50
|
+
* @since 0.9.0
|
|
51
|
+
*/
|
|
52
|
+
export declare function isLifecycleScript(name: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Produces a publish manifest carrying only what a consumer's `tsc` and Node read.
|
|
55
|
+
*
|
|
56
|
+
* @remarks Operates on a structural clone, so the caller's manifest is left intact. A consumer never enables `source`
|
|
57
|
+
* and resolves `#/` through `types`/`default` to `dist`, so dropping the source lane, the `imports` left pointing
|
|
58
|
+
* outside `files`, the scripts that are not lifecycle hooks, and `devDependencies` leaves the published surface whole.
|
|
59
|
+
*
|
|
60
|
+
* @since 0.8.1
|
|
61
|
+
*/
|
|
62
|
+
export declare function slimPublishManifest(manifest: Record<string, unknown>): SlimManifestResult;
|
|
63
|
+
/**
|
|
64
|
+
* Strips every `sourceMappingURL` directive line from an emitted file's text.
|
|
65
|
+
*
|
|
66
|
+
* @since 0.8.1
|
|
67
|
+
*/
|
|
68
|
+
export declare function stripSourceMappingComment(text: string): StripCommentResult;
|
|
69
|
+
export {};
|