@sparkelf/dsh-plus 0.2.9-alpha.54 → 0.2.9-alpha.56
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/lib/{apply-B7DcTB5T.js → apply-CvePS57c.js} +185 -4
- package/lib/apply.js +2 -2
- package/lib/bin.js +3 -122
- package/lib/types/apply.d.ts +13 -0
- package/lib/types/apply.js +69 -2
- package/package.json +1 -1
|
@@ -2,9 +2,128 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
5
|
import { satisfies, valid, validRange } from "semver";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
7
|
import { parseDocument } from "yaml";
|
|
8
|
+
//#region lib/types/patch-set.js
|
|
9
|
+
/**
|
|
10
|
+
* Read the Plus distribution's embedded patch set.
|
|
11
|
+
*
|
|
12
|
+
* The distribution owns one patch set for official DSH and, separately, the patches it
|
|
13
|
+
* carries for third-party packages. Both live inside the distribution package: the
|
|
14
|
+
* manifest declares entries, and each entry's payload is a file under `patches/`. A
|
|
15
|
+
* consumer resolves no independently published patch package.
|
|
16
|
+
*
|
|
17
|
+
* The two lists are governed differently. A Plus entry must target an official package
|
|
18
|
+
* that the profile republishes and overrides; a third-party entry must name its upstream
|
|
19
|
+
* and a retirement condition, and never becomes part of the official patch set.
|
|
20
|
+
*/
|
|
21
|
+
function object(value, label) {
|
|
22
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(label + " must be an object");
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
function string(value, label) {
|
|
26
|
+
if (typeof value !== "string" || value === "") throw new Error(label + " must be a non-empty string");
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function range(value, label) {
|
|
30
|
+
const text = string(value, label);
|
|
31
|
+
if (validRange(text) === null) throw new Error(label + " is not a semantic-version range: " + text);
|
|
32
|
+
return text;
|
|
33
|
+
}
|
|
34
|
+
/** A payload stays inside the distribution package it is declared by. */
|
|
35
|
+
function patchFile(distributionDirectory, declared, label) {
|
|
36
|
+
const absolute = resolve(distributionDirectory, declared);
|
|
37
|
+
const local = relative(distributionDirectory, absolute);
|
|
38
|
+
if (local === "" || isAbsolute(local) || local === ".." || local.startsWith("../")) throw new Error(label + " must stay inside the distribution package: " + declared);
|
|
39
|
+
if (!existsSync(absolute)) throw new Error(label + " does not exist: " + absolute);
|
|
40
|
+
return local.replaceAll("\\", "/");
|
|
41
|
+
}
|
|
42
|
+
function sourceTarget(value, sourceBaseRevision, label) {
|
|
43
|
+
const target = object(value, label);
|
|
44
|
+
if (target.kind !== "dsh-source") throw new Error(label + ".kind must be dsh-source");
|
|
45
|
+
if (!Array.isArray(target.paths) || target.paths.length === 0) throw new Error(label + ".paths must be a non-empty array");
|
|
46
|
+
const paths = target.paths.map((entry, index) => {
|
|
47
|
+
const path = string(entry, label + ".paths[" + String(index) + "]");
|
|
48
|
+
if (!path.endsWith("/")) throw new Error(label + ".paths entries must be repository directory prefixes");
|
|
49
|
+
return path;
|
|
50
|
+
});
|
|
51
|
+
if (!Array.isArray(target.packages) || target.packages.length === 0) throw new Error(label + ".packages must be a non-empty array");
|
|
52
|
+
return {
|
|
53
|
+
kind: "dsh-source",
|
|
54
|
+
baseRevision: sourceBaseRevision,
|
|
55
|
+
packages: target.packages.map((entry, index) => {
|
|
56
|
+
const name = string(entry, label + ".packages[" + String(index) + "]");
|
|
57
|
+
if (!name.startsWith("@deepseek-ai/")) throw new Error(label + ".packages entries must be official package names");
|
|
58
|
+
return name;
|
|
59
|
+
}),
|
|
60
|
+
paths
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function npmTarget(value, label) {
|
|
64
|
+
const target = object(value, label);
|
|
65
|
+
if (target.kind !== "npm") throw new Error(label + ".kind must be npm");
|
|
66
|
+
return {
|
|
67
|
+
kind: "npm",
|
|
68
|
+
name: string(target.name, label + ".name"),
|
|
69
|
+
range: range(target.range, label + ".range")
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function entry(value, scope, sourceBaseRevision, distributionDirectory, label) {
|
|
73
|
+
const record = object(value, label);
|
|
74
|
+
const id = string(record.id, label + ".id");
|
|
75
|
+
const dsh = range(record.dsh, label + ".dsh");
|
|
76
|
+
const file = patchFile(distributionDirectory, string(record.file, label + ".file"), label + ".file");
|
|
77
|
+
const retireWhen = string(record.retireWhen, label + ".retireWhen");
|
|
78
|
+
const targetLabel = label + ".target";
|
|
79
|
+
const target = scope === "plus" ? object(record.target, targetLabel).kind === "dsh-source" ? sourceTarget(record.target, sourceBaseRevision, targetLabel) : npmTarget(record.target, targetLabel) : npmTarget(record.target, targetLabel);
|
|
80
|
+
if (scope === "third-party") return {
|
|
81
|
+
id,
|
|
82
|
+
scope,
|
|
83
|
+
dsh,
|
|
84
|
+
file,
|
|
85
|
+
retireWhen,
|
|
86
|
+
upstreamUrl: string(record.upstreamUrl, label + ".upstreamUrl"),
|
|
87
|
+
target
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
id,
|
|
91
|
+
scope,
|
|
92
|
+
dsh,
|
|
93
|
+
file,
|
|
94
|
+
retireWhen,
|
|
95
|
+
target
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Read and validate the embedded patch set from an installed distribution.
|
|
100
|
+
* @param distributionDirectory - installed `@sparkelf/dsh-plus` directory.
|
|
101
|
+
* @param manifest - its parsed package manifest.
|
|
102
|
+
* @returns the ordered Plus entries, third-party entries, and the exact source base.
|
|
103
|
+
*/
|
|
104
|
+
function readPatchSet(distributionDirectory, manifest) {
|
|
105
|
+
const plus = object(manifest.dshPlus, "dshPlus");
|
|
106
|
+
const sourceBaseRevision = string(object(plus.sourceBase, "dshPlus.sourceBase").revision, "dshPlus.sourceBase.revision");
|
|
107
|
+
const declaration = object(plus.patchSet, "dshPlus.patchSet");
|
|
108
|
+
if (declaration.formatVersion !== 1) throw new Error("dshPlus.patchSet.formatVersion must be 1");
|
|
109
|
+
if (!Array.isArray(declaration.entries) || declaration.entries.length === 0) throw new Error("dshPlus.patchSet.entries must be a non-empty array");
|
|
110
|
+
const entries = declaration.entries.map((value, index) => entry(value, "plus", sourceBaseRevision, distributionDirectory, "dshPlus.patchSet.entries[" + String(index) + "]"));
|
|
111
|
+
const thirdPartyRaw = plus.thirdPartyPatches;
|
|
112
|
+
const thirdParty = thirdPartyRaw === void 0 ? [] : Array.isArray(thirdPartyRaw) ? thirdPartyRaw.map((value, index) => entry(value, "third-party", sourceBaseRevision, distributionDirectory, "dshPlus.thirdPartyPatches[" + String(index) + "]")) : (() => {
|
|
113
|
+
throw new Error("dshPlus.thirdPartyPatches must be an array");
|
|
114
|
+
})();
|
|
115
|
+
const ids = /* @__PURE__ */ new Set();
|
|
116
|
+
for (const item of [...entries, ...thirdParty]) {
|
|
117
|
+
if (ids.has(item.id)) throw new Error("duplicate patch entry id: " + item.id);
|
|
118
|
+
ids.add(item.id);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
entries,
|
|
122
|
+
thirdPartyPatches: thirdParty,
|
|
123
|
+
sourceBaseRevision
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
8
127
|
//#region lib/types/apply.js
|
|
9
128
|
/** Materialize the Plus distribution's independent patch packages without Desktop. */
|
|
10
129
|
const FORMAT_VERSION = 1;
|
|
@@ -156,6 +275,34 @@ function requireSourceBase(root, baseRevision) {
|
|
|
156
275
|
if (checkoutRevision !== baseRevision) throw new Error("DSH checkout must be exact official base " + baseRevision + ", found " + checkoutRevision);
|
|
157
276
|
return checkoutRevision;
|
|
158
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Names of distribution dependencies that carry `dshPatch` variants.
|
|
280
|
+
*
|
|
281
|
+
* `patchPackageVariants()` resolves these names from the Plus install tree, so they must be
|
|
282
|
+
* packages this distribution actually depends on. The current manifest declares `dshPlus.patchSet`
|
|
283
|
+
* instead of a flat list: only entries whose target is an npm package name a `dshPatch` carrier
|
|
284
|
+
* (`dsh-source` entries name the source packages being patched, which are never Plus dependencies).
|
|
285
|
+
* An older tarball may still carry the flat `dshPlus.patchPackages` list, which wins when present.
|
|
286
|
+
*
|
|
287
|
+
* @param plus - Parsed `dshPlus` block of the distribution manifest.
|
|
288
|
+
* @returns Patch-carrier package names; empty when the distribution ships only source patches.
|
|
289
|
+
*/
|
|
290
|
+
function resolvePatchPackageNames(plus) {
|
|
291
|
+
const declared = plus.patchPackages;
|
|
292
|
+
if (declared !== void 0) {
|
|
293
|
+
const names = requireStringArray(declared, "dshPlus.patchPackages");
|
|
294
|
+
if (names.length > 0) return names;
|
|
295
|
+
}
|
|
296
|
+
const entries = requireObject(plus.patchSet, "dshPlus.patchSet").entries;
|
|
297
|
+
if (!Array.isArray(entries)) throw new Error("dshPlus.patchSet.entries must be an array");
|
|
298
|
+
const names = /* @__PURE__ */ new Set();
|
|
299
|
+
for (const [index, value] of entries.entries()) {
|
|
300
|
+
const target = requireObject(requireObject(value, "dshPlus.patchSet.entries[" + String(index) + "]").target, "dshPlus.patchSet.entries[" + String(index) + "].target");
|
|
301
|
+
if (target.kind !== "npm") continue;
|
|
302
|
+
names.add(requireString(target.name, "dshPlus.patchSet.entries[" + String(index) + "].target.name"));
|
|
303
|
+
}
|
|
304
|
+
return [...names].sort();
|
|
305
|
+
}
|
|
159
306
|
function patchPackageVariants(distributionDirectory, names) {
|
|
160
307
|
const variants = [];
|
|
161
308
|
for (const name of names) {
|
|
@@ -167,6 +314,34 @@ function patchPackageVariants(distributionDirectory, names) {
|
|
|
167
314
|
}
|
|
168
315
|
return variants;
|
|
169
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* Build patch variants from the distribution's `dshPlus.patchSet`.
|
|
319
|
+
*
|
|
320
|
+
* The patch files live inside the Plus package (`./patches/*.patch`), so every variant points at
|
|
321
|
+
* the distribution itself as its patch package: `resolvePatchFile()` then resolves the declared
|
|
322
|
+
* path inside the tarball, and `materializePatchFiles()` copies it into the profile's stable
|
|
323
|
+
* patch directory. Unlike the retired `dshPatch` carrier packages, the source packages named in
|
|
324
|
+
* `target.packages` are never resolved from the Plus tree -- they are the packages being patched.
|
|
325
|
+
*
|
|
326
|
+
* @param distribution - Installed Plus distribution package.
|
|
327
|
+
*/
|
|
328
|
+
function patchSetVariants(distribution) {
|
|
329
|
+
const patchSet = readPatchSet(distribution.directory, distribution.manifest);
|
|
330
|
+
return [...patchSet.entries, ...patchSet.thirdPartyPatches].map((entry) => ({
|
|
331
|
+
id: entry.id,
|
|
332
|
+
dsh: entry.dsh,
|
|
333
|
+
file: entry.file,
|
|
334
|
+
patchPackage: distribution,
|
|
335
|
+
target: entry.target.kind === "npm" ? {
|
|
336
|
+
kind: "npm",
|
|
337
|
+
name: entry.target.name,
|
|
338
|
+
range: entry.target.range
|
|
339
|
+
} : {
|
|
340
|
+
kind: "dsh-source",
|
|
341
|
+
baseRevision: entry.target.baseRevision
|
|
342
|
+
}
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
170
345
|
function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
|
|
171
346
|
const distributionManifest = readJsonObject(resolve(distributionDirectory, "package.json"), "Plus distribution manifest");
|
|
172
347
|
const distributionName = requireString(distributionManifest.name, "Plus distribution name");
|
|
@@ -186,13 +361,19 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
|
|
|
186
361
|
if (typeof allowed !== "boolean") throw new Error("dshPlus.profile.allowBuilds." + name + " must be a boolean");
|
|
187
362
|
allowBuilds[name] = allowed;
|
|
188
363
|
}
|
|
189
|
-
const patchPackageNames =
|
|
364
|
+
const patchPackageNames = resolvePatchPackageNames(plus);
|
|
190
365
|
const dependencies = requireObject(distributionManifest.dependencies, "Plus distribution dependencies");
|
|
191
366
|
const dshVersion = requireVersion(readJsonObject(resolve(dshRoot, "package.json"), "DSH source manifest").version, "DSH source version");
|
|
192
367
|
if (!satisfies(dshVersion, dshRange, { includePrerelease: true })) throw new Error(distributionName + "@" + distributionVersion + " requires DSH " + dshRange + ", found " + dshVersion);
|
|
193
368
|
const checkoutRevision = requireSourceBase(dshRoot, baseRevision);
|
|
369
|
+
const variants = plus.patchPackages === void 0 ? patchSetVariants({
|
|
370
|
+
name: distributionName,
|
|
371
|
+
version: distributionVersion,
|
|
372
|
+
directory: distributionDirectory,
|
|
373
|
+
manifest: distributionManifest
|
|
374
|
+
}) : patchPackageVariants(distributionDirectory, patchPackageNames);
|
|
194
375
|
const groups = /* @__PURE__ */ new Map();
|
|
195
|
-
for (const variant of
|
|
376
|
+
for (const variant of variants) {
|
|
196
377
|
const entries = groups.get(variant.id) ?? [];
|
|
197
378
|
entries.push(variant);
|
|
198
379
|
groups.set(variant.id, entries);
|
|
@@ -639,4 +820,4 @@ function runApply(argv) {
|
|
|
639
820
|
process.stdout.write("[dsh-plus] applied " + String(selection.patches.length) + " patches; lock " + lock + "\n");
|
|
640
821
|
}
|
|
641
822
|
//#endregion
|
|
642
|
-
export { parseOfficialWorkspacePackages as n,
|
|
823
|
+
export { readPatchSet as a, runApply as i, parseOfficialWorkspacePackages as n, resolvePatchPackageNames as r, materializeOfficialPackageScope as t };
|
package/lib/apply.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as parseOfficialWorkspacePackages, r as
|
|
2
|
-
export { materializeOfficialPackageScope, parseOfficialWorkspacePackages, runApply };
|
|
1
|
+
import { i as runApply, n as parseOfficialWorkspacePackages, r as resolvePatchPackageNames, t as materializeOfficialPackageScope } from "./apply-CvePS57c.js";
|
|
2
|
+
export { materializeOfficialPackageScope, parseOfficialWorkspacePackages, resolvePatchPackageNames, runApply };
|
package/lib/bin.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { a as readPatchSet, i as runApply } from "./apply-CvePS57c.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
5
5
|
import { createWriteStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { dirname,
|
|
7
|
-
import { homedir } from "node:os";
|
|
6
|
+
import { dirname, join, posix, resolve, win32 } from "node:path";
|
|
8
7
|
import semver, { valid, validRange } from "semver";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
9
|
import { parseDocument } from "yaml";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
import { createServer } from "node:net";
|
|
@@ -1084,125 +1084,6 @@ async function waitForAuthenticatedUrl(logPath, timeoutMilliseconds) {
|
|
|
1084
1084
|
}
|
|
1085
1085
|
}
|
|
1086
1086
|
//#endregion
|
|
1087
|
-
//#region lib/types/patch-set.js
|
|
1088
|
-
/**
|
|
1089
|
-
* Read the Plus distribution's embedded patch set.
|
|
1090
|
-
*
|
|
1091
|
-
* The distribution owns one patch set for official DSH and, separately, the patches it
|
|
1092
|
-
* carries for third-party packages. Both live inside the distribution package: the
|
|
1093
|
-
* manifest declares entries, and each entry's payload is a file under `patches/`. A
|
|
1094
|
-
* consumer resolves no independently published patch package.
|
|
1095
|
-
*
|
|
1096
|
-
* The two lists are governed differently. A Plus entry must target an official package
|
|
1097
|
-
* that the profile republishes and overrides; a third-party entry must name its upstream
|
|
1098
|
-
* and a retirement condition, and never becomes part of the official patch set.
|
|
1099
|
-
*/
|
|
1100
|
-
function object(value, label) {
|
|
1101
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error(label + " must be an object");
|
|
1102
|
-
return value;
|
|
1103
|
-
}
|
|
1104
|
-
function string(value, label) {
|
|
1105
|
-
if (typeof value !== "string" || value === "") throw new Error(label + " must be a non-empty string");
|
|
1106
|
-
return value;
|
|
1107
|
-
}
|
|
1108
|
-
function range(value, label) {
|
|
1109
|
-
const text = string(value, label);
|
|
1110
|
-
if (validRange(text) === null) throw new Error(label + " is not a semantic-version range: " + text);
|
|
1111
|
-
return text;
|
|
1112
|
-
}
|
|
1113
|
-
/** A payload stays inside the distribution package it is declared by. */
|
|
1114
|
-
function patchFile(distributionDirectory, declared, label) {
|
|
1115
|
-
const absolute = resolve(distributionDirectory, declared);
|
|
1116
|
-
const local = relative(distributionDirectory, absolute);
|
|
1117
|
-
if (local === "" || isAbsolute(local) || local === ".." || local.startsWith("../")) throw new Error(label + " must stay inside the distribution package: " + declared);
|
|
1118
|
-
if (!existsSync(absolute)) throw new Error(label + " does not exist: " + absolute);
|
|
1119
|
-
return local.replaceAll("\\", "/");
|
|
1120
|
-
}
|
|
1121
|
-
function sourceTarget(value, sourceBaseRevision, label) {
|
|
1122
|
-
const target = object(value, label);
|
|
1123
|
-
if (target.kind !== "dsh-source") throw new Error(label + ".kind must be dsh-source");
|
|
1124
|
-
if (!Array.isArray(target.paths) || target.paths.length === 0) throw new Error(label + ".paths must be a non-empty array");
|
|
1125
|
-
const paths = target.paths.map((entry, index) => {
|
|
1126
|
-
const path = string(entry, label + ".paths[" + String(index) + "]");
|
|
1127
|
-
if (!path.endsWith("/")) throw new Error(label + ".paths entries must be repository directory prefixes");
|
|
1128
|
-
return path;
|
|
1129
|
-
});
|
|
1130
|
-
if (!Array.isArray(target.packages) || target.packages.length === 0) throw new Error(label + ".packages must be a non-empty array");
|
|
1131
|
-
return {
|
|
1132
|
-
kind: "dsh-source",
|
|
1133
|
-
baseRevision: sourceBaseRevision,
|
|
1134
|
-
packages: target.packages.map((entry, index) => {
|
|
1135
|
-
const name = string(entry, label + ".packages[" + String(index) + "]");
|
|
1136
|
-
if (!name.startsWith("@deepseek-ai/")) throw new Error(label + ".packages entries must be official package names");
|
|
1137
|
-
return name;
|
|
1138
|
-
}),
|
|
1139
|
-
paths
|
|
1140
|
-
};
|
|
1141
|
-
}
|
|
1142
|
-
function npmTarget(value, label) {
|
|
1143
|
-
const target = object(value, label);
|
|
1144
|
-
if (target.kind !== "npm") throw new Error(label + ".kind must be npm");
|
|
1145
|
-
return {
|
|
1146
|
-
kind: "npm",
|
|
1147
|
-
name: string(target.name, label + ".name"),
|
|
1148
|
-
range: range(target.range, label + ".range")
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
function entry(value, scope, sourceBaseRevision, distributionDirectory, label) {
|
|
1152
|
-
const record = object(value, label);
|
|
1153
|
-
const id = string(record.id, label + ".id");
|
|
1154
|
-
const dsh = range(record.dsh, label + ".dsh");
|
|
1155
|
-
const file = patchFile(distributionDirectory, string(record.file, label + ".file"), label + ".file");
|
|
1156
|
-
const retireWhen = string(record.retireWhen, label + ".retireWhen");
|
|
1157
|
-
const targetLabel = label + ".target";
|
|
1158
|
-
const target = scope === "plus" ? object(record.target, targetLabel).kind === "dsh-source" ? sourceTarget(record.target, sourceBaseRevision, targetLabel) : npmTarget(record.target, targetLabel) : npmTarget(record.target, targetLabel);
|
|
1159
|
-
if (scope === "third-party") return {
|
|
1160
|
-
id,
|
|
1161
|
-
scope,
|
|
1162
|
-
dsh,
|
|
1163
|
-
file,
|
|
1164
|
-
retireWhen,
|
|
1165
|
-
upstreamUrl: string(record.upstreamUrl, label + ".upstreamUrl"),
|
|
1166
|
-
target
|
|
1167
|
-
};
|
|
1168
|
-
return {
|
|
1169
|
-
id,
|
|
1170
|
-
scope,
|
|
1171
|
-
dsh,
|
|
1172
|
-
file,
|
|
1173
|
-
retireWhen,
|
|
1174
|
-
target
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Read and validate the embedded patch set from an installed distribution.
|
|
1179
|
-
* @param distributionDirectory - installed `@sparkelf/dsh-plus` directory.
|
|
1180
|
-
* @param manifest - its parsed package manifest.
|
|
1181
|
-
* @returns the ordered Plus entries, third-party entries, and the exact source base.
|
|
1182
|
-
*/
|
|
1183
|
-
function readPatchSet(distributionDirectory, manifest) {
|
|
1184
|
-
const plus = object(manifest.dshPlus, "dshPlus");
|
|
1185
|
-
const sourceBaseRevision = string(object(plus.sourceBase, "dshPlus.sourceBase").revision, "dshPlus.sourceBase.revision");
|
|
1186
|
-
const declaration = object(plus.patchSet, "dshPlus.patchSet");
|
|
1187
|
-
if (declaration.formatVersion !== 1) throw new Error("dshPlus.patchSet.formatVersion must be 1");
|
|
1188
|
-
if (!Array.isArray(declaration.entries) || declaration.entries.length === 0) throw new Error("dshPlus.patchSet.entries must be a non-empty array");
|
|
1189
|
-
const entries = declaration.entries.map((value, index) => entry(value, "plus", sourceBaseRevision, distributionDirectory, "dshPlus.patchSet.entries[" + String(index) + "]"));
|
|
1190
|
-
const thirdPartyRaw = plus.thirdPartyPatches;
|
|
1191
|
-
const thirdParty = thirdPartyRaw === void 0 ? [] : Array.isArray(thirdPartyRaw) ? thirdPartyRaw.map((value, index) => entry(value, "third-party", sourceBaseRevision, distributionDirectory, "dshPlus.thirdPartyPatches[" + String(index) + "]")) : (() => {
|
|
1192
|
-
throw new Error("dshPlus.thirdPartyPatches must be an array");
|
|
1193
|
-
})();
|
|
1194
|
-
const ids = /* @__PURE__ */ new Set();
|
|
1195
|
-
for (const item of [...entries, ...thirdParty]) {
|
|
1196
|
-
if (ids.has(item.id)) throw new Error("duplicate patch entry id: " + item.id);
|
|
1197
|
-
ids.add(item.id);
|
|
1198
|
-
}
|
|
1199
|
-
return {
|
|
1200
|
-
entries,
|
|
1201
|
-
thirdPartyPatches: thirdParty,
|
|
1202
|
-
sourceBaseRevision
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
//#endregion
|
|
1206
1087
|
//#region lib/types/profile.js
|
|
1207
1088
|
/**
|
|
1208
1089
|
* Runtime paths and profile composition for a standalone Plus installation.
|
package/lib/types/apply.d.ts
CHANGED
|
@@ -4,6 +4,19 @@ export interface OfficialWorkspacePackage {
|
|
|
4
4
|
name: string;
|
|
5
5
|
directory: string;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Names of distribution dependencies that carry `dshPatch` variants.
|
|
9
|
+
*
|
|
10
|
+
* `patchPackageVariants()` resolves these names from the Plus install tree, so they must be
|
|
11
|
+
* packages this distribution actually depends on. The current manifest declares `dshPlus.patchSet`
|
|
12
|
+
* instead of a flat list: only entries whose target is an npm package name a `dshPatch` carrier
|
|
13
|
+
* (`dsh-source` entries name the source packages being patched, which are never Plus dependencies).
|
|
14
|
+
* An older tarball may still carry the flat `dshPlus.patchPackages` list, which wins when present.
|
|
15
|
+
*
|
|
16
|
+
* @param plus - Parsed `dshPlus` block of the distribution manifest.
|
|
17
|
+
* @returns Patch-carrier package names; empty when the distribution ships only source patches.
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolvePatchPackageNames(plus: Record<string, unknown>): string[];
|
|
7
20
|
/**
|
|
8
21
|
* Parse pnpm's workspace roster into exact official package directories.
|
|
9
22
|
* @param dshRoot - exact official DSH checkout root.
|
package/lib/types/apply.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
+
import { readPatchSet } from "./patch-set.js";
|
|
5
6
|
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
6
7
|
import { tmpdir } from 'node:os';
|
|
7
8
|
import { satisfies, valid, validRange } from 'semver';
|
|
@@ -148,6 +149,39 @@ function requireSourceBase(root, baseRevision) {
|
|
|
148
149
|
}
|
|
149
150
|
return checkoutRevision;
|
|
150
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Names of distribution dependencies that carry `dshPatch` variants.
|
|
154
|
+
*
|
|
155
|
+
* `patchPackageVariants()` resolves these names from the Plus install tree, so they must be
|
|
156
|
+
* packages this distribution actually depends on. The current manifest declares `dshPlus.patchSet`
|
|
157
|
+
* instead of a flat list: only entries whose target is an npm package name a `dshPatch` carrier
|
|
158
|
+
* (`dsh-source` entries name the source packages being patched, which are never Plus dependencies).
|
|
159
|
+
* An older tarball may still carry the flat `dshPlus.patchPackages` list, which wins when present.
|
|
160
|
+
*
|
|
161
|
+
* @param plus - Parsed `dshPlus` block of the distribution manifest.
|
|
162
|
+
* @returns Patch-carrier package names; empty when the distribution ships only source patches.
|
|
163
|
+
*/
|
|
164
|
+
export function resolvePatchPackageNames(plus) {
|
|
165
|
+
const declared = plus.patchPackages;
|
|
166
|
+
if (declared !== undefined) {
|
|
167
|
+
const names = requireStringArray(declared, 'dshPlus.patchPackages');
|
|
168
|
+
if (names.length > 0)
|
|
169
|
+
return names;
|
|
170
|
+
}
|
|
171
|
+
const patchSet = requireObject(plus.patchSet, 'dshPlus.patchSet');
|
|
172
|
+
const entries = patchSet.entries;
|
|
173
|
+
if (!Array.isArray(entries))
|
|
174
|
+
throw new Error('dshPlus.patchSet.entries must be an array');
|
|
175
|
+
const names = new Set();
|
|
176
|
+
for (const [index, value] of entries.entries()) {
|
|
177
|
+
const entry = requireObject(value, 'dshPlus.patchSet.entries[' + String(index) + ']');
|
|
178
|
+
const target = requireObject(entry.target, 'dshPlus.patchSet.entries[' + String(index) + '].target');
|
|
179
|
+
if (target.kind !== 'npm')
|
|
180
|
+
continue;
|
|
181
|
+
names.add(requireString(target.name, 'dshPlus.patchSet.entries[' + String(index) + '].target.name'));
|
|
182
|
+
}
|
|
183
|
+
return [...names].sort();
|
|
184
|
+
}
|
|
151
185
|
function patchPackageVariants(distributionDirectory, names) {
|
|
152
186
|
const variants = [];
|
|
153
187
|
for (const name of names) {
|
|
@@ -165,6 +199,29 @@ function patchPackageVariants(distributionDirectory, names) {
|
|
|
165
199
|
}
|
|
166
200
|
return variants;
|
|
167
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Build patch variants from the distribution's `dshPlus.patchSet`.
|
|
204
|
+
*
|
|
205
|
+
* The patch files live inside the Plus package (`./patches/*.patch`), so every variant points at
|
|
206
|
+
* the distribution itself as its patch package: `resolvePatchFile()` then resolves the declared
|
|
207
|
+
* path inside the tarball, and `materializePatchFiles()` copies it into the profile's stable
|
|
208
|
+
* patch directory. Unlike the retired `dshPatch` carrier packages, the source packages named in
|
|
209
|
+
* `target.packages` are never resolved from the Plus tree -- they are the packages being patched.
|
|
210
|
+
*
|
|
211
|
+
* @param distribution - Installed Plus distribution package.
|
|
212
|
+
*/
|
|
213
|
+
function patchSetVariants(distribution) {
|
|
214
|
+
const patchSet = readPatchSet(distribution.directory, distribution.manifest);
|
|
215
|
+
return [...patchSet.entries, ...patchSet.thirdPartyPatches].map((entry) => ({
|
|
216
|
+
id: entry.id,
|
|
217
|
+
dsh: entry.dsh,
|
|
218
|
+
file: entry.file,
|
|
219
|
+
patchPackage: distribution,
|
|
220
|
+
target: entry.target.kind === 'npm'
|
|
221
|
+
? { kind: 'npm', name: entry.target.name, range: entry.target.range }
|
|
222
|
+
: { kind: 'dsh-source', baseRevision: entry.target.baseRevision },
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
168
225
|
// 先验证official source,再物化Plus声明的profile依赖,避免source不匹配时改动用户profile。
|
|
169
226
|
function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
|
|
170
227
|
const distributionManifest = readJsonObject(resolve(distributionDirectory, 'package.json'), 'Plus distribution manifest');
|
|
@@ -192,7 +249,7 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
|
|
|
192
249
|
throw new Error('dshPlus.profile.allowBuilds.' + name + ' must be a boolean');
|
|
193
250
|
allowBuilds[name] = allowed;
|
|
194
251
|
}
|
|
195
|
-
const patchPackageNames =
|
|
252
|
+
const patchPackageNames = resolvePatchPackageNames(plus);
|
|
196
253
|
const dependencies = requireObject(distributionManifest.dependencies, 'Plus distribution dependencies');
|
|
197
254
|
const dshManifest = readJsonObject(resolve(dshRoot, 'package.json'), 'DSH source manifest');
|
|
198
255
|
const dshVersion = requireVersion(dshManifest.version, 'DSH source version');
|
|
@@ -200,8 +257,18 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
|
|
|
200
257
|
throw new Error(distributionName + '@' + distributionVersion + ' requires DSH ' + dshRange + ', found ' + dshVersion);
|
|
201
258
|
}
|
|
202
259
|
const checkoutRevision = requireSourceBase(dshRoot, baseRevision);
|
|
260
|
+
// Legacy tarballs declare `dshPlus.patchPackages` (dshPatch carrier packages); the current
|
|
261
|
+
// distribution declares `dshPlus.patchSet` with the patch files inside the Plus package.
|
|
262
|
+
const variants = plus.patchPackages === undefined
|
|
263
|
+
? patchSetVariants({
|
|
264
|
+
name: distributionName,
|
|
265
|
+
version: distributionVersion,
|
|
266
|
+
directory: distributionDirectory,
|
|
267
|
+
manifest: distributionManifest,
|
|
268
|
+
})
|
|
269
|
+
: patchPackageVariants(distributionDirectory, patchPackageNames);
|
|
203
270
|
const groups = new Map();
|
|
204
|
-
for (const variant of
|
|
271
|
+
for (const variant of variants) {
|
|
205
272
|
const entries = groups.get(variant.id) ?? [];
|
|
206
273
|
entries.push(variant);
|
|
207
274
|
groups.set(variant.id, entries);
|
package/package.json
CHANGED