@mxpicture/build-api 0.2.56 → 0.2.58
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 -2
- 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 +33 -0
- package/dist/common/common.json.d.ts.map +1 -1
- package/dist/common/common.json.js +45 -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/ExportExtractor.d.ts +44 -0
- package/dist/pkg/ExportExtractor.d.ts.map +1 -0
- package/dist/pkg/ExportExtractor.js +180 -0
- package/dist/pkg/ExportExtractor.js.map +1 -0
- 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/index.d.ts +1 -0
- package/dist/pkg/index.d.ts.map +1 -1
- package/dist/pkg/index.js +1 -0
- package/dist/pkg/index.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 +57 -5
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.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.exports.d.ts +42 -0
- package/dist/types/types.exports.d.ts.map +1 -0
- package/dist/types/types.exports.js +2 -0
- package/dist/types/types.exports.js.map +1 -0
- 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 +28 -3
- 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 +23 -3
- 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 +19 -2
- 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 +3 -1
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
|
-
import json5 from "json5";
|
|
3
2
|
import { dirname } from "node:path";
|
|
3
|
+
import { jsonParse } from "../common/common.json.js";
|
|
4
4
|
const __workspaces = {};
|
|
5
|
+
/**
|
|
6
|
+
* Reads and returns a parsed VS Code `.code-workspace` file.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* The result is cached per `workspaceFile` path. A shallow copy is returned
|
|
10
|
+
* so that callers cannot mutate the cached object.
|
|
11
|
+
*
|
|
12
|
+
* @param workspaceFile - Absolute path to the `.code-workspace` file.
|
|
13
|
+
* @returns A promise that resolves to a shallow copy of the parsed
|
|
14
|
+
* {@link VSCodeWorkspace}.
|
|
15
|
+
*/
|
|
5
16
|
export const vscodeWorkspace = async (workspaceFile) => {
|
|
6
17
|
let found = __workspaces[workspaceFile];
|
|
7
18
|
if (!found) {
|
|
8
19
|
const raw = await readFile(workspaceFile, "utf-8");
|
|
9
|
-
found =
|
|
20
|
+
found = jsonParse(raw);
|
|
10
21
|
__workspaces[workspaceFile] = found;
|
|
11
22
|
}
|
|
12
23
|
return { ...found };
|
|
13
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Returns the directory that contains the given workspace file.
|
|
27
|
+
*
|
|
28
|
+
* @param workspaceFile - Absolute path to the `.code-workspace` file.
|
|
29
|
+
* @returns The parent directory of the workspace file.
|
|
30
|
+
*/
|
|
14
31
|
export const vscodeWorkspaceRoot = (workspaceFile) => dirname(workspaceFile);
|
|
15
32
|
//# sourceMappingURL=vscode.workspace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vscode.workspace.js","sourceRoot":"","sources":["../../src/vscode/vscode.workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,
|
|
1
|
+
{"version":3,"file":"vscode.workspace.js","sourceRoot":"","sources":["../../src/vscode/vscode.workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,MAAM,YAAY,GAAoC,EAAE,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,aAAqB,EACK,EAAE;IAC5B,IAAI,KAAK,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACnD,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QACvB,YAAY,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;IACtC,CAAC;IAED,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,aAAqB,EAAE,EAAE,CAC3D,OAAO,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { VSCodeWorkspace } from \"../types/types.vscode.js\";\nimport { dirname } from \"node:path\";\nimport { jsonParse } from \"../common/common.json.js\";\n\nconst __workspaces: Record<string, VSCodeWorkspace> = {};\n\n/**\n * Reads and returns a parsed VS Code `.code-workspace` file.\n *\n * @remarks\n * The result is cached per `workspaceFile` path. A shallow copy is returned\n * so that callers cannot mutate the cached object.\n *\n * @param workspaceFile - Absolute path to the `.code-workspace` file.\n * @returns A promise that resolves to a shallow copy of the parsed\n * {@link VSCodeWorkspace}.\n */\nexport const vscodeWorkspace = async (\n workspaceFile: string,\n): Promise<VSCodeWorkspace> => {\n let found = __workspaces[workspaceFile];\n if (!found) {\n const raw = await readFile(workspaceFile, \"utf-8\");\n found = jsonParse(raw);\n __workspaces[workspaceFile] = found;\n }\n\n return { ...found };\n};\n\n/**\n * Returns the directory that contains the given workspace file.\n *\n * @param workspaceFile - Absolute path to the `.code-workspace` file.\n * @returns The parent directory of the workspace file.\n */\nexport const vscodeWorkspaceRoot = (workspaceFile: string) =>\n dirname(workspaceFile);\n"]}
|
|
@@ -1,24 +1,109 @@
|
|
|
1
1
|
import { PnpmWorkspace } from "../types/types.workspace.js";
|
|
2
2
|
import { Pkg } from "../pkg/Pkg.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create and register the global {@link Workspace} singleton.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This is the primary entry point for bootstrapping a workspace. It must be
|
|
8
|
+
* called before {@link workspace} can be used. Subsequent calls replace the
|
|
9
|
+
* existing singleton.
|
|
10
|
+
*
|
|
11
|
+
* @param repoRoot - Absolute path to the repository root directory.
|
|
12
|
+
* @returns The newly created {@link Workspace} instance.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const ws = initWorkspace("/path/to/repo");
|
|
17
|
+
* await ws.read();
|
|
18
|
+
* console.log(ws.packages);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
3
21
|
export declare const initWorkspace: (repoRoot: string) => Workspace;
|
|
22
|
+
/**
|
|
23
|
+
* Retrieve the global {@link Workspace} singleton.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Throws if {@link initWorkspace} has not been called first.
|
|
27
|
+
*
|
|
28
|
+
* @returns The current {@link Workspace} instance.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const ws = workspace();
|
|
33
|
+
* console.log(ws.rootPackage.name);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
4
36
|
export declare const workspace: () => Workspace;
|
|
5
37
|
interface WorkspaceData {
|
|
6
38
|
pnpmWs: PnpmWorkspace;
|
|
7
39
|
rootPackage: Pkg;
|
|
8
40
|
packages: Pkg[];
|
|
9
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents a pnpm monorepo workspace rooted at a given directory.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* {@link Workspace} is implemented as a singleton managed via the
|
|
47
|
+
* {@link initWorkspace} and {@link workspace} helper functions. It lazily
|
|
48
|
+
* reads the `pnpm-workspace.yaml` and every package's `package.json` on the
|
|
49
|
+
* first call to {@link Workspace.read}, and persists pending changes back to
|
|
50
|
+
* disk with {@link Workspace.write}.
|
|
51
|
+
*/
|
|
10
52
|
export declare class Workspace {
|
|
11
53
|
readonly repoRoot: string;
|
|
12
54
|
protected _data: WorkspaceData | null;
|
|
55
|
+
/**
|
|
56
|
+
* Create and register a new singleton instance.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
* @param repoRoot - Absolute path to the repository root directory.
|
|
60
|
+
* @returns The newly created {@link Workspace} instance.
|
|
61
|
+
*/
|
|
13
62
|
static __init(repoRoot: string): Workspace;
|
|
63
|
+
/**
|
|
64
|
+
* Return the current singleton instance.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
* @returns The existing {@link Workspace} instance.
|
|
68
|
+
* @throws {Error} If the singleton has not been initialised via {@link Workspace.__init}.
|
|
69
|
+
*/
|
|
14
70
|
static __get(): Workspace;
|
|
15
71
|
private constructor();
|
|
72
|
+
/**
|
|
73
|
+
* A deep-cloned copy of the parsed `pnpm-workspace.yaml` configuration.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* Returns a clone so that callers cannot mutate the internal state.
|
|
77
|
+
*/
|
|
16
78
|
get pnpmWs(): PnpmWorkspace;
|
|
79
|
+
/**
|
|
80
|
+
* The list of {@link Pkg} instances representing each workspace package.
|
|
81
|
+
*/
|
|
17
82
|
get packages(): Pkg[];
|
|
83
|
+
/**
|
|
84
|
+
* The {@link Pkg} instance for the repository root `package.json`.
|
|
85
|
+
*/
|
|
18
86
|
get rootPackage(): Pkg;
|
|
19
87
|
protected set data(c: WorkspaceData);
|
|
20
88
|
protected get data(): WorkspaceData;
|
|
89
|
+
/**
|
|
90
|
+
* Read the workspace configuration and all package manifests from disk.
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* This method is idempotent — if data has already been loaded it returns
|
|
94
|
+
* immediately without re-reading. It parses `pnpm-workspace.yaml`, then
|
|
95
|
+
* reads every referenced `package.json` in parallel.
|
|
96
|
+
*
|
|
97
|
+
* @returns This {@link Workspace} instance for chaining.
|
|
98
|
+
*/
|
|
21
99
|
read(): Promise<Workspace>;
|
|
100
|
+
/**
|
|
101
|
+
* Persist all modified package manifests back to disk.
|
|
102
|
+
*
|
|
103
|
+
* @remarks
|
|
104
|
+
* No-ops if {@link Workspace.read} has not yet been called. Writes the
|
|
105
|
+
* root package and every workspace package in parallel.
|
|
106
|
+
*/
|
|
22
107
|
write(): Promise<void>;
|
|
23
108
|
}
|
|
24
109
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../src/workspace/Workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,cAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"Workspace.d.ts","sourceRoot":"","sources":["../../src/workspace/Workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,cAA+B,CAAC;AAE9E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,iBAA0B,CAAC;AAEjD,UAAU,aAAa;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,GAAG,CAAC;IACjB,QAAQ,EAAE,GAAG,EAAE,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,qBAAa,SAAS;aA2BgB,QAAQ,EAAE,MAAM;IA1BpD,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAQ;IAE7C;;;;;;OAMG;WACW,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS;IAIjD;;;;;;OAMG;WACW,KAAK,IAAI,SAAS;IAMhC,OAAO;IAEP;;;;;OAKG;IACH,IAAW,MAAM,IAAI,aAAa,CAEjC;IAED;;OAEG;IACH,IAAW,QAAQ,IAAI,GAAG,EAAE,CAE3B;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,GAAG,CAE5B;IAED,SAAS,KAAK,IAAI,CAAC,CAAC,EAAE,aAAa,EAElC;IAED,SAAS,KAAK,IAAI,IAAI,aAAa,CAGlC;IAED;;;;;;;;;OASG;IACU,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC;IAqBvC;;;;;;OAMG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAOpC"}
|
|
@@ -2,14 +2,70 @@ import { readWorkspaceYaml } from "./workspace.common.js";
|
|
|
2
2
|
import { Pkg } from "../pkg/Pkg.js";
|
|
3
3
|
import { jsonClone } from "../common/common.json.js";
|
|
4
4
|
let __instance = null;
|
|
5
|
+
/**
|
|
6
|
+
* Create and register the global {@link Workspace} singleton.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* This is the primary entry point for bootstrapping a workspace. It must be
|
|
10
|
+
* called before {@link workspace} can be used. Subsequent calls replace the
|
|
11
|
+
* existing singleton.
|
|
12
|
+
*
|
|
13
|
+
* @param repoRoot - Absolute path to the repository root directory.
|
|
14
|
+
* @returns The newly created {@link Workspace} instance.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const ws = initWorkspace("/path/to/repo");
|
|
19
|
+
* await ws.read();
|
|
20
|
+
* console.log(ws.packages);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
5
23
|
export const initWorkspace = (repoRoot) => Workspace.__init(repoRoot);
|
|
24
|
+
/**
|
|
25
|
+
* Retrieve the global {@link Workspace} singleton.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Throws if {@link initWorkspace} has not been called first.
|
|
29
|
+
*
|
|
30
|
+
* @returns The current {@link Workspace} instance.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const ws = workspace();
|
|
35
|
+
* console.log(ws.rootPackage.name);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
6
38
|
export const workspace = () => Workspace.__get();
|
|
39
|
+
/**
|
|
40
|
+
* Represents a pnpm monorepo workspace rooted at a given directory.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* {@link Workspace} is implemented as a singleton managed via the
|
|
44
|
+
* {@link initWorkspace} and {@link workspace} helper functions. It lazily
|
|
45
|
+
* reads the `pnpm-workspace.yaml` and every package's `package.json` on the
|
|
46
|
+
* first call to {@link Workspace.read}, and persists pending changes back to
|
|
47
|
+
* disk with {@link Workspace.write}.
|
|
48
|
+
*/
|
|
7
49
|
export class Workspace {
|
|
8
50
|
repoRoot;
|
|
9
51
|
_data = null;
|
|
52
|
+
/**
|
|
53
|
+
* Create and register a new singleton instance.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
* @param repoRoot - Absolute path to the repository root directory.
|
|
57
|
+
* @returns The newly created {@link Workspace} instance.
|
|
58
|
+
*/
|
|
10
59
|
static __init(repoRoot) {
|
|
11
60
|
return (__instance = new Workspace(repoRoot));
|
|
12
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Return the current singleton instance.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
* @returns The existing {@link Workspace} instance.
|
|
67
|
+
* @throws {Error} If the singleton has not been initialised via {@link Workspace.__init}.
|
|
68
|
+
*/
|
|
13
69
|
static __get() {
|
|
14
70
|
if (!__instance)
|
|
15
71
|
throw new Error("Workspace not initialized. initWorkspace()");
|
|
@@ -18,12 +74,24 @@ export class Workspace {
|
|
|
18
74
|
constructor(repoRoot) {
|
|
19
75
|
this.repoRoot = repoRoot;
|
|
20
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* A deep-cloned copy of the parsed `pnpm-workspace.yaml` configuration.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* Returns a clone so that callers cannot mutate the internal state.
|
|
82
|
+
*/
|
|
21
83
|
get pnpmWs() {
|
|
22
84
|
return jsonClone(this.data.pnpmWs);
|
|
23
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* The list of {@link Pkg} instances representing each workspace package.
|
|
88
|
+
*/
|
|
24
89
|
get packages() {
|
|
25
90
|
return this.data.packages;
|
|
26
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The {@link Pkg} instance for the repository root `package.json`.
|
|
94
|
+
*/
|
|
27
95
|
get rootPackage() {
|
|
28
96
|
return this.data.rootPackage;
|
|
29
97
|
}
|
|
@@ -35,6 +103,16 @@ export class Workspace {
|
|
|
35
103
|
throw new Error(`Data not loaded. ${this.repoRoot}`);
|
|
36
104
|
return this._data;
|
|
37
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Read the workspace configuration and all package manifests from disk.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* This method is idempotent — if data has already been loaded it returns
|
|
111
|
+
* immediately without re-reading. It parses `pnpm-workspace.yaml`, then
|
|
112
|
+
* reads every referenced `package.json` in parallel.
|
|
113
|
+
*
|
|
114
|
+
* @returns This {@link Workspace} instance for chaining.
|
|
115
|
+
*/
|
|
38
116
|
async read() {
|
|
39
117
|
if (this._data)
|
|
40
118
|
return this;
|
|
@@ -52,6 +130,13 @@ export class Workspace {
|
|
|
52
130
|
};
|
|
53
131
|
return this;
|
|
54
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Persist all modified package manifests back to disk.
|
|
135
|
+
*
|
|
136
|
+
* @remarks
|
|
137
|
+
* No-ops if {@link Workspace.read} has not yet been called. Writes the
|
|
138
|
+
* root package and every workspace package in parallel.
|
|
139
|
+
*/
|
|
55
140
|
async write() {
|
|
56
141
|
if (!this._data)
|
|
57
142
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Workspace.js","sourceRoot":"","sources":["../../src/workspace/Workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,IAAI,UAAU,GAAqB,IAAI,CAAC;AAExC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Workspace.js","sourceRoot":"","sources":["../../src/workspace/Workspace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,IAAI,UAAU,GAAqB,IAAI,CAAC;AAExC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAE9E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;AAQjD;;;;;;;;;GASG;AACH,MAAM,OAAO,SAAS;IA2BgB;IA1B1B,KAAK,GAAyB,IAAI,CAAC;IAE7C;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,QAAgB;QACnC,OAAO,CAAC,UAA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Q,CAAC,CAC/C,CAAC;QAEF,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,WAAW,CAAC,IAAI,EAAE;YAClB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACrC,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,GAAG;YACV,MAAM;YACN,QAAQ;YACR,WAAW;SACZ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,IAAI,CAAC,KAAK;YAAE,OAAO;QACxB,MAAM,OAAO,CAAC,GAAG,CAAC;YAChB,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;YACxB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;SAC3C,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { PnpmWorkspace } from \"../types/types.workspace.js\";\nimport { readWorkspaceYaml } from \"./workspace.common.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { jsonClone } from \"../common/common.json.js\";\n\nlet __instance: Workspace | null = null;\n\n/**\n * Create and register the global {@link Workspace} singleton.\n *\n * @remarks\n * This is the primary entry point for bootstrapping a workspace. It must be\n * called before {@link workspace} can be used. Subsequent calls replace the\n * existing singleton.\n *\n * @param repoRoot - Absolute path to the repository root directory.\n * @returns The newly created {@link Workspace} instance.\n *\n * @example\n * ```ts\n * const ws = initWorkspace(\"/path/to/repo\");\n * await ws.read();\n * console.log(ws.packages);\n * ```\n */\nexport const initWorkspace = (repoRoot: string) => Workspace.__init(repoRoot);\n\n/**\n * Retrieve the global {@link Workspace} singleton.\n *\n * @remarks\n * Throws if {@link initWorkspace} has not been called first.\n *\n * @returns The current {@link Workspace} instance.\n *\n * @example\n * ```ts\n * const ws = workspace();\n * console.log(ws.rootPackage.name);\n * ```\n */\nexport const workspace = () => Workspace.__get();\n\ninterface WorkspaceData {\n pnpmWs: PnpmWorkspace;\n rootPackage: Pkg;\n packages: Pkg[];\n}\n\n/**\n * Represents a pnpm monorepo workspace rooted at a given directory.\n *\n * @remarks\n * {@link Workspace} is implemented as a singleton managed via the\n * {@link initWorkspace} and {@link workspace} helper functions. It lazily\n * reads the `pnpm-workspace.yaml` and every package's `package.json` on the\n * first call to {@link Workspace.read}, and persists pending changes back to\n * disk with {@link Workspace.write}.\n */\nexport class Workspace {\n protected _data: WorkspaceData | null = null;\n\n /**\n * Create and register a new singleton instance.\n *\n * @internal\n * @param repoRoot - Absolute path to the repository root directory.\n * @returns The newly created {@link Workspace} instance.\n */\n public static __init(repoRoot: string): Workspace {\n return (__instance = new Workspace(repoRoot));\n }\n\n /**\n * Return the current singleton instance.\n *\n * @internal\n * @returns The existing {@link Workspace} instance.\n * @throws {Error} If the singleton has not been initialised via {@link Workspace.__init}.\n */\n public static __get(): Workspace {\n if (!__instance)\n throw new Error(\"Workspace not initialized. initWorkspace()\");\n return __instance;\n }\n\n private constructor(public readonly repoRoot: string) {}\n\n /**\n * A deep-cloned copy of the parsed `pnpm-workspace.yaml` configuration.\n *\n * @remarks\n * Returns a clone so that callers cannot mutate the internal state.\n */\n public get pnpmWs(): PnpmWorkspace {\n return jsonClone(this.data.pnpmWs);\n }\n\n /**\n * The list of {@link Pkg} instances representing each workspace package.\n */\n public get packages(): Pkg[] {\n return this.data.packages;\n }\n\n /**\n * The {@link Pkg} instance for the repository root `package.json`.\n */\n public get rootPackage(): Pkg {\n return this.data.rootPackage;\n }\n\n protected set data(c: WorkspaceData) {\n this._data = c;\n }\n\n protected get data(): WorkspaceData {\n if (!this._data) throw new Error(`Data not loaded. ${this.repoRoot}`);\n return this._data;\n }\n\n /**\n * Read the workspace configuration and all package manifests from disk.\n *\n * @remarks\n * This method is idempotent — if data has already been loaded it returns\n * immediately without re-reading. It parses `pnpm-workspace.yaml`, then\n * reads every referenced `package.json` in parallel.\n *\n * @returns This {@link Workspace} instance for chaining.\n */\n public async read(): Promise<Workspace> {\n if (this._data) return this;\n const pnpmWs = await readWorkspaceYaml(this.repoRoot);\n const rootPackage = new Pkg(this.repoRoot, \".\");\n const packages = pnpmWs.packages.map(\n (repoPath) => new Pkg(this.repoRoot, repoPath),\n );\n\n await Promise.all([\n rootPackage.read(),\n ...packages.map((pkg) => pkg.read()),\n ]);\n\n this.data = {\n pnpmWs,\n packages,\n rootPackage,\n };\n return this;\n }\n\n /**\n * Persist all modified package manifests back to disk.\n *\n * @remarks\n * No-ops if {@link Workspace.read} has not yet been called. Writes the\n * root package and every workspace package in parallel.\n */\n public async write(): Promise<void> {\n if (!this._data) return;\n await Promise.all([\n this.rootPackage.write(),\n ...this.packages.map((pkg) => pkg.write()),\n ]);\n }\n}\n"]}
|
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
import { PnpmWorkspace, WorkspaceFile, WorkspaceFileType } from "../types/types.workspace.js";
|
|
2
|
+
/**
|
|
3
|
+
* File extension used to identify VS Code / editor workspace files.
|
|
4
|
+
*/
|
|
2
5
|
export declare const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
6
|
+
/**
|
|
7
|
+
* Classify a filename into a {@link WorkspaceFileType}.
|
|
8
|
+
*
|
|
9
|
+
* @param filename - The base filename to classify (e.g. `"package.json"`).
|
|
10
|
+
* @returns The corresponding {@link WorkspaceFileType} enum value.
|
|
11
|
+
*/
|
|
3
12
|
export declare const getFileType: (filename: string) => WorkspaceFileType;
|
|
13
|
+
/**
|
|
14
|
+
* Walk up the directory tree from `startPath` to locate the workspace root.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The search runs every ancestor directory in parallel. A `.code-workspace`
|
|
18
|
+
* file is preferred over a bare `package.json`. The result is cached so that
|
|
19
|
+
* subsequent calls return immediately.
|
|
20
|
+
*
|
|
21
|
+
* @param startPath - Absolute path from which to begin the upward search.
|
|
22
|
+
* @returns The {@link WorkspaceFile} describing the workspace root.
|
|
23
|
+
* @throws {Error} If no workspace or package file is found in any ancestor.
|
|
24
|
+
*/
|
|
4
25
|
export declare const findWorkspaceRoot: (startPath: string) => Promise<WorkspaceFile>;
|
|
26
|
+
/**
|
|
27
|
+
* Parse the `pnpm-workspace.yaml` file at the given repository root.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Glob patterns ending with `/*` are expanded into their concrete
|
|
31
|
+
* sub-directory names by reading the filesystem. Hidden directories
|
|
32
|
+
* (names starting with `.`) are excluded from the expansion.
|
|
33
|
+
*
|
|
34
|
+
* @param repoRoot - Absolute path to the repository root containing `pnpm-workspace.yaml`.
|
|
35
|
+
* @returns The parsed {@link PnpmWorkspace} with fully-resolved package paths.
|
|
36
|
+
* @throws {Error} If the YAML file is missing or lacks a valid `packages` array.
|
|
37
|
+
*/
|
|
5
38
|
export declare const readWorkspaceYaml: (repoRoot: string) => Promise<PnpmWorkspace>;
|
|
6
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Reset the cached workspace root to `null`.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Intended for test isolation only — clears the module-level cache so that
|
|
46
|
+
* {@link findWorkspaceRoot} re-discovers the workspace on the next call.
|
|
47
|
+
*/
|
|
7
48
|
export declare const __resetWorkspaceRoot: () => void;
|
|
8
49
|
//# sourceMappingURL=workspace.common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.common.d.ts","sourceRoot":"","sources":["../../src/workspace/workspace.common.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAIrC,eAAO,MAAM,6BAA6B,oBAAoB,CAAC;AAE/D,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,KAAG,iBAKhB,CAAC;AAIhC,eAAO,MAAM,iBAAiB,GAC5B,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CAyDvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,UAAU,MAAM,KACf,OAAO,CAAC,aAAa,CAuBvB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"workspace.common.d.ts","sourceRoot":"","sources":["../../src/workspace/workspace.common.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,aAAa,EACb,iBAAiB,EAClB,MAAM,6BAA6B,CAAC;AAIrC;;GAEG;AACH,eAAO,MAAM,6BAA6B,oBAAoB,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,MAAM,KAAG,iBAKhB,CAAC;AAIhC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,WAAW,MAAM,KAChB,OAAO,CAAC,aAAa,CAyDvB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAU,MAAM,KACf,OAAO,CAAC,aAAa,CAuBvB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,YAEhC,CAAC"}
|
|
@@ -2,13 +2,34 @@ import { readdir, readFile } from "node:fs/promises";
|
|
|
2
2
|
import { WorkspaceFileType, } from "../types/types.workspace.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { parse } from "yaml";
|
|
5
|
+
/**
|
|
6
|
+
* File extension used to identify VS Code / editor workspace files.
|
|
7
|
+
*/
|
|
5
8
|
export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
9
|
+
/**
|
|
10
|
+
* Classify a filename into a {@link WorkspaceFileType}.
|
|
11
|
+
*
|
|
12
|
+
* @param filename - The base filename to classify (e.g. `"package.json"`).
|
|
13
|
+
* @returns The corresponding {@link WorkspaceFileType} enum value.
|
|
14
|
+
*/
|
|
6
15
|
export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
|
|
7
16
|
? WorkspaceFileType.workspace
|
|
8
17
|
: filename === "package.json"
|
|
9
18
|
? WorkspaceFileType.package
|
|
10
19
|
: WorkspaceFileType.other;
|
|
11
20
|
let __workspaceRoot = null;
|
|
21
|
+
/**
|
|
22
|
+
* Walk up the directory tree from `startPath` to locate the workspace root.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* The search runs every ancestor directory in parallel. A `.code-workspace`
|
|
26
|
+
* file is preferred over a bare `package.json`. The result is cached so that
|
|
27
|
+
* subsequent calls return immediately.
|
|
28
|
+
*
|
|
29
|
+
* @param startPath - Absolute path from which to begin the upward search.
|
|
30
|
+
* @returns The {@link WorkspaceFile} describing the workspace root.
|
|
31
|
+
* @throws {Error} If no workspace or package file is found in any ancestor.
|
|
32
|
+
*/
|
|
12
33
|
export const findWorkspaceRoot = async (startPath) => {
|
|
13
34
|
if (__workspaceRoot)
|
|
14
35
|
return __workspaceRoot;
|
|
@@ -58,6 +79,18 @@ export const findWorkspaceRoot = async (startPath) => {
|
|
|
58
79
|
__workspaceRoot = result;
|
|
59
80
|
return result;
|
|
60
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Parse the `pnpm-workspace.yaml` file at the given repository root.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* Glob patterns ending with `/*` are expanded into their concrete
|
|
87
|
+
* sub-directory names by reading the filesystem. Hidden directories
|
|
88
|
+
* (names starting with `.`) are excluded from the expansion.
|
|
89
|
+
*
|
|
90
|
+
* @param repoRoot - Absolute path to the repository root containing `pnpm-workspace.yaml`.
|
|
91
|
+
* @returns The parsed {@link PnpmWorkspace} with fully-resolved package paths.
|
|
92
|
+
* @throws {Error} If the YAML file is missing or lacks a valid `packages` array.
|
|
93
|
+
*/
|
|
61
94
|
export const readWorkspaceYaml = async (repoRoot) => {
|
|
62
95
|
const workspaceFilePath = join(repoRoot, "pnpm-workspace.yaml");
|
|
63
96
|
const fileContent = await readFile(workspaceFilePath, "utf8");
|
|
@@ -75,7 +108,15 @@ export const readWorkspaceYaml = async (repoRoot) => {
|
|
|
75
108
|
}))).flat();
|
|
76
109
|
return { packages };
|
|
77
110
|
};
|
|
78
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Reset the cached workspace root to `null`.
|
|
113
|
+
*
|
|
114
|
+
* @internal
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Intended for test isolation only — clears the module-level cache so that
|
|
118
|
+
* {@link findWorkspaceRoot} re-discovers the workspace on the next call.
|
|
119
|
+
*/
|
|
79
120
|
export const __resetWorkspaceRoot = () => {
|
|
80
121
|
__workspaceRoot = null;
|
|
81
122
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.common.js","sourceRoot":"","sources":["../../src/workspace/workspace.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAGL,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,6BAA6B,GAAG,iBAAiB,CAAC;AAE/D,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAAgB,EAAqB,EAAE,CACjE,QAAQ,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IAC9C,CAAC,CAAC,iBAAiB,CAAC,SAAS;IAC7B,CAAC,CAAC,QAAQ,KAAK,cAAc;QAC3B,CAAC,CAAC,iBAAiB,CAAC,OAAO;QAC3B,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC;AAEhC,IAAI,eAAe,GAAyB,IAAI,CAAC;AAEjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,SAAiB,EACO,EAAE;IAC1B,IAAI,eAAe;QAAE,OAAO,eAAe,CAAC;IAC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,GAAG,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CACH,CACF,CAAC,IAAI,EAAE,CAAC;IAET,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,eAAe,GAAG,IAAI,CAAC;AACzB,CAAC,CAAC","sourcesContent":["import { readdir, readFile } from \"node:fs/promises\";\nimport {\n PnpmWorkspace,\n WorkspaceFile,\n WorkspaceFileType,\n} from \"../types/types.workspace.js\";\nimport { join } from \"node:path\";\nimport { parse } from \"yaml\";\n\n/**\n * File extension used to identify VS Code / editor workspace files.\n */\nexport const DEFAULT_WORKSPACE_FILE_ENDING = \".code-workspace\";\n\n/**\n * Classify a filename into a {@link WorkspaceFileType}.\n *\n * @param filename - The base filename to classify (e.g. `\"package.json\"`).\n * @returns The corresponding {@link WorkspaceFileType} enum value.\n */\nexport const getFileType = (filename: string): WorkspaceFileType =>\n filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)\n ? WorkspaceFileType.workspace\n : filename === \"package.json\"\n ? WorkspaceFileType.package\n : WorkspaceFileType.other;\n\nlet __workspaceRoot: WorkspaceFile | null = null;\n\n/**\n * Walk up the directory tree from `startPath` to locate the workspace root.\n *\n * @remarks\n * The search runs every ancestor directory in parallel. A `.code-workspace`\n * file is preferred over a bare `package.json`. The result is cached so that\n * subsequent calls return immediately.\n *\n * @param startPath - Absolute path from which to begin the upward search.\n * @returns The {@link WorkspaceFile} describing the workspace root.\n * @throws {Error} If no workspace or package file is found in any ancestor.\n */\nexport const findWorkspaceRoot = async (\n startPath: string,\n): Promise<WorkspaceFile> => {\n if (__workspaceRoot) return __workspaceRoot;\n let path = startPath;\n let level = 0;\n const promises: Promise<WorkspaceFile>[] = [];\n\n while (path.length > 0) {\n promises.push(\n (async () => {\n const workingPath = path.substring(0);\n const l = level;\n const entries = await readdir(workingPath, { withFileTypes: true });\n let pkg: WorkspaceFile | null = null;\n\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const type = getFileType(entry.name);\n\n if (type === WorkspaceFileType.workspace)\n return {\n filePath: join(workingPath, entry.name),\n dirPath: workingPath,\n filename: entry.name,\n level: l,\n type,\n };\n\n if (!pkg && type === WorkspaceFileType.package)\n pkg = {\n filePath: join(workingPath, entry.name),\n dirPath: workingPath,\n filename: entry.name,\n level: l,\n type,\n };\n }\n\n if (!pkg) throw new Error(\"\");\n return pkg;\n })(),\n );\n level++;\n path = path.replace(/\\/?[^\\/]+\\/?$/, \"\"); // remove last dir\n }\n\n const results = (await Promise.allSettled(promises)).filter(\n (r) => r.status === \"fulfilled\",\n );\n results.sort((a, b) => a.value.level - b.value.level);\n\n const result =\n results.find((r) => r.value.type === WorkspaceFileType.workspace)?.value ??\n results.find((r) => r.value.type === WorkspaceFileType.package)?.value;\n\n if (!result) throw new Error(\"findWorkspaceRoot: no file found\");\n __workspaceRoot = result;\n return result;\n};\n\n/**\n * Parse the `pnpm-workspace.yaml` file at the given repository root.\n *\n * @remarks\n * Glob patterns ending with `/*` are expanded into their concrete\n * sub-directory names by reading the filesystem. Hidden directories\n * (names starting with `.`) are excluded from the expansion.\n *\n * @param repoRoot - Absolute path to the repository root containing `pnpm-workspace.yaml`.\n * @returns The parsed {@link PnpmWorkspace} with fully-resolved package paths.\n * @throws {Error} If the YAML file is missing or lacks a valid `packages` array.\n */\nexport const readWorkspaceYaml = async (\n repoRoot: string,\n): Promise<PnpmWorkspace> => {\n const workspaceFilePath = join(repoRoot, \"pnpm-workspace.yaml\");\n const fileContent = await readFile(workspaceFilePath, \"utf8\");\n const parsed = parse(fileContent) as Partial<PnpmWorkspace>;\n\n if (!parsed || !parsed.packages || !Array.isArray(parsed.packages))\n throw new Error(\"No 'packages' field found in pnpm-workspace.yaml\");\n\n const packages: string[] = (\n await Promise.all(\n parsed.packages.map(async (p) => {\n if (!p.endsWith(\"/*\")) return [p];\n const base = p.substring(0, p.length - 2);\n const pkgs = await readdir(join(repoRoot, base));\n\n return pkgs\n .filter((pkg) => !pkg.startsWith(\".\"))\n .map((pkg) => join(base, pkg));\n }),\n )\n ).flat();\n\n return { packages };\n};\n\n/**\n * Reset the cached workspace root to `null`.\n *\n * @internal\n *\n * @remarks\n * Intended for test isolation only — clears the module-level cache so that\n * {@link findWorkspaceRoot} re-discovers the workspace on the next call.\n */\nexport const __resetWorkspaceRoot = () => {\n __workspaceRoot = null;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/build-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.58",
|
|
4
4
|
"description": "Build utilities API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -42,9 +42,11 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@mxpicture/dep-analyzer": "^0.1.0",
|
|
44
44
|
"@types/micromatch": "^4.0.10",
|
|
45
|
+
"glob": "^13.0.6",
|
|
45
46
|
"json5": "^2.2.3",
|
|
46
47
|
"micromatch": "^4.0.8",
|
|
47
48
|
"prettier": "^3.8.1",
|
|
49
|
+
"resolve.exports": "^2.0.3",
|
|
48
50
|
"simple-git": "^3.32.3",
|
|
49
51
|
"typescript": "^5.9.3",
|
|
50
52
|
"yaml": "^2.8.2"
|