@jsenv/plugin-supervisor 1.6.10 → 1.6.12

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.
@@ -1,320 +1,6 @@
1
1
  import { applyBabelPlugins, parseHtml, visitHtmlNodes, analyzeScriptNode, getHtmlNodeAttribute, getHtmlNodeText, injectJsenvScript, stringifyHtmlAst, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeText, setHtmlNodeAttributes } from "@jsenv/ast";
2
- import process$1 from "node:process";
3
- import os from "node:os";
4
- import tty from "node:tty";
5
- import "string-width";
6
2
  import { createRequire } from "node:module";
7
- import { existsSync, readFileSync, realpathSync } from "node:fs";
8
- import { fileURLToPath, pathToFileURL } from "node:url";
9
3
 
10
- // From: https://github.com/sindresorhus/has-flag/blob/main/index.js
11
- /// function hasFlag(flag, argv = globalThis.Deno?.args ?? process.argv) {
12
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process$1.argv) {
13
- const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
14
- const position = argv.indexOf(prefix + flag);
15
- const terminatorPosition = argv.indexOf('--');
16
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
17
- }
18
- const {
19
- env
20
- } = process$1;
21
- let flagForceColor;
22
- if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
23
- flagForceColor = 0;
24
- } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
25
- flagForceColor = 1;
26
- }
27
- function envForceColor() {
28
- if (!('FORCE_COLOR' in env)) {
29
- return;
30
- }
31
- if (env.FORCE_COLOR === 'true') {
32
- return 1;
33
- }
34
- if (env.FORCE_COLOR === 'false') {
35
- return 0;
36
- }
37
- if (env.FORCE_COLOR.length === 0) {
38
- return 1;
39
- }
40
- const level = Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
41
- if (![0, 1, 2, 3].includes(level)) {
42
- return;
43
- }
44
- return level;
45
- }
46
- function translateLevel(level) {
47
- if (level === 0) {
48
- return false;
49
- }
50
- return {
51
- level,
52
- hasBasic: true,
53
- has256: level >= 2,
54
- has16m: level >= 3
55
- };
56
- }
57
- function _supportsColor(haveStream, {
58
- streamIsTTY,
59
- sniffFlags = true
60
- } = {}) {
61
- const noFlagForceColor = envForceColor();
62
- if (noFlagForceColor !== undefined) {
63
- flagForceColor = noFlagForceColor;
64
- }
65
- const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
66
- if (forceColor === 0) {
67
- return 0;
68
- }
69
- if (sniffFlags) {
70
- if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
71
- return 3;
72
- }
73
- if (hasFlag('color=256')) {
74
- return 2;
75
- }
76
- }
77
-
78
- // Check for Azure DevOps pipelines.
79
- // Has to be above the `!streamIsTTY` check.
80
- if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
81
- return 1;
82
- }
83
- if (haveStream && !streamIsTTY && forceColor === undefined) {
84
- return 0;
85
- }
86
- const min = forceColor || 0;
87
- if (env.TERM === 'dumb') {
88
- return min;
89
- }
90
- if (process$1.platform === 'win32') {
91
- // Windows 10 build 10586 is the first Windows release that supports 256 colors.
92
- // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
93
- const osRelease = os.release().split('.');
94
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
95
- return Number(osRelease[2]) >= 14931 ? 3 : 2;
96
- }
97
- return 1;
98
- }
99
- if ('CI' in env) {
100
- if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
101
- return 3;
102
- }
103
- if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
104
- return 1;
105
- }
106
- return min;
107
- }
108
- if ('TEAMCITY_VERSION' in env) {
109
- return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
110
- }
111
- if (env.COLORTERM === 'truecolor') {
112
- return 3;
113
- }
114
- if (env.TERM === 'xterm-kitty') {
115
- return 3;
116
- }
117
- if ('TERM_PROGRAM' in env) {
118
- const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
119
- switch (env.TERM_PROGRAM) {
120
- case 'iTerm.app':
121
- {
122
- return version >= 3 ? 3 : 2;
123
- }
124
- case 'Apple_Terminal':
125
- {
126
- return 2;
127
- }
128
- // No default
129
- }
130
- }
131
- if (/-256(color)?$/i.test(env.TERM)) {
132
- return 2;
133
- }
134
- if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
135
- return 1;
136
- }
137
- if ('COLORTERM' in env) {
138
- return 1;
139
- }
140
- return min;
141
- }
142
- function createSupportsColor(stream, options = {}) {
143
- const level = _supportsColor(stream, {
144
- streamIsTTY: stream && stream.isTTY,
145
- ...options
146
- });
147
- return translateLevel(level);
148
- }
149
- ({
150
- stdout: createSupportsColor({
151
- isTTY: tty.isatty(1)
152
- }),
153
- stderr: createSupportsColor({
154
- isTTY: tty.isatty(2)
155
- })
156
- });
157
- function isUnicodeSupported() {
158
- const {
159
- env
160
- } = process$1;
161
- const {
162
- TERM,
163
- TERM_PROGRAM
164
- } = env;
165
- if (process$1.platform !== 'win32') {
166
- return TERM !== 'linux'; // Linux console (kernel)
167
- }
168
- return Boolean(env.WT_SESSION) // Windows Terminal
169
- || Boolean(env.TERMINUS_SUBLIME) // Terminus (<0.2.27)
170
- || env.ConEmuTask === '{cmd::Cmder}' // ConEmu and cmder
171
- || TERM_PROGRAM === 'Terminus-Sublime' || TERM_PROGRAM === 'vscode' || TERM === 'xterm-256color' || TERM === 'alacritty' || TERM === 'rxvt-unicode' || TERM === 'rxvt-unicode-256color' || env.TERMINAL_EMULATOR === 'JetBrains-JediTerm';
172
- }
173
-
174
- /* globals WorkerGlobalScope, DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, ServiceWorkerGlobalScope */
175
-
176
- const isBrowser = globalThis.window?.document !== undefined;
177
- globalThis.process?.versions?.node !== undefined;
178
- globalThis.process?.versions?.bun !== undefined;
179
- globalThis.Deno?.version?.deno !== undefined;
180
- globalThis.process?.versions?.electron !== undefined;
181
- globalThis.navigator?.userAgent?.includes('jsdom') === true;
182
- typeof WorkerGlobalScope !== 'undefined' && globalThis instanceof WorkerGlobalScope;
183
- typeof DedicatedWorkerGlobalScope !== 'undefined' && globalThis instanceof DedicatedWorkerGlobalScope;
184
- typeof SharedWorkerGlobalScope !== 'undefined' && globalThis instanceof SharedWorkerGlobalScope;
185
- typeof ServiceWorkerGlobalScope !== 'undefined' && globalThis instanceof ServiceWorkerGlobalScope;
186
-
187
- // Note: I'm intentionally not DRYing up the other variables to keep them "lazy".
188
- const platform = globalThis.navigator?.userAgentData?.platform;
189
- platform === 'macOS' || globalThis.navigator?.platform === 'MacIntel' // Even on Apple silicon Macs.
190
- || globalThis.navigator?.userAgent?.includes(' Mac ') === true || globalThis.process?.platform === 'darwin';
191
- platform === 'Windows' || globalThis.navigator?.platform === 'Win32' || globalThis.process?.platform === 'win32';
192
- platform === 'Linux' || globalThis.navigator?.platform?.startsWith('Linux') === true || globalThis.navigator?.userAgent?.includes(' Linux ') === true || globalThis.process?.platform === 'linux';
193
- platform === 'Android' || globalThis.navigator?.platform === 'Android' || globalThis.navigator?.userAgent?.includes(' Android ') === true || globalThis.process?.platform === 'android';
194
- !isBrowser && process$1.env.TERM_PROGRAM === 'Apple_Terminal';
195
- !isBrowser && process$1.platform === 'win32';
196
- isBrowser ? () => {
197
- throw new Error('`process.cwd()` only works in Node.js, not the browser.');
198
- } : process$1.cwd;
199
-
200
- // https://github.com/Marak/colors.js/blob/master/lib/styles.js
201
- // https://stackoverflow.com/a/75985833/2634179
202
- const RESET = "\x1b[0m";
203
- const createAnsi = ({
204
- supported
205
- }) => {
206
- const ANSI = {
207
- supported,
208
- RED: "\x1b[31m",
209
- GREEN: "\x1b[32m",
210
- YELLOW: "\x1b[33m",
211
- BLUE: "\x1b[34m",
212
- MAGENTA: "\x1b[35m",
213
- CYAN: "\x1b[36m",
214
- GREY: "\x1b[90m",
215
- color: (text, color) => {
216
- if (!ANSI.supported) {
217
- return text;
218
- }
219
- if (!color) {
220
- return text;
221
- }
222
- if (typeof text === "string" && text.trim() === "") {
223
- // cannot set color of blank chars
224
- return text;
225
- }
226
- return "".concat(color).concat(text).concat(RESET);
227
- },
228
- BOLD: "\x1b[1m",
229
- UNDERLINE: "\x1b[4m",
230
- STRIKE: "\x1b[9m",
231
- effect: (text, effect) => {
232
- if (!ANSI.supported) {
233
- return text;
234
- }
235
- if (!effect) {
236
- return text;
237
- }
238
- // cannot add effect to empty string
239
- if (text === "") {
240
- return text;
241
- }
242
- return "".concat(effect).concat(text).concat(RESET);
243
- }
244
- };
245
- return ANSI;
246
- };
247
- const processSupportsBasicColor = createSupportsColor(process.stdout).hasBasic;
248
- const ANSI = createAnsi({
249
- supported: process.env.FORCE_COLOR === "1" || processSupportsBasicColor ||
250
- // GitHub workflow does support ANSI but "supports-color" returns false
251
- // because stream.isTTY returns false, see https://github.com/actions/runner/issues/241
252
- process.env.GITHUB_WORKFLOW
253
- });
254
-
255
- // see also https://github.com/sindresorhus/figures
256
-
257
- const createUnicode = ({
258
- supported,
259
- ANSI
260
- }) => {
261
- const UNICODE = {
262
- supported,
263
- get COMMAND_RAW() {
264
- return UNICODE.supported ? "\u276F" : ">";
265
- },
266
- get OK_RAW() {
267
- return UNICODE.supported ? "\u2714" : "\u221A";
268
- },
269
- get FAILURE_RAW() {
270
- return UNICODE.supported ? "\u2716" : "\xD7";
271
- },
272
- get DEBUG_RAW() {
273
- return UNICODE.supported ? "\u25C6" : "\u2666";
274
- },
275
- get INFO_RAW() {
276
- return UNICODE.supported ? "\u2139" : "i";
277
- },
278
- get WARNING_RAW() {
279
- return UNICODE.supported ? "\u26A0" : "\u203C";
280
- },
281
- get CIRCLE_CROSS_RAW() {
282
- return UNICODE.supported ? "\u24E7" : "(\xD7)";
283
- },
284
- get CIRCLE_DOTTED_RAW() {
285
- return UNICODE.supported ? "\u25CC" : "*";
286
- },
287
- get COMMAND() {
288
- return ANSI.color(UNICODE.COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
289
- },
290
- get OK() {
291
- return ANSI.color(UNICODE.OK_RAW, ANSI.GREEN);
292
- },
293
- get FAILURE() {
294
- return ANSI.color(UNICODE.FAILURE_RAW, ANSI.RED);
295
- },
296
- get DEBUG() {
297
- return ANSI.color(UNICODE.DEBUG_RAW, ANSI.GREY);
298
- },
299
- get INFO() {
300
- return ANSI.color(UNICODE.INFO_RAW, ANSI.BLUE);
301
- },
302
- get WARNING() {
303
- return ANSI.color(UNICODE.WARNING_RAW, ANSI.YELLOW);
304
- },
305
- get CIRCLE_CROSS() {
306
- return ANSI.color(UNICODE.CIRCLE_CROSS_RAW, ANSI.RED);
307
- },
308
- get ELLIPSIS() {
309
- return UNICODE.supported ? "\u2026" : "...";
310
- }
311
- };
312
- return UNICODE;
313
- };
314
- createUnicode({
315
- supported: process.env.FORCE_UNICODE === "1" || isUnicodeSupported(),
316
- ANSI
317
- });
318
4
  const formatDefault = v => v;
319
5
  const generateContentFrame = ({
320
6
  content,
@@ -469,30 +155,38 @@ const fillLeft = (value, biggestValue, char = " ") => {
469
155
  // becoming "file:///file.css?css_module="
470
156
  // we want to get rid of the "=" and consider it's the same url
471
157
  const normalizeUrl = url => {
472
- if (url.includes("?")) {
473
- // disable on data urls (would mess up base64 encoding)
474
- if (url.startsWith("data:")) {
475
- return url;
476
- }
477
- return url.replace(/[=](?=&|$)/g, "");
158
+ const calledWithString = typeof url === "string";
159
+ const urlObject = calledWithString ? new URL(url) : url;
160
+ let urlString = urlObject.href;
161
+ if (!urlString.includes("?")) {
162
+ return url;
478
163
  }
479
- return url;
164
+ // disable on data urls (would mess up base64 encoding)
165
+ if (urlString.startsWith("data:")) {
166
+ return url;
167
+ }
168
+ urlString = urlString.replace(/[=](?=&|$)/g, "");
169
+ if (calledWithString) {
170
+ return urlString;
171
+ }
172
+ urlObject.href = urlString;
173
+ return urlObject;
480
174
  };
481
175
  const injectQueryParams = (url, params) => {
482
- const urlObject = new URL(url);
176
+ const calledWithString = typeof url === "string";
177
+ const urlObject = calledWithString ? new URL(url) : url;
483
178
  const {
484
179
  searchParams
485
180
  } = urlObject;
486
- Object.keys(params).forEach(key => {
181
+ for (const key of Object.keys(params)) {
487
182
  const value = params[key];
488
183
  if (value === undefined) {
489
184
  searchParams.delete(key);
490
185
  } else {
491
186
  searchParams.set(key, value);
492
187
  }
493
- });
494
- const urlWithParams = urlObject.href;
495
- return normalizeUrl(urlWithParams);
188
+ }
189
+ return normalizeUrl(calledWithString ? urlObject.href : urlObject);
496
190
  };
497
191
 
498
192
  const getCommonPathname = (pathname, otherPathname) => {
@@ -1210,856 +904,6 @@ const generateCodeToSuperviseScriptWithSrc = ({
1210
904
  return "window.__supervisor__.superviseScript(".concat(srcEncoded, ");");
1211
905
  };
1212
906
 
1213
- // https://nodejs.org/api/packages.html#resolving-user-conditions
1214
- const readCustomConditionsFromProcessArgs = () => {
1215
- const packageConditions = [];
1216
- for (const arg of process.execArgv) {
1217
- if (arg.includes("-C=")) {
1218
- const packageCondition = arg.slice(0, "-C=".length);
1219
- packageConditions.push(packageCondition);
1220
- }
1221
- if (arg.includes("--conditions=")) {
1222
- const packageCondition = arg.slice("--conditions=".length);
1223
- packageConditions.push(packageCondition);
1224
- }
1225
- }
1226
- return packageConditions;
1227
- };
1228
-
1229
- const asDirectoryUrl = url => {
1230
- const {
1231
- pathname
1232
- } = new URL(url);
1233
- if (pathname.endsWith("/")) {
1234
- return url;
1235
- }
1236
- return new URL("./", url).href;
1237
- };
1238
- const getParentUrl = url => {
1239
- if (url.startsWith("file://")) {
1240
- // With node.js new URL('../', 'file:///C:/').href
1241
- // returns "file:///C:/" instead of "file:///"
1242
- const resource = url.slice("file://".length);
1243
- const slashLastIndex = resource.lastIndexOf("/");
1244
- if (slashLastIndex === -1) {
1245
- return url;
1246
- }
1247
- const lastCharIndex = resource.length - 1;
1248
- if (slashLastIndex === lastCharIndex) {
1249
- const slashBeforeLastIndex = resource.lastIndexOf("/", slashLastIndex - 1);
1250
- if (slashBeforeLastIndex === -1) {
1251
- return url;
1252
- }
1253
- return "file://".concat(resource.slice(0, slashBeforeLastIndex + 1));
1254
- }
1255
- return "file://".concat(resource.slice(0, slashLastIndex + 1));
1256
- }
1257
- return new URL(url.endsWith("/") ? "../" : "./", url).href;
1258
- };
1259
- const isValidUrl = url => {
1260
- try {
1261
- // eslint-disable-next-line no-new
1262
- new URL(url);
1263
- return true;
1264
- } catch (_unused) {
1265
- return false;
1266
- }
1267
- };
1268
-
1269
- const defaultLookupPackageScope = url => {
1270
- let scopeUrl = asDirectoryUrl(url);
1271
- while (scopeUrl !== "file:///") {
1272
- if (scopeUrl.endsWith("node_modules/")) {
1273
- return null;
1274
- }
1275
- const packageJsonUrlObject = new URL("package.json", scopeUrl);
1276
- if (existsSync(packageJsonUrlObject)) {
1277
- return scopeUrl;
1278
- }
1279
- scopeUrl = getParentUrl(scopeUrl);
1280
- }
1281
- return null;
1282
- };
1283
-
1284
- const defaultReadPackageJson = packageUrl => {
1285
- const packageJsonUrl = new URL("package.json", packageUrl);
1286
- const buffer = readFileSync(packageJsonUrl);
1287
- const string = String(buffer);
1288
- try {
1289
- return JSON.parse(string);
1290
- } catch (_unused) {
1291
- throw new Error("Invalid package configuration");
1292
- }
1293
- };
1294
-
1295
- // https://github.com/nodejs/node/blob/0367b5c35ea0f98b323175a4aaa8e651af7a91e7/tools/node_modules/eslint/node_modules/%40babel/core/lib/vendor/import-meta-resolve.js#L2473
1296
- const createInvalidModuleSpecifierError = (reason, specifier, {
1297
- parentUrl
1298
- }) => {
1299
- const error = new Error("Invalid module \"".concat(specifier, "\" ").concat(reason, " imported from ").concat(fileURLToPath(parentUrl)));
1300
- error.code = "INVALID_MODULE_SPECIFIER";
1301
- return error;
1302
- };
1303
- const createInvalidPackageTargetError = (reason, target, {
1304
- parentUrl,
1305
- packageDirectoryUrl,
1306
- key,
1307
- isImport
1308
- }) => {
1309
- let message;
1310
- if (key === ".") {
1311
- message = "Invalid \"exports\" main target defined in ".concat(fileURLToPath(packageDirectoryUrl), "package.json imported from ").concat(fileURLToPath(parentUrl), "; ").concat(reason);
1312
- } else {
1313
- message = "Invalid \"".concat(isImport ? "imports" : "exports", "\" target ").concat(JSON.stringify(target), " defined for \"").concat(key, "\" in ").concat(fileURLToPath(packageDirectoryUrl), "package.json imported from ").concat(fileURLToPath(parentUrl), "; ").concat(reason);
1314
- }
1315
- const error = new Error(message);
1316
- error.code = "INVALID_PACKAGE_TARGET";
1317
- return error;
1318
- };
1319
- const createPackagePathNotExportedError = (subpath, {
1320
- parentUrl,
1321
- packageDirectoryUrl
1322
- }) => {
1323
- let message;
1324
- if (subpath === ".") {
1325
- message = "No \"exports\" main defined in ".concat(fileURLToPath(packageDirectoryUrl), "package.json imported from ").concat(fileURLToPath(parentUrl));
1326
- } else {
1327
- message = "Package subpath \"".concat(subpath, "\" is not defined by \"exports\" in ").concat(fileURLToPath(packageDirectoryUrl), "package.json imported from ").concat(fileURLToPath(parentUrl));
1328
- }
1329
- const error = new Error(message);
1330
- error.code = "PACKAGE_PATH_NOT_EXPORTED";
1331
- return error;
1332
- };
1333
- const createModuleNotFoundError = (specifier, {
1334
- parentUrl
1335
- }) => {
1336
- const error = new Error("Cannot find \"".concat(specifier, "\" imported from ").concat(fileURLToPath(parentUrl)));
1337
- error.code = "MODULE_NOT_FOUND";
1338
- return error;
1339
- };
1340
- const createPackageImportNotDefinedError = (specifier, {
1341
- parentUrl,
1342
- packageDirectoryUrl
1343
- }) => {
1344
- const error = new Error("Package import specifier \"".concat(specifier, "\" is not defined in ").concat(fileURLToPath(packageDirectoryUrl), "package.json imported from ").concat(fileURLToPath(parentUrl)));
1345
- error.code = "PACKAGE_IMPORT_NOT_DEFINED";
1346
- return error;
1347
- };
1348
-
1349
- const isSpecifierForNodeBuiltin = specifier => {
1350
- return specifier.startsWith("node:") || NODE_BUILTIN_MODULE_SPECIFIERS.includes(specifier);
1351
- };
1352
- const NODE_BUILTIN_MODULE_SPECIFIERS = ["assert", "assert/strict", "async_hooks", "buffer_ieee754", "buffer", "child_process", "cluster", "console", "constants", "crypto", "_debugger", "dgram", "dns", "domain", "events", "freelist", "fs", "fsevents", "fs/promises", "_http_agent", "_http_client", "_http_common", "_http_incoming", "_http_outgoing", "_http_server", "http", "http2", "https", "inspector", "_linklist", "module", "net", "node-inspect/lib/_inspect", "node-inspect/lib/internal/inspect_client", "node-inspect/lib/internal/inspect_repl", "os", "path", "perf_hooks", "process", "punycode", "querystring", "readline", "repl", "smalloc", "_stream_duplex", "_stream_transform", "_stream_wrap", "_stream_passthrough", "_stream_readable", "_stream_writable", "stream", "stream/promises", "string_decoder", "sys", "timers", "_tls_common", "_tls_legacy", "_tls_wrap", "tls", "trace_events", "tty", "url", "util", "v8/tools/arguments", "v8/tools/codemap", "v8/tools/consarray", "v8/tools/csvparser", "v8/tools/logreader", "v8/tools/profile_view", "v8/tools/splaytree", "v8", "vm", "worker_threads", "zlib",
1353
- // global is special
1354
- "global"];
1355
-
1356
- /*
1357
- * https://nodejs.org/api/esm.html#resolver-algorithm-specification
1358
- * https://github.com/nodejs/node/blob/0367b5c35ea0f98b323175a4aaa8e651af7a91e7/lib/internal/modules/esm/resolve.js#L1
1359
- * deviations from the spec:
1360
- * - take into account "browser", "module" and "jsnext"
1361
- * - the check for isDirectory -> throw is delayed is descoped to the caller
1362
- * - the call to real path ->
1363
- * delayed to the caller so that we can decide to
1364
- * maintain symlink as facade url when it's outside project directory
1365
- * or use the real path when inside
1366
- */
1367
- const applyNodeEsmResolution = ({
1368
- specifier,
1369
- parentUrl,
1370
- conditions = [...readCustomConditionsFromProcessArgs(), "node", "import"],
1371
- lookupPackageScope = defaultLookupPackageScope,
1372
- readPackageJson = defaultReadPackageJson,
1373
- preservesSymlink = false
1374
- }) => {
1375
- const resolution = applyPackageSpecifierResolution(specifier, {
1376
- parentUrl: String(parentUrl),
1377
- conditions,
1378
- lookupPackageScope,
1379
- readPackageJson,
1380
- preservesSymlink
1381
- });
1382
- const {
1383
- url
1384
- } = resolution;
1385
- if (url.startsWith("file:")) {
1386
- if (url.includes("%2F") || url.includes("%5C")) {
1387
- throw createInvalidModuleSpecifierError("must not include encoded \"/\" or \"\\\" characters", specifier, {
1388
- parentUrl
1389
- });
1390
- }
1391
- return resolution;
1392
- }
1393
- return resolution;
1394
- };
1395
- const applyPackageSpecifierResolution = (specifier, resolutionContext) => {
1396
- const {
1397
- parentUrl
1398
- } = resolutionContext;
1399
- // relative specifier
1400
- if (specifier[0] === "/" || specifier.startsWith("./") || specifier.startsWith("../")) {
1401
- if (specifier[0] !== "/") {
1402
- const browserFieldResolution = applyBrowserFieldResolution(specifier, resolutionContext);
1403
- if (browserFieldResolution) {
1404
- return browserFieldResolution;
1405
- }
1406
- }
1407
- return {
1408
- type: "relative_specifier",
1409
- url: new URL(specifier, parentUrl).href
1410
- };
1411
- }
1412
- if (specifier[0] === "#") {
1413
- return applyPackageImportsResolution(specifier, resolutionContext);
1414
- }
1415
- try {
1416
- const urlObject = new URL(specifier);
1417
- if (specifier.startsWith("node:")) {
1418
- return {
1419
- type: "node_builtin_specifier",
1420
- url: specifier
1421
- };
1422
- }
1423
- return {
1424
- type: "absolute_specifier",
1425
- url: urlObject.href
1426
- };
1427
- } catch (_unused) {
1428
- // bare specifier
1429
- const browserFieldResolution = applyBrowserFieldResolution(specifier, resolutionContext);
1430
- if (browserFieldResolution) {
1431
- return browserFieldResolution;
1432
- }
1433
- const packageResolution = applyPackageResolve(specifier, resolutionContext);
1434
- const search = new URL(specifier, "file:///").search;
1435
- if (search && !new URL(packageResolution.url).search) {
1436
- packageResolution.url = "".concat(packageResolution.url).concat(search);
1437
- }
1438
- return packageResolution;
1439
- }
1440
- };
1441
- const applyBrowserFieldResolution = (specifier, resolutionContext) => {
1442
- const {
1443
- parentUrl,
1444
- conditions,
1445
- lookupPackageScope,
1446
- readPackageJson
1447
- } = resolutionContext;
1448
- const browserCondition = conditions.includes("browser");
1449
- if (!browserCondition) {
1450
- return null;
1451
- }
1452
- const packageDirectoryUrl = lookupPackageScope(parentUrl);
1453
- if (!packageDirectoryUrl) {
1454
- return null;
1455
- }
1456
- const packageJson = readPackageJson(packageDirectoryUrl);
1457
- if (!packageJson) {
1458
- return null;
1459
- }
1460
- const {
1461
- browser
1462
- } = packageJson;
1463
- if (!browser) {
1464
- return null;
1465
- }
1466
- if (typeof browser !== "object") {
1467
- return null;
1468
- }
1469
- let url;
1470
- if (specifier.startsWith(".")) {
1471
- const specifierUrl = new URL(specifier, parentUrl).href;
1472
- const specifierRelativeUrl = specifierUrl.slice(packageDirectoryUrl.length);
1473
- const secifierRelativeNotation = "./".concat(specifierRelativeUrl);
1474
- const browserMapping = browser[secifierRelativeNotation];
1475
- if (typeof browserMapping === "string") {
1476
- url = new URL(browserMapping, packageDirectoryUrl).href;
1477
- } else if (browserMapping === false) {
1478
- url = "file:///@ignore/".concat(specifierUrl.slice("file:///"));
1479
- }
1480
- } else {
1481
- const browserMapping = browser[specifier];
1482
- if (typeof browserMapping === "string") {
1483
- url = new URL(browserMapping, packageDirectoryUrl).href;
1484
- } else if (browserMapping === false) {
1485
- url = "file:///@ignore/".concat(specifier);
1486
- }
1487
- }
1488
- if (url) {
1489
- return {
1490
- type: "field:browser",
1491
- isMain: true,
1492
- packageDirectoryUrl,
1493
- packageJson,
1494
- url
1495
- };
1496
- }
1497
- return null;
1498
- };
1499
- const applyPackageImportsResolution = (internalSpecifier, resolutionContext) => {
1500
- const {
1501
- parentUrl,
1502
- lookupPackageScope,
1503
- readPackageJson
1504
- } = resolutionContext;
1505
- if (internalSpecifier === "#" || internalSpecifier.startsWith("#/")) {
1506
- throw createInvalidModuleSpecifierError("not a valid internal imports specifier name", internalSpecifier, resolutionContext);
1507
- }
1508
- const packageDirectoryUrl = lookupPackageScope(parentUrl);
1509
- if (packageDirectoryUrl !== null) {
1510
- const packageJson = readPackageJson(packageDirectoryUrl);
1511
- const {
1512
- imports
1513
- } = packageJson;
1514
- if (imports !== null && typeof imports === "object") {
1515
- const resolved = applyPackageImportsExportsResolution(internalSpecifier, {
1516
- ...resolutionContext,
1517
- packageDirectoryUrl,
1518
- packageJson,
1519
- isImport: true
1520
- });
1521
- if (resolved) {
1522
- return resolved;
1523
- }
1524
- }
1525
- }
1526
- throw createPackageImportNotDefinedError(internalSpecifier, {
1527
- ...resolutionContext,
1528
- packageDirectoryUrl
1529
- });
1530
- };
1531
- const applyPackageResolve = (packageSpecifier, resolutionContext) => {
1532
- const {
1533
- parentUrl,
1534
- conditions,
1535
- readPackageJson,
1536
- preservesSymlink
1537
- } = resolutionContext;
1538
- if (packageSpecifier === "") {
1539
- throw new Error("invalid module specifier");
1540
- }
1541
- if (conditions.includes("node") && isSpecifierForNodeBuiltin(packageSpecifier)) {
1542
- return {
1543
- type: "node_builtin_specifier",
1544
- url: "node:".concat(packageSpecifier)
1545
- };
1546
- }
1547
- let {
1548
- packageName,
1549
- packageSubpath
1550
- } = parsePackageSpecifier(packageSpecifier);
1551
- if (packageName[0] === "." || packageName.includes("\\") || packageName.includes("%")) {
1552
- throw createInvalidModuleSpecifierError("is not a valid package name", packageName, resolutionContext);
1553
- }
1554
- if (packageSubpath.endsWith("/")) {
1555
- throw new Error("invalid module specifier");
1556
- }
1557
- const questionCharIndex = packageName.indexOf("?");
1558
- if (questionCharIndex > -1) {
1559
- packageName = packageName.slice(0, questionCharIndex);
1560
- }
1561
- const selfResolution = applyPackageSelfResolution(packageSubpath, {
1562
- ...resolutionContext,
1563
- packageName
1564
- });
1565
- if (selfResolution) {
1566
- return selfResolution;
1567
- }
1568
- let currentUrl = parentUrl;
1569
- while (currentUrl !== "file:///") {
1570
- const packageDirectoryFacadeUrl = new URL("node_modules/".concat(packageName, "/"), currentUrl).href;
1571
- if (!existsSync(new URL(packageDirectoryFacadeUrl))) {
1572
- currentUrl = getParentUrl(currentUrl);
1573
- continue;
1574
- }
1575
- const packageDirectoryUrl = preservesSymlink ? packageDirectoryFacadeUrl : resolvePackageSymlink(packageDirectoryFacadeUrl);
1576
- const packageJson = readPackageJson(packageDirectoryUrl);
1577
- if (packageJson !== null) {
1578
- const {
1579
- exports
1580
- } = packageJson;
1581
- if (exports !== null && exports !== undefined) {
1582
- return applyPackageExportsResolution(packageSubpath, {
1583
- ...resolutionContext,
1584
- packageDirectoryUrl,
1585
- packageJson,
1586
- exports
1587
- });
1588
- }
1589
- }
1590
- return applyLegacySubpathResolution(packageSubpath, {
1591
- ...resolutionContext,
1592
- packageDirectoryUrl,
1593
- packageJson
1594
- });
1595
- }
1596
- throw createModuleNotFoundError(packageName, resolutionContext);
1597
- };
1598
- const applyPackageSelfResolution = (packageSubpath, resolutionContext) => {
1599
- const {
1600
- parentUrl,
1601
- packageName,
1602
- lookupPackageScope,
1603
- readPackageJson
1604
- } = resolutionContext;
1605
- const packageDirectoryUrl = lookupPackageScope(parentUrl);
1606
- if (!packageDirectoryUrl) {
1607
- return undefined;
1608
- }
1609
- const packageJson = readPackageJson(packageDirectoryUrl);
1610
- if (!packageJson) {
1611
- return undefined;
1612
- }
1613
- if (packageJson.name !== packageName) {
1614
- return undefined;
1615
- }
1616
- const {
1617
- exports
1618
- } = packageJson;
1619
- if (!exports) {
1620
- const subpathResolution = applyLegacySubpathResolution(packageSubpath, {
1621
- ...resolutionContext,
1622
- packageDirectoryUrl,
1623
- packageJson
1624
- });
1625
- if (subpathResolution && subpathResolution.type !== "subpath") {
1626
- return subpathResolution;
1627
- }
1628
- return undefined;
1629
- }
1630
- return applyPackageExportsResolution(packageSubpath, {
1631
- ...resolutionContext,
1632
- packageDirectoryUrl,
1633
- packageJson
1634
- });
1635
- };
1636
-
1637
- // https://github.com/nodejs/node/blob/0367b5c35ea0f98b323175a4aaa8e651af7a91e7/lib/internal/modules/esm/resolve.js#L642
1638
- const applyPackageExportsResolution = (packageSubpath, resolutionContext) => {
1639
- if (packageSubpath === ".") {
1640
- const mainExport = applyMainExportResolution(resolutionContext);
1641
- if (!mainExport) {
1642
- throw createPackagePathNotExportedError(packageSubpath, resolutionContext);
1643
- }
1644
- const resolved = applyPackageTargetResolution(mainExport, {
1645
- ...resolutionContext,
1646
- key: "."
1647
- });
1648
- if (resolved) {
1649
- return resolved;
1650
- }
1651
- throw createPackagePathNotExportedError(packageSubpath, resolutionContext);
1652
- }
1653
- const packageExportsInfo = readExports(resolutionContext);
1654
- if (packageExportsInfo.type === "object" && packageExportsInfo.allKeysAreRelative) {
1655
- const resolved = applyPackageImportsExportsResolution(packageSubpath, {
1656
- ...resolutionContext,
1657
- isImport: false
1658
- });
1659
- if (resolved) {
1660
- return resolved;
1661
- }
1662
- }
1663
- throw createPackagePathNotExportedError(packageSubpath, resolutionContext);
1664
- };
1665
- const applyPackageImportsExportsResolution = (matchKey, resolutionContext) => {
1666
- const {
1667
- packageJson,
1668
- isImport
1669
- } = resolutionContext;
1670
- const matchObject = isImport ? packageJson.imports : packageJson.exports;
1671
- if (!matchKey.includes("*") && matchObject.hasOwnProperty(matchKey)) {
1672
- const target = matchObject[matchKey];
1673
- return applyPackageTargetResolution(target, {
1674
- ...resolutionContext,
1675
- key: matchKey,
1676
- isImport
1677
- });
1678
- }
1679
- const expansionKeys = Object.keys(matchObject).filter(key => key.split("*").length === 2).sort(comparePatternKeys);
1680
- for (const expansionKey of expansionKeys) {
1681
- const [patternBase, patternTrailer] = expansionKey.split("*");
1682
- if (matchKey === patternBase) continue;
1683
- if (!matchKey.startsWith(patternBase)) continue;
1684
- if (patternTrailer.length > 0) {
1685
- if (!matchKey.endsWith(patternTrailer)) continue;
1686
- if (matchKey.length < expansionKey.length) continue;
1687
- }
1688
- const target = matchObject[expansionKey];
1689
- const subpath = matchKey.slice(patternBase.length, matchKey.length - patternTrailer.length);
1690
- return applyPackageTargetResolution(target, {
1691
- ...resolutionContext,
1692
- key: matchKey,
1693
- subpath,
1694
- pattern: true,
1695
- isImport
1696
- });
1697
- }
1698
- return null;
1699
- };
1700
- const applyPackageTargetResolution = (target, resolutionContext) => {
1701
- const {
1702
- conditions,
1703
- packageDirectoryUrl,
1704
- packageJson,
1705
- key,
1706
- subpath = "",
1707
- pattern = false,
1708
- isImport = false
1709
- } = resolutionContext;
1710
- if (typeof target === "string") {
1711
- if (pattern === false && subpath !== "" && !target.endsWith("/")) {
1712
- throw new Error("invalid module specifier");
1713
- }
1714
- if (target.startsWith("./")) {
1715
- const targetUrl = new URL(target, packageDirectoryUrl).href;
1716
- if (!targetUrl.startsWith(packageDirectoryUrl)) {
1717
- throw createInvalidPackageTargetError("target must be inside package", target, resolutionContext);
1718
- }
1719
- return {
1720
- type: isImport ? "field:imports" : "field:exports",
1721
- isMain: subpath === "" || subpath === ".",
1722
- packageDirectoryUrl,
1723
- packageJson,
1724
- url: pattern ? targetUrl.replaceAll("*", subpath) : new URL(subpath, targetUrl).href
1725
- };
1726
- }
1727
- if (!isImport || target.startsWith("../") || isValidUrl(target)) {
1728
- throw createInvalidPackageTargetError("target must starst with \"./\"", target, resolutionContext);
1729
- }
1730
- return applyPackageResolve(pattern ? target.replaceAll("*", subpath) : "".concat(target).concat(subpath), {
1731
- ...resolutionContext,
1732
- parentUrl: packageDirectoryUrl
1733
- });
1734
- }
1735
- if (Array.isArray(target)) {
1736
- if (target.length === 0) {
1737
- return null;
1738
- }
1739
- let lastResult;
1740
- let i = 0;
1741
- while (i < target.length) {
1742
- const targetValue = target[i];
1743
- i++;
1744
- try {
1745
- const resolved = applyPackageTargetResolution(targetValue, {
1746
- ...resolutionContext,
1747
- key: "".concat(key, "[").concat(i, "]"),
1748
- subpath,
1749
- pattern,
1750
- isImport
1751
- });
1752
- if (resolved) {
1753
- return resolved;
1754
- }
1755
- lastResult = resolved;
1756
- } catch (e) {
1757
- if (e.code === "INVALID_PACKAGE_TARGET") {
1758
- continue;
1759
- }
1760
- lastResult = e;
1761
- }
1762
- }
1763
- if (lastResult) {
1764
- throw lastResult;
1765
- }
1766
- return null;
1767
- }
1768
- if (target === null) {
1769
- return null;
1770
- }
1771
- if (typeof target === "object") {
1772
- const keys = Object.keys(target);
1773
- for (const key of keys) {
1774
- if (Number.isInteger(key)) {
1775
- throw new Error("Invalid package configuration");
1776
- }
1777
- if (key === "default" || conditions.includes(key)) {
1778
- const targetValue = target[key];
1779
- const resolved = applyPackageTargetResolution(targetValue, {
1780
- ...resolutionContext,
1781
- key,
1782
- subpath,
1783
- pattern,
1784
- isImport
1785
- });
1786
- if (resolved) {
1787
- return resolved;
1788
- }
1789
- }
1790
- }
1791
- return null;
1792
- }
1793
- throw createInvalidPackageTargetError("target must be a string, array, object or null", target, resolutionContext);
1794
- };
1795
- const readExports = ({
1796
- packageDirectoryUrl,
1797
- packageJson
1798
- }) => {
1799
- const packageExports = packageJson.exports;
1800
- if (Array.isArray(packageExports)) {
1801
- return {
1802
- type: "array"
1803
- };
1804
- }
1805
- if (packageExports === null) {
1806
- return {};
1807
- }
1808
- if (typeof packageExports === "object") {
1809
- const keys = Object.keys(packageExports);
1810
- const relativeKeys = [];
1811
- const conditionalKeys = [];
1812
- keys.forEach(availableKey => {
1813
- if (availableKey.startsWith(".")) {
1814
- relativeKeys.push(availableKey);
1815
- } else {
1816
- conditionalKeys.push(availableKey);
1817
- }
1818
- });
1819
- const hasRelativeKey = relativeKeys.length > 0;
1820
- if (hasRelativeKey && conditionalKeys.length > 0) {
1821
- throw new Error("Invalid package configuration: cannot mix relative and conditional keys in package.exports\n--- unexpected keys ---\n".concat(conditionalKeys.map(key => "\"".concat(key, "\"")).join("\n"), "\n--- package directory url ---\n").concat(packageDirectoryUrl));
1822
- }
1823
- return {
1824
- type: "object",
1825
- hasRelativeKey,
1826
- allKeysAreRelative: relativeKeys.length === keys.length
1827
- };
1828
- }
1829
- if (typeof packageExports === "string") {
1830
- return {
1831
- type: "string"
1832
- };
1833
- }
1834
- return {};
1835
- };
1836
- const parsePackageSpecifier = packageSpecifier => {
1837
- if (packageSpecifier[0] === "@") {
1838
- const firstSlashIndex = packageSpecifier.indexOf("/");
1839
- if (firstSlashIndex === -1) {
1840
- throw new Error("invalid module specifier");
1841
- }
1842
- const secondSlashIndex = packageSpecifier.indexOf("/", firstSlashIndex + 1);
1843
- if (secondSlashIndex === -1) {
1844
- return {
1845
- packageName: packageSpecifier,
1846
- packageSubpath: ".",
1847
- isScoped: true
1848
- };
1849
- }
1850
- const packageName = packageSpecifier.slice(0, secondSlashIndex);
1851
- const afterSecondSlash = packageSpecifier.slice(secondSlashIndex + 1);
1852
- const packageSubpath = "./".concat(afterSecondSlash);
1853
- return {
1854
- packageName,
1855
- packageSubpath,
1856
- isScoped: true
1857
- };
1858
- }
1859
- const firstSlashIndex = packageSpecifier.indexOf("/");
1860
- if (firstSlashIndex === -1) {
1861
- return {
1862
- packageName: packageSpecifier,
1863
- packageSubpath: "."
1864
- };
1865
- }
1866
- const packageName = packageSpecifier.slice(0, firstSlashIndex);
1867
- const afterFirstSlash = packageSpecifier.slice(firstSlashIndex + 1);
1868
- const packageSubpath = "./".concat(afterFirstSlash);
1869
- return {
1870
- packageName,
1871
- packageSubpath
1872
- };
1873
- };
1874
- const applyMainExportResolution = resolutionContext => {
1875
- const {
1876
- packageJson
1877
- } = resolutionContext;
1878
- const packageExportsInfo = readExports(resolutionContext);
1879
- if (packageExportsInfo.type === "array" || packageExportsInfo.type === "string") {
1880
- return packageJson.exports;
1881
- }
1882
- if (packageExportsInfo.type === "object") {
1883
- if (packageExportsInfo.hasRelativeKey) {
1884
- return packageJson.exports["."];
1885
- }
1886
- return packageJson.exports;
1887
- }
1888
- return undefined;
1889
- };
1890
- const applyLegacySubpathResolution = (packageSubpath, resolutionContext) => {
1891
- const {
1892
- packageDirectoryUrl,
1893
- packageJson
1894
- } = resolutionContext;
1895
- if (packageSubpath === ".") {
1896
- return applyLegacyMainResolution(packageSubpath, resolutionContext);
1897
- }
1898
- const browserFieldResolution = applyBrowserFieldResolution(packageSubpath, resolutionContext);
1899
- if (browserFieldResolution) {
1900
- return browserFieldResolution;
1901
- }
1902
- return {
1903
- type: "subpath",
1904
- isMain: packageSubpath === ".",
1905
- packageDirectoryUrl,
1906
- packageJson,
1907
- url: new URL(packageSubpath, packageDirectoryUrl).href
1908
- };
1909
- };
1910
- const applyLegacyMainResolution = (packageSubpath, resolutionContext) => {
1911
- const {
1912
- conditions,
1913
- packageDirectoryUrl,
1914
- packageJson
1915
- } = resolutionContext;
1916
- for (const condition of conditions) {
1917
- const conditionResolver = mainLegacyResolvers[condition];
1918
- if (!conditionResolver) {
1919
- continue;
1920
- }
1921
- const resolved = conditionResolver(resolutionContext);
1922
- if (resolved) {
1923
- return {
1924
- type: resolved.type,
1925
- isMain: resolved.isMain,
1926
- packageDirectoryUrl,
1927
- packageJson,
1928
- url: new URL(resolved.path, packageDirectoryUrl).href
1929
- };
1930
- }
1931
- }
1932
- return {
1933
- type: "field:main",
1934
- // the absence of "main" field
1935
- isMain: true,
1936
- packageDirectoryUrl,
1937
- packageJson,
1938
- url: new URL("index.js", packageDirectoryUrl).href
1939
- };
1940
- };
1941
- const mainLegacyResolvers = {
1942
- import: ({
1943
- packageJson
1944
- }) => {
1945
- if (typeof packageJson.module === "string") {
1946
- return {
1947
- type: "field:module",
1948
- isMain: true,
1949
- path: packageJson.module
1950
- };
1951
- }
1952
- if (typeof packageJson.jsnext === "string") {
1953
- return {
1954
- type: "field:jsnext",
1955
- isMain: true,
1956
- path: packageJson.jsnext
1957
- };
1958
- }
1959
- if (typeof packageJson.main === "string") {
1960
- return {
1961
- type: "field:main",
1962
- isMain: true,
1963
- path: packageJson.main
1964
- };
1965
- }
1966
- return null;
1967
- },
1968
- browser: ({
1969
- packageDirectoryUrl,
1970
- packageJson
1971
- }) => {
1972
- const browserMain = (() => {
1973
- if (typeof packageJson.browser === "string") {
1974
- return packageJson.browser;
1975
- }
1976
- if (typeof packageJson.browser === "object" && packageJson.browser !== null) {
1977
- return packageJson.browser["."];
1978
- }
1979
- return "";
1980
- })();
1981
- if (!browserMain) {
1982
- if (typeof packageJson.module === "string") {
1983
- return {
1984
- type: "field:module",
1985
- isMain: true,
1986
- path: packageJson.module
1987
- };
1988
- }
1989
- return null;
1990
- }
1991
- if (typeof packageJson.module !== "string" || packageJson.module === browserMain) {
1992
- return {
1993
- type: "field:browser",
1994
- isMain: true,
1995
- path: browserMain
1996
- };
1997
- }
1998
- const browserMainUrlObject = new URL(browserMain, packageDirectoryUrl);
1999
- const content = readFileSync(browserMainUrlObject, "utf-8");
2000
- if (/typeof exports\s*==/.test(content) && /typeof module\s*==/.test(content) || /module\.exports\s*=/.test(content)) {
2001
- return {
2002
- type: "field:module",
2003
- isMain: true,
2004
- path: packageJson.module
2005
- };
2006
- }
2007
- return {
2008
- type: "field:browser",
2009
- isMain: true,
2010
- path: browserMain
2011
- };
2012
- },
2013
- node: ({
2014
- packageJson
2015
- }) => {
2016
- if (typeof packageJson.main === "string") {
2017
- return {
2018
- type: "field:main",
2019
- isMain: true,
2020
- path: packageJson.main
2021
- };
2022
- }
2023
- return null;
2024
- }
2025
- };
2026
- const comparePatternKeys = (keyA, keyB) => {
2027
- if (!keyA.endsWith("/") && !keyA.includes("*")) {
2028
- throw new Error("Invalid package configuration");
2029
- }
2030
- if (!keyB.endsWith("/") && !keyB.includes("*")) {
2031
- throw new Error("Invalid package configuration");
2032
- }
2033
- const aStarIndex = keyA.indexOf("*");
2034
- const baseLengthA = aStarIndex > -1 ? aStarIndex + 1 : keyA.length;
2035
- const bStarIndex = keyB.indexOf("*");
2036
- const baseLengthB = bStarIndex > -1 ? bStarIndex + 1 : keyB.length;
2037
- if (baseLengthA > baseLengthB) {
2038
- return -1;
2039
- }
2040
- if (baseLengthB > baseLengthA) {
2041
- return 1;
2042
- }
2043
- if (aStarIndex === -1) {
2044
- return 1;
2045
- }
2046
- if (bStarIndex === -1) {
2047
- return -1;
2048
- }
2049
- if (keyA.length > keyB.length) {
2050
- return -1;
2051
- }
2052
- if (keyB.length > keyA.length) {
2053
- return 1;
2054
- }
2055
- return 0;
2056
- };
2057
- const resolvePackageSymlink = packageDirectoryUrl => {
2058
- const packageDirectoryPath = realpathSync(new URL(packageDirectoryUrl));
2059
- const packageDirectoryResolvedUrl = pathToFileURL(packageDirectoryPath).href;
2060
- return "".concat(packageDirectoryResolvedUrl, "/");
2061
- };
2062
-
2063
907
  /*
2064
908
  * This plugin provides a way for jsenv to supervisor js execution:
2065
909
  * - Know how many js are executed, when they are done, collect errors, etc...
@@ -2199,11 +1043,7 @@ const jsenvPluginSupervisor = ({
2199
1043
  }
2200
1044
  const {
2201
1045
  url
2202
- } = applyNodeEsmResolution({
2203
- conditions: [],
2204
- parentUrl: kitchen.context.rootDirectoryUrl,
2205
- specifier: file
2206
- });
1046
+ } = kitchen.resolve(file, kitchen.context.rootDirectoryUrl);
2207
1047
  file = url;
2208
1048
  const getErrorCauseInfo = () => {
2209
1049
  const urlInfo = kitchen.graph.getUrlInfo(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.6.10",
3
+ "version": "1.6.12",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,9 +29,9 @@
29
29
  "./src/client/supervisor.js"
30
30
  ],
31
31
  "dependencies": {
32
- "@jsenv/ast": "6.6.5",
33
- "@jsenv/urls": "2.6.3",
34
- "@jsenv/sourcemap": "1.3.2"
32
+ "@jsenv/ast": "6.6.7",
33
+ "@jsenv/urls": "2.7.1",
34
+ "@jsenv/sourcemap": "1.3.4"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "node ./scripts/build.mjs",
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { generateContentFrame } from "@jsenv/humanize";
7
- import { applyNodeEsmResolution } from "@jsenv/node-esm-resolution";
8
7
  import { getOriginalPosition } from "@jsenv/sourcemap";
9
8
  import { injectQueryParams } from "@jsenv/urls";
10
9
  import {
@@ -151,11 +150,10 @@ export const jsenvPluginSupervisor = ({
151
150
  body: "Missing file in url",
152
151
  };
153
152
  }
154
- const { url } = applyNodeEsmResolution({
155
- conditions: [],
156
- parentUrl: kitchen.context.rootDirectoryUrl,
157
- specifier: file,
158
- });
153
+ const { url } = kitchen.resolve(
154
+ file,
155
+ kitchen.context.rootDirectoryUrl,
156
+ );
159
157
  file = url;
160
158
  const getErrorCauseInfo = () => {
161
159
  const urlInfo = kitchen.graph.getUrlInfo(file);