@sparkelf/dsh-plus 0.2.9-alpha.52 → 0.2.9-alpha.54

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.
@@ -363,6 +363,46 @@ function profilePatchConfiguration(profileDirectory, npmPatchFiles) {
363
363
  changed
364
364
  };
365
365
  }
366
+ /**
367
+ * Profile-local pnpm hook that keeps the CDN-only xlsx dependency installable.
368
+ *
369
+ * `@deepseek-ai/dsh-client-ui-sidebar-documentpreview` declares `xlsx` as
370
+ * `https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz`. SheetJS stopped publishing to npm
371
+ * after 0.18.5, so no registry mirror carries 0.20.3, and the build network cannot reach that
372
+ * CDN (measured 2026-11-06: every request times out). The image vendors the tarball at
373
+ * /opt/dsh-vendor; this hook rewrites the spec wherever it appears so a cold profile install
374
+ * never requests the CDN.
375
+ *
376
+ * Written into the profile root rather than a template: the Plus bundle has no profile
377
+ * template directory, the profile manifest and pnpm-workspace.yaml are generated here.
378
+ */
379
+ const PROFILE_PNPMFILE = `// Generated by @sparkelf/dsh-plus -- do not edit; rewritten on every apply.
380
+ const VENDORED_XLSX = '/opt/dsh-vendor/xlsx-0.20.3.tgz'
381
+ const CDN_XLSX = /^https?:\\/\\/cdn\\.sheetjs\\.com\\//
382
+ const FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
383
+
384
+ module.exports = {
385
+ hooks: {
386
+ readPackage(pkg) {
387
+ for (const field of FIELDS) {
388
+ const deps = pkg && pkg[field]
389
+ if (deps && typeof deps.xlsx === 'string' && CDN_XLSX.test(deps.xlsx)) {
390
+ deps.xlsx = 'file:' + VENDORED_XLSX
391
+ }
392
+ }
393
+ return pkg
394
+ },
395
+ },
396
+ }
397
+ `;
398
+ /** Write the profile pnpmfile when its content changed; returns whether it wrote. */
399
+ function writeProfilePnpmfile(profileDirectory) {
400
+ const path = resolve(profileDirectory, ".pnpmfile.cjs");
401
+ if ((existsSync(path) ? readFileSync(path, "utf8") : void 0) === PROFILE_PNPMFILE) return false;
402
+ writeFileSync(path, PROFILE_PNPMFILE);
403
+ console.log("profile pnpmfile: xlsx -> /opt/dsh-vendor/xlsx-0.20.3.tgz");
404
+ return true;
405
+ }
366
406
  function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds) {
367
407
  const manifestPath = resolve(profileDirectory, "package.json");
368
408
  const manifest = readJsonObject(manifestPath, "DSH profile manifest");
@@ -413,7 +453,8 @@ function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds
413
453
  writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2) + "\n");
414
454
  }
415
455
  if (workspaceChanged) writeFileSync(workspacePath, String(document));
416
- return manifestChanged || workspaceChanged;
456
+ const pnpmfileChanged = writeProfilePnpmfile(profileDirectory);
457
+ return manifestChanged || workspaceChanged || pnpmfileChanged;
417
458
  }
418
459
  function writeProfileComposition(profileDirectory, bundles, runtimePackages) {
419
460
  const path = resolve(profileDirectory, "package.json");
package/lib/apply.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as parseOfficialWorkspacePackages, r as runApply, t as materializeOfficialPackageScope } from "./apply-08huHfLG.js";
1
+ import { n as parseOfficialWorkspacePackages, r as runApply, t as materializeOfficialPackageScope } from "./apply-B7DcTB5T.js";
2
2
  export { materializeOfficialPackageScope, parseOfficialWorkspacePackages, runApply };
package/lib/bin.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { i as readPatchSet, r as runApply } from "./apply-08huHfLG.js";
2
+ import { r as runApply } from "./apply-B7DcTB5T.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, join, posix, resolve, win32 } from "node:path";
6
+ import { dirname, isAbsolute, join, posix, relative, resolve, win32 } from "node:path";
7
7
  import { homedir } from "node:os";
8
8
  import semver, { valid, validRange } from "semver";
9
9
  import { parseDocument } from "yaml";
@@ -1084,6 +1084,125 @@ 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
1087
1206
  //#region lib/types/profile.js
