@mxpicture/build-api 0.2.56 → 0.2.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/barrel/Barrel.d.ts +66 -0
- package/dist/barrel/Barrel.d.ts.map +1 -1
- package/dist/barrel/Barrel.js +66 -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 +27 -0
- package/dist/common/common.json.d.ts.map +1 -1
- package/dist/common/common.json.js +27 -0
- package/dist/common/common.json.js.map +1 -1
- package/dist/deps/FixWorkspaceDeps.d.ts +132 -0
- package/dist/deps/FixWorkspaceDeps.d.ts.map +1 -1
- package/dist/deps/FixWorkspaceDeps.js +120 -2
- package/dist/deps/FixWorkspaceDeps.js.map +1 -1
- package/dist/git/GitChanges.d.ts +60 -13
- package/dist/git/GitChanges.d.ts.map +1 -1
- package/dist/git/GitChanges.js +60 -13
- package/dist/git/GitChanges.js.map +1 -1
- package/dist/git/git.util.d.ts +58 -3
- package/dist/git/git.util.d.ts.map +1 -1
- package/dist/git/git.util.js +58 -3
- package/dist/git/git.util.js.map +1 -1
- package/dist/logger/Logger.d.ts +74 -0
- package/dist/logger/Logger.d.ts.map +1 -1
- package/dist/logger/Logger.js +49 -0
- package/dist/logger/Logger.js.map +1 -1
- package/dist/npmPublish/NpmPublisher.d.ts +36 -0
- package/dist/npmPublish/NpmPublisher.d.ts.map +1 -1
- package/dist/npmPublish/NpmPublisher.js +36 -0
- package/dist/npmPublish/NpmPublisher.js.map +1 -1
- package/dist/osInfo/osInfo.common.d.ts +45 -1
- package/dist/osInfo/osInfo.common.d.ts.map +1 -1
- package/dist/osInfo/osInfo.common.js +45 -1
- package/dist/osInfo/osInfo.common.js.map +1 -1
- package/dist/pkg/Pkg.d.ts +69 -0
- package/dist/pkg/Pkg.d.ts.map +1 -1
- package/dist/pkg/Pkg.js +69 -0
- package/dist/pkg/Pkg.js.map +1 -1
- package/dist/pkg/SyncPkgVersion.d.ts +35 -0
- package/dist/pkg/SyncPkgVersion.d.ts.map +1 -1
- package/dist/pkg/SyncPkgVersion.js +35 -0
- package/dist/pkg/SyncPkgVersion.js.map +1 -1
- package/dist/pkg/UpdatePackages.d.ts +36 -0
- package/dist/pkg/UpdatePackages.d.ts.map +1 -1
- package/dist/pkg/UpdatePackages.js +36 -0
- package/dist/pkg/UpdatePackages.js.map +1 -1
- package/dist/pkg/pkg.common.d.ts +73 -0
- package/dist/pkg/pkg.common.d.ts.map +1 -1
- package/dist/pkg/pkg.common.js +73 -0
- package/dist/pkg/pkg.common.js.map +1 -1
- package/dist/pkg/pkg.fs.d.ts +53 -0
- package/dist/pkg/pkg.fs.d.ts.map +1 -1
- package/dist/pkg/pkg.fs.js +53 -0
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/types/types.barrel.d.ts +28 -0
- package/dist/types/types.barrel.d.ts.map +1 -1
- package/dist/types/types.barrel.js.map +1 -1
- package/dist/types/types.changelog.d.ts +28 -0
- package/dist/types/types.changelog.d.ts.map +1 -1
- package/dist/types/types.changelog.js +9 -0
- package/dist/types/types.changelog.js.map +1 -1
- package/dist/types/types.cleanup.d.ts +19 -0
- package/dist/types/types.cleanup.d.ts.map +1 -1
- package/dist/types/types.cleanup.js.map +1 -1
- package/dist/types/types.code.d.ts +36 -0
- package/dist/types/types.code.d.ts.map +1 -1
- package/dist/types/types.code.js.map +1 -1
- package/dist/types/types.deps.d.ts +27 -0
- package/dist/types/types.deps.d.ts.map +1 -1
- package/dist/types/types.deps.js +10 -0
- package/dist/types/types.deps.js.map +1 -1
- package/dist/types/types.documents.d.ts +9 -0
- package/dist/types/types.documents.d.ts.map +1 -1
- package/dist/types/types.documents.js.map +1 -1
- package/dist/types/types.git.d.ts +25 -0
- package/dist/types/types.git.d.ts.map +1 -1
- package/dist/types/types.git.js.map +1 -1
- package/dist/types/types.npm.d.ts +7 -0
- package/dist/types/types.npm.d.ts.map +1 -1
- package/dist/types/types.npm.js.map +1 -1
- package/dist/types/types.os.d.ts +8 -0
- package/dist/types/types.os.d.ts.map +1 -1
- package/dist/types/types.os.js.map +1 -1
- package/dist/types/types.package.d.ts +48 -0
- package/dist/types/types.package.d.ts.map +1 -1
- package/dist/types/types.package.js.map +1 -1
- package/dist/types/types.run.d.ts +4 -0
- package/dist/types/types.run.d.ts.map +1 -1
- package/dist/types/types.run.js.map +1 -1
- package/dist/types/types.vscode.d.ts +46 -0
- package/dist/types/types.vscode.d.ts.map +1 -1
- package/dist/types/types.vscode.js.map +1 -1
- package/dist/types/types.workspace.d.ts +18 -0
- package/dist/types/types.workspace.d.ts.map +1 -1
- package/dist/types/types.workspace.js +6 -0
- package/dist/types/types.workspace.js.map +1 -1
- package/dist/vscode/vscode.config.d.ts +18 -0
- package/dist/vscode/vscode.config.d.ts.map +1 -1
- package/dist/vscode/vscode.config.js +18 -0
- package/dist/vscode/vscode.config.js.map +1 -1
- package/dist/vscode/vscode.profiles.d.ts +37 -0
- package/dist/vscode/vscode.profiles.d.ts.map +1 -1
- package/dist/vscode/vscode.profiles.js +37 -0
- package/dist/vscode/vscode.profiles.js.map +1 -1
- package/dist/vscode/vscode.settings.d.ts +26 -1
- package/dist/vscode/vscode.settings.d.ts.map +1 -1
- package/dist/vscode/vscode.settings.js +26 -1
- package/dist/vscode/vscode.settings.js.map +1 -1
- package/dist/vscode/vscode.storage.d.ts +21 -1
- package/dist/vscode/vscode.storage.d.ts.map +1 -1
- package/dist/vscode/vscode.storage.js +21 -1
- package/dist/vscode/vscode.storage.js.map +1 -1
- package/dist/vscode/vscode.workspace.d.ts +17 -0
- package/dist/vscode/vscode.workspace.d.ts.map +1 -1
- package/dist/vscode/vscode.workspace.js +17 -0
- package/dist/vscode/vscode.workspace.js.map +1 -1
- package/dist/workspace/Workspace.d.ts +85 -0
- package/dist/workspace/Workspace.d.ts.map +1 -1
- package/dist/workspace/Workspace.js +85 -0
- package/dist/workspace/Workspace.js.map +1 -1
- package/dist/workspace/workspace.common.d.ts +42 -1
- package/dist/workspace/workspace.common.d.ts.map +1 -1
- package/dist/workspace/workspace.common.js +42 -1
- package/dist/workspace/workspace.common.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,18 +2,74 @@ import { relative } from "path";
|
|
|
2
2
|
import { logError, logInfo, logSuccess } from "../logger/Logger.js";
|
|
3
3
|
import { DepsReplacementMode, } from "../types/types.deps.js";
|
|
4
4
|
import { initWorkspace, workspace } from "../workspace/Workspace.js";
|
|
5
|
+
/**
|
|
6
|
+
* Fix or restore workspace dependency references across all packages.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Initializes the workspace from the given repository root, selects the
|
|
10
|
+
* appropriate replacement strategy ({@link FixWorkspaceDepsVersion} or
|
|
11
|
+
* {@link FixWorkspaceDepsFile}), and executes the full fix/restore run.
|
|
12
|
+
*
|
|
13
|
+
* @param p - Parameters specifying the repo root, processing mode, and replacement strategy.
|
|
14
|
+
* @returns A promise that resolves when all workspace dependencies have been processed and written.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* await runFixDeps({
|
|
19
|
+
* repoRoot: "/path/to/repo",
|
|
20
|
+
* mode: DepsProcessMode.fix,
|
|
21
|
+
* replacement: DepsReplacementMode.version,
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
5
25
|
export const runFixDeps = async (p) => {
|
|
6
26
|
initWorkspace(p.repoRoot);
|
|
7
27
|
return instanceFixDeps(p).run();
|
|
8
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Create the appropriate {@link IFixWorkspaceDeps} instance for the given replacement mode.
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Acts as a factory function that returns a {@link FixWorkspaceDepsVersion}
|
|
34
|
+
* when the replacement mode is `version`, or a {@link FixWorkspaceDepsFile}
|
|
35
|
+
* when it is `file`.
|
|
36
|
+
*
|
|
37
|
+
* @param p - Object containing the processing mode and replacement strategy.
|
|
38
|
+
* @returns A concrete {@link IFixWorkspaceDeps} subclass ready to execute.
|
|
39
|
+
*/
|
|
9
40
|
export const instanceFixDeps = (p) => p.replacement === DepsReplacementMode.version
|
|
10
41
|
? new FixWorkspaceDepsVersion(p.mode)
|
|
11
42
|
: new FixWorkspaceDepsFile(p.mode);
|
|
43
|
+
/**
|
|
44
|
+
* Abstract base class for fixing or restoring workspace dependency references.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* Implements the template-method pattern: subclasses provide concrete
|
|
48
|
+
* {@link IFixWorkspaceDeps.fixVersion | fixVersion} and
|
|
49
|
+
* {@link IFixWorkspaceDeps.restoreVersion | restoreVersion} implementations
|
|
50
|
+
* while the base class orchestrates reading, processing, and writing all
|
|
51
|
+
* workspace packages.
|
|
52
|
+
*/
|
|
12
53
|
export class IFixWorkspaceDeps {
|
|
13
54
|
mode;
|
|
55
|
+
/**
|
|
56
|
+
* Create a new workspace dependency fixer.
|
|
57
|
+
*
|
|
58
|
+
* @param mode - Whether to `fix` (replace `workspace:*`) or `restore` (revert to `workspace:*`).
|
|
59
|
+
*/
|
|
14
60
|
constructor(mode) {
|
|
15
61
|
this.mode = mode;
|
|
16
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Execute the full fix or restore operation across every workspace package.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Reads the workspace, builds a version map and map entries, iterates over
|
|
68
|
+
* each package to apply the appropriate transformation, and writes all
|
|
69
|
+
* modified `package.json` files back to disk.
|
|
70
|
+
*
|
|
71
|
+
* @returns A promise that resolves when all packages have been written.
|
|
72
|
+
*/
|
|
17
73
|
async run() {
|
|
18
74
|
if (this.mode === "fix")
|
|
19
75
|
logInfo("🔧 Fixing workspace dependencies...\n");
|
|
@@ -53,7 +109,12 @@ export class IFixWorkspaceDeps {
|
|
|
53
109
|
else
|
|
54
110
|
logSuccess("✅ Done restoring workspace dependencies!");
|
|
55
111
|
}
|
|
56
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Process a single dependency map, replacing matching versions in place.
|
|
114
|
+
*
|
|
115
|
+
* @param deps - The dependency record (e.g. `dependencies`, `devDependencies`) to mutate.
|
|
116
|
+
* @param p - Contextual data for the consuming package and workspace.
|
|
117
|
+
*/
|
|
57
118
|
handleDependencies(deps, p) {
|
|
58
119
|
if (!deps)
|
|
59
120
|
return;
|
|
@@ -66,12 +127,27 @@ export class IFixWorkspaceDeps {
|
|
|
66
127
|
deps[name] = newVersion;
|
|
67
128
|
}
|
|
68
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Process all dependency groups for a single consuming package.
|
|
132
|
+
*
|
|
133
|
+
* @param p - Contextual data including the consuming package, map entries, and version map.
|
|
134
|
+
*/
|
|
69
135
|
runSingle(p) {
|
|
70
136
|
this.handleDependencies(p.consumingPkg.content.dependencies, p);
|
|
71
137
|
this.handleDependencies(p.consumingPkg.content.devDependencies, p);
|
|
72
138
|
this.handleDependencies(p.consumingPkg.content.peerDependencies, p);
|
|
73
139
|
}
|
|
74
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Build pairwise mapping entries between all workspace packages.
|
|
142
|
+
*
|
|
143
|
+
* @remarks
|
|
144
|
+
* Produces a cartesian product (excluding self-pairs) of packages, computing
|
|
145
|
+
* the relative filesystem path from each source package to every other
|
|
146
|
+
* target package.
|
|
147
|
+
*
|
|
148
|
+
* @param pkgs - The list of workspace packages.
|
|
149
|
+
* @returns An array of {@link MapEntry} objects describing each package-to-package relationship.
|
|
150
|
+
*/
|
|
75
151
|
buildMapEntries(pkgs) {
|
|
76
152
|
const versionEntries = [];
|
|
77
153
|
for (const fromPkg of pkgs)
|
|
@@ -85,7 +161,22 @@ export class IFixWorkspaceDeps {
|
|
|
85
161
|
return versionEntries;
|
|
86
162
|
}
|
|
87
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Workspace dependency fixer that replaces `workspace:*` with caret version ranges.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* During a `fix` pass, `workspace:*` is replaced with `^{resolved-version}`.
|
|
169
|
+
* During a `restore` pass, caret-prefixed versions that match the workspace
|
|
170
|
+
* version map are reverted back to `workspace:*`.
|
|
171
|
+
*/
|
|
88
172
|
export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
173
|
+
/**
|
|
174
|
+
* Replace a `workspace:*` reference with a caret version range.
|
|
175
|
+
*
|
|
176
|
+
* @param p - Data about the dependency being processed.
|
|
177
|
+
* @returns A string like `^1.2.3`, or `null` if the dependency is not `workspace:*`.
|
|
178
|
+
* @throws Error if the package cannot be found in the workspace version map.
|
|
179
|
+
*/
|
|
89
180
|
fixVersion(p) {
|
|
90
181
|
if (p.version !== "workspace:*")
|
|
91
182
|
return null;
|
|
@@ -96,6 +187,12 @@ export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
|
96
187
|
}
|
|
97
188
|
return `^${actualVersion}`;
|
|
98
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Restore a caret version range back to `workspace:*`.
|
|
192
|
+
*
|
|
193
|
+
* @param p - Data about the dependency being processed.
|
|
194
|
+
* @returns The string `workspace:*` if the version matches the expected caret range, or `null` otherwise.
|
|
195
|
+
*/
|
|
99
196
|
restoreVersion(p) {
|
|
100
197
|
if (p.workspacePackages.has(p.pkg) && p.version.startsWith("^")) {
|
|
101
198
|
// Verify the version matches what fix script would have created
|
|
@@ -107,7 +204,22 @@ export class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {
|
|
|
107
204
|
return null;
|
|
108
205
|
}
|
|
109
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Workspace dependency fixer that replaces `workspace:*` with `file:` protocol paths.
|
|
209
|
+
*
|
|
210
|
+
* @remarks
|
|
211
|
+
* During a `fix` pass, `workspace:*` is replaced with a relative `file:` path
|
|
212
|
+
* pointing to the dependency's package directory.
|
|
213
|
+
* During a `restore` pass, any `file:`-prefixed version is reverted to `workspace:*`.
|
|
214
|
+
*/
|
|
110
215
|
export class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
216
|
+
/**
|
|
217
|
+
* Replace a `workspace:*` reference with a relative `file:` path.
|
|
218
|
+
*
|
|
219
|
+
* @param p - Data about the dependency being processed.
|
|
220
|
+
* @returns A string like `file:../sibling-pkg`, or `null` if the dependency is not `workspace:*`.
|
|
221
|
+
* @throws Error if no map entry can be found for the dependency.
|
|
222
|
+
*/
|
|
111
223
|
fixVersion(p) {
|
|
112
224
|
if (p.version !== "workspace:*")
|
|
113
225
|
return null;
|
|
@@ -119,6 +231,12 @@ export class FixWorkspaceDepsFile extends IFixWorkspaceDeps {
|
|
|
119
231
|
}
|
|
120
232
|
return `file:${mapEntry.relPath}`;
|
|
121
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Restore a `file:` path reference back to `workspace:*`.
|
|
236
|
+
*
|
|
237
|
+
* @param p - Data about the dependency being processed.
|
|
238
|
+
* @returns The string `workspace:*` if the version uses the `file:` protocol, or `null` otherwise.
|
|
239
|
+
*/
|
|
122
240
|
restoreVersion(p) {
|
|
123
241
|
if (!p.version.startsWith("file:"))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AAQ,EAAE,EAAE,CACX,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI;YAC7D,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CACxC,CAAC;QACF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,CACN,4DAA4D,CAAC,CAAC,GAAG,EAAE,CACpE,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,QAAQ,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;IAEkB,cAAc,CAAC,CAAuB;QACvD,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QAChD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { relative } from \"path\";\nimport { logError, logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport {\n DepsProcessMode,\n DepsReplacementMode,\n FixWorkspaceDepsData,\n FixWorkspaceDepsMain,\n FixWorkspaceDepsParams,\n} from \"../types/types.deps.js\";\nimport { MapEntry } from \"../types/types.package.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\n\nexport const runFixDeps = async (p: FixWorkspaceDepsParams) => {\n initWorkspace(p.repoRoot);\n return instanceFixDeps(p).run();\n};\n\nexport const instanceFixDeps = (p: {\n mode: DepsProcessMode;\n replacement: DepsReplacementMode;\n}) =>\n p.replacement === DepsReplacementMode.version\n ? new FixWorkspaceDepsVersion(p.mode)\n : new FixWorkspaceDepsFile(p.mode);\n\nexport abstract class IFixWorkspaceDeps {\n public constructor(public readonly mode: DepsProcessMode) {}\n\n protected abstract fixVersion(p: FixWorkspaceDepsData): string | null;\n protected abstract restoreVersion(p: FixWorkspaceDepsData): string | null;\n\n public async run() {\n if (this.mode === \"fix\") logInfo(\"🔧 Fixing workspace dependencies...\\n\");\n else logInfo(\"🔧 Restoring workspace dependencies...\\n\");\n\n const ws = await workspace().read();\n const pkgs = ws.packages;\n const mapEntries = this.buildMapEntries(pkgs);\n\n const versionMap = new Map<string, string>();\n const workspacePackages = new Set<string>();\n for (const pkg of pkgs) {\n versionMap.set(pkg.content.name, pkg.content.version);\n workspacePackages.add(pkg.content.name);\n }\n\n logInfo(\"📋 Version map:\");\n for (const map of mapEntries)\n logInfo(\n ` ${map.fromPkg.content.name} --> ${map.toPkg.content.name}: ${map.relPath}`,\n );\n logInfo();\n\n for (const consumingPkg of pkgs) {\n logInfo(`📦 Processing ${consumingPkg.content.name}...`);\n\n try {\n this.runSingle({\n consumingPkg,\n mapEntries,\n versionMap,\n workspacePackages,\n });\n } catch (err) {\n logError(`\\nError processing ${consumingPkg.content.name}:`, err);\n throw err;\n }\n }\n\n await ws.write();\n if (this.mode === \"fix\")\n logSuccess(\"✅ Done fixing workspace dependencies!\");\n else logSuccess(\"✅ Done restoring workspace dependencies!\");\n }\n\n // Replace workspace:* with file:...\n protected handleDependencies(\n deps: Record<string, string> | undefined,\n p: FixWorkspaceDepsMain,\n ): void {\n if (!deps) return;\n\n const handler = this.mode === \"fix\" ? this.fixVersion : this.restoreVersion;\n\n for (const [name, version] of Object.entries(deps)) {\n const newVersion = handler({ ...p, pkg: name, version });\n if (!newVersion) continue;\n logInfo(` ✓ Replaced ${name}: ${version} → ${newVersion}`);\n deps[name] = newVersion;\n }\n }\n\n protected runSingle(p: FixWorkspaceDepsMain): void {\n this.handleDependencies(p.consumingPkg.content.dependencies, p);\n this.handleDependencies(p.consumingPkg.content.devDependencies, p);\n this.handleDependencies(p.consumingPkg.content.peerDependencies, p);\n }\n\n // Build a map of package names to their versions\n protected buildMapEntries(pkgs: Pkg[]): MapEntry[] {\n const versionEntries: MapEntry[] = [];\n for (const fromPkg of pkgs)\n for (const toPkg of pkgs)\n if (fromPkg.content.name !== toPkg.content.name)\n versionEntries.push({\n fromPkg,\n toPkg,\n relPath: relative(fromPkg.filePath, toPkg.filePath),\n });\n return versionEntries;\n }\n}\n\nexport class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {\n protected override fixVersion(p: FixWorkspaceDepsData): string | null {\n if (p.version !== \"workspace:*\") return null;\n const actualVersion = p.versionMap.get(p.pkg);\n if (!actualVersion) {\n logError(\n ` ERROR: Could not find version for workspace dependency ${p.pkg}`,\n );\n throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);\n }\n return `^${actualVersion}`;\n }\n\n protected override restoreVersion(p: FixWorkspaceDepsData): string | null {\n if (p.workspacePackages.has(p.pkg) && p.version.startsWith(\"^\")) {\n // Verify the version matches what fix script would have created\n const actualVersion = p.versionMap.get(p.pkg);\n if (actualVersion && p.version === `^${actualVersion}`) {\n return \"workspace:*\";\n }\n }\n return null;\n }\n}\n\nexport class FixWorkspaceDepsFile extends IFixWorkspaceDeps {\n protected override fixVersion(p: FixWorkspaceDepsData): string | null {\n if (p.version !== \"workspace:*\") return null;\n\n const mapEntry = p.mapEntries.find(\n (mapEntry) =>\n mapEntry.fromPkg.content.name === p.consumingPkg.content.name &&\n mapEntry.toPkg.content.name === p.pkg,\n );\n if (!mapEntry) {\n logError(\n ` ERROR: Could not find version for workspace dependency ${p.pkg}`,\n );\n throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);\n }\n\n return `file:${mapEntry.relPath}`;\n }\n\n protected override restoreVersion(p: FixWorkspaceDepsData): string | null {\n if (!p.version.startsWith(\"file:\")) return null;\n return \"workspace:*\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FixWorkspaceDeps.js","sourceRoot":"","sources":["../../src/deps/FixWorkspaceDeps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qB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AAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI;YAC7D,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,GAAG,CACxC,CAAC;QACF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,CACN,4DAA4D,CAAC,CAAC,GAAG,EAAE,CACpE,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,QAAQ,QAAQ,CAAC,OAAO,EAAE,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACgB,cAAc,CAAC,CAAuB;QACvD,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QAChD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { relative } from \"path\";\nimport { logError, logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport {\n DepsProcessMode,\n DepsReplacementMode,\n FixWorkspaceDepsData,\n FixWorkspaceDepsMain,\n FixWorkspaceDepsParams,\n} from \"../types/types.deps.js\";\nimport { MapEntry } from \"../types/types.package.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\n\n/**\n * Fix or restore workspace dependency references across all packages.\n *\n * @remarks\n * Initializes the workspace from the given repository root, selects the\n * appropriate replacement strategy ({@link FixWorkspaceDepsVersion} or\n * {@link FixWorkspaceDepsFile}), and executes the full fix/restore run.\n *\n * @param p - Parameters specifying the repo root, processing mode, and replacement strategy.\n * @returns A promise that resolves when all workspace dependencies have been processed and written.\n *\n * @example\n * ```ts\n * await runFixDeps({\n * repoRoot: \"/path/to/repo\",\n * mode: DepsProcessMode.fix,\n * replacement: DepsReplacementMode.version,\n * });\n * ```\n */\nexport const runFixDeps = async (p: FixWorkspaceDepsParams) => {\n initWorkspace(p.repoRoot);\n return instanceFixDeps(p).run();\n};\n\n/**\n * Create the appropriate {@link IFixWorkspaceDeps} instance for the given replacement mode.\n *\n * @remarks\n * Acts as a factory function that returns a {@link FixWorkspaceDepsVersion}\n * when the replacement mode is `version`, or a {@link FixWorkspaceDepsFile}\n * when it is `file`.\n *\n * @param p - Object containing the processing mode and replacement strategy.\n * @returns A concrete {@link IFixWorkspaceDeps} subclass ready to execute.\n */\nexport const instanceFixDeps = (p: {\n mode: DepsProcessMode;\n replacement: DepsReplacementMode;\n}) =>\n p.replacement === DepsReplacementMode.version\n ? new FixWorkspaceDepsVersion(p.mode)\n : new FixWorkspaceDepsFile(p.mode);\n\n/**\n * Abstract base class for fixing or restoring workspace dependency references.\n *\n * @remarks\n * Implements the template-method pattern: subclasses provide concrete\n * {@link IFixWorkspaceDeps.fixVersion | fixVersion} and\n * {@link IFixWorkspaceDeps.restoreVersion | restoreVersion} implementations\n * while the base class orchestrates reading, processing, and writing all\n * workspace packages.\n */\nexport abstract class IFixWorkspaceDeps {\n /**\n * Create a new workspace dependency fixer.\n *\n * @param mode - Whether to `fix` (replace `workspace:*`) or `restore` (revert to `workspace:*`).\n */\n public constructor(public readonly mode: DepsProcessMode) {}\n\n /**\n * Compute the replacement version string when fixing a dependency.\n *\n * @param p - Data about the dependency being processed.\n * @returns The replacement version string, or `null` if no replacement is needed.\n */\n protected abstract fixVersion(p: FixWorkspaceDepsData): string | null;\n\n /**\n * Compute the original version string when restoring a dependency.\n *\n * @param p - Data about the dependency being processed.\n * @returns The restored version string, or `null` if no restoration is needed.\n */\n protected abstract restoreVersion(p: FixWorkspaceDepsData): string | null;\n\n /**\n * Execute the full fix or restore operation across every workspace package.\n *\n * @remarks\n * Reads the workspace, builds a version map and map entries, iterates over\n * each package to apply the appropriate transformation, and writes all\n * modified `package.json` files back to disk.\n *\n * @returns A promise that resolves when all packages have been written.\n */\n public async run() {\n if (this.mode === \"fix\") logInfo(\"🔧 Fixing workspace dependencies...\\n\");\n else logInfo(\"🔧 Restoring workspace dependencies...\\n\");\n\n const ws = await workspace().read();\n const pkgs = ws.packages;\n const mapEntries = this.buildMapEntries(pkgs);\n\n const versionMap = new Map<string, string>();\n const workspacePackages = new Set<string>();\n for (const pkg of pkgs) {\n versionMap.set(pkg.content.name, pkg.content.version);\n workspacePackages.add(pkg.content.name);\n }\n\n logInfo(\"📋 Version map:\");\n for (const map of mapEntries)\n logInfo(\n ` ${map.fromPkg.content.name} --> ${map.toPkg.content.name}: ${map.relPath}`,\n );\n logInfo();\n\n for (const consumingPkg of pkgs) {\n logInfo(`📦 Processing ${consumingPkg.content.name}...`);\n\n try {\n this.runSingle({\n consumingPkg,\n mapEntries,\n versionMap,\n workspacePackages,\n });\n } catch (err) {\n logError(`\\nError processing ${consumingPkg.content.name}:`, err);\n throw err;\n }\n }\n\n await ws.write();\n if (this.mode === \"fix\")\n logSuccess(\"✅ Done fixing workspace dependencies!\");\n else logSuccess(\"✅ Done restoring workspace dependencies!\");\n }\n\n /**\n * Process a single dependency map, replacing matching versions in place.\n *\n * @param deps - The dependency record (e.g. `dependencies`, `devDependencies`) to mutate.\n * @param p - Contextual data for the consuming package and workspace.\n */\n protected handleDependencies(\n deps: Record<string, string> | undefined,\n p: FixWorkspaceDepsMain,\n ): void {\n if (!deps) return;\n\n const handler = this.mode === \"fix\" ? this.fixVersion : this.restoreVersion;\n\n for (const [name, version] of Object.entries(deps)) {\n const newVersion = handler({ ...p, pkg: name, version });\n if (!newVersion) continue;\n logInfo(` ✓ Replaced ${name}: ${version} → ${newVersion}`);\n deps[name] = newVersion;\n }\n }\n\n /**\n * Process all dependency groups for a single consuming package.\n *\n * @param p - Contextual data including the consuming package, map entries, and version map.\n */\n protected runSingle(p: FixWorkspaceDepsMain): void {\n this.handleDependencies(p.consumingPkg.content.dependencies, p);\n this.handleDependencies(p.consumingPkg.content.devDependencies, p);\n this.handleDependencies(p.consumingPkg.content.peerDependencies, p);\n }\n\n /**\n * Build pairwise mapping entries between all workspace packages.\n *\n * @remarks\n * Produces a cartesian product (excluding self-pairs) of packages, computing\n * the relative filesystem path from each source package to every other\n * target package.\n *\n * @param pkgs - The list of workspace packages.\n * @returns An array of {@link MapEntry} objects describing each package-to-package relationship.\n */\n protected buildMapEntries(pkgs: Pkg[]): MapEntry[] {\n const versionEntries: MapEntry[] = [];\n for (const fromPkg of pkgs)\n for (const toPkg of pkgs)\n if (fromPkg.content.name !== toPkg.content.name)\n versionEntries.push({\n fromPkg,\n toPkg,\n relPath: relative(fromPkg.filePath, toPkg.filePath),\n });\n return versionEntries;\n }\n}\n\n/**\n * Workspace dependency fixer that replaces `workspace:*` with caret version ranges.\n *\n * @remarks\n * During a `fix` pass, `workspace:*` is replaced with `^{resolved-version}`.\n * During a `restore` pass, caret-prefixed versions that match the workspace\n * version map are reverted back to `workspace:*`.\n */\nexport class FixWorkspaceDepsVersion extends IFixWorkspaceDeps {\n /**\n * Replace a `workspace:*` reference with a caret version range.\n *\n * @param p - Data about the dependency being processed.\n * @returns A string like `^1.2.3`, or `null` if the dependency is not `workspace:*`.\n * @throws Error if the package cannot be found in the workspace version map.\n */\n protected override fixVersion(p: FixWorkspaceDepsData): string | null {\n if (p.version !== \"workspace:*\") return null;\n const actualVersion = p.versionMap.get(p.pkg);\n if (!actualVersion) {\n logError(\n ` ERROR: Could not find version for workspace dependency ${p.pkg}`,\n );\n throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);\n }\n return `^${actualVersion}`;\n }\n\n /**\n * Restore a caret version range back to `workspace:*`.\n *\n * @param p - Data about the dependency being processed.\n * @returns The string `workspace:*` if the version matches the expected caret range, or `null` otherwise.\n */\n protected override restoreVersion(p: FixWorkspaceDepsData): string | null {\n if (p.workspacePackages.has(p.pkg) && p.version.startsWith(\"^\")) {\n // Verify the version matches what fix script would have created\n const actualVersion = p.versionMap.get(p.pkg);\n if (actualVersion && p.version === `^${actualVersion}`) {\n return \"workspace:*\";\n }\n }\n return null;\n }\n}\n\n/**\n * Workspace dependency fixer that replaces `workspace:*` with `file:` protocol paths.\n *\n * @remarks\n * During a `fix` pass, `workspace:*` is replaced with a relative `file:` path\n * pointing to the dependency's package directory.\n * During a `restore` pass, any `file:`-prefixed version is reverted to `workspace:*`.\n */\nexport class FixWorkspaceDepsFile extends IFixWorkspaceDeps {\n /**\n * Replace a `workspace:*` reference with a relative `file:` path.\n *\n * @param p - Data about the dependency being processed.\n * @returns A string like `file:../sibling-pkg`, or `null` if the dependency is not `workspace:*`.\n * @throws Error if no map entry can be found for the dependency.\n */\n protected override fixVersion(p: FixWorkspaceDepsData): string | null {\n if (p.version !== \"workspace:*\") return null;\n\n const mapEntry = p.mapEntries.find(\n (mapEntry) =>\n mapEntry.fromPkg.content.name === p.consumingPkg.content.name &&\n mapEntry.toPkg.content.name === p.pkg,\n );\n if (!mapEntry) {\n logError(\n ` ERROR: Could not find version for workspace dependency ${p.pkg}`,\n );\n throw new Error(`Cannot resolve workspace dependency: ${p.pkg}`);\n }\n\n return `file:${mapEntry.relPath}`;\n }\n\n /**\n * Restore a `file:` path reference back to `workspace:*`.\n *\n * @param p - Data about the dependency being processed.\n * @returns The string `workspace:*` if the version uses the `file:` protocol, or `null` otherwise.\n */\n protected override restoreVersion(p: FixWorkspaceDepsData): string | null {\n if (!p.version.startsWith(\"file:\")) return null;\n return \"workspace:*\";\n }\n}\n"]}
|
package/dist/git/GitChanges.d.ts
CHANGED
|
@@ -1,32 +1,79 @@
|
|
|
1
1
|
import { GitChangedResult, GitChangedContentsResult } from "../types/types.git.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates and initialises a singleton {@link GitChanges} instance.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The baseline reference (`sinceRef`) is resolved in the following priority
|
|
7
|
+
* order: explicit argument → latest tag → latest commit hash → `"HEAD~1"`.
|
|
8
|
+
*
|
|
9
|
+
* @param repoRoot - Absolute path to the repository working directory.
|
|
10
|
+
* @param sinceRef - Optional explicit git reference to use as the baseline.
|
|
11
|
+
* @returns The initialised {@link GitChanges} singleton.
|
|
12
|
+
*/
|
|
2
13
|
export declare const initGitChanges: (repoRoot: string, sinceRef?: string) => Promise<GitChanges>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the current {@link GitChanges} singleton.
|
|
16
|
+
*
|
|
17
|
+
* @returns The previously initialised {@link GitChanges} instance.
|
|
18
|
+
* @throws If {@link initGitChanges} has not been called yet.
|
|
19
|
+
*/
|
|
3
20
|
export declare const gitChanges: () => GitChanges;
|
|
21
|
+
/**
|
|
22
|
+
* Provides methods for detecting and reading files that changed since a git reference.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Prefer the {@link initGitChanges} / {@link gitChanges} helpers over direct
|
|
26
|
+
* construction — they manage a singleton and resolve the baseline reference
|
|
27
|
+
* automatically.
|
|
28
|
+
*/
|
|
4
29
|
export declare class GitChanges {
|
|
5
30
|
readonly rootDir: string;
|
|
31
|
+
/** The baseline git reference. Set via {@link sinceRef}. */
|
|
6
32
|
protected _sinceRef: string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new instance bound to the given repository root.
|
|
35
|
+
*
|
|
36
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
37
|
+
*/
|
|
7
38
|
constructor(rootDir: string);
|
|
39
|
+
/**
|
|
40
|
+
* Sets the baseline git reference used by change-detection methods.
|
|
41
|
+
*
|
|
42
|
+
* @param sinceRef - A valid git ref (SHA, tag, or branch name).
|
|
43
|
+
*/
|
|
8
44
|
set sinceRef(sinceRef: string);
|
|
45
|
+
/**
|
|
46
|
+
* Gets the baseline git reference.
|
|
47
|
+
*
|
|
48
|
+
* @returns The current baseline ref string.
|
|
49
|
+
* @throws If `sinceRef` has not been set.
|
|
50
|
+
*/
|
|
9
51
|
get sinceRef(): string;
|
|
10
52
|
/**
|
|
11
|
-
* Checks
|
|
12
|
-
*
|
|
53
|
+
* Checks whether a file or directory has changed since the baseline ref.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* The comparison includes both committed and uncommitted changes
|
|
57
|
+
* (staged and unstaged).
|
|
13
58
|
*
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
16
|
-
*
|
|
59
|
+
* @param path - Relative path (from {@link rootDir}) to the file or directory to check.
|
|
60
|
+
* @returns A {@link GitChangedResult} indicating whether changes were detected
|
|
61
|
+
* and which files were affected.
|
|
62
|
+
* @throws If the resolved target path does not exist on disk.
|
|
17
63
|
*/
|
|
18
64
|
hasChanged(path: string): Promise<GitChangedResult>;
|
|
19
65
|
/**
|
|
20
|
-
* Reads the current content of all files that have changed since
|
|
21
|
-
* within a specific file or directory scope.
|
|
22
|
-
* Includes both committed and uncommitted changes (staged + unstaged).
|
|
66
|
+
* Reads the current content of all files that have changed since the baseline ref.
|
|
23
67
|
*
|
|
24
|
-
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* The comparison is scoped to {@link rootDir} and includes both committed
|
|
70
|
+
* and uncommitted changes (staged and unstaged). Deleted files are excluded
|
|
71
|
+
* because they no longer exist on disk.
|
|
25
72
|
*
|
|
26
|
-
* @param
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
73
|
+
* @param readContent - When `true`, each file's content is read from disk;
|
|
74
|
+
* when `false` or omitted, `content` is set to `null`.
|
|
75
|
+
* @returns A {@link GitChangedContentsResult} containing metadata and
|
|
76
|
+
* optionally the content of each changed file.
|
|
30
77
|
*/
|
|
31
78
|
readChangedFiles(readContent?: boolean): Promise<GitChangedContentsResult>;
|
|
32
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitChanges.d.ts","sourceRoot":"","sources":["../../src/git/GitChanges.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EAEzB,MAAM,uBAAuB,CAAC;AAK/B,eAAO,MAAM,cAAc,GAAU,UAAU,MAAM,EAAE,WAAW,MAAM,wBAQvE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,UAI7B,CAAC;AAEF,qBAAa,UAAU;
|
|
1
|
+
{"version":3,"file":"GitChanges.d.ts","sourceRoot":"","sources":["../../src/git/GitChanges.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EAEzB,MAAM,uBAAuB,CAAC;AAK/B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAU,UAAU,MAAM,EAAE,WAAW,MAAM,wBAQvE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAO,UAI7B,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,UAAU;aASc,OAAO,EAAE,MAAM;IARlD,4DAA4D;IAC5D,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE1C;;;;OAIG;gBACgC,OAAO,EAAE,MAAM;IAElD;;;;OAIG;IACH,IAAW,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAEnC;IAED;;;;;OAKG;IACH,IAAW,QAAQ,IAAI,MAAM,CAG5B;IAED;;;;;;;;;;;OAWG;IACU,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAsBhE;;;;;;;;;;;;OAYG;IACU,gBAAgB,CAC3B,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,wBAAwB,CAAC;CA6BrC"}
|
package/dist/git/GitChanges.js
CHANGED
|
@@ -3,6 +3,17 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { lastCommitHash, lastTag, verifiedGit } from "./git.util.js";
|
|
5
5
|
let __instance = null;
|
|
6
|
+
/**
|
|
7
|
+
* Creates and initialises a singleton {@link GitChanges} instance.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* The baseline reference (`sinceRef`) is resolved in the following priority
|
|
11
|
+
* order: explicit argument → latest tag → latest commit hash → `"HEAD~1"`.
|
|
12
|
+
*
|
|
13
|
+
* @param repoRoot - Absolute path to the repository working directory.
|
|
14
|
+
* @param sinceRef - Optional explicit git reference to use as the baseline.
|
|
15
|
+
* @returns The initialised {@link GitChanges} singleton.
|
|
16
|
+
*/
|
|
6
17
|
export const initGitChanges = async (repoRoot, sinceRef) => {
|
|
7
18
|
__instance = new GitChanges(repoRoot);
|
|
8
19
|
__instance.sinceRef =
|
|
@@ -12,32 +23,67 @@ export const initGitChanges = async (repoRoot, sinceRef) => {
|
|
|
12
23
|
"HEAD~1";
|
|
13
24
|
return __instance;
|
|
14
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Returns the current {@link GitChanges} singleton.
|
|
28
|
+
*
|
|
29
|
+
* @returns The previously initialised {@link GitChanges} instance.
|
|
30
|
+
* @throws If {@link initGitChanges} has not been called yet.
|
|
31
|
+
*/
|
|
15
32
|
export const gitChanges = () => {
|
|
16
33
|
if (!__instance)
|
|
17
34
|
throw new Error("GitChanges not initialized. initGitChanges[Ref]()");
|
|
18
35
|
return __instance;
|
|
19
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Provides methods for detecting and reading files that changed since a git reference.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
* Prefer the {@link initGitChanges} / {@link gitChanges} helpers over direct
|
|
42
|
+
* construction — they manage a singleton and resolve the baseline reference
|
|
43
|
+
* automatically.
|
|
44
|
+
*/
|
|
20
45
|
export class GitChanges {
|
|
21
46
|
rootDir;
|
|
47
|
+
/** The baseline git reference. Set via {@link sinceRef}. */
|
|
22
48
|
_sinceRef = null;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new instance bound to the given repository root.
|
|
51
|
+
*
|
|
52
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
53
|
+
*/
|
|
23
54
|
constructor(rootDir) {
|
|
24
55
|
this.rootDir = rootDir;
|
|
25
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the baseline git reference used by change-detection methods.
|
|
59
|
+
*
|
|
60
|
+
* @param sinceRef - A valid git ref (SHA, tag, or branch name).
|
|
61
|
+
*/
|
|
26
62
|
set sinceRef(sinceRef) {
|
|
27
63
|
this._sinceRef = sinceRef;
|
|
28
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the baseline git reference.
|
|
67
|
+
*
|
|
68
|
+
* @returns The current baseline ref string.
|
|
69
|
+
* @throws If `sinceRef` has not been set.
|
|
70
|
+
*/
|
|
29
71
|
get sinceRef() {
|
|
30
72
|
if (!this._sinceRef)
|
|
31
73
|
throw new Error("SinceRef missing");
|
|
32
74
|
return this._sinceRef;
|
|
33
75
|
}
|
|
34
76
|
/**
|
|
35
|
-
* Checks
|
|
36
|
-
*
|
|
77
|
+
* Checks whether a file or directory has changed since the baseline ref.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The comparison includes both committed and uncommitted changes
|
|
81
|
+
* (staged and unstaged).
|
|
37
82
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @
|
|
40
|
-
*
|
|
83
|
+
* @param path - Relative path (from {@link rootDir}) to the file or directory to check.
|
|
84
|
+
* @returns A {@link GitChangedResult} indicating whether changes were detected
|
|
85
|
+
* and which files were affected.
|
|
86
|
+
* @throws If the resolved target path does not exist on disk.
|
|
41
87
|
*/
|
|
42
88
|
async hasChanged(path) {
|
|
43
89
|
const sinceRef = this.sinceRef;
|
|
@@ -57,16 +103,17 @@ export class GitChanges {
|
|
|
57
103
|
};
|
|
58
104
|
}
|
|
59
105
|
/**
|
|
60
|
-
* Reads the current content of all files that have changed since
|
|
61
|
-
* within a specific file or directory scope.
|
|
62
|
-
* Includes both committed and uncommitted changes (staged + unstaged).
|
|
106
|
+
* Reads the current content of all files that have changed since the baseline ref.
|
|
63
107
|
*
|
|
64
|
-
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* The comparison is scoped to {@link rootDir} and includes both committed
|
|
110
|
+
* and uncommitted changes (staged and unstaged). Deleted files are excluded
|
|
111
|
+
* because they no longer exist on disk.
|
|
65
112
|
*
|
|
66
|
-
* @param
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
69
|
-
*
|
|
113
|
+
* @param readContent - When `true`, each file's content is read from disk;
|
|
114
|
+
* when `false` or omitted, `content` is set to `null`.
|
|
115
|
+
* @returns A {@link GitChangedContentsResult} containing metadata and
|
|
116
|
+
* optionally the content of each changed file.
|
|
70
117
|
*/
|
|
71
118
|
async readChangedFiles(readContent) {
|
|
72
119
|
const sinceRef = this.sinceRef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GitChanges.js","sourceRoot":"","sources":["../../src/git/GitChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAErE,IAAI,UAAU,GAAsB,IAAI,CAAC;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,QAAgB,EAAE,QAAiB,EAAE,EAAE;IAC1E,UAAU,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,UAAU,CAAC,QAAQ;QACjB,QAAQ;YACR,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,CAAC;YACzB,CAAC,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAC;YAChC,QAAQ,CAAC;IACX,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,GAAe,EAAE;IACzC,IAAI,CAAC,UAAU;QACb,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,OAAO,UAAU;
|
|
1
|
+
{"version":3,"file":"GitChanges.js","sourceRoot":"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,KAAK,EAAE,CAAC;YAC/B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC;YAChC,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YAExD,oDAAoD;YACpD,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7B,SAAS;YACX,CAAC;YAED,2DAA2D;YAC3D,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC1E,KAAK,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,OAAO;YAClB,QAAQ;YACR,KAAK;SACN,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport {\n GitChangedResult,\n GitChangedContentsResult,\n GitChangedContent,\n} from \"../types/types.git.js\";\nimport { lastCommitHash, lastTag, verifiedGit } from \"./git.util.js\";\n\nlet __instance: GitChanges | null = null;\n\n/**\n * Creates and initialises a singleton {@link GitChanges} instance.\n *\n * @remarks\n * The baseline reference (`sinceRef`) is resolved in the following priority\n * order: explicit argument → latest tag → latest commit hash → `\"HEAD~1\"`.\n *\n * @param repoRoot - Absolute path to the repository working directory.\n * @param sinceRef - Optional explicit git reference to use as the baseline.\n * @returns The initialised {@link GitChanges} singleton.\n */\nexport const initGitChanges = async (repoRoot: string, sinceRef?: string) => {\n __instance = new GitChanges(repoRoot);\n __instance.sinceRef =\n sinceRef ??\n (await lastTag(repoRoot)) ??\n (await lastCommitHash(repoRoot)) ??\n \"HEAD~1\";\n return __instance;\n};\n\n/**\n * Returns the current {@link GitChanges} singleton.\n *\n * @returns The previously initialised {@link GitChanges} instance.\n * @throws If {@link initGitChanges} has not been called yet.\n */\nexport const gitChanges = (): GitChanges => {\n if (!__instance)\n throw new Error(\"GitChanges not initialized. initGitChanges[Ref]()\");\n return __instance;\n};\n\n/**\n * Provides methods for detecting and reading files that changed since a git reference.\n *\n * @remarks\n * Prefer the {@link initGitChanges} / {@link gitChanges} helpers over direct\n * construction — they manage a singleton and resolve the baseline reference\n * automatically.\n */\nexport class GitChanges {\n /** The baseline git reference. Set via {@link sinceRef}. */\n protected _sinceRef: string | null = null;\n\n /**\n * Creates a new instance bound to the given repository root.\n *\n * @param rootDir - Absolute path to the repository working directory.\n */\n public constructor(public readonly rootDir: string) {}\n\n /**\n * Sets the baseline git reference used by change-detection methods.\n *\n * @param sinceRef - A valid git ref (SHA, tag, or branch name).\n */\n public set sinceRef(sinceRef: string) {\n this._sinceRef = sinceRef;\n }\n\n /**\n * Gets the baseline git reference.\n *\n * @returns The current baseline ref string.\n * @throws If `sinceRef` has not been set.\n */\n public get sinceRef(): string {\n if (!this._sinceRef) throw new Error(\"SinceRef missing\");\n return this._sinceRef;\n }\n\n /**\n * Checks whether a file or directory has changed since the baseline ref.\n *\n * @remarks\n * The comparison includes both committed and uncommitted changes\n * (staged and unstaged).\n *\n * @param path - Relative path (from {@link rootDir}) to the file or directory to check.\n * @returns A {@link GitChangedResult} indicating whether changes were detected\n * and which files were affected.\n * @throws If the resolved target path does not exist on disk.\n */\n public async hasChanged(path: string): Promise<GitChangedResult> {\n const sinceRef = this.sinceRef;\n const resolvedTarget = resolve(this.rootDir, path);\n\n if (!existsSync(resolvedTarget)) {\n throw new Error(`Target path does not exist: ${resolvedTarget}`);\n }\n\n const git = await verifiedGit(this.rootDir, sinceRef);\n\n // Compare commit to working directory (includes uncommitted changes)\n const diff = await git.diffSummary([sinceRef, \"--\", path]);\n const changedFiles = diff.files.map((file) => file.file);\n\n return {\n path,\n sinceRef,\n hasChanged: changedFiles.length > 0,\n changedFiles,\n };\n }\n\n /**\n * Reads the current content of all files that have changed since the baseline ref.\n *\n * @remarks\n * The comparison is scoped to {@link rootDir} and includes both committed\n * and uncommitted changes (staged and unstaged). Deleted files are excluded\n * because they no longer exist on disk.\n *\n * @param readContent - When `true`, each file's content is read from disk;\n * when `false` or omitted, `content` is set to `null`.\n * @returns A {@link GitChangedContentsResult} containing metadata and\n * optionally the content of each changed file.\n */\n public async readChangedFiles(\n readContent?: boolean,\n ): Promise<GitChangedContentsResult> {\n const sinceRef = this.sinceRef;\n const git = await verifiedGit(this.rootDir, sinceRef);\n\n // Compare commit to working directory (includes uncommitted changes)\n const diff = await git.diffSummary([sinceRef, \"--\", this.rootDir]);\n\n const files: GitChangedContent[] = [];\n\n for (const entry of diff.files) {\n const repoFilePath = entry.file;\n const absFilePath = resolve(this.rootDir, repoFilePath);\n\n // Skip deleted files — they no longer exist on disk\n if (!existsSync(absFilePath)) {\n continue;\n }\n\n // Read from the file system to capture uncommitted changes\n const content = readContent ? await readFile(absFilePath, \"utf-8\") : null;\n files.push({ absFilePath, content, repoFilePath });\n }\n\n return {\n path: this.rootDir,\n sinceRef,\n files,\n };\n }\n}\n"]}
|
package/dist/git/git.util.d.ts
CHANGED
|
@@ -1,15 +1,70 @@
|
|
|
1
1
|
import { SimpleGit } from "simple-git";
|
|
2
2
|
import { GitCommitHash } from "../types/types.git.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Returns a verified {@link SimpleGit} instance for the given repository root.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Instances are cached by `rootDir` and `commitRef` pair. On the first call
|
|
8
|
+
* for a given pair the function verifies that `rootDir` is a git repository
|
|
9
|
+
* and, when supplied, that `commitRef` resolves to a valid object.
|
|
10
|
+
*
|
|
11
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
12
|
+
* @param commitRef - Optional git ref (SHA, tag, branch) to validate.
|
|
13
|
+
* @returns A {@link SimpleGit} instance bound to `rootDir`.
|
|
14
|
+
* @throws If `rootDir` is not a git repository or `commitRef` is invalid.
|
|
6
15
|
*/
|
|
7
16
|
export declare const verifiedGit: (rootDir: string, commitRef?: string) => Promise<SimpleGit>;
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves the most recent tag in the repository.
|
|
19
|
+
*
|
|
20
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
21
|
+
* @returns The name of the latest tag, or `null` if no tags exist.
|
|
22
|
+
*/
|
|
8
23
|
export declare const lastTag: (rootDir: string) => Promise<string | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves all tags in the repository.
|
|
26
|
+
*
|
|
27
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
28
|
+
* @returns An array of tag names.
|
|
29
|
+
*/
|
|
9
30
|
export declare const tags: (rootDir: string) => Promise<string[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the hash of the most recent commit on the current branch.
|
|
33
|
+
*
|
|
34
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
35
|
+
* @returns The SHA hash of the latest commit, or `null` if the log is empty.
|
|
36
|
+
*/
|
|
10
37
|
export declare const lastCommitHash: (rootDir: string) => Promise<string | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the full commit log as an array of {@link GitCommitHash} objects.
|
|
40
|
+
*
|
|
41
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
42
|
+
* @returns An array of commit hashes with dates and optional diff data.
|
|
43
|
+
*/
|
|
11
44
|
export declare const commitHashs: (rootDir: string) => Promise<GitCommitHash[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a git reference, falling back to a secondary ref if the primary is invalid.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* Attempts to verify `ref` against the repository. If verification fails
|
|
50
|
+
* (e.g. the ref does not exist), `fallback` is verified and returned instead.
|
|
51
|
+
* An error is thrown only when *both* refs are invalid.
|
|
52
|
+
*
|
|
53
|
+
* @param ref - The preferred git reference to validate.
|
|
54
|
+
* @param fallback - A fallback git reference used when `ref` is invalid.
|
|
55
|
+
* @param rootDir - Absolute path to the repository working directory.
|
|
56
|
+
* @returns The verified git reference string (`ref` or `fallback`).
|
|
57
|
+
* @throws If neither `ref` nor `fallback` resolves to a valid git object.
|
|
58
|
+
*/
|
|
12
59
|
export declare const ensureCommitRef: (ref: string, fallback: string, rootDir: string) => Promise<string>;
|
|
13
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Resets the internal cache of verified git entries.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* This is intended for test cleanup only and should never be called in
|
|
65
|
+
* production code.
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
14
69
|
export declare const __resetGitEntries: () => void;
|
|
15
70
|
//# sourceMappingURL=git.util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.util.d.ts","sourceRoot":"","sources":["../../src/git/git.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAUtD
|
|
1
|
+
{"version":3,"file":"git.util.d.ts","sourceRoot":"","sources":["../../src/git/git.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAUtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,GACtB,SAAS,MAAM,EACf,YAAY,MAAM,KACjB,OAAO,CAAC,SAAS,CAUnB,CAAC;AAqBF;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CACT,CAAC;AAE7D;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CACZ,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CACX,CAAC;AAElE;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,aAAa,EAAE,CAKtE,CAAC;AAEN;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,EACX,UAAU,MAAM,EAChB,SAAS,MAAM,KACd,OAAO,CAAC,MAAM,CAQhB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAE7B,CAAC"}
|