@deepseek-ai/dsh-app-boot 0.1.5-rc.2 → 0.1.6-alpha.2
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/README.i18n.yaml +2 -2
- package/README.md +51 -16
- package/README.zh.md +54 -19
- package/lib/index.js +1453 -258
- package/lib/types/index.d.ts +81 -53
- package/lib/types/profile-context.d.ts +51 -0
- package/lib/types/profile-plugins.d.ts +60 -0
- package/lib/types/profile-resolution/legacy-links.d.ts +35 -0
- package/lib/types/profile-resolution/resolver.d.ts +43 -0
- package/lib/types/profile-resolution/service.d.ts +51 -0
- package/lib/types/profile-resolution/worker-bootstrap.d.ts +3 -0
- package/lib/types/profile-sanitize.d.ts +13 -0
- package/lib/types/profile.d.ts +63 -18
- package/lib/worker/profile-resolution-bootstrap.js +820 -0
- package/package.json +16 -18
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import { createRequire, isBuiltin } from "node:module";
|
|
2
|
+
import { getEnvironmentData } from "node:worker_threads";
|
|
3
|
+
import { existsSync, lstatSync, readFileSync, readlinkSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
//#region ../../../node_modules/.pnpm/resolve.exports@2.0.3/node_modules/resolve.exports/dist/index.mjs
|
|
7
|
+
function e(e, n, r) {
|
|
8
|
+
throw new Error(r ? `No known conditions for "${n}" specifier in "${e}" package` : `Missing "${n}" specifier in "${e}" package`);
|
|
9
|
+
}
|
|
10
|
+
function n(n, i, o, f) {
|
|
11
|
+
let s, u, l = r(n, o), c = function(e) {
|
|
12
|
+
let n = new Set(["default", ...e.conditions || []]);
|
|
13
|
+
return e.unsafe || n.add(e.require ? "require" : "import"), e.unsafe || n.add(e.browser ? "browser" : "node"), n;
|
|
14
|
+
}(f || {}), a = i[l];
|
|
15
|
+
if (void 0 === a) {
|
|
16
|
+
let e, n, r, t;
|
|
17
|
+
for (t in i) n && t.length < n.length || ("/" === t[t.length - 1] && l.startsWith(t) ? (u = l.substring(t.length), n = t) : t.length > 1 && (r = t.indexOf("*", 1), ~r && (e = RegExp("^" + t.substring(0, r) + "(.*)" + t.substring(1 + r) + "$").exec(l), e && e[1] && (u = e[1], n = t))));
|
|
18
|
+
a = i[n];
|
|
19
|
+
}
|
|
20
|
+
return a || e(n, l), s = t(a, c), s || e(n, l, 1), u && function(e, n) {
|
|
21
|
+
let r, t = 0, i = e.length, o = /[*]/g, f = /[/]$/;
|
|
22
|
+
for (; t < i; t++) e[t] = o.test(r = e[t]) ? r.replace(o, n) : f.test(r) ? r + n : r;
|
|
23
|
+
}(s, u), s;
|
|
24
|
+
}
|
|
25
|
+
function r(e, n, r) {
|
|
26
|
+
if (e === n || "." === n) return ".";
|
|
27
|
+
let t = e + "/", i = t.length, o = n.slice(0, i) === t, f = o ? n.slice(i) : n;
|
|
28
|
+
return "#" === f[0] ? f : o || !r ? "./" === f.slice(0, 2) ? f : "./" + f : f;
|
|
29
|
+
}
|
|
30
|
+
function t(e, n, r) {
|
|
31
|
+
if (e) {
|
|
32
|
+
if ("string" == typeof e) return r && r.add(e), [e];
|
|
33
|
+
let i, o;
|
|
34
|
+
if (Array.isArray(e)) {
|
|
35
|
+
for (o = r || /* @__PURE__ */ new Set(), i = 0; i < e.length; i++) t(e[i], n, o);
|
|
36
|
+
if (!r && o.size) return [...o];
|
|
37
|
+
} else for (i in e) if (n.has(i)) return t(e[i], n, r);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function f(e, r, t) {
|
|
41
|
+
if (e.imports) return n(e.name, e.imports, r, t);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region lib/types/profile-resolution/legacy-links.js
|
|
45
|
+
/** Legacy profile-link inspection shared by the disk materializer and runtime resolver. */
|
|
46
|
+
/** Profile-private package links projected into its pnpm-managed node_modules. */
|
|
47
|
+
const PROFILE_MODULE_FALLBACK_DIR = ".dsh-module-fallback";
|
|
48
|
+
/**
|
|
49
|
+
* Return whether the process reads application modules from pkg's virtual filesystem.
|
|
50
|
+
* @returns whether pkg owns the module filesystem.
|
|
51
|
+
*/
|
|
52
|
+
function isPackagedExecutable() {
|
|
53
|
+
return process.pkg !== void 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a directory through the active carrier's filesystem implementation.
|
|
57
|
+
* @param path - directory path to canonicalize.
|
|
58
|
+
* @returns the canonical directory path.
|
|
59
|
+
*/
|
|
60
|
+
function realModuleDirectory(path) {
|
|
61
|
+
return isPackagedExecutable() ? realpathSync(path) : realpathSync.native(path);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve a link target without following the final path component.
|
|
65
|
+
* @param path - candidate path whose parent is canonicalized.
|
|
66
|
+
* @returns the canonical candidate, or undefined when its parent is absent.
|
|
67
|
+
*/
|
|
68
|
+
function canonicalLinkPath(path) {
|
|
69
|
+
try {
|
|
70
|
+
return join(realModuleDirectory(dirname(path)), basename(path));
|
|
71
|
+
} catch (error) {
|
|
72
|
+
/* v8 ignore next 2 -- a non-ENOENT realpath failure requires a host filesystem fault */
|
|
73
|
+
if (error.code === "ENOENT") return void 0;
|
|
74
|
+
/* v8 ignore next -- see the host-filesystem exception above */
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Return whether a symlink or junction points at the same path as `target`.
|
|
80
|
+
* @param link - symlink or junction to inspect.
|
|
81
|
+
* @param target - expected target path.
|
|
82
|
+
* @returns whether both paths identify the same entry.
|
|
83
|
+
*/
|
|
84
|
+
function symlinkPointsTo(link, target) {
|
|
85
|
+
const canonicalActual = canonicalLinkPath(resolve(dirname(link), readlinkSync(link)));
|
|
86
|
+
const canonicalTarget = canonicalLinkPath(resolve(target));
|
|
87
|
+
return canonicalActual !== void 0 && canonicalActual === canonicalTarget;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Return whether an observed profile package must not claim local precedence.
|
|
91
|
+
* @param profileDir - profile directory containing the package projection.
|
|
92
|
+
* @param packageName - bare package name to inspect.
|
|
93
|
+
* @returns whether the entry is a managed fallback link or disappeared during inspection.
|
|
94
|
+
*/
|
|
95
|
+
function isProfileModuleFallbackLink(profileDir, packageName) {
|
|
96
|
+
const link = join(profileDir, "node_modules", packageName);
|
|
97
|
+
const target = join(profileDir, PROFILE_MODULE_FALLBACK_DIR, "node_modules", packageName);
|
|
98
|
+
try {
|
|
99
|
+
return lstatSync(link).isSymbolicLink() && symlinkPointsTo(link, target);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
/* v8 ignore next 2 -- a vanished candidate cannot claim local precedence */
|
|
102
|
+
if (error.code === "ENOENT") return true;
|
|
103
|
+
/* v8 ignore next -- non-ENOENT lstat/readlink failures require a host filesystem fault */
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region lib/types/profile-resolution/resolver.js
|
|
109
|
+
/** In-memory profile package routing for Node's default ESM and CommonJS loaders. */
|
|
110
|
+
const EMPTY_ATTRIBUTES = Object.freeze({});
|
|
111
|
+
/**
|
|
112
|
+
* Split a bare request into its package name without allocating path segments.
|
|
113
|
+
* @param request - module specifier to classify.
|
|
114
|
+
* @returns the bare package name, or undefined for non-package requests.
|
|
115
|
+
*/
|
|
116
|
+
function barePackageName(request) {
|
|
117
|
+
if (!request || request[0] === "." || request[0] === "/" || request[0] === "\\" || request[0] === "#" || request.includes(":") || isBuiltin(request)) return;
|
|
118
|
+
const first = request.indexOf("/");
|
|
119
|
+
if (request[0] !== "@") return first < 0 ? request : request.slice(0, first);
|
|
120
|
+
if (first < 0) return;
|
|
121
|
+
const second = request.indexOf("/", first + 1);
|
|
122
|
+
return second < 0 ? request : request.slice(0, second);
|
|
123
|
+
}
|
|
124
|
+
function canonicalPath(path) {
|
|
125
|
+
try {
|
|
126
|
+
return realpathSync(path);
|
|
127
|
+
} catch {
|
|
128
|
+
return resolve(path);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function prefixes(path) {
|
|
132
|
+
const configured = resolve(path) + sep;
|
|
133
|
+
const canonical = canonicalPath(path) + sep;
|
|
134
|
+
return canonical === configured ? [configured] : [configured, canonical];
|
|
135
|
+
}
|
|
136
|
+
function compileGeneration(generation) {
|
|
137
|
+
const profilePaths = prefixes(generation.profilesDir);
|
|
138
|
+
const profile = generation.profileDir === void 0 ? [] : prefixes(generation.profileDir);
|
|
139
|
+
return {
|
|
140
|
+
entries: new Map(generation.entries.map((entry) => [entry.name, entry])),
|
|
141
|
+
profilesDir: generation.profilesDir,
|
|
142
|
+
profileDir: generation.profileDir,
|
|
143
|
+
profilePaths,
|
|
144
|
+
profileUrls: profilePaths.map((path) => pathToFileURL(path).href),
|
|
145
|
+
profile,
|
|
146
|
+
activeProfileUrls: profile.map((path) => pathToFileURL(path).href),
|
|
147
|
+
localPackageNames: new Set(generation.localPackageNames),
|
|
148
|
+
shared: new Set(profilePaths.map((prefix) => join(prefix, "node_modules"))),
|
|
149
|
+
esmRoutes: /* @__PURE__ */ new Map(),
|
|
150
|
+
cjsRoutes: /* @__PURE__ */ new Map()
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function startsWithin(path, roots) {
|
|
154
|
+
for (const root of roots) if (path.startsWith(root)) return true;
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
function nativePackageDir(parent, name) {
|
|
158
|
+
for (const searchPath of createRequire(parent).resolve.paths(name)) {
|
|
159
|
+
const candidate = join(searchPath, name);
|
|
160
|
+
if (existsSync(join(candidate, "package.json"))) return candidate;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function localPackageCandidate(searchPath, name, flavor) {
|
|
164
|
+
const candidate = join(searchPath, name);
|
|
165
|
+
const stat = statSync(candidate, { throwIfNoEntry: false });
|
|
166
|
+
return (flavor === "esm" ? stat?.isDirectory() === true : stat !== void 0 || [
|
|
167
|
+
".js",
|
|
168
|
+
".json",
|
|
169
|
+
".node"
|
|
170
|
+
].some((extension) => existsSync(candidate + extension))) ? {
|
|
171
|
+
packageDir: candidate,
|
|
172
|
+
canBeManagedLink: stat !== void 0
|
|
173
|
+
} : void 0;
|
|
174
|
+
}
|
|
175
|
+
function selfReferenceName(parent) {
|
|
176
|
+
let current = dirname(parent);
|
|
177
|
+
while (true) {
|
|
178
|
+
const manifestPath = join(current, "package.json");
|
|
179
|
+
if (existsSync(manifestPath)) {
|
|
180
|
+
let manifest;
|
|
181
|
+
try {
|
|
182
|
+
manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
183
|
+
} catch (_error) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return typeof manifest.name === "string" && manifest.exports != null ? manifest.name : false;
|
|
187
|
+
}
|
|
188
|
+
/* v8 ignore next -- scoped module requests normally find an owning manifest before node_modules. */
|
|
189
|
+
if (basename(current) === "node_modules") return false;
|
|
190
|
+
const next = dirname(current);
|
|
191
|
+
if (next === current) return false;
|
|
192
|
+
current = next;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function packageImportsTarget(parent, request, conditions) {
|
|
196
|
+
let current = dirname(parent);
|
|
197
|
+
while (true) {
|
|
198
|
+
const manifestPath = join(current, "package.json");
|
|
199
|
+
if (existsSync(manifestPath)) {
|
|
200
|
+
let manifest;
|
|
201
|
+
try {
|
|
202
|
+
manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
203
|
+
} catch (_error) {
|
|
204
|
+
/* v8 ignore next -- native resolution cannot report MODULE_NOT_FOUND after an invalid scope manifest */
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
const target = f(manifest, request, {
|
|
209
|
+
conditions: [...conditions],
|
|
210
|
+
unsafe: true
|
|
211
|
+
})?.[0];
|
|
212
|
+
return target !== void 0 && barePackageName(target) !== void 0 ? {
|
|
213
|
+
specifier: target,
|
|
214
|
+
parentURL: pathToFileURL(manifestPath).href
|
|
215
|
+
} : void 0;
|
|
216
|
+
} catch (_error) {
|
|
217
|
+
/* v8 ignore next -- native resolution cannot report MODULE_NOT_FOUND before selecting a valid mapping */
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (basename(current) === "node_modules") return void 0;
|
|
222
|
+
const next = dirname(current);
|
|
223
|
+
/* v8 ignore next -- a MODULE_NOT_FOUND package-import target always has an owning package scope */
|
|
224
|
+
if (next === current) return void 0;
|
|
225
|
+
current = next;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function packageSearchPaths(entry, request, cjs) {
|
|
229
|
+
const name = barePackageName(request);
|
|
230
|
+
/* v8 ignore next -- fallback routes are created only for bare package requests */
|
|
231
|
+
if (name === void 0) return cjs._nodeModulePaths(dirname(entry.declarer));
|
|
232
|
+
const suffix = sep + name.split("/").join(sep);
|
|
233
|
+
return entry.packageDir.endsWith(suffix) ? [entry.packageDir.slice(0, -suffix.length)] : cjs._nodeModulePaths(dirname(entry.declarer));
|
|
234
|
+
}
|
|
235
|
+
function localCandidateOwnsResolution(candidate, resolved, request, name) {
|
|
236
|
+
if (startsWithin(resolved, prefixes(candidate))) return true;
|
|
237
|
+
if (sameResolution(candidate, resolved)) return true;
|
|
238
|
+
if ([
|
|
239
|
+
".js",
|
|
240
|
+
".json",
|
|
241
|
+
".node"
|
|
242
|
+
].some((extension) => sameResolution(candidate + extension, resolved))) return true;
|
|
243
|
+
/* v8 ignore next -- a bounded native lookup can escape a candidate only through its root legacy main */
|
|
244
|
+
if (request !== name) return false;
|
|
245
|
+
try {
|
|
246
|
+
const manifest = JSON.parse(readFileSync(join(candidate, "package.json"), "utf8"));
|
|
247
|
+
/* v8 ignore next -- a bounded native lookup outside the package directory requires a legacy main */
|
|
248
|
+
if (typeof manifest.main !== "string") return false;
|
|
249
|
+
return sameResolution(createRequire(join(candidate, "package.json")).resolve(resolve(candidate, manifest.main)), resolved);
|
|
250
|
+
} catch (_error) {
|
|
251
|
+
/* v8 ignore next -- this helper runs only after the same native resolution succeeded */
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function isUnselectedPackageMiss(error) {
|
|
256
|
+
const failure = error;
|
|
257
|
+
return failure.code === "MODULE_NOT_FOUND" && failure.path === void 0;
|
|
258
|
+
}
|
|
259
|
+
function sameResolution(left, right) {
|
|
260
|
+
if (left === right) return true;
|
|
261
|
+
const leftPath = left.startsWith("file:") ? fileURLToPath(left) : left;
|
|
262
|
+
const rightPath = right.startsWith("file:") ? fileURLToPath(right) : right;
|
|
263
|
+
return canonicalPath(leftPath) === canonicalPath(rightPath);
|
|
264
|
+
}
|
|
265
|
+
/** One mutable pointer to immutable generation data. */
|
|
266
|
+
var ResolutionRouter = class {
|
|
267
|
+
current;
|
|
268
|
+
constructor(generation) {
|
|
269
|
+
this.current = compileGeneration(generation);
|
|
270
|
+
}
|
|
271
|
+
replace(generation) {
|
|
272
|
+
const entries = new Map(generation.entries.map((entry) => [entry.name, entry]));
|
|
273
|
+
if (generation.profilesDir !== this.current.profilesDir || generation.profileDir !== this.current.profileDir) throw new Error("profile resolution: a generation cannot change its profile scope");
|
|
274
|
+
for (const [name, current] of this.current.entries) {
|
|
275
|
+
const next = entries.get(name);
|
|
276
|
+
if (next === void 0 || !sameResolution(current.packageDir, next.packageDir) || !sameResolution(current.declarer, next.declarer) || current.version !== next.version || current.scope !== next.scope) throw new Error(`profile resolution: replacing ${JSON.stringify(name)} requires a process restart`);
|
|
277
|
+
}
|
|
278
|
+
const localPackageNames = new Set(generation.localPackageNames);
|
|
279
|
+
for (const name of this.current.localPackageNames) if (!localPackageNames.has(name)) throw new Error(`profile resolution: removing local package ${JSON.stringify(name)} requires a process restart`);
|
|
280
|
+
for (const name of localPackageNames) if (!this.current.localPackageNames.has(name) && this.current.entries.has(name)) throw new Error(`profile resolution: overriding ${JSON.stringify(name)} locally requires a process restart`);
|
|
281
|
+
this.current = compileGeneration(generation);
|
|
282
|
+
}
|
|
283
|
+
routeScoped(request, parentRoutes, generation, flavor, nativeResolve, cacheable = false) {
|
|
284
|
+
const { parent, profilesDir, requests } = parentRoutes;
|
|
285
|
+
const name = barePackageName(request);
|
|
286
|
+
if (name === void 0) return void 0;
|
|
287
|
+
if (parentRoutes.selfReferenceName === void 0) parentRoutes.selfReferenceName = selfReferenceName(parent);
|
|
288
|
+
if (parentRoutes.selfReferenceName === name || parentRoutes.selfReferenceName === null) {
|
|
289
|
+
const state = { route: { kind: "native" } };
|
|
290
|
+
requests.set(request, state);
|
|
291
|
+
return state;
|
|
292
|
+
}
|
|
293
|
+
const target = generation.entries.get(name);
|
|
294
|
+
const candidates = [];
|
|
295
|
+
const localSearchPaths = [];
|
|
296
|
+
for (const searchPath of createRequire(parent).resolve.paths(name)) {
|
|
297
|
+
if (generation.shared.has(resolve(searchPath))) break;
|
|
298
|
+
localSearchPaths.push(searchPath);
|
|
299
|
+
const candidate = localPackageCandidate(searchPath, name, flavor);
|
|
300
|
+
if (candidate !== void 0) {
|
|
301
|
+
if (!(candidate.canBeManagedLink && generation.profile.some((prefix) => candidate.packageDir === join(prefix, "node_modules", name) && isProfileModuleFallbackLink(prefix.slice(0, -1), name)))) candidates.push(candidate);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (candidates.length > 0) if (flavor === "cjs" && nativeResolve !== void 0) try {
|
|
305
|
+
const resolved = nativeResolve(localSearchPaths);
|
|
306
|
+
const selected = candidates.find((candidate) => localCandidateOwnsResolution(candidate.packageDir, resolved, request, name));
|
|
307
|
+
if (selected !== void 0) {
|
|
308
|
+
const state = {
|
|
309
|
+
route: {
|
|
310
|
+
kind: "native",
|
|
311
|
+
packageDir: selected.packageDir
|
|
312
|
+
},
|
|
313
|
+
packageDir: selected.packageDir,
|
|
314
|
+
...cacheable ? { cjs: resolved } : {}
|
|
315
|
+
};
|
|
316
|
+
requests.set(request, state);
|
|
317
|
+
return state;
|
|
318
|
+
}
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (!isUnselectedPackageMiss(error)) throw error;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
const selected = candidates[0];
|
|
324
|
+
const state = {
|
|
325
|
+
route: {
|
|
326
|
+
kind: "native",
|
|
327
|
+
packageDir: selected.packageDir
|
|
328
|
+
},
|
|
329
|
+
packageDir: selected.packageDir
|
|
330
|
+
};
|
|
331
|
+
requests.set(request, state);
|
|
332
|
+
return state;
|
|
333
|
+
}
|
|
334
|
+
const eligible = target?.scope === "installation" || target?.scope === "profile" && parentRoutes.activeProfile;
|
|
335
|
+
const after = join(dirname(profilesDir), "package.json");
|
|
336
|
+
const route = eligible ? {
|
|
337
|
+
kind: "fallback",
|
|
338
|
+
entry: target,
|
|
339
|
+
after
|
|
340
|
+
} : {
|
|
341
|
+
kind: "after-fallback",
|
|
342
|
+
parent: after
|
|
343
|
+
};
|
|
344
|
+
const state = { route };
|
|
345
|
+
if (route.kind === "fallback") requests.set(request, state);
|
|
346
|
+
return state;
|
|
347
|
+
}
|
|
348
|
+
routeLocalPackage(request, parentRoutes, generation) {
|
|
349
|
+
const name = barePackageName(request);
|
|
350
|
+
if (name === void 0 || !parentRoutes.activeProfile || !generation.localPackageNames.has(name)) return void 0;
|
|
351
|
+
const state = { route: { kind: "native" } };
|
|
352
|
+
parentRoutes.requests.set(request, state);
|
|
353
|
+
return state;
|
|
354
|
+
}
|
|
355
|
+
routeUrl(request, parentURL) {
|
|
356
|
+
const generation = this.current;
|
|
357
|
+
let parentRoutes = generation.esmRoutes.get(parentURL);
|
|
358
|
+
if (parentRoutes === false) return void 0;
|
|
359
|
+
const cached = parentRoutes?.requests.get(request);
|
|
360
|
+
if (cached !== void 0) return cached;
|
|
361
|
+
if (parentRoutes === void 0) {
|
|
362
|
+
const profileIndex = generation.profileUrls.findIndex((prefix) => parentURL.startsWith(prefix));
|
|
363
|
+
const activeProfileIndex = generation.activeProfileUrls.findIndex((prefix) => parentURL.startsWith(prefix));
|
|
364
|
+
if (profileIndex < 0 && activeProfileIndex < 0) {
|
|
365
|
+
generation.esmRoutes.set(parentURL, false);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
let parent;
|
|
369
|
+
try {
|
|
370
|
+
parent = fileURLToPath(parentURL);
|
|
371
|
+
} catch {
|
|
372
|
+
generation.esmRoutes.set(parentURL, false);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const profileRoot = profileIndex >= 0 ? generation.profilePaths[profileIndex] : generation.profile[activeProfileIndex];
|
|
376
|
+
/* v8 ignore next -- one matching index was established above */
|
|
377
|
+
if (profileRoot === void 0) return void 0;
|
|
378
|
+
parentRoutes = {
|
|
379
|
+
parent,
|
|
380
|
+
profilesDir: profileRoot.slice(0, -1),
|
|
381
|
+
activeProfile: activeProfileIndex >= 0,
|
|
382
|
+
requests: /* @__PURE__ */ new Map()
|
|
383
|
+
};
|
|
384
|
+
generation.esmRoutes.set(parentURL, parentRoutes);
|
|
385
|
+
}
|
|
386
|
+
const local = this.routeLocalPackage(request, parentRoutes, generation);
|
|
387
|
+
if (local !== void 0) return local;
|
|
388
|
+
return this.routeScoped(request, parentRoutes, generation, "esm");
|
|
389
|
+
}
|
|
390
|
+
routePath(request, parent, nativeResolve, cacheable = false) {
|
|
391
|
+
const generation = this.current;
|
|
392
|
+
let parentRoutes = generation.cjsRoutes.get(parent);
|
|
393
|
+
if (parentRoutes === false) return void 0;
|
|
394
|
+
const cached = parentRoutes?.requests.get(request);
|
|
395
|
+
if (cached !== void 0) return cached;
|
|
396
|
+
if (parentRoutes === void 0) {
|
|
397
|
+
const profilesDir = generation.profilePaths.find((prefix) => parent.startsWith(prefix));
|
|
398
|
+
const activeProfile = generation.profile.find((prefix) => parent.startsWith(prefix));
|
|
399
|
+
if (profilesDir !== void 0 || activeProfile !== void 0) {
|
|
400
|
+
const profileRoot = profilesDir ?? activeProfile;
|
|
401
|
+
/* v8 ignore next -- one matching root was established above */
|
|
402
|
+
if (profileRoot === void 0) return void 0;
|
|
403
|
+
parentRoutes = {
|
|
404
|
+
parent,
|
|
405
|
+
profilesDir: profileRoot.slice(0, -1),
|
|
406
|
+
activeProfile: activeProfile !== void 0,
|
|
407
|
+
requests: /* @__PURE__ */ new Map()
|
|
408
|
+
};
|
|
409
|
+
generation.cjsRoutes.set(parent, parentRoutes);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (parentRoutes === void 0) {
|
|
413
|
+
generation.cjsRoutes.set(parent, false);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
return this.routeScoped(request, parentRoutes, generation, "cjs", nativeResolve, cacheable);
|
|
417
|
+
}
|
|
418
|
+
explicitRoute(request, paths) {
|
|
419
|
+
if (barePackageName(request) === void 0) return void 0;
|
|
420
|
+
for (const [index, path] of paths.entries()) {
|
|
421
|
+
const parent = join(resolve(path), ".dsh-profile-resolution.cjs");
|
|
422
|
+
if (startsWithin(parent, this.current.profilePaths) || startsWithin(parent, this.current.profile)) return {
|
|
423
|
+
index,
|
|
424
|
+
parent
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
nativeSelfReference(request, parent) {
|
|
429
|
+
const name = barePackageName(request);
|
|
430
|
+
if (name === void 0) return false;
|
|
431
|
+
const self = selfReferenceName(parent);
|
|
432
|
+
return self === name || self === null;
|
|
433
|
+
}
|
|
434
|
+
packageDir(specifier, parentURL) {
|
|
435
|
+
const name = barePackageName(specifier);
|
|
436
|
+
if (name === void 0) return void 0;
|
|
437
|
+
const state = this.routeUrl(specifier, parentURL);
|
|
438
|
+
if (state?.route.kind === "fallback") return state.route.entry.packageDir;
|
|
439
|
+
if (state?.packageDir !== void 0) return state.packageDir;
|
|
440
|
+
let parent;
|
|
441
|
+
try {
|
|
442
|
+
parent = state?.route.kind === "after-fallback" ? state.route.parent : fileURLToPath(parentURL);
|
|
443
|
+
} catch {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const found = nativePackageDir(parent, name);
|
|
447
|
+
if (state !== void 0 && found !== void 0) state.packageDir = found;
|
|
448
|
+
return found;
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
function internalModules() {
|
|
452
|
+
const addon = createRequire(import.meta.url)("node-addon-require-builtin");
|
|
453
|
+
const esmModule = addon.requireBuiltin("internal/modules/esm/loader");
|
|
454
|
+
const cjsModule = addon.requireBuiltin("internal/modules/cjs/loader");
|
|
455
|
+
const cjsHelpers = addon.requireBuiltin("internal/modules/helpers");
|
|
456
|
+
const esmUtils = addon.requireBuiltin("internal/modules/esm/utils");
|
|
457
|
+
const esmResolve = addon.requireBuiltin("internal/modules/esm/resolve");
|
|
458
|
+
const esm = esmModule.getOrInitializeCascadedLoader();
|
|
459
|
+
const modern = "getOrCreateModuleJob" in esm;
|
|
460
|
+
/* v8 ignore start -- the supported Node 22/24/26 matrix validates each available Internal interface */
|
|
461
|
+
if (typeof esm.resolveSync !== "function" || typeof Reflect.get(esm, modern ? "getOrCreateModuleJob" : "getModuleJobForImport") !== "function" || !modern && typeof Reflect.get(esm, "resolve") !== "function" || typeof cjsModule.Module._resolveFilename !== "function" || typeof cjsHelpers.getCjsConditions !== "function" || typeof esmUtils.getDefaultConditions !== "function" || typeof esmResolve.defaultResolve !== "function") throw new Error("profile resolution: unsupported Node module loader");
|
|
462
|
+
/* v8 ignore stop */
|
|
463
|
+
return {
|
|
464
|
+
esm,
|
|
465
|
+
esmDefaultResolve: (specifier, context) => esmResolve.defaultResolve(specifier, context),
|
|
466
|
+
esmConditions: esmUtils.getDefaultConditions(),
|
|
467
|
+
cjs: cjsModule.Module,
|
|
468
|
+
cjsConditions: cjsHelpers.getCjsConditions(),
|
|
469
|
+
modern
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
function throwWithImporter(error, routedParent, parent) {
|
|
473
|
+
const code = error.code;
|
|
474
|
+
if (error instanceof Error && (code === "ERR_MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED")) {
|
|
475
|
+
const routedPath = fileURLToPath(routedParent);
|
|
476
|
+
const parentPath = fileURLToPath(parent);
|
|
477
|
+
const originalMessage = error.message;
|
|
478
|
+
const message = originalMessage.replaceAll(routedParent, parent).replaceAll(routedPath, parentPath);
|
|
479
|
+
const stack = error.stack;
|
|
480
|
+
error.message = message;
|
|
481
|
+
/* v8 ignore next -- Node's resolver errors always carry a stack */
|
|
482
|
+
if (stack !== void 0) error.stack = stack.replace(originalMessage, message);
|
|
483
|
+
}
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
function throwWithoutCjsAnchor(error, anchor) {
|
|
487
|
+
const resolved = error;
|
|
488
|
+
const requireStack = resolved.requireStack;
|
|
489
|
+
if (error instanceof Error && resolved.code === "MODULE_NOT_FOUND" && requireStack?.[0] !== void 0 && sameResolution(requireStack[0], anchor)) {
|
|
490
|
+
const originalMessage = error.message;
|
|
491
|
+
const originalBlock = `\nRequire stack:\n${requireStack.map((path) => `- ${path}`).join("\n")}`;
|
|
492
|
+
const remaining = requireStack.slice(1);
|
|
493
|
+
/* v8 ignore next -- routed calls always retain the original importing module */
|
|
494
|
+
const replacement = remaining.length === 0 ? "" : `\nRequire stack:\n${remaining.map((path) => `- ${path}`).join("\n")}`;
|
|
495
|
+
error.message = originalMessage.replace(originalBlock, replacement);
|
|
496
|
+
resolved.requireStack = remaining;
|
|
497
|
+
const stack = error.stack;
|
|
498
|
+
/* v8 ignore next -- Node's resolver errors always carry a stack */
|
|
499
|
+
if (stack !== void 0) error.stack = stack.replace(originalMessage, error.message);
|
|
500
|
+
}
|
|
501
|
+
throw error;
|
|
502
|
+
}
|
|
503
|
+
function assertEquivalent(actual, expected, request, parent) {
|
|
504
|
+
if (sameResolution(actual, expected)) return;
|
|
505
|
+
throw new Error(`profile resolution mismatch for ${JSON.stringify(request)} from ${parent}: disk resolved ${actual}, generation resolved ${expected}`);
|
|
506
|
+
}
|
|
507
|
+
function assertOptionalEquivalent(actual, expected, request, parent) {
|
|
508
|
+
if (actual === void 0 && expected === void 0) return;
|
|
509
|
+
if (actual !== void 0 && expected !== void 0 && sameResolution(actual, expected)) return;
|
|
510
|
+
throw new Error(`profile resolution mismatch for ${JSON.stringify(request)} from ${parent}: disk selected ${actual ?? "nothing"}, generation selected ${expected ?? "nothing"}`);
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Install one profile generation on Node's default ESM and CommonJS resolvers.
|
|
514
|
+
* @param generation - complete package table and profile scope.
|
|
515
|
+
* @param behavior - enforce the generation, or verify a materialized generation.
|
|
516
|
+
* @returns a registration that replaces the generation or restores the native methods.
|
|
517
|
+
*/
|
|
518
|
+
function installProfileResolution(generation, behavior = "enforce") {
|
|
519
|
+
const router = new ResolutionRouter(generation);
|
|
520
|
+
const { esm, esmDefaultResolve, esmConditions, cjs, cjsConditions, modern } = internalModules();
|
|
521
|
+
const esmScope = /* @__PURE__ */ new Map();
|
|
522
|
+
const profilePaths = [...prefixes(generation.profilesDir), ...generation.profileDir === void 0 ? [] : prefixes(generation.profileDir)];
|
|
523
|
+
const profileUrls = profilePaths.map((path) => pathToFileURL(path).href);
|
|
524
|
+
let recentEsmParent;
|
|
525
|
+
let recentEsmScoped = false;
|
|
526
|
+
let delegatedEsm;
|
|
527
|
+
const adaptEsm = (native) => {
|
|
528
|
+
const adapted = (request, parent, attributes) => {
|
|
529
|
+
const delegated = delegatedEsm;
|
|
530
|
+
/* v8 ignore next -- reentry requires a separate synchronous Node hook; supported launches install none */
|
|
531
|
+
if (delegated !== void 0 && delegated.parent === parent && delegated.request === request) return native(request, parent, attributes);
|
|
532
|
+
if (parent === void 0) return native(request, parent, attributes);
|
|
533
|
+
let scoped = recentEsmParent === parent ? recentEsmScoped : esmScope.get(parent);
|
|
534
|
+
if (scoped === void 0) {
|
|
535
|
+
scoped = startsWithin(parent, profileUrls);
|
|
536
|
+
esmScope.set(parent, scoped);
|
|
537
|
+
}
|
|
538
|
+
if (recentEsmParent !== parent) {
|
|
539
|
+
recentEsmParent = parent;
|
|
540
|
+
recentEsmScoped = scoped;
|
|
541
|
+
}
|
|
542
|
+
if (!scoped) return native(request, parent, attributes);
|
|
543
|
+
const state = router.routeUrl(request, parent);
|
|
544
|
+
if (state === void 0) {
|
|
545
|
+
const target = request[0] === "#" ? packageImportsTarget(fileURLToPath(parent), request, esmConditions) : void 0;
|
|
546
|
+
if (target === void 0) return native(request, parent, attributes);
|
|
547
|
+
const restoreImporter = (error) => throwWithImporter(error, target.parentURL, parent);
|
|
548
|
+
let expected;
|
|
549
|
+
try {
|
|
550
|
+
expected = adapted(target.specifier, target.parentURL, attributes);
|
|
551
|
+
/* v8 ignore next -- Node 24+ resolves synchronously; the Node 22 matrix covers its Promise result */
|
|
552
|
+
if (expected instanceof Promise) expected = expected.catch(restoreImporter);
|
|
553
|
+
} catch (error) {
|
|
554
|
+
return restoreImporter(error);
|
|
555
|
+
}
|
|
556
|
+
if (behavior === "enforce") return expected;
|
|
557
|
+
const actual = native(request, parent, attributes);
|
|
558
|
+
/* v8 ignore start -- Node 22 is the asynchronous adapter and is covered by the external version matrix */
|
|
559
|
+
if (expected instanceof Promise || actual instanceof Promise) return Promise.all([actual, expected]).then(([resolved, wanted]) => {
|
|
560
|
+
assertEquivalent(resolved.url, wanted.url, request, parent);
|
|
561
|
+
return resolved;
|
|
562
|
+
});
|
|
563
|
+
/* v8 ignore stop */
|
|
564
|
+
assertEquivalent(actual.url, expected.url, request, parent);
|
|
565
|
+
return actual;
|
|
566
|
+
}
|
|
567
|
+
const cacheable = attributes === EMPTY_ATTRIBUTES || Object.keys(attributes).length === 0;
|
|
568
|
+
if (cacheable && state.esm !== void 0) return state.esm;
|
|
569
|
+
const route = state.route;
|
|
570
|
+
if (route.kind === "native") {
|
|
571
|
+
const result = native(request, parent, attributes);
|
|
572
|
+
if (cacheable && !(result instanceof Promise)) state.esm = result;
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
const routedParent = pathToFileURL(route.kind === "fallback" ? route.entry.declarer : route.parent).href;
|
|
576
|
+
if (behavior === "enforce") {
|
|
577
|
+
const previous = delegatedEsm;
|
|
578
|
+
delegatedEsm = {
|
|
579
|
+
parent: routedParent,
|
|
580
|
+
request
|
|
581
|
+
};
|
|
582
|
+
const restoreImporter = (error) => throwWithImporter(error, routedParent, parent);
|
|
583
|
+
try {
|
|
584
|
+
let result;
|
|
585
|
+
try {
|
|
586
|
+
result = native(request, routedParent, attributes);
|
|
587
|
+
} catch (error) {
|
|
588
|
+
return restoreImporter(error);
|
|
589
|
+
}
|
|
590
|
+
/* v8 ignore next -- Node 24+ resolves synchronously; the Node 22 matrix covers its Promise result */
|
|
591
|
+
if (result instanceof Promise) return result.catch(restoreImporter);
|
|
592
|
+
if (cacheable) state.esm = result;
|
|
593
|
+
return result;
|
|
594
|
+
} finally {
|
|
595
|
+
delegatedEsm = previous;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const actual = native(request, parent, attributes);
|
|
599
|
+
const previous = delegatedEsm;
|
|
600
|
+
delegatedEsm = {
|
|
601
|
+
parent: routedParent,
|
|
602
|
+
request
|
|
603
|
+
};
|
|
604
|
+
const restoreImporter = (error) => throwWithImporter(error, routedParent, parent);
|
|
605
|
+
try {
|
|
606
|
+
let expected;
|
|
607
|
+
try {
|
|
608
|
+
const result = native(request, routedParent, attributes);
|
|
609
|
+
expected = result;
|
|
610
|
+
/* v8 ignore next -- Node 24+ resolves synchronously; the Node 22 matrix covers its Promise result */
|
|
611
|
+
if (result instanceof Promise) expected = result.catch(restoreImporter);
|
|
612
|
+
} catch (error) {
|
|
613
|
+
return restoreImporter(error);
|
|
614
|
+
}
|
|
615
|
+
/* v8 ignore start -- Node 22 is the asynchronous adapter and is covered by the external version matrix */
|
|
616
|
+
if (expected instanceof Promise || actual instanceof Promise) return Promise.all([actual, expected]).then(([resolved, wanted]) => {
|
|
617
|
+
assertEquivalent(resolved.url, wanted.url, request, parent);
|
|
618
|
+
if (cacheable) state.esm = resolved;
|
|
619
|
+
return resolved;
|
|
620
|
+
});
|
|
621
|
+
/* v8 ignore stop */
|
|
622
|
+
assertEquivalent(actual.url, expected.url, request, parent);
|
|
623
|
+
if (cacheable) state.esm = actual;
|
|
624
|
+
return actual;
|
|
625
|
+
} finally {
|
|
626
|
+
delegatedEsm = previous;
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
return adapted;
|
|
630
|
+
};
|
|
631
|
+
let restoreEsm;
|
|
632
|
+
/* v8 ignore else -- CI coverage runs Node 24 v2; the Node 22 matrix exercises the v1 adapter */
|
|
633
|
+
if (modern) {
|
|
634
|
+
const loader = esm;
|
|
635
|
+
const original = Reflect.get(loader, "resolveSync");
|
|
636
|
+
const resolveRequest = adaptEsm((request, parent, attributes) => original.call(loader, parent, {
|
|
637
|
+
specifier: request,
|
|
638
|
+
attributes
|
|
639
|
+
}));
|
|
640
|
+
const wrapped = (parent, request, ...rest) => rest.length ? Reflect.apply(original, loader, [
|
|
641
|
+
parent,
|
|
642
|
+
request,
|
|
643
|
+
...rest
|
|
644
|
+
]) : resolveRequest(request.specifier, parent, request.attributes ?? EMPTY_ATTRIBUTES);
|
|
645
|
+
loader.resolveSync = wrapped;
|
|
646
|
+
restoreEsm = () => {
|
|
647
|
+
/* v8 ignore else -- registrations are disposed in reverse installation order */
|
|
648
|
+
if (loader.resolveSync === wrapped) loader.resolveSync = original;
|
|
649
|
+
};
|
|
650
|
+
} else {
|
|
651
|
+
const loader = esm;
|
|
652
|
+
const original = Reflect.get(loader, "resolve");
|
|
653
|
+
const originalSync = Reflect.get(loader, "resolveSync");
|
|
654
|
+
const resolveRequest = adaptEsm((request, parent, attributes) => original.call(loader, request, parent, attributes));
|
|
655
|
+
const resolveRequestSync = adaptEsm((request, parent, attributes) => originalSync.call(loader, request, parent, attributes));
|
|
656
|
+
const wrapped = (request, parent, attributes = EMPTY_ATTRIBUTES) => resolveRequest(request, parent, attributes);
|
|
657
|
+
const wrappedSync = (request, parent, attributes = EMPTY_ATTRIBUTES) => resolveRequestSync(request, parent, attributes);
|
|
658
|
+
loader.resolve = wrapped;
|
|
659
|
+
loader.resolveSync = wrappedSync;
|
|
660
|
+
restoreEsm = () => {
|
|
661
|
+
if (loader.resolve === wrapped) loader.resolve = original;
|
|
662
|
+
if (loader.resolveSync === wrappedSync) loader.resolveSync = originalSync;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
const originalFilename = Reflect.get(cjs, "_resolveFilename");
|
|
666
|
+
let delegatedCjs = 0;
|
|
667
|
+
const resolveRoutedCjs = (request, routed, parent, main, options) => {
|
|
668
|
+
const anchor = routed.kind === "fallback" ? routed.entry.declarer : routed.parent;
|
|
669
|
+
const synthetic = new cjs(anchor);
|
|
670
|
+
synthetic.parent = parent;
|
|
671
|
+
synthetic.filename = anchor;
|
|
672
|
+
synthetic.paths = routed.kind === "fallback" ? packageSearchPaths(routed.entry, request, cjs) : cjs._nodeModulePaths(dirname(anchor));
|
|
673
|
+
try {
|
|
674
|
+
return originalFilename.call(cjs, request, synthetic, main, options);
|
|
675
|
+
} catch (error) {
|
|
676
|
+
return throwWithoutCjsAnchor(error, anchor);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
const resolveNativeCjs = (request, searchPaths, parent, parentFilename, main, conditions) => {
|
|
680
|
+
const synthetic = new cjs(parentFilename);
|
|
681
|
+
synthetic.parent = parent;
|
|
682
|
+
synthetic.filename = parentFilename;
|
|
683
|
+
synthetic.paths = [...searchPaths];
|
|
684
|
+
const options = conditions === void 0 ? void 0 : { conditions };
|
|
685
|
+
return originalFilename.call(cjs, request, synthetic, main, options);
|
|
686
|
+
};
|
|
687
|
+
const resolvePackageImportCjs = (target, conditions) => {
|
|
688
|
+
const state = router.routeUrl(target.specifier, target.parentURL);
|
|
689
|
+
const resolveFrom = (parentURL) => fileURLToPath(esmDefaultResolve(target.specifier, {
|
|
690
|
+
parentURL,
|
|
691
|
+
conditions: [...conditions]
|
|
692
|
+
}).url);
|
|
693
|
+
/* v8 ignore next -- the target manifest was found inside the established profile scope */
|
|
694
|
+
if (state === void 0) return resolveFrom(target.parentURL);
|
|
695
|
+
if (state.route.kind === "native") return resolveFrom(target.parentURL);
|
|
696
|
+
const route = state.route;
|
|
697
|
+
if (route.kind === "after-fallback") return resolveFrom(pathToFileURL(route.parent).href);
|
|
698
|
+
return resolveFrom(pathToFileURL(route.entry.declarer).href);
|
|
699
|
+
};
|
|
700
|
+
const wrappedFilename = (request, parent, main, options) => {
|
|
701
|
+
if (delegatedCjs || !parent?.filename) return originalFilename.call(cjs, request, parent, main, options);
|
|
702
|
+
const parentFilename = parent.filename;
|
|
703
|
+
const cacheable = options?.paths === void 0 && options?.conditions === void 0;
|
|
704
|
+
const explicitPaths = Array.isArray(options?.paths) ? options.paths : void 0;
|
|
705
|
+
if (explicitPaths !== void 0 && router.nativeSelfReference(request, parentFilename)) return originalFilename.call(cjs, request, parent, main, options);
|
|
706
|
+
const explicit = explicitPaths === void 0 ? void 0 : router.explicitRoute(request, explicitPaths);
|
|
707
|
+
if (options?.paths !== void 0 && explicit === void 0) return originalFilename.call(cjs, request, parent, main, options);
|
|
708
|
+
if (explicit !== void 0 && explicitPaths !== void 0 && explicit.index > 0) try {
|
|
709
|
+
return originalFilename.call(cjs, request, parent, main, {
|
|
710
|
+
...options,
|
|
711
|
+
paths: explicitPaths.slice(0, explicit.index)
|
|
712
|
+
});
|
|
713
|
+
} catch (error) {
|
|
714
|
+
if (!isUnselectedPackageMiss(error)) throw error;
|
|
715
|
+
}
|
|
716
|
+
const state = router.routePath(request, explicit?.parent ?? parentFilename, (searchPaths) => resolveNativeCjs(request, searchPaths, parent, parentFilename, main, options?.conditions), explicit === void 0 && cacheable);
|
|
717
|
+
if (state === void 0) {
|
|
718
|
+
const scoped = startsWithin(parentFilename, profilePaths);
|
|
719
|
+
const conditions = options?.conditions ?? cjsConditions;
|
|
720
|
+
const target = request[0] === "#" && scoped ? packageImportsTarget(parentFilename, request, conditions) : void 0;
|
|
721
|
+
if (target === void 0) return originalFilename.call(cjs, request, parent, main, options);
|
|
722
|
+
const expected = resolvePackageImportCjs(target, conditions);
|
|
723
|
+
if (behavior === "enforce") return expected;
|
|
724
|
+
const actual = originalFilename.call(cjs, request, parent, main, options);
|
|
725
|
+
assertEquivalent(actual, expected, request, parentFilename);
|
|
726
|
+
return actual;
|
|
727
|
+
}
|
|
728
|
+
if (cacheable && state.cjs !== void 0) return state.cjs;
|
|
729
|
+
const route = state.route;
|
|
730
|
+
if (route.kind === "native") {
|
|
731
|
+
const result = originalFilename.call(cjs, request, parent, main, options);
|
|
732
|
+
if (cacheable) state.cjs = result;
|
|
733
|
+
return result;
|
|
734
|
+
}
|
|
735
|
+
if (route.kind === "after-fallback" && explicit !== void 0 && explicitPaths !== void 0) try {
|
|
736
|
+
return originalFilename.call(cjs, request, parent, main, {
|
|
737
|
+
...options,
|
|
738
|
+
paths: [dirname(route.parent)]
|
|
739
|
+
});
|
|
740
|
+
} catch (error) {
|
|
741
|
+
if (!isUnselectedPackageMiss(error)) throw error;
|
|
742
|
+
const remaining = explicitPaths.slice(explicit.index + 1);
|
|
743
|
+
if (remaining.length === 0) throw error;
|
|
744
|
+
return wrappedFilename(request, parent, main, {
|
|
745
|
+
...options,
|
|
746
|
+
paths: remaining
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
delegatedCjs++;
|
|
750
|
+
try {
|
|
751
|
+
const routedOptions = options?.conditions === void 0 ? void 0 : { conditions: options.conditions };
|
|
752
|
+
let expected;
|
|
753
|
+
try {
|
|
754
|
+
expected = resolveRoutedCjs(request, route, parent, main, routedOptions);
|
|
755
|
+
} catch (error) {
|
|
756
|
+
if (route.kind !== "fallback" || !isUnselectedPackageMiss(error)) throw error;
|
|
757
|
+
try {
|
|
758
|
+
expected = resolveRoutedCjs(request, {
|
|
759
|
+
kind: "after-fallback",
|
|
760
|
+
parent: route.after
|
|
761
|
+
}, parent, main, routedOptions);
|
|
762
|
+
} catch (afterError) {
|
|
763
|
+
const remaining = explicit === void 0 || explicitPaths === void 0 ? [] : explicitPaths.slice(explicit.index + 1);
|
|
764
|
+
if (!isUnselectedPackageMiss(afterError) || remaining.length === 0) throw afterError;
|
|
765
|
+
delegatedCjs--;
|
|
766
|
+
try {
|
|
767
|
+
return wrappedFilename(request, parent, main, {
|
|
768
|
+
...options,
|
|
769
|
+
paths: remaining
|
|
770
|
+
});
|
|
771
|
+
} finally {
|
|
772
|
+
delegatedCjs++;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (behavior === "enforce") {
|
|
777
|
+
if (cacheable) state.cjs = expected;
|
|
778
|
+
return expected;
|
|
779
|
+
}
|
|
780
|
+
const actual = originalFilename.call(cjs, request, parent, main, options);
|
|
781
|
+
assertEquivalent(actual, expected, request, parentFilename);
|
|
782
|
+
if (cacheable) state.cjs = actual;
|
|
783
|
+
return actual;
|
|
784
|
+
} finally {
|
|
785
|
+
delegatedCjs--;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
cjs._resolveFilename = wrappedFilename;
|
|
789
|
+
return {
|
|
790
|
+
packageDir(specifier, parentURL) {
|
|
791
|
+
const expected = router.packageDir(specifier, parentURL);
|
|
792
|
+
if (behavior !== "verify" || !startsWithin(parentURL, profileUrls)) return expected;
|
|
793
|
+
const name = barePackageName(specifier);
|
|
794
|
+
if (name === void 0) return expected;
|
|
795
|
+
let parent;
|
|
796
|
+
try {
|
|
797
|
+
parent = fileURLToPath(parentURL);
|
|
798
|
+
} catch {
|
|
799
|
+
return expected;
|
|
800
|
+
}
|
|
801
|
+
assertOptionalEquivalent(nativePackageDir(parent, name), expected, specifier, parentURL);
|
|
802
|
+
return expected;
|
|
803
|
+
},
|
|
804
|
+
replace(next) {
|
|
805
|
+
router.replace(next);
|
|
806
|
+
},
|
|
807
|
+
dispose() {
|
|
808
|
+
/* v8 ignore else -- registrations are disposed in reverse installation order */
|
|
809
|
+
if (cjs._resolveFilename === wrappedFilename) cjs._resolveFilename = originalFilename;
|
|
810
|
+
restoreEsm();
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
//#endregion
|
|
815
|
+
//#region lib/types/profile-resolution/worker-bootstrap.js
|
|
816
|
+
/** Install an inherited profile resolution generation in one Harness-owned Worker. */
|
|
817
|
+
const registration = getEnvironmentData("@deepseek-ai/dsh-app-boot/profile-resolution");
|
|
818
|
+
if (registration !== void 0) installProfileResolution(registration.generation, registration.behavior);
|
|
819
|
+
//#endregion
|
|
820
|
+
export {};
|