@mxpicture/build-api 0.2.55 โ 0.2.57
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/dist/barrel/Barrel.d.ts +66 -0
- package/dist/barrel/Barrel.d.ts.map +1 -1
- package/dist/barrel/Barrel.js +66 -3
- package/dist/barrel/Barrel.js.map +1 -1
- package/dist/cleanup/Cleanup.d.ts +70 -0
- package/dist/cleanup/Cleanup.d.ts.map +1 -1
- package/dist/cleanup/Cleanup.js +70 -0
- package/dist/cleanup/Cleanup.js.map +1 -1
- package/dist/code/code.common.d.ts +37 -4
- package/dist/code/code.common.d.ts.map +1 -1
- package/dist/code/code.common.js +37 -4
- package/dist/code/code.common.js.map +1 -1
- package/dist/code/code.exports.d.ts +25 -0
- package/dist/code/code.exports.d.ts.map +1 -1
- package/dist/code/code.exports.js +25 -1
- package/dist/code/code.exports.js.map +1 -1
- package/dist/code/code.format.d.ts +23 -0
- package/dist/code/code.format.d.ts.map +1 -1
- package/dist/code/code.format.js +23 -0
- package/dist/code/code.format.js.map +1 -1
- package/dist/common/common.fs.d.ts +22 -0
- package/dist/common/common.fs.d.ts.map +1 -1
- package/dist/common/common.fs.js +22 -0
- package/dist/common/common.fs.js.map +1 -1
- package/dist/common/common.json.d.ts +27 -0
- package/dist/common/common.json.d.ts.map +1 -1
- package/dist/common/common.json.js +27 -0
- package/dist/common/common.json.js.map +1 -1
- package/dist/deps/FixWorkspaceDeps.d.ts +132 -0
- package/dist/deps/FixWorkspaceDeps.d.ts.map +1 -1
- package/dist/deps/FixWorkspaceDeps.js +120 -2
- package/dist/deps/FixWorkspaceDeps.js.map +1 -1
- package/dist/git/GitChanges.d.ts +60 -13
- package/dist/git/GitChanges.d.ts.map +1 -1
- package/dist/git/GitChanges.js +60 -13
- package/dist/git/GitChanges.js.map +1 -1
- package/dist/git/git.util.d.ts +58 -3
- package/dist/git/git.util.d.ts.map +1 -1
- package/dist/git/git.util.js +58 -3
- package/dist/git/git.util.js.map +1 -1
- package/dist/logger/Logger.d.ts +74 -0
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +49 -0
- package/dist/logger/Logger.js.map +1 -1
- package/dist/npmPublish/NpmPublisher.d.ts +36 -0
- package/dist/npmPublish/NpmPublisher.d.ts.map +1 -1
- package/dist/npmPublish/NpmPublisher.js +36 -0
- package/dist/npmPublish/NpmPublisher.js.map +1 -1
- package/dist/osInfo/osInfo.common.d.ts +45 -1
- package/dist/osInfo/osInfo.common.d.ts.map +1 -1
- package/dist/osInfo/osInfo.common.js +45 -1
- package/dist/osInfo/osInfo.common.js.map +1 -1
- package/dist/pkg/Pkg.d.ts +69 -0
- package/dist/pkg/Pkg.d.ts.map +1 -1
- package/dist/pkg/Pkg.js +69 -0
- package/dist/pkg/Pkg.js.map +1 -1
- package/dist/pkg/SyncPkgVersion.d.ts +35 -0
- package/dist/pkg/SyncPkgVersion.d.ts.map +1 -1
- package/dist/pkg/SyncPkgVersion.js +35 -0
- package/dist/pkg/SyncPkgVersion.js.map +1 -1
- package/dist/pkg/UpdatePackages.d.ts +36 -0
- package/dist/pkg/UpdatePackages.d.ts.map +1 -1
- package/dist/pkg/UpdatePackages.js +36 -0
- package/dist/pkg/UpdatePackages.js.map +1 -1
- package/dist/pkg/pkg.common.d.ts +73 -0
- package/dist/pkg/pkg.common.d.ts.map +1 -1
- package/dist/pkg/pkg.common.js +73 -0
- package/dist/pkg/pkg.common.js.map +1 -1
- package/dist/pkg/pkg.fs.d.ts +53 -0
- package/dist/pkg/pkg.fs.d.ts.map +1 -1
- package/dist/pkg/pkg.fs.js +53 -0
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/types/types.barrel.d.ts +28 -0
- package/dist/types/types.barrel.d.ts.map +1 -1
- package/dist/types/types.barrel.js.map +1 -1
- package/dist/types/types.changelog.d.ts +28 -0
- package/dist/types/types.changelog.d.ts.map +1 -1
- package/dist/types/types.changelog.js +9 -0
- package/dist/types/types.changelog.js.map +1 -1
- package/dist/types/types.cleanup.d.ts +19 -0
- package/dist/types/types.cleanup.d.ts.map +1 -1
- package/dist/types/types.cleanup.js.map +1 -1
- package/dist/types/types.code.d.ts +36 -0
- package/dist/types/types.code.d.ts.map +1 -1
- package/dist/types/types.code.js.map +1 -1
- package/dist/types/types.deps.d.ts +27 -0
- package/dist/types/types.deps.d.ts.map +1 -1
- package/dist/types/types.deps.js +10 -0
- package/dist/types/types.deps.js.map +1 -1
- package/dist/types/types.documents.d.ts +9 -0
- package/dist/types/types.documents.d.ts.map +1 -1
- package/dist/types/types.documents.js.map +1 -1
- package/dist/types/types.git.d.ts +25 -0
- package/dist/types/types.git.d.ts.map +1 -1
- package/dist/types/types.git.js.map +1 -1
- package/dist/types/types.npm.d.ts +7 -0
- package/dist/types/types.npm.d.ts.map +1 -1
- package/dist/types/types.npm.js.map +1 -1
- package/dist/types/types.os.d.ts +8 -0
- package/dist/types/types.os.d.ts.map +1 -1
- package/dist/types/types.os.js.map +1 -1
- package/dist/types/types.package.d.ts +48 -0
- package/dist/types/types.package.d.ts.map +1 -1
- package/dist/types/types.package.js.map +1 -1
- package/dist/types/types.run.d.ts +4 -0
- package/dist/types/types.run.d.ts.map +1 -1
- package/dist/types/types.run.js.map +1 -1
- package/dist/types/types.vscode.d.ts +46 -0
- package/dist/types/types.vscode.d.ts.map +1 -1
- package/dist/types/types.vscode.js.map +1 -1
- package/dist/types/types.workspace.d.ts +18 -0
- package/dist/types/types.workspace.d.ts.map +1 -1
- package/dist/types/types.workspace.js +6 -0
- package/dist/types/types.workspace.js.map +1 -1
- package/dist/vscode/vscode.config.d.ts +18 -0
- package/dist/vscode/vscode.config.d.ts.map +1 -1
- package/dist/vscode/vscode.config.js +18 -0
- package/dist/vscode/vscode.config.js.map +1 -1
- package/dist/vscode/vscode.profiles.d.ts +37 -0
- package/dist/vscode/vscode.profiles.d.ts.map +1 -1
- package/dist/vscode/vscode.profiles.js +37 -0
- package/dist/vscode/vscode.profiles.js.map +1 -1
- package/dist/vscode/vscode.settings.d.ts +26 -1
- package/dist/vscode/vscode.settings.d.ts.map +1 -1
- package/dist/vscode/vscode.settings.js +26 -1
- package/dist/vscode/vscode.settings.js.map +1 -1
- package/dist/vscode/vscode.storage.d.ts +21 -1
- package/dist/vscode/vscode.storage.d.ts.map +1 -1
- package/dist/vscode/vscode.storage.js +21 -1
- package/dist/vscode/vscode.storage.js.map +1 -1
- package/dist/vscode/vscode.workspace.d.ts +17 -0
- package/dist/vscode/vscode.workspace.d.ts.map +1 -1
- package/dist/vscode/vscode.workspace.js +17 -0
- package/dist/vscode/vscode.workspace.js.map +1 -1
- package/dist/workspace/Workspace.d.ts +85 -0
- package/dist/workspace/Workspace.d.ts.map +1 -1
- package/dist/workspace/Workspace.js +85 -0
- package/dist/workspace/Workspace.js.map +1 -1
- package/dist/workspace/workspace.common.d.ts +42 -1
- package/dist/workspace/workspace.common.d.ts.map +1 -1
- package/dist/workspace/workspace.common.js +42 -1
- package/dist/workspace/workspace.common.js.map +1 -1
- package/package.json +1 -1
package/dist/barrel/Barrel.d.ts
CHANGED
|
@@ -1,13 +1,79 @@
|
|
|
1
1
|
import { BarrelGroup, BarrelParams, BarrelPersistParams, BarrelResult } from "../types/types.barrel.js";
|
|
2
2
|
import { Pkg } from "../pkg/Pkg.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default file patterns excluded from barrel exports.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Matches test files, declaration files, existing barrel index files,
|
|
8
|
+
* script directories, and `4testing` helper directories so they are
|
|
9
|
+
* never re-exported in generated barrel files.
|
|
10
|
+
*/
|
|
3
11
|
export declare const DEFAULT_EXCLUDED_PATTERNS: RegExp[];
|
|
12
|
+
/**
|
|
13
|
+
* Header comment prepended to every generated barrel file.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Warns consumers that the file is auto-generated and should not be
|
|
17
|
+
* edited by hand.
|
|
18
|
+
*/
|
|
4
19
|
export declare const DEFAULT_HEADER = "// This file is auto-generated by build-cli. Do not edit manually.\n";
|
|
20
|
+
/**
|
|
21
|
+
* Run barrel-file generation for every package in the workspace.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This is the main entry point for the barrel command. It initialises the
|
|
25
|
+
* workspace, then delegates to the {@link Barrel} class to collect source
|
|
26
|
+
* files and write barrel (index) files.
|
|
27
|
+
*
|
|
28
|
+
* @param params - Configuration for the barrel generation run.
|
|
29
|
+
* @returns A promise that resolves when all barrel files have been written.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { runBarrel } from "@mxpicture/build-api";
|
|
34
|
+
*
|
|
35
|
+
* await runBarrel({ repoRoot: process.cwd() });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
5
38
|
export declare const runBarrel: (params: BarrelParams) => Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Generates and maintains barrel (index) files for workspace packages.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* The generation is split into two phases:
|
|
44
|
+
*
|
|
45
|
+
* 1. **Collect** โ recursively scan each package's `src` directory to build
|
|
46
|
+
* {@link BarrelGroup} instances that describe which files belong together.
|
|
47
|
+
* 2. **Build & Persist** โ optionally create a TypeScript `SourceFile` map for
|
|
48
|
+
* selective exports, then write every barrel file to disk in parallel.
|
|
49
|
+
*
|
|
50
|
+
* After barrels are written the class also updates each package's
|
|
51
|
+
* `package.json` exports map when the set of entry-points has changed.
|
|
52
|
+
*/
|
|
6
53
|
export declare class Barrel {
|
|
7
54
|
protected readonly excludes: RegExp[];
|
|
8
55
|
protected readonly fileHeader: string;
|
|
9
56
|
protected readonly selectiveExport: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new Barrel generator.
|
|
59
|
+
*
|
|
60
|
+
* @param excludes - Regular expressions that match file paths to skip.
|
|
61
|
+
* @param fileHeader - Comment block prepended to every generated barrel file.
|
|
62
|
+
* @param selectiveExport - When `true`, use the TypeScript Compiler API
|
|
63
|
+
* to emit named exports instead of wildcard re-exports.
|
|
64
|
+
*/
|
|
10
65
|
constructor(excludes: RegExp[], fileHeader: string, selectiveExport: boolean);
|
|
66
|
+
/**
|
|
67
|
+
* Execute barrel generation for all packages in the current workspace.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
* Reads the workspace, collects barrel groups per package, then builds
|
|
71
|
+
* and persists every barrel file. Package `exports` fields are updated
|
|
72
|
+
* when the set of entry-points changes.
|
|
73
|
+
*
|
|
74
|
+
* @returns A promise that resolves when all barrel files have been written
|
|
75
|
+
* and all `package.json` exports have been updated.
|
|
76
|
+
*/
|
|
11
77
|
run(): Promise<void>;
|
|
12
78
|
protected isExcluded(fileName: string): boolean;
|
|
13
79
|
protected persistBarrel(p: BarrelPersistParams): Promise<BarrelGroup>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barrel.d.ts","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Barrel.d.ts","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AASpC;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAQ7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,yEAC6C,CAAC;AAEzE;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,SAAS,GAAU,QAAQ,YAAY,kBAOnD,CAAC;AAEF;;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AC,IAAI,CAAC;CA+EjB"}
|
package/dist/barrel/Barrel.js
CHANGED
|
@@ -5,8 +5,14 @@ import { initWorkspace, workspace } from "../workspace/Workspace.js";
|
|
|
5
5
|
import { formatCode } from "../code/code.format.js";
|
|
6
6
|
import { fileExportsByFile, fileExportsCompilerApi, } from "../code/code.exports.js";
|
|
7
7
|
import { createSourceFileMap } from "../code/code.common.js";
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Default file patterns excluded from barrel exports.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Matches test files, declaration files, existing barrel index files,
|
|
13
|
+
* script directories, and `4testing` helper directories so they are
|
|
14
|
+
* never re-exported in generated barrel files.
|
|
15
|
+
*/
|
|
10
16
|
export const DEFAULT_EXCLUDED_PATTERNS = [
|
|
11
17
|
/\.test\.ts$/,
|
|
12
18
|
/\.spec\.ts$/,
|
|
@@ -16,21 +22,78 @@ export const DEFAULT_EXCLUDED_PATTERNS = [
|
|
|
16
22
|
/(.+\/|^)src\/(.+\/|)scripts?\/.+\.m?ts$/,
|
|
17
23
|
/\/4testing(\/|$)/,
|
|
18
24
|
];
|
|
19
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Header comment prepended to every generated barrel file.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* Warns consumers that the file is auto-generated and should not be
|
|
30
|
+
* edited by hand.
|
|
31
|
+
*/
|
|
20
32
|
export const DEFAULT_HEADER = "// This file is auto-generated by build-cli. Do not edit manually.\n";
|
|
33
|
+
/**
|
|
34
|
+
* Run barrel-file generation for every package in the workspace.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* This is the main entry point for the barrel command. It initialises the
|
|
38
|
+
* workspace, then delegates to the {@link Barrel} class to collect source
|
|
39
|
+
* files and write barrel (index) files.
|
|
40
|
+
*
|
|
41
|
+
* @param params - Configuration for the barrel generation run.
|
|
42
|
+
* @returns A promise that resolves when all barrel files have been written.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { runBarrel } from "@mxpicture/build-api";
|
|
47
|
+
*
|
|
48
|
+
* await runBarrel({ repoRoot: process.cwd() });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
21
51
|
export const runBarrel = async (params) => {
|
|
22
52
|
initWorkspace(params.repoRoot);
|
|
23
53
|
return new Barrel(params.excludes ?? DEFAULT_EXCLUDED_PATTERNS, params.fileHeader ?? DEFAULT_HEADER, !!params.useCompilerApi).run();
|
|
24
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* Generates and maintains barrel (index) files for workspace packages.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* The generation is split into two phases:
|
|
60
|
+
*
|
|
61
|
+
* 1. **Collect** โ recursively scan each package's `src` directory to build
|
|
62
|
+
* {@link BarrelGroup} instances that describe which files belong together.
|
|
63
|
+
* 2. **Build & Persist** โ optionally create a TypeScript `SourceFile` map for
|
|
64
|
+
* selective exports, then write every barrel file to disk in parallel.
|
|
65
|
+
*
|
|
66
|
+
* After barrels are written the class also updates each package's
|
|
67
|
+
* `package.json` exports map when the set of entry-points has changed.
|
|
68
|
+
*/
|
|
25
69
|
export class Barrel {
|
|
26
70
|
excludes;
|
|
27
71
|
fileHeader;
|
|
28
72
|
selectiveExport;
|
|
73
|
+
/**
|
|
74
|
+
* Create a new Barrel generator.
|
|
75
|
+
*
|
|
76
|
+
* @param excludes - Regular expressions that match file paths to skip.
|
|
77
|
+
* @param fileHeader - Comment block prepended to every generated barrel file.
|
|
78
|
+
* @param selectiveExport - When `true`, use the TypeScript Compiler API
|
|
79
|
+
* to emit named exports instead of wildcard re-exports.
|
|
80
|
+
*/
|
|
29
81
|
constructor(excludes, fileHeader, selectiveExport) {
|
|
30
82
|
this.excludes = excludes;
|
|
31
83
|
this.fileHeader = fileHeader;
|
|
32
84
|
this.selectiveExport = selectiveExport;
|
|
33
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Execute barrel generation for all packages in the current workspace.
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Reads the workspace, collects barrel groups per package, then builds
|
|
91
|
+
* and persists every barrel file. Package `exports` fields are updated
|
|
92
|
+
* when the set of entry-points changes.
|
|
93
|
+
*
|
|
94
|
+
* @returns A promise that resolves when all barrel files have been written
|
|
95
|
+
* and all `package.json` exports have been updated.
|
|
96
|
+
*/
|
|
34
97
|
async run() {
|
|
35
98
|
const ws = workspace();
|
|
36
99
|
await ws.read();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barrel.js","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAO9D,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,yEAAyE;AAEzE,sDAAsD;AACtD,MAAM,CAAC,MAAM,yBAAyB,GAAa;IACjD,aAAa;IACb,aAAa;IACb,uBAAuB;IACvB,UAAU;IACV,YAAY;IACZ,yCAAyC;IACzC,kBAAkB;CACnB,CAAC;AAEF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,cAAc,GACzB,sEAAsE,CAAC;AAEzE,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,MAAoB,EAAE,EAAE;IACtD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1B,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC;gBACpC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;YAE7D,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG;gBACnC,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI;gBACrC,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;aAC5B,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAC1C,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CACnD,CACF,CAAC;IACJ,CAAC;CAmBF","sourcesContent":["import { basename, dirname, join, relative } from \"node:path\";\nimport {\n BarrelGroup,\n BarrelParams,\n BarrelPersistParams,\n BarrelResult,\n} from \"../types/types.barrel.js\";\nimport { readdir, rm, stat, writeFile } from \"node:fs/promises\";\nimport { logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { formatCode } from \"../code/code.format.js\";\nimport {\n fileExportsByFile,\n fileExportsCompilerApi,\n} from \"../code/code.exports.js\";\nimport { createSourceFileMap } from \"../code/code.common.js\";\nimport { FileExportsParams, SourceFile } from \"../types/types.code.js\";\n\n// todo restore old version only using \"export *\" --> make both available\n\n// /** File patterns to exclude from barrel exports */\nexport const DEFAULT_EXCLUDED_PATTERNS: RegExp[] = [\n /\\.test\\.ts$/,\n /\\.spec\\.ts$/,\n /(^|\\/)__tests__(\\/|$)/,\n /\\.d\\.ts$/,\n /index\\.ts$/,\n /(.+\\/|^)src\\/(.+\\/|)scripts?\\/.+\\.m?ts$/,\n /\\/4testing(\\/|$)/,\n];\n\n// /** Header comment added to every generated barrel file */\nexport const DEFAULT_HEADER =\n \"// This file is auto-generated by build-cli. Do not edit manually.\\n\";\n\nexport const runBarrel = async (params: BarrelParams) => {\n initWorkspace(params.repoRoot);\n return new Barrel(\n params.excludes ?? DEFAULT_EXCLUDED_PATTERNS,\n params.fileHeader ?? DEFAULT_HEADER,\n !!params.useCompilerApi,\n ).run();\n};\n\nexport class Barrel {\n public constructor(\n protected readonly excludes: RegExp[],\n protected readonly fileHeader: string,\n protected readonly selectiveExport: boolean,\n ) {}\n\n public async run(): Promise<void> {\n const ws = workspace();\n await ws.read();\n\n // Phase 1: collect all barrel groups, keyed by package name\n const groupsByPkg = await this.collectGroups(ws.packages);\n\n // todo Phase 1.5: find changed files\n\n // Phase 2: build one ts.Program per package, then persist all groups in parallel\n await this.buildAndPersist(groupsByPkg);\n }\n\n protected isExcluded(fileName: string): boolean {\n return this.excludes.some((pattern) => pattern.test(fileName));\n }\n\n protected async persistBarrel(p: BarrelPersistParams): Promise<BarrelGroup> {\n // no files --> skip/delete index.ts\n if (p.group.files.length === 0) {\n await rm(p.group.barrelFilePath, { recursive: true, force: true });\n return p.group;\n }\n\n // todo Skip if all source files are older than the existing barrel\n // if (!(await this.hasGroupChanged(group, group.barrelFilePath)))\n // return group;\n\n const exportLines: string[] = [];\n for (const file of p.group.files.sort()) {\n const filePath = join(p.group.dirPath, file);\n\n const params: FileExportsParams = {\n filePath,\n preBuiltSource: p.sourceFileMap?.get(filePath),\n };\n\n const expResult = this.selectiveExport\n ? fileExportsCompilerApi(params)\n : fileExportsByFile(params);\n\n if (expResult.selectiveExport && expResult.items.length === 0) continue;\n\n const exports = expResult.items.map((item) => item.name);\n const moduleRef = `./${basename(file, \".ts\")}.js`;\n\n if (!expResult.selectiveExport) {\n exportLines.push(`export * from \"${moduleRef}\";`);\n } else if (exports.length > 0) {\n exportLines.push(\n `export { ${exports.join(\", \")} } from \"${moduleRef}\";`,\n );\n }\n }\n\n let content = `${this.fileHeader}${exportLines.length > 0 ? exportLines.join(\"\\n\") + \"\\n\" : \"\"}`;\n content = await formatCode(content);\n await writeFile(p.group.barrelFilePath, content);\n return p.group;\n }\n\n /**\n * Returns true if any source file in the group is newer than the barrel\n * file, or if the barrel file does not yet exist. File deletions are handled\n * implicitly because the group is rebuilt from readdir on every run.\n */\n protected async hasGroupChanged(\n group: BarrelGroup,\n barrelPath: string,\n ): Promise<boolean> {\n let barrelMtime: number;\n try {\n barrelMtime = (await stat(barrelPath)).mtimeMs;\n } catch {\n return true; // barrel doesn't exist yet\n }\n\n for (const file of group.files) {\n try {\n const fileMtime = (await stat(join(group.dirPath, file))).mtimeMs;\n if (fileMtime > barrelMtime) return true;\n } catch {\n return true; // file accessibility changed\n }\n }\n return false;\n }\n\n protected async collectPkgGroups(pkg: Pkg): Promise<BarrelGroup[]> {\n const items = (await readdir(pkg.srcPath, { recursive: true })).sort();\n const groups: BarrelGroup[] = [];\n let currentGroup: BarrelGroup | undefined;\n\n const pushGroup = (g: BarrelGroup) => groups.push({ ...g });\n\n for (const item of items) {\n const filename = basename(item);\n const dirPath = join(pkg.srcPath, dirname(item));\n const filePath = join(dirPath, filename);\n\n if (dirPath !== currentGroup?.dirPath) {\n if (currentGroup) pushGroup(currentGroup);\n currentGroup = {\n dirPath,\n files: [],\n pkg,\n barrelFilePath: join(dirPath, \"index.ts\"),\n barrelExists: false,\n };\n }\n\n if (filename === \"index.ts\") currentGroup.barrelExists = true;\n\n if (\n this.isExcluded(filePath) ||\n (!filename.endsWith(\".ts\") && !filename.endsWith(\".mts\"))\n )\n continue;\n\n currentGroup.files.push(filename);\n }\n\n if (currentGroup) pushGroup(currentGroup);\n return groups;\n }\n\n protected async collectGroups(\n packages: Pkg[],\n ): Promise<Map<string, BarrelGroup[]>> {\n const groupsByPkg = new Map<string, BarrelGroup[]>();\n\n const pushGroup = (g: BarrelGroup) => {\n const key = g.pkg.content.name;\n if (!groupsByPkg.has(key)) groupsByPkg.set(key, []);\n groupsByPkg.get(key)!.push({ ...g });\n };\n\n const results = (\n await Promise.all(packages.map((pkg) => this.collectPkgGroups(pkg)))\n ).flat();\n\n results.map(pushGroup);\n return groupsByPkg;\n }\n\n protected async updatePackageExports(\n pkg: Pkg,\n exports: Record<string, string>,\n ) {\n try {\n // const pkgName = relative(this.paths.workspacesDir, packageDir);\n // // const pkgs = await workspace().loadPackages();\n\n logInfo(`๐ฆ updating ${pkg.repoDirPath} package.json ...`);\n // const pkg = await readPackageJsonThrow(packageJsonPath);\n if (!this.hasExportsChanged(exports, pkg.content.exports)) {\n logInfo(`๐งน No changes in ${pkg.repoDirPath}, nothing to do`);\n return;\n }\n pkg.content.exports = { ...exports };\n await pkg.write();\n logSuccess(`โ
${pkg.repoDirPath} update successful`);\n } catch (error) {\n logInfo(error);\n }\n }\n\n protected hasExportsChanged(\n a: Record<string, string> | undefined,\n b: Record<string, string> | undefined,\n ): boolean {\n if (!a) a = {};\n if (!b) b = {};\n\n if (Object.keys(a).length !== Object.keys(b).length) return true;\n if (!a && !b) return false;\n if (!a || !b) return true;\n\n for (const entryA of Object.entries(a)) {\n if (b[entryA[0]] !== entryA[1]) return true;\n }\n return false;\n }\n\n protected extractExports(result: BarrelResult): Record<string, string> {\n const record: Record<string, string> = {};\n for (const barrelDir of result.barrelDirs) {\n const ex = relative(result.pkg.srcPath, barrelDir);\n record[`./${ex}`] = `./dist/${ex}/index.js`;\n }\n record[\"./package.json\"] = \"./package.json\";\n return record;\n }\n\n protected async buildAndPersist(\n groupsByPkg: Map<string, BarrelGroup[]>,\n ): Promise<void> {\n const promises: Promise<BarrelGroup>[] = [];\n\n for (const groups of groupsByPkg.values()) {\n const allFilePaths = groups.flatMap((g) =>\n g.files.map((f) => join(g.dirPath, f)),\n );\n\n const sourceFileMap: Map<string, SourceFile> | undefined = !this\n .selectiveExport\n ? undefined\n : allFilePaths.length > 0\n ? createSourceFileMap(allFilePaths)\n : new Map<string, SourceFile>();\n\n for (const group of groups) {\n promises.push(\n this.persistBarrel({ group: { ...group }, sourceFileMap }),\n );\n }\n }\n\n const barrelGroups = (await Promise.all(promises)).filter(\n (prom) => prom.files.length > 0,\n );\n\n const results: BarrelResult[] = [];\n\n for (const barrelGroup of barrelGroups) {\n let found = results.find(\n (res) => barrelGroup.dirPath === res.pkg.dirPath,\n );\n if (!found) {\n found = {\n barrelDirs: [],\n pkg: barrelGroup.pkg,\n };\n results.push(found);\n }\n\n found.barrelDirs.push(barrelGroup.dirPath);\n }\n\n const pkgExps: Record<string, { pkg: Pkg; exps: Record<string, string> }> =\n {};\n for (const res of results) {\n if (!(res.pkg.content.name in pkgExps))\n pkgExps[res.pkg.content.name] = { pkg: res.pkg, exps: {} };\n\n pkgExps[res.pkg.content.name].exps = {\n ...pkgExps[res.pkg.content.name].exps,\n ...this.extractExports(res),\n };\n }\n\n await Promise.all(\n Object.values(pkgExps).map(async (pkgExp) =>\n this.updatePackageExports(pkgExp.pkg, pkgExp.exps),\n ),\n );\n }\n\n // protected async persistBarrel(p: BarrelPersistParams): Promise<BarrelGroup> {\n // const barrelPath = join(p.group.dirPath, \"index.ts\");\n // // no files --> skip/delete index.ts\n // if (p.group.files.length === 0) {\n // await rm(barrelPath, { recursive: true, force: true });\n // return p.group;\n // }\n\n // let content = `${this.fileHeader}${p.group.files\n // .sort()\n // .map((f) => `export * from \"./${basename(f, \".ts\")}.js\";`)\n // .join(\"\\n\")}\\n`;\n\n // content = await formatCode(content);\n // await writeFile(barrelPath, content);\n // return p.group;\n // }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Barrel.js","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EA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AAC,GAAG,CAAC;aAC5B,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAC1C,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CACnD,CACF,CAAC;IACJ,CAAC;CAmBF","sourcesContent":["import { basename, dirname, join, relative } from \"node:path\";\nimport {\n BarrelGroup,\n BarrelParams,\n BarrelPersistParams,\n BarrelResult,\n} from \"../types/types.barrel.js\";\nimport { readdir, rm, stat, writeFile } from \"node:fs/promises\";\nimport { logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { formatCode } from \"../code/code.format.js\";\nimport {\n fileExportsByFile,\n fileExportsCompilerApi,\n} from \"../code/code.exports.js\";\nimport { createSourceFileMap } from \"../code/code.common.js\";\nimport { FileExportsParams, SourceFile } from \"../types/types.code.js\";\n\n/**\n * Default file patterns excluded from barrel exports.\n *\n * @remarks\n * Matches test files, declaration files, existing barrel index files,\n * script directories, and `4testing` helper directories so they are\n * never re-exported in generated barrel files.\n */\nexport const DEFAULT_EXCLUDED_PATTERNS: RegExp[] = [\n /\\.test\\.ts$/,\n /\\.spec\\.ts$/,\n /(^|\\/)__tests__(\\/|$)/,\n /\\.d\\.ts$/,\n /index\\.ts$/,\n /(.+\\/|^)src\\/(.+\\/|)scripts?\\/.+\\.m?ts$/,\n /\\/4testing(\\/|$)/,\n];\n\n/**\n * Header comment prepended to every generated barrel file.\n *\n * @remarks\n * Warns consumers that the file is auto-generated and should not be\n * edited by hand.\n */\nexport const DEFAULT_HEADER =\n \"// This file is auto-generated by build-cli. Do not edit manually.\\n\";\n\n/**\n * Run barrel-file generation for every package in the workspace.\n *\n * @remarks\n * This is the main entry point for the barrel command. It initialises the\n * workspace, then delegates to the {@link Barrel} class to collect source\n * files and write barrel (index) files.\n *\n * @param params - Configuration for the barrel generation run.\n * @returns A promise that resolves when all barrel files have been written.\n *\n * @example\n * ```ts\n * import { runBarrel } from \"@mxpicture/build-api\";\n *\n * await runBarrel({ repoRoot: process.cwd() });\n * ```\n */\nexport const runBarrel = async (params: BarrelParams) => {\n initWorkspace(params.repoRoot);\n return new Barrel(\n params.excludes ?? DEFAULT_EXCLUDED_PATTERNS,\n params.fileHeader ?? DEFAULT_HEADER,\n !!params.useCompilerApi,\n ).run();\n};\n\n/**\n * Generates and maintains barrel (index) files for workspace packages.\n *\n * @remarks\n * The generation is split into two phases:\n *\n * 1. **Collect** โ recursively scan each package's `src` directory to build\n * {@link BarrelGroup} instances that describe which files belong together.\n * 2. **Build & Persist** โ optionally create a TypeScript `SourceFile` map for\n * selective exports, then write every barrel file to disk in parallel.\n *\n * After barrels are written the class also updates each package's\n * `package.json` exports map when the set of entry-points has changed.\n */\nexport class Barrel {\n /**\n * Create a new Barrel generator.\n *\n * @param excludes - Regular expressions that match file paths to skip.\n * @param fileHeader - Comment block prepended to every generated barrel file.\n * @param selectiveExport - When `true`, use the TypeScript Compiler API\n * to emit named exports instead of wildcard re-exports.\n */\n public constructor(\n protected readonly excludes: RegExp[],\n protected readonly fileHeader: string,\n protected readonly selectiveExport: boolean,\n ) {}\n\n /**\n * Execute barrel generation for all packages in the current workspace.\n *\n * @remarks\n * Reads the workspace, collects barrel groups per package, then builds\n * and persists every barrel file. Package `exports` fields are updated\n * when the set of entry-points changes.\n *\n * @returns A promise that resolves when all barrel files have been written\n * and all `package.json` exports have been updated.\n */\n public async run(): Promise<void> {\n const ws = workspace();\n await ws.read();\n\n // Phase 1: collect all barrel groups, keyed by package name\n const groupsByPkg = await this.collectGroups(ws.packages);\n\n // todo Phase 1.5: find changed files\n\n // Phase 2: build one ts.Program per package, then persist all groups in parallel\n await this.buildAndPersist(groupsByPkg);\n }\n\n protected isExcluded(fileName: string): boolean {\n return this.excludes.some((pattern) => pattern.test(fileName));\n }\n\n protected async persistBarrel(p: BarrelPersistParams): Promise<BarrelGroup> {\n // no files --> skip/delete index.ts\n if (p.group.files.length === 0) {\n await rm(p.group.barrelFilePath, { recursive: true, force: true });\n return p.group;\n }\n\n // todo Skip if all source files are older than the existing barrel\n // if (!(await this.hasGroupChanged(group, group.barrelFilePath)))\n // return group;\n\n const exportLines: string[] = [];\n for (const file of p.group.files.sort()) {\n const filePath = join(p.group.dirPath, file);\n\n const params: FileExportsParams = {\n filePath,\n preBuiltSource: p.sourceFileMap?.get(filePath),\n };\n\n const expResult = this.selectiveExport\n ? fileExportsCompilerApi(params)\n : fileExportsByFile(params);\n\n if (expResult.selectiveExport && expResult.items.length === 0) continue;\n\n const exports = expResult.items.map((item) => item.name);\n const moduleRef = `./${basename(file, \".ts\")}.js`;\n\n if (!expResult.selectiveExport) {\n exportLines.push(`export * from \"${moduleRef}\";`);\n } else if (exports.length > 0) {\n exportLines.push(\n `export { ${exports.join(\", \")} } from \"${moduleRef}\";`,\n );\n }\n }\n\n let content = `${this.fileHeader}${exportLines.length > 0 ? exportLines.join(\"\\n\") + \"\\n\" : \"\"}`;\n content = await formatCode(content);\n await writeFile(p.group.barrelFilePath, content);\n return p.group;\n }\n\n /**\n * Returns true if any source file in the group is newer than the barrel\n * file, or if the barrel file does not yet exist. File deletions are handled\n * implicitly because the group is rebuilt from readdir on every run.\n */\n protected async hasGroupChanged(\n group: BarrelGroup,\n barrelPath: string,\n ): Promise<boolean> {\n let barrelMtime: number;\n try {\n barrelMtime = (await stat(barrelPath)).mtimeMs;\n } catch {\n return true; // barrel doesn't exist yet\n }\n\n for (const file of group.files) {\n try {\n const fileMtime = (await stat(join(group.dirPath, file))).mtimeMs;\n if (fileMtime > barrelMtime) return true;\n } catch {\n return true; // file accessibility changed\n }\n }\n return false;\n }\n\n protected async collectPkgGroups(pkg: Pkg): Promise<BarrelGroup[]> {\n const items = (await readdir(pkg.srcPath, { recursive: true })).sort();\n const groups: BarrelGroup[] = [];\n let currentGroup: BarrelGroup | undefined;\n\n const pushGroup = (g: BarrelGroup) => groups.push({ ...g });\n\n for (const item of items) {\n const filename = basename(item);\n const dirPath = join(pkg.srcPath, dirname(item));\n const filePath = join(dirPath, filename);\n\n if (dirPath !== currentGroup?.dirPath) {\n if (currentGroup) pushGroup(currentGroup);\n currentGroup = {\n dirPath,\n files: [],\n pkg,\n barrelFilePath: join(dirPath, \"index.ts\"),\n barrelExists: false,\n };\n }\n\n if (filename === \"index.ts\") currentGroup.barrelExists = true;\n\n if (\n this.isExcluded(filePath) ||\n (!filename.endsWith(\".ts\") && !filename.endsWith(\".mts\"))\n )\n continue;\n\n currentGroup.files.push(filename);\n }\n\n if (currentGroup) pushGroup(currentGroup);\n return groups;\n }\n\n protected async collectGroups(\n packages: Pkg[],\n ): Promise<Map<string, BarrelGroup[]>> {\n const groupsByPkg = new Map<string, BarrelGroup[]>();\n\n const pushGroup = (g: BarrelGroup) => {\n const key = g.pkg.content.name;\n if (!groupsByPkg.has(key)) groupsByPkg.set(key, []);\n groupsByPkg.get(key)!.push({ ...g });\n };\n\n const results = (\n await Promise.all(packages.map((pkg) => this.collectPkgGroups(pkg)))\n ).flat();\n\n results.map(pushGroup);\n return groupsByPkg;\n }\n\n protected async updatePackageExports(\n pkg: Pkg,\n exports: Record<string, string>,\n ) {\n try {\n // const pkgName = relative(this.paths.workspacesDir, packageDir);\n // // const pkgs = await workspace().loadPackages();\n\n logInfo(`๐ฆ updating ${pkg.repoDirPath} package.json ...`);\n // const pkg = await readPackageJsonThrow(packageJsonPath);\n if (!this.hasExportsChanged(exports, pkg.content.exports)) {\n logInfo(`๐งน No changes in ${pkg.repoDirPath}, nothing to do`);\n return;\n }\n pkg.content.exports = { ...exports };\n await pkg.write();\n logSuccess(`โ
${pkg.repoDirPath} update successful`);\n } catch (error) {\n logInfo(error);\n }\n }\n\n protected hasExportsChanged(\n a: Record<string, string> | undefined,\n b: Record<string, string> | undefined,\n ): boolean {\n if (!a) a = {};\n if (!b) b = {};\n\n if (Object.keys(a).length !== Object.keys(b).length) return true;\n if (!a && !b) return false;\n if (!a || !b) return true;\n\n for (const entryA of Object.entries(a)) {\n if (b[entryA[0]] !== entryA[1]) return true;\n }\n return false;\n }\n\n protected extractExports(result: BarrelResult): Record<string, string> {\n const record: Record<string, string> = {};\n for (const barrelDir of result.barrelDirs) {\n const ex = relative(result.pkg.srcPath, barrelDir);\n record[`./${ex}`] = `./dist/${ex}/index.js`;\n }\n record[\"./package.json\"] = \"./package.json\";\n return record;\n }\n\n protected async buildAndPersist(\n groupsByPkg: Map<string, BarrelGroup[]>,\n ): Promise<void> {\n const promises: Promise<BarrelGroup>[] = [];\n\n for (const groups of groupsByPkg.values()) {\n const allFilePaths = groups.flatMap((g) =>\n g.files.map((f) => join(g.dirPath, f)),\n );\n\n const sourceFileMap: Map<string, SourceFile> | undefined = !this\n .selectiveExport\n ? undefined\n : allFilePaths.length > 0\n ? createSourceFileMap(allFilePaths)\n : new Map<string, SourceFile>();\n\n for (const group of groups) {\n promises.push(\n this.persistBarrel({ group: { ...group }, sourceFileMap }),\n );\n }\n }\n\n const barrelGroups = (await Promise.all(promises)).filter(\n (prom) => prom.files.length > 0,\n );\n\n const results: BarrelResult[] = [];\n\n for (const barrelGroup of barrelGroups) {\n let found = results.find(\n (res) => barrelGroup.dirPath === res.pkg.dirPath,\n );\n if (!found) {\n found = {\n barrelDirs: [],\n pkg: barrelGroup.pkg,\n };\n results.push(found);\n }\n\n found.barrelDirs.push(barrelGroup.dirPath);\n }\n\n const pkgExps: Record<string, { pkg: Pkg; exps: Record<string, string> }> =\n {};\n for (const res of results) {\n if (!(res.pkg.content.name in pkgExps))\n pkgExps[res.pkg.content.name] = { pkg: res.pkg, exps: {} };\n\n pkgExps[res.pkg.content.name].exps = {\n ...pkgExps[res.pkg.content.name].exps,\n ...this.extractExports(res),\n };\n }\n\n await Promise.all(\n Object.values(pkgExps).map(async (pkgExp) =>\n this.updatePackageExports(pkgExp.pkg, pkgExp.exps),\n ),\n );\n }\n\n // protected async persistBarrel(p: BarrelPersistParams): Promise<BarrelGroup> {\n // const barrelPath = join(p.group.dirPath, \"index.ts\");\n // // no files --> skip/delete index.ts\n // if (p.group.files.length === 0) {\n // await rm(barrelPath, { recursive: true, force: true });\n // return p.group;\n // }\n\n // let content = `${this.fileHeader}${p.group.files\n // .sort()\n // .map((f) => `export * from \"./${basename(f, \".ts\")}.js\";`)\n // .join(\"\\n\")}\\n`;\n\n // content = await formatCode(content);\n // await writeFile(barrelPath, content);\n // return p.group;\n // }\n}\n"]}
|
|
@@ -1,11 +1,81 @@
|
|
|
1
1
|
import { CleanupParams, ToBeDeleted, ToCleanup } from "../types/types.cleanup.js";
|
|
2
|
+
/**
|
|
3
|
+
* Run the cleanup operation across all workspace packages.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This is the main entry point for the cleanup command. It initialises the
|
|
7
|
+
* workspace, then delegates to the {@link Cleanup} class to resolve and
|
|
8
|
+
* remove the configured targets.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Configuration for the cleanup run, including which items
|
|
11
|
+
* to delete and the repository root path.
|
|
12
|
+
* @returns A promise that resolves when all items have been cleaned up.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { runCleanup } from "@mxpicture/build-api";
|
|
17
|
+
*
|
|
18
|
+
* await runCleanup({ repoRoot: process.cwd() });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
2
21
|
export declare const runCleanup: (params: CleanupParams) => Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Removes build artifacts and temporary directories from workspace packages.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* For each configured target the class supports two strategies:
|
|
27
|
+
*
|
|
28
|
+
* - **Direct removal** โ delete the item immediately via `rm -rf`.
|
|
29
|
+
* - **Move-then-remove** โ rename the item first (appending a suffix) so the
|
|
30
|
+
* directory is freed instantly, then delete the renamed copy asynchronously.
|
|
31
|
+
*
|
|
32
|
+
* The move strategy is useful for large directories like `node_modules` where
|
|
33
|
+
* an immediate `rm -rf` would block the event loop for a noticeable duration.
|
|
34
|
+
*/
|
|
3
35
|
export declare class Cleanup {
|
|
4
36
|
protected readonly toBeDeleted: ToBeDeleted[];
|
|
37
|
+
/**
|
|
38
|
+
* Create a new Cleanup instance.
|
|
39
|
+
*
|
|
40
|
+
* @param toBeDeleted - Items to remove from every workspace package and the
|
|
41
|
+
* repository root.
|
|
42
|
+
*/
|
|
5
43
|
constructor(toBeDeleted: ToBeDeleted[]);
|
|
44
|
+
/**
|
|
45
|
+
* Execute the full cleanup: read targets then remove them.
|
|
46
|
+
*
|
|
47
|
+
* @returns A promise that resolves when every target has been cleaned up.
|
|
48
|
+
*/
|
|
6
49
|
run(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Resolve cleanup targets for every workspace package and the repo root.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Reads the workspace to discover all packages, then maps each configured
|
|
55
|
+
* {@link ToBeDeleted} entry to a fully-resolved {@link ToCleanup} with
|
|
56
|
+
* absolute paths.
|
|
57
|
+
*
|
|
58
|
+
* @returns An array of resolved cleanup targets.
|
|
59
|
+
*/
|
|
7
60
|
read(): Promise<ToCleanup[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Remove all resolved cleanup targets in parallel.
|
|
63
|
+
*
|
|
64
|
+
* @param toCleanups - Resolved targets to remove.
|
|
65
|
+
* @returns A promise that resolves when every target has been processed.
|
|
66
|
+
*/
|
|
8
67
|
cleanup(toCleanups: ToCleanup[]): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Clean up a single target, using the move-then-remove strategy when a
|
|
70
|
+
* {@link ToCleanup.moveTo | moveTo} path is configured.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* When `moveTo` is set the item is renamed first so the original path is
|
|
74
|
+
* freed immediately. The actual deletion of the renamed copy happens
|
|
75
|
+
* asynchronously (fire-and-forget) to avoid blocking.
|
|
76
|
+
*
|
|
77
|
+
* @param toCleanup - The resolved cleanup target to process.
|
|
78
|
+
*/
|
|
9
79
|
cleanupSingle(toCleanup: ToCleanup): Promise<void>;
|
|
10
80
|
protected buildRemovePaths(basePath: string): ToCleanup[];
|
|
11
81
|
protected move(toCleanup: ToCleanup): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cleanup.d.ts","sourceRoot":"","sources":["../../src/cleanup/Cleanup.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,WAAW,EACX,SAAS,EACV,MAAM,2BAA2B,CAAC;AAanC,eAAO,MAAM,UAAU,GAAU,QAAQ,aAAa,kBAGrD,CAAC;AAEF,qBAAa,OAAO;
|
|
1
|
+
{"version":3,"file":"Cleanup.d.ts","sourceRoot":"","sources":["../../src/cleanup/Cleanup.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,WAAW,EACX,SAAS,EACV,MAAM,2BAA2B,CAAC;AAanC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,GAAU,QAAQ,aAAa,kBAGrD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,qBAAa,OAAO;IAOC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE;IANhE;;;;;OAKG;gBACmC,WAAW,EAAE,WAAW,EAAE;IAEhE;;;;OAIG;IACU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;;;;;;;;OASG;IACU,IAAI,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAUzC;;;;;OAKG;IACU,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;;;;;;;;;OAUG;IACU,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B/D,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE;cAWzC,IAAI,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;cAIzC,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAM5D"}
|
package/dist/cleanup/Cleanup.js
CHANGED
|
@@ -9,19 +9,72 @@ const DEFAULT_TO_BE_DELETED = [
|
|
|
9
9
|
{ name: "tsconfig.tsbuildinfo" },
|
|
10
10
|
{ name: ".tsbuildinfo" },
|
|
11
11
|
];
|
|
12
|
+
/**
|
|
13
|
+
* Run the cleanup operation across all workspace packages.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* This is the main entry point for the cleanup command. It initialises the
|
|
17
|
+
* workspace, then delegates to the {@link Cleanup} class to resolve and
|
|
18
|
+
* remove the configured targets.
|
|
19
|
+
*
|
|
20
|
+
* @param params - Configuration for the cleanup run, including which items
|
|
21
|
+
* to delete and the repository root path.
|
|
22
|
+
* @returns A promise that resolves when all items have been cleaned up.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { runCleanup } from "@mxpicture/build-api";
|
|
27
|
+
*
|
|
28
|
+
* await runCleanup({ repoRoot: process.cwd() });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
12
31
|
export const runCleanup = async (params) => {
|
|
13
32
|
initWorkspace(params.repoRoot);
|
|
14
33
|
return new Cleanup(params.toBeDeleted ?? DEFAULT_TO_BE_DELETED).run();
|
|
15
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Removes build artifacts and temporary directories from workspace packages.
|
|
37
|
+
*
|
|
38
|
+
* @remarks
|
|
39
|
+
* For each configured target the class supports two strategies:
|
|
40
|
+
*
|
|
41
|
+
* - **Direct removal** โ delete the item immediately via `rm -rf`.
|
|
42
|
+
* - **Move-then-remove** โ rename the item first (appending a suffix) so the
|
|
43
|
+
* directory is freed instantly, then delete the renamed copy asynchronously.
|
|
44
|
+
*
|
|
45
|
+
* The move strategy is useful for large directories like `node_modules` where
|
|
46
|
+
* an immediate `rm -rf` would block the event loop for a noticeable duration.
|
|
47
|
+
*/
|
|
16
48
|
export class Cleanup {
|
|
17
49
|
toBeDeleted;
|
|
50
|
+
/**
|
|
51
|
+
* Create a new Cleanup instance.
|
|
52
|
+
*
|
|
53
|
+
* @param toBeDeleted - Items to remove from every workspace package and the
|
|
54
|
+
* repository root.
|
|
55
|
+
*/
|
|
18
56
|
constructor(toBeDeleted) {
|
|
19
57
|
this.toBeDeleted = toBeDeleted;
|
|
20
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Execute the full cleanup: read targets then remove them.
|
|
61
|
+
*
|
|
62
|
+
* @returns A promise that resolves when every target has been cleaned up.
|
|
63
|
+
*/
|
|
21
64
|
async run() {
|
|
22
65
|
const items = await this.read();
|
|
23
66
|
return this.cleanup(items);
|
|
24
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve cleanup targets for every workspace package and the repo root.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* Reads the workspace to discover all packages, then maps each configured
|
|
73
|
+
* {@link ToBeDeleted} entry to a fully-resolved {@link ToCleanup} with
|
|
74
|
+
* absolute paths.
|
|
75
|
+
*
|
|
76
|
+
* @returns An array of resolved cleanup targets.
|
|
77
|
+
*/
|
|
25
78
|
async read() {
|
|
26
79
|
const ws = workspace();
|
|
27
80
|
await ws.read();
|
|
@@ -29,9 +82,26 @@ export class Cleanup {
|
|
|
29
82
|
const toCleanups = this.buildRemovePaths(workspace().repoRoot);
|
|
30
83
|
return [...toCleanups, ...toCleanupsTmp];
|
|
31
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Remove all resolved cleanup targets in parallel.
|
|
87
|
+
*
|
|
88
|
+
* @param toCleanups - Resolved targets to remove.
|
|
89
|
+
* @returns A promise that resolves when every target has been processed.
|
|
90
|
+
*/
|
|
32
91
|
async cleanup(toCleanups) {
|
|
33
92
|
await Promise.all(toCleanups.map(async (x) => this.cleanupSingle(x)));
|
|
34
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Clean up a single target, using the move-then-remove strategy when a
|
|
96
|
+
* {@link ToCleanup.moveTo | moveTo} path is configured.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* When `moveTo` is set the item is renamed first so the original path is
|
|
100
|
+
* freed immediately. The actual deletion of the renamed copy happens
|
|
101
|
+
* asynchronously (fire-and-forget) to avoid blocking.
|
|
102
|
+
*
|
|
103
|
+
* @param toCleanup - The resolved cleanup target to process.
|
|
104
|
+
*/
|
|
35
105
|
async cleanupSingle(toCleanup) {
|
|
36
106
|
logInfo(`๐งน Cleanup started ${toCleanup.name} ...`);
|
|
37
107
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cleanup.js","sourceRoot":"","sources":["../../src/cleanup/Cleanup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAM9C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAErE,uFAAuF;AACvF,MAAM,qBAAqB,GAAkB;IAC3C,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE;IAC5C,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE;IACpC,EAAE,IAAI,EAAE,sBAAsB,EAAE;IAChC,EAAE,IAAI,EAAE,cAAc,EAAE;CACzB,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,MAAqB,EAAE,EAAE;IACxD,aAAa,CAAC,MAAM,CAAC,QAAQ,CA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,CAAC;CACF","sourcesContent":["import { rename, rm } from \"node:fs/promises\";\nimport {\n CleanupParams,\n ToBeDeleted,\n ToCleanup,\n} from \"../types/types.cleanup.js\";\nimport { join } from \"node:path\";\nimport { logError, logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\n\n// moveSuffix: e.g. mv node_modules node_modules_tmp && rm -rf node_modules_tmp (async)\nconst DEFAULT_TO_BE_DELETED: ToBeDeleted[] = [\n { name: \"node_modules\", moveSuffix: \"_tmp\" },\n { name: \"dist\", moveSuffix: \"_tmp\" },\n { name: \"tsconfig.tsbuildinfo\" },\n { name: \".tsbuildinfo\" },\n];\n\n/**\n * Run the cleanup operation across all workspace packages.\n *\n * @remarks\n * This is the main entry point for the cleanup command. It initialises the\n * workspace, then delegates to the {@link Cleanup} class to resolve and\n * remove the configured targets.\n *\n * @param params - Configuration for the cleanup run, including which items\n * to delete and the repository root path.\n * @returns A promise that resolves when all items have been cleaned up.\n *\n * @example\n * ```ts\n * import { runCleanup } from \"@mxpicture/build-api\";\n *\n * await runCleanup({ repoRoot: process.cwd() });\n * ```\n */\nexport const runCleanup = async (params: CleanupParams) => {\n initWorkspace(params.repoRoot);\n return new Cleanup(params.toBeDeleted ?? DEFAULT_TO_BE_DELETED).run();\n};\n\n/**\n * Removes build artifacts and temporary directories from workspace packages.\n *\n * @remarks\n * For each configured target the class supports two strategies:\n *\n * - **Direct removal** โ delete the item immediately via `rm -rf`.\n * - **Move-then-remove** โ rename the item first (appending a suffix) so the\n * directory is freed instantly, then delete the renamed copy asynchronously.\n *\n * The move strategy is useful for large directories like `node_modules` where\n * an immediate `rm -rf` would block the event loop for a noticeable duration.\n */\nexport class Cleanup {\n /**\n * Create a new Cleanup instance.\n *\n * @param toBeDeleted - Items to remove from every workspace package and the\n * repository root.\n */\n public constructor(protected readonly toBeDeleted: ToBeDeleted[]) {}\n\n /**\n * Execute the full cleanup: read targets then remove them.\n *\n * @returns A promise that resolves when every target has been cleaned up.\n */\n public async run(): Promise<void> {\n const items = await this.read();\n return this.cleanup(items);\n }\n\n /**\n * Resolve cleanup targets for every workspace package and the repo root.\n *\n * @remarks\n * Reads the workspace to discover all packages, then maps each configured\n * {@link ToBeDeleted} entry to a fully-resolved {@link ToCleanup} with\n * absolute paths.\n *\n * @returns An array of resolved cleanup targets.\n */\n public async read(): Promise<ToCleanup[]> {\n const ws = workspace();\n await ws.read();\n const toCleanupsTmp = ws.packages.flatMap((pkg) =>\n this.buildRemovePaths(pkg.dirPath),\n );\n const toCleanups = this.buildRemovePaths(workspace().repoRoot);\n return [...toCleanups, ...toCleanupsTmp];\n }\n\n /**\n * Remove all resolved cleanup targets in parallel.\n *\n * @param toCleanups - Resolved targets to remove.\n * @returns A promise that resolves when every target has been processed.\n */\n public async cleanup(toCleanups: ToCleanup[]): Promise<void> {\n await Promise.all(toCleanups.map(async (x) => this.cleanupSingle(x)));\n }\n\n /**\n * Clean up a single target, using the move-then-remove strategy when a\n * {@link ToCleanup.moveTo | moveTo} path is configured.\n *\n * @remarks\n * When `moveTo` is set the item is renamed first so the original path is\n * freed immediately. The actual deletion of the renamed copy happens\n * asynchronously (fire-and-forget) to avoid blocking.\n *\n * @param toCleanup - The resolved cleanup target to process.\n */\n public async cleanupSingle(toCleanup: ToCleanup): Promise<void> {\n logInfo(`๐งน Cleanup started ${toCleanup.name} ...`);\n try {\n if (!toCleanup.moveTo) {\n await this.remove(toCleanup);\n logSuccess(`โ
${toCleanup.name} removed sucessfully`);\n return;\n }\n\n logInfo(\n `๐ฆ Moving ${toCleanup.name} to ${toCleanup.name}${toCleanup.moveSuffix}`,\n );\n await this.move(toCleanup);\n\n logInfo(\n `๐ฆ Start async removing ${toCleanup.name} (${toCleanup.name}${toCleanup.moveSuffix})`,\n );\n\n this.remove(toCleanup)\n .then(() =>\n logSuccess(`โ
${toCleanup.name} (async) removed sucessfully`),\n )\n .catch((e) => {\n logError(`โ Removing ${toCleanup.name} (async) failed ${e}`);\n });\n } catch (error) {\n logError(`โ Removing ${toCleanup.name} failed ${error}`);\n }\n }\n\n protected buildRemovePaths(basePath: string): ToCleanup[] {\n return this.toBeDeleted.map((d) => {\n const path = join(basePath, d.name);\n return {\n ...d,\n path,\n moveTo: d.moveSuffix ? `${path}${d.moveSuffix}` : undefined,\n };\n });\n }\n\n protected async move(toCleanup: ToCleanup): Promise<void> {\n if (toCleanup.moveTo) return rename(toCleanup.path, toCleanup.moveTo);\n }\n\n protected async remove(toCleanup: ToCleanup): Promise<void> {\n return rm(toCleanup.moveTo ?? toCleanup.path, {\n force: true,\n recursive: true,\n });\n }\n}\n"]}
|
|
@@ -1,13 +1,46 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { SourceFile } from "../types/types.code.js";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a TypeScript program and returns an array of {@link SourceFile} entries.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A new `ts.Program` is created for every call. When you need to process many
|
|
8
|
+
* files, prefer {@link createSourceFileMap} which is more efficient because the
|
|
9
|
+
* compiler is only instantiated once and results are keyed by path.
|
|
10
|
+
*
|
|
11
|
+
* @param filePaths - Absolute paths to the TypeScript source files to load.
|
|
12
|
+
* @returns An array of successfully parsed {@link SourceFile} entries.
|
|
13
|
+
*/
|
|
3
14
|
export declare const createSourceFiles: (filePaths: string[]) => SourceFile[];
|
|
4
15
|
/**
|
|
5
|
-
* Creates a single
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
16
|
+
* Creates a single TypeScript program and returns a map from file path to {@link SourceFile}.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* This is more efficient than {@link createSourceFiles} when processing many
|
|
20
|
+
* files, because the TypeScript compiler is only instantiated once and the
|
|
21
|
+
* results are keyed by path for O(1) lookup.
|
|
22
|
+
*
|
|
23
|
+
* @param filePaths - Absolute paths to the TypeScript source files to load.
|
|
24
|
+
* @returns A map keyed by file path whose values are the parsed {@link SourceFile} entries.
|
|
9
25
|
*/
|
|
10
26
|
export declare const createSourceFileMap: (filePaths: string[]) => Map<string, SourceFile>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the human-readable syntax-kind name for a TypeScript declaration node.
|
|
29
|
+
*
|
|
30
|
+
* @param d - The TypeScript declaration node to inspect.
|
|
31
|
+
* @returns The name of the declaration's {@link ts.SyntaxKind}, or `"Unknown"` if unmapped.
|
|
32
|
+
*/
|
|
11
33
|
export declare const declarationKindName: (d: ts.Declaration) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Infers a human-readable kind label from a symbol's flags.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* The mapping is approximate โ it checks flags in priority order and returns
|
|
39
|
+
* the first match. This is sufficient for reporting purposes but may not
|
|
40
|
+
* capture every nuance of the TypeScript symbol model.
|
|
41
|
+
*
|
|
42
|
+
* @param sym - The TypeScript symbol whose kind should be inferred.
|
|
43
|
+
* @returns A lowercase label such as `"function"`, `"class"`, or `"unknown"`.
|
|
44
|
+
*/
|
|
12
45
|
export declare const guessKindFromFlags: (sym: ts.Symbol) => string;
|
|
13
46
|
//# sourceMappingURL=code.common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.common.d.ts","sourceRoot":"","sources":["../../src/code/code.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,KAAG,UAAU,EAgBjE,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"code.common.d.ts","sourceRoot":"","sources":["../../src/code/code.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,KAAG,UAAU,EAgBjE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,MAAM,EAAE,KAClB,GAAG,CAAC,MAAM,EAAE,UAAU,CAcxB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,GAAG,EAAE,CAAC,WAAW,WACjB,CAAC;AAErC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,EAAE,CAAC,MAAM,KAAG,MAYnD,CAAC"}
|
package/dist/code/code.common.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a TypeScript program and returns an array of {@link SourceFile} entries.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* A new `ts.Program` is created for every call. When you need to process many
|
|
7
|
+
* files, prefer {@link createSourceFileMap} which is more efficient because the
|
|
8
|
+
* compiler is only instantiated once and results are keyed by path.
|
|
9
|
+
*
|
|
10
|
+
* @param filePaths - Absolute paths to the TypeScript source files to load.
|
|
11
|
+
* @returns An array of successfully parsed {@link SourceFile} entries.
|
|
12
|
+
*/
|
|
2
13
|
export const createSourceFiles = (filePaths) => {
|
|
3
14
|
const program = ts.createProgram(filePaths, {
|
|
4
15
|
target: ts.ScriptTarget.ES2023,
|
|
@@ -16,10 +27,15 @@ export const createSourceFiles = (filePaths) => {
|
|
|
16
27
|
return results;
|
|
17
28
|
};
|
|
18
29
|
/**
|
|
19
|
-
* Creates a single
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
30
|
+
* Creates a single TypeScript program and returns a map from file path to {@link SourceFile}.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* This is more efficient than {@link createSourceFiles} when processing many
|
|
34
|
+
* files, because the TypeScript compiler is only instantiated once and the
|
|
35
|
+
* results are keyed by path for O(1) lookup.
|
|
36
|
+
*
|
|
37
|
+
* @param filePaths - Absolute paths to the TypeScript source files to load.
|
|
38
|
+
* @returns A map keyed by file path whose values are the parsed {@link SourceFile} entries.
|
|
23
39
|
*/
|
|
24
40
|
export const createSourceFileMap = (filePaths) => {
|
|
25
41
|
const program = ts.createProgram(filePaths, {
|
|
@@ -37,7 +53,24 @@ export const createSourceFileMap = (filePaths) => {
|
|
|
37
53
|
}
|
|
38
54
|
return map;
|
|
39
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Returns the human-readable syntax-kind name for a TypeScript declaration node.
|
|
58
|
+
*
|
|
59
|
+
* @param d - The TypeScript declaration node to inspect.
|
|
60
|
+
* @returns The name of the declaration's {@link ts.SyntaxKind}, or `"Unknown"` if unmapped.
|
|
61
|
+
*/
|
|
40
62
|
export const declarationKindName = (d) => ts.SyntaxKind[d.kind] ?? "Unknown";
|
|
63
|
+
/**
|
|
64
|
+
* Infers a human-readable kind label from a symbol's flags.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* The mapping is approximate โ it checks flags in priority order and returns
|
|
68
|
+
* the first match. This is sufficient for reporting purposes but may not
|
|
69
|
+
* capture every nuance of the TypeScript symbol model.
|
|
70
|
+
*
|
|
71
|
+
* @param sym - The TypeScript symbol whose kind should be inferred.
|
|
72
|
+
* @returns A lowercase label such as `"function"`, `"class"`, or `"unknown"`.
|
|
73
|
+
*/
|
|
41
74
|
export const guessKindFromFlags = (sym) => {
|
|
42
75
|
// Not perfect, but good enough for reporting.
|
|
43
76
|
const f = sym.getFlags();
|