1088
1207
  /**
1089
1208
  * Runtime paths and profile composition for a standalone Plus installation.
@@ -1,4 +1,4 @@
1
- /** Materialize the Plus distribution's embedded patch set without Desktop. */
1
+ /** Materialize the Plus distribution's independent patch packages without Desktop. */
2
2
  /** One official workspace package available as a profile peer dependency. */
3
3
  export interface OfficialWorkspacePackage {
4
4
  name: string;
@@ -1,12 +1,11 @@
1
- /** Materialize the Plus distribution's embedded patch set without Desktop. */
1
+ /** Materialize the Plus distribution's independent patch packages without Desktop. */
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 { basename, dirname, isAbsolute, relative, resolve } from 'node:path';
5
+ import { dirname, isAbsolute, relative, resolve } from 'node:path';
6
6
  import { tmpdir } from 'node:os';
7
7
  import { satisfies, valid, validRange } from 'semver';
8
8
  import { parseDocument } from 'yaml';
9
- import { readPatchSet } from "./patch-set.js";
10
9
  const FORMAT_VERSION = 1;
11
10
  function isSelectedNpmPatch(patch) {
12
11
  return patch.target.kind === 'npm';
@@ -51,22 +50,7 @@ function requireStringArray(value, label) {
51
50
  }
52
51
  function resolveInstalledPackage(distributionDirectory, packageName) {
53
52
  const requireFromDistribution = createRequire(resolve(distributionDirectory, 'package.json'));
54
- let manifestPath;
55
- try {
56
- manifestPath = requireFromDistribution.resolve(packageName + '/package.json');
57
- }
58
- catch {
59
- // Some packages do not export `./package.json`; resolve the entry module instead and walk
60
- // up to the directory that holds the manifest.
61
- let directory = dirname(requireFromDistribution.resolve(packageName));
62
- while (!existsSync(resolve(directory, 'package.json'))) {
63
- const parent = dirname(directory);
64
- if (parent === directory)
65
- throw new Error(packageName + ' has no resolvable package manifest');
66
- directory = parent;
67
- }
68
- manifestPath = resolve(directory, 'package.json');
69
- }
53
+ const manifestPath = requireFromDistribution.resolve(packageName + '/package.json');
70
54
  const manifest = readJsonObject(manifestPath, packageName + ' manifest');
71
55
  return {
72
56
  name: packageName,
@@ -75,6 +59,48 @@ function resolveInstalledPackage(distributionDirectory, packageName) {
75
59
  manifest,
76
60
  };
77
61
  }
62
+ function resolvePatchFile(packageDirectory, declared) {
63
+ const absoluteFile = resolve(packageDirectory, declared);
64
+ const local = relative(packageDirectory, absoluteFile);
65
+ if (isAbsolute(local) || local === '..' || local.startsWith('../')) {
66
+ throw new Error('patch file must stay inside its patch package: ' + declared);
67
+ }
68
+ if (!existsSync(absoluteFile))
69
+ throw new Error('patch file does not exist: ' + absoluteFile);
70
+ return { relativeFile: local.replaceAll('\\', '/'), absoluteFile };
71
+ }
72
+ function parseVariant(value, index, patchPackage) {
73
+ const label = patchPackage.name + ' dshPatch.variants[' + String(index) + ']';
74
+ const variant = requireObject(value, label);
75
+ const target = requireObject(variant.target, label + '.target');
76
+ const kind = requireString(target.kind, label + '.target.kind');
77
+ const common = {
78
+ id: requireString(variant.id, label + '.id'),
79
+ dsh: requireRange(variant.dsh, label + '.dsh'),
80
+ file: requireString(variant.file, label + '.file'),
81
+ patchPackage,
82
+ };
83
+ if (kind === 'npm') {
84
+ return {
85
+ ...common,
86
+ target: {
87
+ kind,
88
+ name: requireString(target.name, label + '.target.name'),
89
+ range: requireRange(target.range, label + '.target.range'),
90
+ },
91
+ };
92
+ }
93
+ if (kind === 'dsh-source') {
94
+ return {
95
+ ...common,
96
+ target: {
97
+ kind,
98
+ baseRevision: requireString(target.baseRevision, label + '.target.baseRevision'),
99
+ },
100
+ };
101
+ }
102
+ throw new Error('unsupported patch target kind: ' + kind);
103
+ }
78
104
  function git(root, args, acceptFailure = false) {
79
105
  const result = spawnSync('git', args, { cwd: root, encoding: 'utf8' });
80
106
  if (result.status === 0)
@@ -122,6 +148,23 @@ function requireSourceBase(root, baseRevision) {
122
148
  }
123
149
  return checkoutRevision;
124
150
  }
151
+ function patchPackageVariants(distributionDirectory, names) {
152
+ const variants = [];
153
+ for (const name of names) {
154
+ const patchPackage = resolveInstalledPackage(distributionDirectory, name);
155
+ const declaration = requireObject(patchPackage.manifest.dshPatch, name + ' dshPatch');
156
+ if (declaration.formatVersion !== FORMAT_VERSION) {
157
+ throw new Error('unsupported dshPatch formatVersion in ' + name + ': ' + String(declaration.formatVersion));
158
+ }
159
+ if (!Array.isArray(declaration.variants) || declaration.variants.length === 0) {
160
+ throw new Error(name + ' dshPatch.variants must be a non-empty array');
161
+ }
162
+ for (const [index, value] of declaration.variants.entries()) {
163
+ variants.push(parseVariant(value, index, patchPackage));
164
+ }
165
+ }
166
+ return variants;
167
+ }
125
168
  // 先验证official source,再物化Plus声明的profile依赖,避免source不匹配时改动用户profile。
126
169
  function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
127
170
  const distributionManifest = readJsonObject(resolve(distributionDirectory, 'package.json'), 'Plus distribution manifest');
@@ -149,24 +192,31 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
149
192
  throw new Error('dshPlus.profile.allowBuilds.' + name + ' must be a boolean');
150
193
  allowBuilds[name] = allowed;
151
194
  }
152
- const patchSet = readPatchSet(distributionDirectory, distributionManifest);
195
+ const patchPackageNames = requireStringArray(plus.patchPackages, 'dshPlus.patchPackages');
153
196
  const dependencies = requireObject(distributionManifest.dependencies, 'Plus distribution dependencies');
154
197
  const dshManifest = readJsonObject(resolve(dshRoot, 'package.json'), 'DSH source manifest');
155
198
  const dshVersion = requireVersion(dshManifest.version, 'DSH source version');
156
199
  if (!satisfies(dshVersion, dshRange, { includePrerelease: true })) {
157
200
  throw new Error(distributionName + '@' + distributionVersion + ' requires DSH ' + dshRange + ', found ' + dshVersion);
158
201
  }
159
- const checkoutRevision = requireSourceBase(dshRoot, patchSet.sourceBaseRevision);
160
- const patchEntries = [...patchSet.entries, ...patchSet.thirdPartyPatches];
202
+ const checkoutRevision = requireSourceBase(dshRoot, baseRevision);
203
+ const groups = new Map();
204
+ for (const variant of patchPackageVariants(distributionDirectory, patchPackageNames)) {
205
+ const entries = groups.get(variant.id) ?? [];
206
+ entries.push(variant);
207
+ groups.set(variant.id, entries);
208
+ }
161
209
  const sourceStates = new Map();
162
- for (const item of patchEntries) {
163
- if (!satisfies(dshVersion, item.dsh, { includePrerelease: true })) {
164
- throw new Error('patch ' + item.id + ' declares DSH ' + item.dsh + ', found ' + dshVersion);
210
+ const orderedGroups = [...groups].sort(([left], [right]) => left.localeCompare(right));
211
+ for (const [, variants] of orderedGroups) {
212
+ for (const variant of variants) {
213
+ if (variant.target.kind !== 'dsh-source'
214
+ || variant.target.baseRevision !== baseRevision
215
+ || !satisfies(dshVersion, variant.dsh, { includePrerelease: true }))
216
+ continue;
217
+ const file = resolvePatchFile(variant.patchPackage.directory, variant.file);
218
+ sourceStates.set(file.absoluteFile, sourcePatchState(dshRoot, file.absoluteFile));
165
219
  }
166
- if (item.target.kind !== 'dsh-source')
167
- continue;
168
- const absoluteFile = resolve(distributionDirectory, item.file);
169
- sourceStates.set(absoluteFile, sourcePatchState(dshRoot, absoluteFile));
170
220
  }
171
221
  const pendingSourceFiles = [...sourceStates].flatMap(([file, state]) => state === 'pending' ? [file] : []);
172
222
  preflightSourcePatches(dshRoot, pendingSourceFiles);
@@ -177,38 +227,49 @@ function prepareSelection(distributionDirectory, profileDirectory, dshRoot) {
177
227
  return { name, version: installed.version };
178
228
  });
179
229
  const runtimePackages = [
180
- ...Object.keys(dependencies).sort().map((name) => {
230
+ ...Object.keys(dependencies).filter(name => !patchPackageNames.includes(name)).sort().map((name) => {
181
231
  const installed = resolveInstalledPackage(distributionDirectory, name);
182
232
  return { name, version: installed.version };
183
233
  }),
184
234
  ...profileDependencies,
185
235
  ].sort((left, right) => left.name.localeCompare(right.name));
186
236
  const selected = [];
187
- for (const item of patchEntries) {
188
- const absoluteFile = resolve(distributionDirectory, item.file);
189
- if (item.target.kind === 'dsh-source') {
190
- selected.push({
191
- id: item.id,
192
- scope: item.scope,
193
- file: item.file,
194
- absoluteFile,
195
- target: { kind: 'dsh-source', baseRevision: patchSet.sourceBaseRevision },
196
- alreadyApplied: sourceStates.get(absoluteFile) === 'applied',
197
- });
198
- continue;
199
- }
200
- const targetDirectory = item.target.name in profileDependencySpecs ? profileDirectory : distributionDirectory;
201
- const targetVersion = resolveInstalledPackage(targetDirectory, item.target.name).version;
202
- if (!satisfies(targetVersion, item.target.range, { includePrerelease: true })) {
203
- throw new Error('patch ' + item.id + ' targets ' + item.target.name + ' ' + item.target.range + ', found ' + targetVersion);
204
- }
205
- selected.push({
206
- id: item.id,
207
- scope: item.scope,
208
- file: item.file,
209
- absoluteFile,
210
- target: { kind: 'npm', name: item.target.name, version: targetVersion },
237
+ // 每个patch id必须在当前DSH、official base与installed npm graph上唯一命中,不能fallback到第二variant。
238
+ for (const [id, variants] of orderedGroups) {
239
+ const candidates = variants.flatMap((variant) => {
240
+ if (!satisfies(dshVersion, variant.dsh, { includePrerelease: true }))
241
+ return [];
242
+ const file = resolvePatchFile(variant.patchPackage.directory, variant.file);
243
+ if (variant.target.kind === 'dsh-source') {
244
+ if (variant.target.baseRevision !== baseRevision)
245
+ return [];
246
+ return [{
247
+ id,
248
+ patchPackage: { name: variant.patchPackage.name, version: variant.patchPackage.version },
249
+ file: file.relativeFile,
250
+ absoluteFile: file.absoluteFile,
251
+ target: { kind: 'dsh-source', baseRevision },
252
+ alreadyApplied: sourceStates.get(file.absoluteFile) === 'applied',
253
+ }];
254
+ }
255
+ const targetDirectory = variant.target.name in profileDependencySpecs ? profileDirectory : distributionDirectory;
256
+ const targetVersion = resolveInstalledPackage(targetDirectory, variant.target.name).version;
257
+ if (!satisfies(targetVersion, variant.target.range, { includePrerelease: true }))
258
+ return [];
259
+ return [{
260
+ id,
261
+ patchPackage: { name: variant.patchPackage.name, version: variant.patchPackage.version },
262
+ file: file.relativeFile,
263
+ absoluteFile: file.absoluteFile,
264
+ target: { kind: 'npm', name: variant.target.name, version: targetVersion },
265
+ }];
211
266
  });
267
+ const [candidate] = candidates;
268
+ if (candidate === undefined)
269
+ throw new Error('no compatible patch variant for ' + id + ' on DSH ' + dshVersion);
270
+ if (candidates.length > 1)
271
+ throw new Error('multiple compatible patch variants for ' + id + ' on DSH ' + dshVersion);
272
+ selected.push(candidate);
212
273
  }
213
274
  const lockPatches = selected.map((patch) => {
214
275
  if ('alreadyApplied' in patch) {
@@ -238,7 +299,7 @@ function materializePatchFiles(profileDirectory, patches) {
238
299
  const root = resolve(profileDirectory, '.dsh-plus', 'patches');
239
300
  rmSync(root, { recursive: true, force: true });
240
301
  const stablePatches = patches.map((patch) => {
241
- const destination = resolve(root, patch.scope, patch.id, basename(patch.file));
302
+ const destination = resolve(root, patch.patchPackage.name, patch.patchPackage.version, patch.file);
242
303
  mkdirSync(dirname(destination), { recursive: true });
243
304
  copyFileSync(patch.absoluteFile, destination);
244
305
  return { ...patch, absoluteFile: destination };
@@ -262,7 +323,7 @@ function materializePatchFiles(profileDirectory, patches) {
262
323
  continue;
263
324
  }
264
325
  // 成员或版本变化必须改变workspace路径,使pnpm重新应用新的组合payload。
265
- const members = group.map(patch => encodeURIComponent(patch.id)).join('+');
326
+ const members = group.map(patch => encodeURIComponent(patch.id + '@' + patch.patchPackage.version)).join('+');
266
327
  const destination = resolve(root, 'combined', encodeURIComponent(key), members + '.patch');
267
328
  mkdirSync(dirname(destination), { recursive: true });
268
329
  const contents = group.map((patch) => {
@@ -307,6 +368,48 @@ function profilePatchConfiguration(profileDirectory, npmPatchFiles) {
307
368
  return { text: String(document), changed };
308
369
  }
309
370
  // 用户显式执行apply后,这里一次性写入profile root依赖与唯一native build许可;冲突直接失败。
371
+ /**
372
+ * Profile-local pnpm hook that keeps the CDN-only xlsx dependency installable.
373
+ *
374
+ * `@deepseek-ai/dsh-client-ui-sidebar-documentpreview` declares `xlsx` as
375
+ * `https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz`. SheetJS stopped publishing to npm
376
+ * after 0.18.5, so no registry mirror carries 0.20.3, and the build network cannot reach that
377
+ * CDN (measured 2026-11-06: every request times out). The image vendors the tarball at
378
+ * /opt/dsh-vendor; this hook rewrites the spec wherever it appears so a cold profile install
379
+ * never requests the CDN.
380
+ *
381
+ * Written into the profile root rather than a template: the Plus bundle has no profile
382
+ * template directory, the profile manifest and pnpm-workspace.yaml are generated here.
383
+ */
384
+ const PROFILE_PNPMFILE = `// Generated by @sparkelf/dsh-plus -- do not edit; rewritten on every apply.
385
+ const VENDORED_XLSX = '/opt/dsh-vendor/xlsx-0.20.3.tgz'
386
+ const CDN_XLSX = /^https?:\\/\\/cdn\\.sheetjs\\.com\\//
387
+ const FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']
388
+
389
+ module.exports = {
390
+ hooks: {
391
+ readPackage(pkg) {
392
+ for (const field of FIELDS) {
393
+ const deps = pkg && pkg[field]
394
+ if (deps && typeof deps.xlsx === 'string' && CDN_XLSX.test(deps.xlsx)) {
395
+ deps.xlsx = 'file:' + VENDORED_XLSX
396
+ }
397
+ }
398
+ return pkg
399
+ },
400
+ },
401
+ }
402
+ `;
403
+ /** Write the profile pnpmfile when its content changed; returns whether it wrote. */
404
+ function writeProfilePnpmfile(profileDirectory) {
405
+ const path = resolve(profileDirectory, '.pnpmfile.cjs');
406
+ const current = existsSync(path) ? readFileSync(path, 'utf8') : undefined;
407
+ if (current === PROFILE_PNPMFILE)
408
+ return false;
409
+ writeFileSync(path, PROFILE_PNPMFILE);
410
+ console.log('profile pnpmfile: xlsx -> /opt/dsh-vendor/xlsx-0.20.3.tgz');
411
+ return true;
412
+ }
310
413
  function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds) {
311
414
  const manifestPath = resolve(profileDirectory, 'package.json');
312
415
  const manifest = readJsonObject(manifestPath, 'DSH profile manifest');
@@ -374,7 +477,8 @@ function writeProfileRequirements(profileDirectory, dependencySpecs, allowBuilds
374
477
  }
375
478
  if (workspaceChanged)
376
479
  writeFileSync(workspacePath, String(document));
377
- return manifestChanged || workspaceChanged;
480
+ const pnpmfileChanged = writeProfilePnpmfile(profileDirectory);
481
+ return manifestChanged || workspaceChanged || pnpmfileChanged;
378
482
  }
379
483
  function writeProfileComposition(profileDirectory, bundles, runtimePackages) {
380
484
  const path = resolve(profileDirectory, 'package.json');