@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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { dirname, relative } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { glob } from "glob";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { resolve as resolveExports } from "resolve.exports";
|
|
6
|
+
import { readPackageJson } from "./pkg.fs.js";
|
|
7
|
+
import { initWorkspace } from "../workspace/Workspace.js";
|
|
8
|
+
import { createSourceFileMap } from "../code/code.common.js";
|
|
9
|
+
import { writeFile } from "node:fs/promises";
|
|
10
|
+
import { jsonStringify, JsonStringifyFormat } from "../common/common.json.js";
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
export const runExportExtractor = async (params) => {
|
|
13
|
+
initWorkspace(params.repoRoot);
|
|
14
|
+
const exp = new ExportExtractor(params.package);
|
|
15
|
+
const result = await exp.run();
|
|
16
|
+
if (params.json) {
|
|
17
|
+
await exp.writeJson(params.json, result);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const content = await exp.toJson(result);
|
|
21
|
+
console.log(content);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export class ExportExtractor {
|
|
25
|
+
pkg;
|
|
26
|
+
/**
|
|
27
|
+
* Analyze an installed package and produce
|
|
28
|
+
* a structured API representation.
|
|
29
|
+
*
|
|
30
|
+
* @param pkg package name
|
|
31
|
+
*/
|
|
32
|
+
constructor(pkg) {
|
|
33
|
+
this.pkg = pkg;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Analyze an installed package and build its API model.
|
|
37
|
+
*/
|
|
38
|
+
async run() {
|
|
39
|
+
const root = this.resolvePackageRoot(this.pkg);
|
|
40
|
+
const pkgJson = await readPackageJson(root);
|
|
41
|
+
let entrypoints = this.resolveEntrypoints(this.pkg, pkgJson);
|
|
42
|
+
entrypoints = await this.expandWildcardEntrypoints(root, entrypoints);
|
|
43
|
+
const runtimeExports = await this.inspectRuntimeExports(entrypoints);
|
|
44
|
+
const typeExports = await this.parseTypeExports(root);
|
|
45
|
+
return {
|
|
46
|
+
packageRoot: root,
|
|
47
|
+
entrypoints,
|
|
48
|
+
runtimeExports,
|
|
49
|
+
typeExports,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async writeJson(filePath, content) {
|
|
53
|
+
return writeFile(filePath, await this.toJson(content));
|
|
54
|
+
}
|
|
55
|
+
async toJson(content) {
|
|
56
|
+
return jsonStringify(content, JsonStringifyFormat.jsonStringify);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolve the root directory of an installed package.
|
|
60
|
+
*/
|
|
61
|
+
resolvePackageRoot(pkg) {
|
|
62
|
+
const pkgJson = require.resolve(`${pkg}/package.json`);
|
|
63
|
+
return dirname(pkgJson);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolve entrypoints using the Node exports algorithm.
|
|
67
|
+
*/
|
|
68
|
+
resolveEntrypoints(pkg, pkgJson) {
|
|
69
|
+
const entrypoints = [];
|
|
70
|
+
if (!pkgJson.exports) {
|
|
71
|
+
entrypoints.push({ id: pkg });
|
|
72
|
+
return entrypoints;
|
|
73
|
+
}
|
|
74
|
+
const keys = Object.keys(pkgJson.exports);
|
|
75
|
+
for (const key of keys) {
|
|
76
|
+
try {
|
|
77
|
+
const resolved = resolveExports(pkgJson, key, {
|
|
78
|
+
conditions: ["node", "import", "require", "default"],
|
|
79
|
+
});
|
|
80
|
+
if (!resolved)
|
|
81
|
+
continue;
|
|
82
|
+
const files = Array.isArray(resolved) ? resolved : [resolved];
|
|
83
|
+
for (const file of files) {
|
|
84
|
+
const specifier = key === "." ? pkg : `${pkg}/${key.replace("./", "")}`;
|
|
85
|
+
entrypoints.push({
|
|
86
|
+
id: specifier,
|
|
87
|
+
file,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
}
|
|
93
|
+
return entrypoints;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Expand wildcard export patterns.
|
|
97
|
+
*/
|
|
98
|
+
async expandWildcardEntrypoints(root, entrypoints) {
|
|
99
|
+
return (await Promise.allSettled(entrypoints.map(async (entry) => {
|
|
100
|
+
if (!entry.file?.includes("*"))
|
|
101
|
+
return [entry];
|
|
102
|
+
const pattern = entry.file;
|
|
103
|
+
const files = await glob.glob(pattern, {
|
|
104
|
+
cwd: root,
|
|
105
|
+
absolute: true,
|
|
106
|
+
});
|
|
107
|
+
return files.map((file) => ({
|
|
108
|
+
id: relative(root, file).replace(/\.(js|mjs|cjs)$/, ""),
|
|
109
|
+
file,
|
|
110
|
+
}));
|
|
111
|
+
})))
|
|
112
|
+
.filter((r) => r.status === "fulfilled")
|
|
113
|
+
.flatMap((r) => r.value);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Dynamically import a module supporting ESM and CommonJS.
|
|
117
|
+
*/
|
|
118
|
+
async loadModule(id) {
|
|
119
|
+
try {
|
|
120
|
+
return await import(id);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return require(id);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Extract runtime exports from entrypoints.
|
|
128
|
+
*/
|
|
129
|
+
async inspectRuntimeExports(entrypoints) {
|
|
130
|
+
return (await Promise.allSettled(entrypoints.map(async (entry) => {
|
|
131
|
+
const mod = await this.loadModule(entry.id);
|
|
132
|
+
return Object.keys(mod).map((name) => ({
|
|
133
|
+
name,
|
|
134
|
+
kind: typeof mod[name],
|
|
135
|
+
source: entry.id,
|
|
136
|
+
}));
|
|
137
|
+
})))
|
|
138
|
+
.filter((r) => r.status === "fulfilled")
|
|
139
|
+
.flatMap((r) => r.value);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Parse TypeScript declaration files to extract exported types.
|
|
143
|
+
*/
|
|
144
|
+
async parseTypeExports(root) {
|
|
145
|
+
const nodes = [];
|
|
146
|
+
const filePaths = await glob.glob("**/*.d.ts", {
|
|
147
|
+
cwd: root,
|
|
148
|
+
absolute: true,
|
|
149
|
+
});
|
|
150
|
+
const srcMap = createSourceFileMap(filePaths);
|
|
151
|
+
for (const filePath of filePaths) {
|
|
152
|
+
const file = srcMap.get(filePath);
|
|
153
|
+
if (!file)
|
|
154
|
+
continue;
|
|
155
|
+
ts.forEachChild(file.sourceFile, (node) => {
|
|
156
|
+
if (ts.isInterfaceDeclaration(node) ||
|
|
157
|
+
ts.isTypeAliasDeclaration(node) ||
|
|
158
|
+
ts.isClassDeclaration(node) ||
|
|
159
|
+
ts.isFunctionDeclaration(node)) {
|
|
160
|
+
if (!node.name)
|
|
161
|
+
return;
|
|
162
|
+
nodes.push({
|
|
163
|
+
name: node.name.text,
|
|
164
|
+
kind: ts.SyntaxKind[node.kind],
|
|
165
|
+
source: filePath,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (ts.isEnumDeclaration(node)) {
|
|
169
|
+
nodes.push({
|
|
170
|
+
name: node.name.text,
|
|
171
|
+
kind: "enum",
|
|
172
|
+
source: filePath,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return nodes;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=ExportExtractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportExtractor.js","sourceRoot":"","sources":["../../src/pkg/ExportExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO9C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE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f,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,IAAI;gBAAE,SAAS;YAEpB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxC,IACE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC;oBAC/B,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC;oBAC/B,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;oBAC3B,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAC9B,CAAC;oBACD,IAAI,CAAC,IAAI,CAAC,IAAI;wBAAE,OAAO;oBAEvB,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;wBACpB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;wBAC9B,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,IAAI,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;wBACpB,IAAI,EAAE,MAAM;wBACZ,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { dirname, relative } from \"node:path\";\nimport ts from \"typescript\";\nimport { glob } from \"glob\";\nimport { createRequire } from \"node:module\";\nimport { resolve as resolveExports } from \"resolve.exports\";\nimport { readPackageJson } from \"./pkg.fs.js\";\nimport {\n EntryPoint,\n ExportExtractorParams,\n ExportNode,\n PackageAPI,\n} from \"../types/types.exports.js\";\nimport { initWorkspace } from \"../workspace/Workspace.js\";\nimport { PackageJson } from \"../types/types.package.js\";\nimport { createSourceFileMap } from \"../code/code.common.js\";\nimport { writeFile } from \"node:fs/promises\";\nimport { jsonStringify, JsonStringifyFormat } from \"../common/common.json.js\";\n\nconst require = createRequire(import.meta.url);\n\nexport const runExportExtractor = async (params: ExportExtractorParams) => {\n initWorkspace(params.repoRoot);\n\n const exp = new ExportExtractor(params.package);\n const result = await exp.run();\n if (params.json) {\n await exp.writeJson(params.json, result);\n } else {\n const content = await exp.toJson(result);\n console.log(content);\n }\n};\n\nexport class ExportExtractor {\n /**\n * Analyze an installed package and produce\n * a structured API representation.\n *\n * @param pkg package name\n */\n public constructor(public readonly pkg: string) {}\n\n /**\n * Analyze an installed package and build its API model.\n */\n public async run(): Promise<PackageAPI> {\n const root = this.resolvePackageRoot(this.pkg);\n const pkgJson = await readPackageJson(root);\n\n let entrypoints = this.resolveEntrypoints(this.pkg, pkgJson);\n entrypoints = await this.expandWildcardEntrypoints(root, entrypoints);\n\n const runtimeExports = await this.inspectRuntimeExports(entrypoints);\n const typeExports = await this.parseTypeExports(root);\n\n return {\n packageRoot: root,\n entrypoints,\n runtimeExports,\n typeExports,\n };\n }\n\n public async writeJson(filePath: string, content: PackageAPI): Promise<void> {\n return writeFile(filePath, await this.toJson(content));\n }\n\n public async toJson(content: PackageAPI): Promise<string> {\n return jsonStringify(content, JsonStringifyFormat.jsonStringify);\n }\n\n /**\n * Resolve the root directory of an installed package.\n */\n protected resolvePackageRoot(pkg: string): string {\n const pkgJson = require.resolve(`${pkg}/package.json`);\n return dirname(pkgJson);\n }\n\n /**\n * Resolve entrypoints using the Node exports algorithm.\n */\n protected resolveEntrypoints(\n pkg: string,\n pkgJson: PackageJson,\n ): EntryPoint[] {\n const entrypoints: EntryPoint[] = [];\n\n if (!pkgJson.exports) {\n entrypoints.push({ id: pkg });\n return entrypoints;\n }\n\n const keys = Object.keys(pkgJson.exports);\n\n for (const key of keys) {\n try {\n const resolved = resolveExports(pkgJson, key, {\n conditions: [\"node\", \"import\", \"require\", \"default\"],\n });\n\n if (!resolved) continue;\n\n const files = Array.isArray(resolved) ? resolved : [resolved];\n\n for (const file of files) {\n const specifier =\n key === \".\" ? pkg : `${pkg}/${key.replace(\"./\", \"\")}`;\n\n entrypoints.push({\n id: specifier,\n file,\n });\n }\n } catch {}\n }\n\n return entrypoints;\n }\n\n /**\n * Expand wildcard export patterns.\n */\n protected async expandWildcardEntrypoints(\n root: string,\n entrypoints: EntryPoint[],\n ): Promise<EntryPoint[]> {\n return (\n await Promise.allSettled(\n entrypoints.map(async (entry) => {\n if (!entry.file?.includes(\"*\")) return [entry];\n\n const pattern = entry.file;\n const files = await glob.glob(pattern, {\n cwd: root,\n absolute: true,\n });\n\n return files.map((file) => ({\n id: relative(root, file).replace(/\\.(js|mjs|cjs)$/, \"\"),\n file,\n }));\n }),\n )\n )\n .filter((r) => r.status === \"fulfilled\")\n .flatMap((r) => r.value);\n }\n\n /**\n * Dynamically import a module supporting ESM and CommonJS.\n */\n protected async loadModule(id: string): Promise<Record<string, unknown>> {\n try {\n return await import(id);\n } catch {\n return require(id);\n }\n }\n\n /**\n * Extract runtime exports from entrypoints.\n */\n protected async inspectRuntimeExports(\n entrypoints: EntryPoint[],\n ): Promise<ExportNode[]> {\n return (\n await Promise.allSettled(\n entrypoints.map(async (entry) => {\n const mod = await this.loadModule(entry.id);\n return Object.keys(mod).map((name) => ({\n name,\n kind: typeof mod[name],\n source: entry.id,\n }));\n }),\n )\n )\n .filter((r) => r.status === \"fulfilled\")\n .flatMap((r) => r.value);\n }\n\n /**\n * Parse TypeScript declaration files to extract exported types.\n */\n protected async parseTypeExports(root: string): Promise<ExportNode[]> {\n const nodes: ExportNode[] = [];\n\n const filePaths = await glob.glob(\"**/*.d.ts\", {\n cwd: root,\n absolute: true,\n });\n\n const srcMap = createSourceFileMap(filePaths);\n\n for (const filePath of filePaths) {\n const file = srcMap.get(filePath);\n if (!file) continue;\n\n ts.forEachChild(file.sourceFile, (node) => {\n if (\n ts.isInterfaceDeclaration(node) ||\n ts.isTypeAliasDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isFunctionDeclaration(node)\n ) {\n if (!node.name) return;\n\n nodes.push({\n name: node.name.text,\n kind: ts.SyntaxKind[node.kind],\n source: filePath,\n });\n }\n\n if (ts.isEnumDeclaration(node)) {\n nodes.push({\n name: node.name.text,\n kind: \"enum\",\n source: filePath,\n });\n }\n });\n }\n\n return nodes;\n }\n}\n"]}
|
package/dist/pkg/Pkg.d.ts
CHANGED
|
@@ -1,24 +1,93 @@
|
|
|
1
1
|
import { PackageJson } from "../types/types.package.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a single npm package within a repository workspace.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Wraps a `package.json` file with lazy-load semantics, change-tracking, and
|
|
7
|
+
* convenience accessors for common directory paths (source, dist, repo-relative).
|
|
8
|
+
* Content is only read from disk on the first call to {@link Pkg.read} or {@link Pkg.readSync},
|
|
9
|
+
* and writes are skipped when no modifications have been made.
|
|
10
|
+
*/
|
|
2
11
|
export declare class Pkg {
|
|
3
12
|
readonly repoRoot: string;
|
|
4
13
|
readonly repoPath: string;
|
|
14
|
+
/** Absolute path to the `package.json` file. */
|
|
5
15
|
readonly filePath: string;
|
|
16
|
+
/** Absolute path to the package directory. */
|
|
6
17
|
readonly dirPath: string;
|
|
18
|
+
/** Absolute path to the package `src` directory. */
|
|
7
19
|
readonly srcPath: string;
|
|
20
|
+
/** Absolute path to the package `dist` directory. */
|
|
8
21
|
readonly distPath: string;
|
|
22
|
+
/** Repository-relative path to the `package.json` file. */
|
|
9
23
|
readonly repoFilePath: string;
|
|
24
|
+
/** Repository-relative path to the package directory. */
|
|
10
25
|
readonly repoDirPath: string;
|
|
26
|
+
/** Repository-relative path to the package `src` directory. */
|
|
11
27
|
readonly repoSrcPath: string;
|
|
28
|
+
/** Repository-relative path to the package `dist` directory. */
|
|
12
29
|
readonly repoDistPath: string;
|
|
13
30
|
protected _content: PackageJson | null;
|
|
14
31
|
protected originalContent: PackageJson | null;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new Pkg instance for a package at the given repository-relative path.
|
|
34
|
+
*
|
|
35
|
+
* @param repoRoot - Absolute path to the repository root.
|
|
36
|
+
* @param repoPath - Repository-relative path to the package directory.
|
|
37
|
+
*/
|
|
15
38
|
constructor(repoRoot: string, repoPath: string);
|
|
39
|
+
/**
|
|
40
|
+
* Returns the loaded package.json content.
|
|
41
|
+
*
|
|
42
|
+
* @remarks
|
|
43
|
+
* Throws if content has not yet been loaded via {@link Pkg.read} or {@link Pkg.readSync}.
|
|
44
|
+
*
|
|
45
|
+
* @returns The parsed {@link PackageJson} object.
|
|
46
|
+
*/
|
|
16
47
|
get content(): PackageJson;
|
|
17
48
|
protected set content(c: PackageJson);
|
|
49
|
+
/**
|
|
50
|
+
* Checks whether the in-memory content has been modified since it was last read.
|
|
51
|
+
*
|
|
52
|
+
* @returns `true` if the current content differs from the original on-disk content.
|
|
53
|
+
*/
|
|
18
54
|
modified(): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Asynchronously reads the `package.json` from disk.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* The file is only read once; subsequent calls return the cached content.
|
|
60
|
+
*
|
|
61
|
+
* @returns A promise resolving to the parsed {@link PackageJson}.
|
|
62
|
+
*/
|
|
19
63
|
read(): Promise<PackageJson>;
|
|
64
|
+
/**
|
|
65
|
+
* Synchronously reads the `package.json` from disk.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* The file is only read once; subsequent calls return the cached content.
|
|
69
|
+
*
|
|
70
|
+
* @returns The parsed {@link PackageJson}.
|
|
71
|
+
*/
|
|
20
72
|
readSync(): PackageJson;
|
|
73
|
+
/**
|
|
74
|
+
* Writes the `package.json` back to disk if it has been modified.
|
|
75
|
+
*
|
|
76
|
+
* @remarks
|
|
77
|
+
* Skips the write and logs an informational message when no changes have been made.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that resolves when the write operation completes (or is skipped).
|
|
80
|
+
*/
|
|
21
81
|
write(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Collects all dependency versions declared in the package.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* Merges `dependencies`, `devDependencies`, and `peerDependencies` into a
|
|
87
|
+
* single record. Reads the package from disk if not already loaded.
|
|
88
|
+
*
|
|
89
|
+
* @returns A promise resolving to a record mapping package names to their version specifiers.
|
|
90
|
+
*/
|
|
22
91
|
packageVersions(): Promise<Record<string, string>>;
|
|
23
92
|
protected updateOriginal(content?: PackageJson): void;
|
|
24
93
|
}
|
package/dist/pkg/Pkg.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pkg.d.ts","sourceRoot":"","sources":["../../src/pkg/Pkg.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAUxD,qBAAa,GAAG;
|
|
1
|
+
{"version":3,"file":"Pkg.d.ts","sourceRoot":"","sources":["../../src/pkg/Pkg.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAUxD;;;;;;;;GAQG;AACH,qBAAa,GAAG;aA2BI,QAAQ,EAAE,MAAM;aAChB,QAAQ,EAAE,MAAM;IA3BlC,gDAAgD;IAChD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,8CAA8C;IAC9C,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,oDAAoD;IACpD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,qDAAqD;IACrD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,2DAA2D;IAC3D,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,yDAAyD;IACzD,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,+DAA+D;IAC/D,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,gEAAgE;IAChE,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAS,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAQ;IAC9C,SAAS,CAAC,eAAe,EAAE,WAAW,GAAG,IAAI,CAAQ;IAErD;;;;;OAKG;gBAEe,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;IAYlC;;;;;;;OAOG;IACH,IAAW,OAAO,IAAI,WAAW,CAGhC;IAED,SAAS,KAAK,OAAO,CAAC,CAAC,EAAE,WAAW,EAEnC;IAED;;;;OAIG;IACI,QAAQ,IAAI,OAAO;IAI1B;;;;;;;OAOG;IACU,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC;IAQzC;;;;;;;OAOG;IACI,QAAQ,IAAI,WAAW;IAM9B;;;;;;;OAOG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IASnC;;;;;;;;OAQG;IACU,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAgB/D,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;CAGtD"}
|
package/dist/pkg/Pkg.js
CHANGED
|
@@ -2,19 +2,42 @@ import { join, relative } from "node:path";
|
|
|
2
2
|
import { logInfo, logSuccess } from "../logger/Logger.js";
|
|
3
3
|
import { ensurePkgJsonPath, readPackageJson, readPackageJsonSync, writePackageJson, } from "./pkg.fs.js";
|
|
4
4
|
import { jsonClone, jsonEqual } from "../common/common.json.js";
|
|
5
|
+
/**
|
|
6
|
+
* Represents a single npm package within a repository workspace.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Wraps a `package.json` file with lazy-load semantics, change-tracking, and
|
|
10
|
+
* convenience accessors for common directory paths (source, dist, repo-relative).
|
|
11
|
+
* Content is only read from disk on the first call to {@link Pkg.read} or {@link Pkg.readSync},
|
|
12
|
+
* and writes are skipped when no modifications have been made.
|
|
13
|
+
*/
|
|
5
14
|
export class Pkg {
|
|
6
15
|
repoRoot;
|
|
7
16
|
repoPath;
|
|
17
|
+
/** Absolute path to the `package.json` file. */
|
|
8
18
|
filePath;
|
|
19
|
+
/** Absolute path to the package directory. */
|
|
9
20
|
dirPath;
|
|
21
|
+
/** Absolute path to the package `src` directory. */
|
|
10
22
|
srcPath;
|
|
23
|
+
/** Absolute path to the package `dist` directory. */
|
|
11
24
|
distPath;
|
|
25
|
+
/** Repository-relative path to the `package.json` file. */
|
|
12
26
|
repoFilePath;
|
|
27
|
+
/** Repository-relative path to the package directory. */
|
|
13
28
|
repoDirPath;
|
|
29
|
+
/** Repository-relative path to the package `src` directory. */
|
|
14
30
|
repoSrcPath;
|
|
31
|
+
/** Repository-relative path to the package `dist` directory. */
|
|
15
32
|
repoDistPath;
|
|
16
33
|
_content = null;
|
|
17
34
|
originalContent = null;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new Pkg instance for a package at the given repository-relative path.
|
|
37
|
+
*
|
|
38
|
+
* @param repoRoot - Absolute path to the repository root.
|
|
39
|
+
* @param repoPath - Repository-relative path to the package directory.
|
|
40
|
+
*/
|
|
18
41
|
constructor(repoRoot, repoPath) {
|
|
19
42
|
this.repoRoot = repoRoot;
|
|
20
43
|
this.repoPath = repoPath;
|
|
@@ -27,6 +50,14 @@ export class Pkg {
|
|
|
27
50
|
this.repoSrcPath = relative(repoRoot, this.srcPath);
|
|
28
51
|
this.repoDistPath = relative(repoRoot, this.distPath);
|
|
29
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns the loaded package.json content.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* Throws if content has not yet been loaded via {@link Pkg.read} or {@link Pkg.readSync}.
|
|
58
|
+
*
|
|
59
|
+
* @returns The parsed {@link PackageJson} object.
|
|
60
|
+
*/
|
|
30
61
|
get content() {
|
|
31
62
|
if (!this._content)
|
|
32
63
|
throw new Error(`Content not loaded. ${this.filePath}`);
|
|
@@ -35,19 +66,48 @@ export class Pkg {
|
|
|
35
66
|
set content(c) {
|
|
36
67
|
this._content = c;
|
|
37
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether the in-memory content has been modified since it was last read.
|
|
71
|
+
*
|
|
72
|
+
* @returns `true` if the current content differs from the original on-disk content.
|
|
73
|
+
*/
|
|
38
74
|
modified() {
|
|
39
75
|
return !jsonEqual(this.content, this.originalContent);
|
|
40
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Asynchronously reads the `package.json` from disk.
|
|
79
|
+
*
|
|
80
|
+
* @remarks
|
|
81
|
+
* The file is only read once; subsequent calls return the cached content.
|
|
82
|
+
*
|
|
83
|
+
* @returns A promise resolving to the parsed {@link PackageJson}.
|
|
84
|
+
*/
|
|
41
85
|
async read() {
|
|
42
86
|
if (!this._content)
|
|
43
87
|
this.updateOriginal((this.content = await readPackageJson(this.filePath)));
|
|
44
88
|
return this.content;
|
|
45
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Synchronously reads the `package.json` from disk.
|
|
92
|
+
*
|
|
93
|
+
* @remarks
|
|
94
|
+
* The file is only read once; subsequent calls return the cached content.
|
|
95
|
+
*
|
|
96
|
+
* @returns The parsed {@link PackageJson}.
|
|
97
|
+
*/
|
|
46
98
|
readSync() {
|
|
47
99
|
if (!this._content)
|
|
48
100
|
this.updateOriginal((this.content = readPackageJsonSync(this.filePath)));
|
|
49
101
|
return this.content;
|
|
50
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Writes the `package.json` back to disk if it has been modified.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* Skips the write and logs an informational message when no changes have been made.
|
|
108
|
+
*
|
|
109
|
+
* @returns A promise that resolves when the write operation completes (or is skipped).
|
|
110
|
+
*/
|
|
51
111
|
async write() {
|
|
52
112
|
if (this.content && this.modified()) {
|
|
53
113
|
await writePackageJson(this.filePath, this.content);
|
|
@@ -57,6 +117,15 @@ export class Pkg {
|
|
|
57
117
|
logInfo(` ⏭️ No changes in package.json. ${this.repoFilePath}\n`);
|
|
58
118
|
}
|
|
59
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Collects all dependency versions declared in the package.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* Merges `dependencies`, `devDependencies`, and `peerDependencies` into a
|
|
125
|
+
* single record. Reads the package from disk if not already loaded.
|
|
126
|
+
*
|
|
127
|
+
* @returns A promise resolving to a record mapping package names to their version specifiers.
|
|
128
|
+
*/
|
|
60
129
|
async packageVersions() {
|
|
61
130
|
const pkgJson = await this.read();
|
|
62
131
|
let versions = {};
|
package/dist/pkg/Pkg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pkg.js","sourceRoot":"","sources":["../../src/pkg/Pkg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAEhE,MAAM,OAAO,GAAG;
|
|
1
|
+
{"version":3,"file":"Pkg.js","sourceRoot":"","sources":["../../src/pkg/Pkg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,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C;IACH,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,eAAe;QAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;QAClC,IAAI,QAAQ,GAA2B,EAAE,CAAC;QAE1C,IAAI,OAAO,CAAC,YAAY;YACtB,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QAEtD,IAAI,OAAO,CAAC,eAAe;YACzB,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;QAEzD,IAAI,OAAO,CAAC,gBAAgB;YAC1B,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAE1D,OAAO,QAAQ,CAAC;IAClB,CAAC;IAES,cAAc,CAAC,OAAqB;QAC5C,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import { join, relative } from \"node:path\";\nimport { PackageJson } from \"../types/types.package.js\";\nimport { logInfo, logSuccess } from \"../logger/Logger.js\";\nimport {\n ensurePkgJsonPath,\n readPackageJson,\n readPackageJsonSync,\n writePackageJson,\n} from \"./pkg.fs.js\";\nimport { jsonClone, jsonEqual } from \"../common/common.json.js\";\n\n/**\n * Represents a single npm package within a repository workspace.\n *\n * @remarks\n * Wraps a `package.json` file with lazy-load semantics, change-tracking, and\n * convenience accessors for common directory paths (source, dist, repo-relative).\n * Content is only read from disk on the first call to {@link Pkg.read} or {@link Pkg.readSync},\n * and writes are skipped when no modifications have been made.\n */\nexport class Pkg {\n /** Absolute path to the `package.json` file. */\n public readonly filePath: string;\n /** Absolute path to the package directory. */\n public readonly dirPath: string;\n /** Absolute path to the package `src` directory. */\n public readonly srcPath: string;\n /** Absolute path to the package `dist` directory. */\n public readonly distPath: string;\n /** Repository-relative path to the `package.json` file. */\n public readonly repoFilePath: string;\n /** Repository-relative path to the package directory. */\n public readonly repoDirPath: string;\n /** Repository-relative path to the package `src` directory. */\n public readonly repoSrcPath: string;\n /** Repository-relative path to the package `dist` directory. */\n public readonly repoDistPath: string;\n protected _content: PackageJson | null = null;\n protected originalContent: PackageJson | null = null;\n\n /**\n * Creates a new Pkg instance for a package at the given repository-relative path.\n *\n * @param repoRoot - Absolute path to the repository root.\n * @param repoPath - Repository-relative path to the package directory.\n */\n public constructor(\n public readonly repoRoot: string,\n public readonly repoPath: string,\n ) {\n this.dirPath = join(repoRoot, repoPath);\n this.filePath = ensurePkgJsonPath(this.dirPath);\n this.srcPath = join(repoRoot, repoPath, \"src\");\n this.distPath = join(repoRoot, repoPath, \"dist\");\n this.repoFilePath = relative(repoRoot, this.filePath);\n this.repoDirPath = relative(repoRoot, this.dirPath);\n this.repoSrcPath = relative(repoRoot, this.srcPath);\n this.repoDistPath = relative(repoRoot, this.distPath);\n }\n\n /**\n * Returns the loaded package.json content.\n *\n * @remarks\n * Throws if content has not yet been loaded via {@link Pkg.read} or {@link Pkg.readSync}.\n *\n * @returns The parsed {@link PackageJson} object.\n */\n public get content(): PackageJson {\n if (!this._content) throw new Error(`Content not loaded. ${this.filePath}`);\n return this._content;\n }\n\n protected set content(c: PackageJson) {\n this._content = c;\n }\n\n /**\n * Checks whether the in-memory content has been modified since it was last read.\n *\n * @returns `true` if the current content differs from the original on-disk content.\n */\n public modified(): boolean {\n return !jsonEqual(this.content, this.originalContent);\n }\n\n /**\n * Asynchronously reads the `package.json` from disk.\n *\n * @remarks\n * The file is only read once; subsequent calls return the cached content.\n *\n * @returns A promise resolving to the parsed {@link PackageJson}.\n */\n public async read(): Promise<PackageJson> {\n if (!this._content)\n this.updateOriginal(\n (this.content = await readPackageJson(this.filePath)),\n );\n return this.content;\n }\n\n /**\n * Synchronously reads the `package.json` from disk.\n *\n * @remarks\n * The file is only read once; subsequent calls return the cached content.\n *\n * @returns The parsed {@link PackageJson}.\n */\n public readSync(): PackageJson {\n if (!this._content)\n this.updateOriginal((this.content = readPackageJsonSync(this.filePath)));\n return this.content;\n }\n\n /**\n * Writes the `package.json` back to disk if it has been modified.\n *\n * @remarks\n * Skips the write and logs an informational message when no changes have been made.\n *\n * @returns A promise that resolves when the write operation completes (or is skipped).\n */\n public async write(): Promise<void> {\n if (this.content && this.modified()) {\n await writePackageJson(this.filePath, this.content);\n logSuccess(` ✅ package.json updated ${this.repoFilePath}\\n`);\n } else {\n logInfo(` ⏭️ No changes in package.json. ${this.repoFilePath}\\n`);\n }\n }\n\n /**\n * Collects all dependency versions declared in the package.\n *\n * @remarks\n * Merges `dependencies`, `devDependencies`, and `peerDependencies` into a\n * single record. Reads the package from disk if not already loaded.\n *\n * @returns A promise resolving to a record mapping package names to their version specifiers.\n */\n public async packageVersions(): Promise<Record<string, string>> {\n const pkgJson = await this.read();\n let versions: Record<string, string> = {};\n\n if (pkgJson.dependencies)\n versions = { ...versions, ...pkgJson.dependencies };\n\n if (pkgJson.devDependencies)\n versions = { ...versions, ...pkgJson.devDependencies };\n\n if (pkgJson.peerDependencies)\n versions = { ...versions, ...pkgJson.peerDependencies };\n\n return versions;\n }\n\n protected updateOriginal(content?: PackageJson): void {\n this.originalContent = jsonClone(content ?? this.content);\n }\n}\n"]}
|
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
import { BumpParams, SyncPkgVersionParams } from "../types/types.package.js";
|
|
2
2
|
import { Pkg } from "./Pkg.js";
|
|
3
|
+
/**
|
|
4
|
+
* Initializes the workspace and runs the package-version synchronization workflow.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* This is a convenience entry point that constructs a {@link SyncPkgVersion} instance
|
|
8
|
+
* and immediately invokes its {@link SyncPkgVersion.run} method.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Configuration for the sync operation, including repo root, bump flags, and tag options.
|
|
11
|
+
* @returns A promise that resolves when all package versions have been synchronized.
|
|
12
|
+
*/
|
|
3
13
|
export declare const runSyncPkgVersion: (params: SyncPkgVersionParams) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Synchronizes version numbers across all workspace packages.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
* Determines the highest version from existing git tags and current package versions,
|
|
19
|
+
* optionally bumps it according to the provided {@link BumpParams}, then writes the
|
|
20
|
+
* new version to every workspace package. When tagging is enabled, an annotated git
|
|
21
|
+
* tag is created and pushed.
|
|
22
|
+
*/
|
|
4
23
|
export declare class SyncPkgVersion {
|
|
5
24
|
protected readonly bump: BumpParams | null;
|
|
6
25
|
protected readonly noTag: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new SyncPkgVersion instance.
|
|
28
|
+
*
|
|
29
|
+
* @param bump - The semver component to bump, or `null` to skip bumping.
|
|
30
|
+
* @param noTag - When `true`, skips creating and pushing a git tag.
|
|
31
|
+
*/
|
|
7
32
|
constructor(bump: BumpParams | null, noTag: boolean);
|
|
33
|
+
/**
|
|
34
|
+
* Executes the full version synchronization workflow.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* The workflow reads all workspace packages, collects existing git tag versions,
|
|
38
|
+
* determines the maximum version, optionally bumps it, writes the new version
|
|
39
|
+
* to all packages, and optionally creates and pushes an annotated git tag.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves when the synchronization is complete.
|
|
42
|
+
*/
|
|
8
43
|
run(): Promise<void>;
|
|
9
44
|
protected read(): Promise<Pkg[]>;
|
|
10
45
|
protected write(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncPkgVersion.d.ts","sourceRoot":"","sources":["../../src/pkg/SyncPkgVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAUnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,eAAO,MAAM,iBAAiB,GAAU,QAAQ,oBAAoB,kBAOnE,CAAC;AAEF,qBAAa,cAAc;
|
|
1
|
+
{"version":3,"file":"SyncPkgVersion.d.ts","sourceRoot":"","sources":["../../src/pkg/SyncPkgVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,oBAAoB,EACrB,MAAM,2BAA2B,CAAC;AAUnC,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAU,QAAQ,oBAAoB,kBAOnE,CAAC;AAEF;;;;;;;;GAQG;AACH,qBAAa,cAAc;IAQvB,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAC1C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO;IARnC;;;;;OAKG;gBAEkB,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,KAAK,EAAE,OAAO;IAGnC;;;;;;;;;OASG;IACU,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;cAyDjB,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;cAKtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvC"}
|
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
import { bumpVersion, compareVersions, compareVersionsGT, concatVersion, splitVersion, } from "./pkg.common.js";
|
|
2
2
|
import { tags, verifiedGit } from "../git/git.util.js";
|
|
3
3
|
import { initWorkspace, workspace } from "../workspace/Workspace.js";
|
|
4
|
+
/**
|
|
5
|
+
* Initializes the workspace and runs the package-version synchronization workflow.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This is a convenience entry point that constructs a {@link SyncPkgVersion} instance
|
|
9
|
+
* and immediately invokes its {@link SyncPkgVersion.run} method.
|
|
10
|
+
*
|
|
11
|
+
* @param params - Configuration for the sync operation, including repo root, bump flags, and tag options.
|
|
12
|
+
* @returns A promise that resolves when all package versions have been synchronized.
|
|
13
|
+
*/
|
|
4
14
|
export const runSyncPkgVersion = async (params) => {
|
|
5
15
|
initWorkspace(params.repoRoot);
|
|
6
16
|
return new SyncPkgVersion(params.noBump ? null : (params.bump ?? { patch: true }), !!params.noTag).run();
|
|
7
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Synchronizes version numbers across all workspace packages.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Determines the highest version from existing git tags and current package versions,
|
|
23
|
+
* optionally bumps it according to the provided {@link BumpParams}, then writes the
|
|
24
|
+
* new version to every workspace package. When tagging is enabled, an annotated git
|
|
25
|
+
* tag is created and pushed.
|
|
26
|
+
*/
|
|
8
27
|
export class SyncPkgVersion {
|
|
9
28
|
bump;
|
|
10
29
|
noTag;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new SyncPkgVersion instance.
|
|
32
|
+
*
|
|
33
|
+
* @param bump - The semver component to bump, or `null` to skip bumping.
|
|
34
|
+
* @param noTag - When `true`, skips creating and pushing a git tag.
|
|
35
|
+
*/
|
|
11
36
|
constructor(bump, noTag) {
|
|
12
37
|
this.bump = bump;
|
|
13
38
|
this.noTag = noTag;
|
|
14
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Executes the full version synchronization workflow.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* The workflow reads all workspace packages, collects existing git tag versions,
|
|
45
|
+
* determines the maximum version, optionally bumps it, writes the new version
|
|
46
|
+
* to all packages, and optionally creates and pushes an annotated git tag.
|
|
47
|
+
*
|
|
48
|
+
* @returns A promise that resolves when the synchronization is complete.
|
|
49
|
+
*/
|
|
15
50
|
async run() {
|
|
16
51
|
const packages = await this.read();
|
|
17
52
|
const existingTags = await tags(workspace().repoRoot);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SyncPkgVersion.js","sourceRoot":"","sources":["../../src/pkg/SyncPkgVersion.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,eAAe,EACf,iB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,KAAK;QACnB,OAAO,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {\n BumpParams,\n PackageVersion,\n SyncPkgVersionParams,\n} from \"../types/types.package.js\";\nimport {\n bumpVersion,\n compareVersions,\n compareVersionsGT,\n concatVersion,\n splitVersion,\n} from \"./pkg.common.js\";\nimport { tags, verifiedGit } from \"../git/git.util.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\nimport { Pkg } from \"./Pkg.js\";\n\n/**\n * Initializes the workspace and runs the package-version synchronization workflow.\n *\n * @remarks\n * This is a convenience entry point that constructs a {@link SyncPkgVersion} instance\n * and immediately invokes its {@link SyncPkgVersion.run} method.\n *\n * @param params - Configuration for the sync operation, including repo root, bump flags, and tag options.\n * @returns A promise that resolves when all package versions have been synchronized.\n */\nexport const runSyncPkgVersion = async (params: SyncPkgVersionParams) => {\n initWorkspace(params.repoRoot);\n\n return new SyncPkgVersion(\n params.noBump ? null : (params.bump ?? { patch: true }),\n !!params.noTag,\n ).run();\n};\n\n/**\n * Synchronizes version numbers across all workspace packages.\n *\n * @remarks\n * Determines the highest version from existing git tags and current package versions,\n * optionally bumps it according to the provided {@link BumpParams}, then writes the\n * new version to every workspace package. When tagging is enabled, an annotated git\n * tag is created and pushed.\n */\nexport class SyncPkgVersion {\n /**\n * Creates a new SyncPkgVersion instance.\n *\n * @param bump - The semver component to bump, or `null` to skip bumping.\n * @param noTag - When `true`, skips creating and pushing a git tag.\n */\n public constructor(\n protected readonly bump: BumpParams | null,\n protected readonly noTag: boolean,\n ) {}\n\n /**\n * Executes the full version synchronization workflow.\n *\n * @remarks\n * The workflow reads all workspace packages, collects existing git tag versions,\n * determines the maximum version, optionally bumps it, writes the new version\n * to all packages, and optionally creates and pushes an annotated git tag.\n *\n * @returns A promise that resolves when the synchronization is complete.\n */\n public async run(): Promise<void> {\n const packages = await this.read();\n const existingTags = await tags(workspace().repoRoot);\n const tagVersions: PackageVersion[] = [];\n\n for (const existingTag of existingTags) {\n try {\n tagVersions.push(splitVersion(existingTag));\n } catch {}\n }\n\n // descending\n tagVersions.sort((a, b) => compareVersions(a, b) * -1);\n packages.sort(\n (a, b) => compareVersions(a.content.version, b.content.version) * -1,\n );\n\n const tagMaxVersion = tagVersions.shift() ?? {\n major: 0,\n minor: 0,\n patch: 0,\n prefix: null,\n };\n tagMaxVersion.prefix = null;\n\n const pkg = packages.length > 0 ? packages[0] : null;\n const pkgMaxVersion = pkg\n ? splitVersion(pkg.content.version)\n : {\n major: 0,\n minor: 0,\n patch: 0,\n prefix: null,\n };\n pkgMaxVersion.prefix = null;\n\n let maxVersion = compareVersionsGT(tagMaxVersion, pkgMaxVersion)\n ? tagMaxVersion\n : pkgMaxVersion;\n\n // bump\n if (this.bump) maxVersion = bumpVersion(maxVersion, this.bump);\n const newVersion = concatVersion(maxVersion);\n\n // set/update\n for (const entry of packages) entry.content.version = newVersion;\n\n await this.write();\n\n // create tag\n if (!this.noTag) {\n const git = await verifiedGit(workspace().repoRoot);\n await git.addAnnotatedTag(`v${newVersion}`, `Release v${newVersion}`);\n await git.pushTags();\n }\n }\n\n protected async read(): Promise<Pkg[]> {\n const ws = await workspace().read();\n return [ws.rootPackage, ...ws.packages];\n }\n\n protected async write(): Promise<void> {\n return workspace().write();\n }\n}\n"]}
|
|
@@ -1,9 +1,45 @@
|
|
|
1
1
|
import { PackageJson, UpdatePackagesParams } from "../types/types.package.js";
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the workspace and runs the package-update workflow.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This is a convenience entry point that constructs an {@link UpdatePackages} instance
|
|
7
|
+
* and immediately invokes its {@link UpdatePackages.run} method.
|
|
8
|
+
*
|
|
9
|
+
* @param params - Configuration for the update, including the repo root and a glob pattern to select packages.
|
|
10
|
+
* @returns A promise that resolves when all matching packages have been updated and verified.
|
|
11
|
+
*/
|
|
2
12
|
export declare const runUpdatePackages: (params: UpdatePackagesParams) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Bulk-updates dependencies matching a glob pattern across all workspace packages.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The update pipeline performs five sequential steps:
|
|
18
|
+
* 1. Discover matching dependencies across every workspace package.
|
|
19
|
+
* 2. Run `pnpm update -r --latest` for the matched packages.
|
|
20
|
+
* 3. Deduplicate the dependency tree with `pnpm dedupe`.
|
|
21
|
+
* 4. Remove stale duplicate versions from `node_modules/.pnpm`.
|
|
22
|
+
* 5. Verify that all workspaces converge on the same version for each package.
|
|
23
|
+
*/
|
|
3
24
|
export declare class UpdatePackages {
|
|
4
25
|
protected readonly pattern: string;
|
|
5
26
|
protected patternWoSlash: string;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new UpdatePackages instance.
|
|
29
|
+
*
|
|
30
|
+
* @param pattern - A glob pattern used to match dependency names (e.g. `"@angular/*"`).
|
|
31
|
+
*/
|
|
6
32
|
constructor(pattern: string);
|
|
33
|
+
/**
|
|
34
|
+
* Executes the full package-update pipeline.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Discovers matching packages, updates them, deduplicates, cleans old versions,
|
|
38
|
+
* and verifies consistency. Exits the process with code 1 if version
|
|
39
|
+
* inconsistencies are detected after the update.
|
|
40
|
+
*
|
|
41
|
+
* @returns A promise that resolves when the pipeline completes successfully.
|
|
42
|
+
*/
|
|
7
43
|
run(): Promise<void>;
|
|
8
44
|
protected exec(command: string): Promise<string>;
|
|
9
45
|
protected getPackages(): Promise<Set<string>>;
|