@module-federation/third-party-dts-extractor 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @module-federation/third-party-dts-extractor
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 2add9ef: chore(third-party-dts-extractor): replace `resolve` with `exsolve` (0 transitive deps, ~100KB smaller) for the single `package.json` lookup.
8
+ - a5f123a: chore: replace `find-pkg` with `empathic` (per [e18e replacements](https://e18e.dev/docs/replacements/find-pkg.html)). Removes unused `find-pkg` dependency from `@module-federation/manifest`.
9
+ - 8ec950c: Bump runtime dependencies: echarts 6.1.0 (devtools), hono 4.12.26 and @hono/node-server 1.19.13 (treeshake-server), lodash-es 4.18.1 (rspress-plugin), handlebars 4.7.9 (create-module-federation), resolve 1.22.12 (third-party-dts-extractor).
10
+
3
11
  ## 2.6.0
4
12
 
5
13
  ## 2.5.1
package/dist/index.js CHANGED
@@ -7,11 +7,1081 @@
7
7
  });
8
8
 
9
9
  // src/ThirdPartyExtractor.ts
10
- var _findpkg = require('find-pkg'); var _findpkg2 = _interopRequireDefault(_findpkg);
10
+ var _package = require('empathic/package');
11
11
  var _promises = require('fs/promises');
12
12
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
13
13
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
14
- var _resolve = require('resolve'); var _resolve2 = _interopRequireDefault(_resolve);
14
+
15
+ // ../../node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs
16
+
17
+ var _url = require('url');
18
+
19
+ var _assert = require('assert'); var _assert2 = _interopRequireDefault(_assert);
20
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
21
+ var _v8 = require('v8'); var _v82 = _interopRequireDefault(_v8);
22
+ var _util = require('util');
23
+ var nodeBuiltins = [
24
+ "_http_agent",
25
+ "_http_client",
26
+ "_http_common",
27
+ "_http_incoming",
28
+ "_http_outgoing",
29
+ "_http_server",
30
+ "_stream_duplex",
31
+ "_stream_passthrough",
32
+ "_stream_readable",
33
+ "_stream_transform",
34
+ "_stream_wrap",
35
+ "_stream_writable",
36
+ "_tls_common",
37
+ "_tls_wrap",
38
+ "assert",
39
+ "assert/strict",
40
+ "async_hooks",
41
+ "buffer",
42
+ "child_process",
43
+ "cluster",
44
+ "console",
45
+ "constants",
46
+ "crypto",
47
+ "dgram",
48
+ "diagnostics_channel",
49
+ "dns",
50
+ "dns/promises",
51
+ "domain",
52
+ "events",
53
+ "fs",
54
+ "fs/promises",
55
+ "http",
56
+ "http2",
57
+ "https",
58
+ "inspector",
59
+ "inspector/promises",
60
+ "module",
61
+ "net",
62
+ "os",
63
+ "path",
64
+ "path/posix",
65
+ "path/win32",
66
+ "perf_hooks",
67
+ "process",
68
+ "punycode",
69
+ "querystring",
70
+ "readline",
71
+ "readline/promises",
72
+ "repl",
73
+ "stream",
74
+ "stream/consumers",
75
+ "stream/promises",
76
+ "stream/web",
77
+ "string_decoder",
78
+ "sys",
79
+ "timers",
80
+ "timers/promises",
81
+ "tls",
82
+ "trace_events",
83
+ "tty",
84
+ "url",
85
+ "util",
86
+ "util/types",
87
+ "v8",
88
+ "vm",
89
+ "wasi",
90
+ "worker_threads",
91
+ "zlib"
92
+ ];
93
+ var own$1 = {}.hasOwnProperty;
94
+ var classRegExp = /^([A-Z][a-z\d]*)+$/;
95
+ var kTypes = /* @__PURE__ */ new Set([
96
+ "string",
97
+ "function",
98
+ "number",
99
+ "object",
100
+ "Function",
101
+ "Object",
102
+ "boolean",
103
+ "bigint",
104
+ "symbol"
105
+ ]);
106
+ var messages = /* @__PURE__ */ new Map();
107
+ var nodeInternalPrefix = "__node_internal_";
108
+ var userStackTraceLimit;
109
+ function formatList(array, type = "and") {
110
+ return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array.at(-1)}`;
111
+ }
112
+ function createError(sym, value, constructor) {
113
+ messages.set(sym, value);
114
+ return makeNodeErrorWithCode(constructor, sym);
115
+ }
116
+ function makeNodeErrorWithCode(Base, key) {
117
+ return function NodeError(...parameters) {
118
+ const limit = Error.stackTraceLimit;
119
+ if (isErrorStackTraceLimitWritable())
120
+ Error.stackTraceLimit = 0;
121
+ const error = new Base();
122
+ if (isErrorStackTraceLimitWritable())
123
+ Error.stackTraceLimit = limit;
124
+ const message = getMessage(key, parameters, error);
125
+ Object.defineProperties(error, {
126
+ message: {
127
+ value: message,
128
+ enumerable: false,
129
+ writable: true,
130
+ configurable: true
131
+ },
132
+ toString: {
133
+ value() {
134
+ return `${this.name} [${key}]: ${this.message}`;
135
+ },
136
+ enumerable: false,
137
+ writable: true,
138
+ configurable: true
139
+ }
140
+ });
141
+ captureLargerStackTrace(error);
142
+ error.code = key;
143
+ return error;
144
+ };
145
+ }
146
+ function isErrorStackTraceLimitWritable() {
147
+ try {
148
+ if (_v82.default.startupSnapshot.isBuildingSnapshot())
149
+ return false;
150
+ } catch (e) {
151
+ }
152
+ const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
153
+ if (desc === void 0)
154
+ return Object.isExtensible(Error);
155
+ return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
156
+ }
157
+ function hideStackFrames(wrappedFunction) {
158
+ const hidden = nodeInternalPrefix + wrappedFunction.name;
159
+ Object.defineProperty(wrappedFunction, "name", { value: hidden });
160
+ return wrappedFunction;
161
+ }
162
+ var captureLargerStackTrace = hideStackFrames(function(error) {
163
+ const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
164
+ if (stackTraceLimitIsWritable) {
165
+ userStackTraceLimit = Error.stackTraceLimit;
166
+ Error.stackTraceLimit = Number.POSITIVE_INFINITY;
167
+ }
168
+ Error.captureStackTrace(error);
169
+ if (stackTraceLimitIsWritable)
170
+ Error.stackTraceLimit = userStackTraceLimit;
171
+ return error;
172
+ });
173
+ function getMessage(key, parameters, self) {
174
+ const message = messages.get(key);
175
+ _assert2.default.ok(message !== void 0, "expected `message` to be found");
176
+ if (typeof message === "function") {
177
+ _assert2.default.ok(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
178
+ return Reflect.apply(message, self, parameters);
179
+ }
180
+ const regex = /%[dfijoOs]/g;
181
+ let expectedLength = 0;
182
+ while (regex.exec(message) !== null)
183
+ expectedLength++;
184
+ _assert2.default.ok(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
185
+ if (parameters.length === 0)
186
+ return message;
187
+ parameters.unshift(message);
188
+ return Reflect.apply(_util.format, null, parameters);
189
+ }
190
+ function determineSpecificType(value) {
191
+ if (value === null || value === void 0)
192
+ return String(value);
193
+ if (typeof value === "function" && value.name)
194
+ return `function ${value.name}`;
195
+ if (typeof value === "object") {
196
+ if (value.constructor && value.constructor.name)
197
+ return `an instance of ${value.constructor.name}`;
198
+ return `${_util.inspect.call(void 0, value, { depth: -1 })}`;
199
+ }
200
+ let inspected = _util.inspect.call(void 0, value, { colors: false });
201
+ if (inspected.length > 28)
202
+ inspected = `${inspected.slice(0, 25)}...`;
203
+ return `type ${typeof value} (${inspected})`;
204
+ }
205
+ var ERR_INVALID_ARG_TYPE = createError("ERR_INVALID_ARG_TYPE", (name, expected, actual) => {
206
+ var _a;
207
+ _assert2.default.ok(typeof name === "string", "'name' must be a string");
208
+ if (!Array.isArray(expected))
209
+ expected = [expected];
210
+ let message = "The ";
211
+ if (name.endsWith(" argument"))
212
+ message += `${name} `;
213
+ else {
214
+ const type = name.includes(".") ? "property" : "argument";
215
+ message += `"${name}" ${type} `;
216
+ }
217
+ message += "must be ";
218
+ const types = [];
219
+ const instances = [];
220
+ const other = [];
221
+ for (const value of expected) {
222
+ _assert2.default.ok(typeof value === "string", "All expected entries have to be of type string");
223
+ if (kTypes.has(value))
224
+ types.push(value.toLowerCase());
225
+ else if (classRegExp.exec(value) === null) {
226
+ _assert2.default.ok(value !== "object", 'The value "object" should be written as "Object"');
227
+ other.push(value);
228
+ } else
229
+ instances.push(value);
230
+ }
231
+ if (instances.length > 0) {
232
+ const pos = types.indexOf("object");
233
+ if (pos !== -1) {
234
+ types.slice(pos, 1);
235
+ instances.push("Object");
236
+ }
237
+ }
238
+ if (types.length > 0) {
239
+ message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
240
+ if (instances.length > 0 || other.length > 0)
241
+ message += " or ";
242
+ }
243
+ if (instances.length > 0) {
244
+ message += `an instance of ${formatList(instances, "or")}`;
245
+ if (other.length > 0)
246
+ message += " or ";
247
+ }
248
+ if (other.length > 0)
249
+ if (other.length > 1)
250
+ message += `one of ${formatList(other, "or")}`;
251
+ else {
252
+ if (((_a = other[0]) == null ? void 0 : _a.toLowerCase()) !== other[0])
253
+ message += "an ";
254
+ message += `${other[0]}`;
255
+ }
256
+ message += `. Received ${determineSpecificType(actual)}`;
257
+ return message;
258
+ }, TypeError);
259
+ var ERR_INVALID_MODULE_SPECIFIER = createError(
260
+ "ERR_INVALID_MODULE_SPECIFIER",
261
+ /**
262
+ * @param {string} request
263
+ * @param {string} reason
264
+ * @param {string} [base]
265
+ */
266
+ (request, reason, base) => {
267
+ return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
268
+ },
269
+ TypeError
270
+ );
271
+ var ERR_INVALID_PACKAGE_CONFIG = createError("ERR_INVALID_PACKAGE_CONFIG", (path$1, base, message) => {
272
+ return `Invalid package config ${path$1}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
273
+ }, Error);
274
+ var ERR_INVALID_PACKAGE_TARGET = createError("ERR_INVALID_PACKAGE_TARGET", (packagePath, key, target, isImport = false, base) => {
275
+ const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
276
+ if (key === ".") {
277
+ _assert2.default.ok(isImport === false);
278
+ return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
279
+ }
280
+ return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(target)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? '; targets must start with "./"' : ""}`;
281
+ }, Error);
282
+ var ERR_MODULE_NOT_FOUND = createError("ERR_MODULE_NOT_FOUND", (path$1, base, exactUrl = false) => {
283
+ return `Cannot find ${exactUrl ? "module" : "package"} '${path$1}' imported from ${base}`;
284
+ }, Error);
285
+ var ERR_NETWORK_IMPORT_DISALLOWED = createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
286
+ var ERR_PACKAGE_IMPORT_NOT_DEFINED = createError("ERR_PACKAGE_IMPORT_NOT_DEFINED", (specifier, packagePath, base) => {
287
+ return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath || ""}package.json` : ""} imported from ${base}`;
288
+ }, TypeError);
289
+ var ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
290
+ "ERR_PACKAGE_PATH_NOT_EXPORTED",
291
+ /**
292
+ * @param {string} packagePath
293
+ * @param {string} subpath
294
+ * @param {string} [base]
295
+ */
296
+ (packagePath, subpath, base) => {
297
+ if (subpath === ".")
298
+ return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
299
+ return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
300
+ },
301
+ Error
302
+ );
303
+ var ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
304
+ var ERR_UNSUPPORTED_RESOLVE_REQUEST = createError("ERR_UNSUPPORTED_RESOLVE_REQUEST", 'Failed to resolve module specifier "%s" from "%s": Invalid relative URL or base scheme is not hierarchical.', TypeError);
305
+ var ERR_UNKNOWN_FILE_EXTENSION = createError("ERR_UNKNOWN_FILE_EXTENSION", (extension, path$1) => {
306
+ return `Unknown file extension "${extension}" for ${path$1}`;
307
+ }, TypeError);
308
+ var ERR_INVALID_ARG_VALUE = createError("ERR_INVALID_ARG_VALUE", (name, value, reason = "is invalid") => {
309
+ let inspected = _util.inspect.call(void 0, value);
310
+ if (inspected.length > 128)
311
+ inspected = `${inspected.slice(0, 128)}...`;
312
+ return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
313
+ }, TypeError);
314
+ var hasOwnProperty$1 = {}.hasOwnProperty;
315
+ var cache = /* @__PURE__ */ new Map();
316
+ function read(jsonPath, { base, specifier }) {
317
+ const existing = cache.get(jsonPath);
318
+ if (existing)
319
+ return existing;
320
+ let string;
321
+ try {
322
+ string = _fs2.default.readFileSync(_path2.default.toNamespacedPath(jsonPath), "utf8");
323
+ } catch (error) {
324
+ const exception = error;
325
+ if (exception.code !== "ENOENT")
326
+ throw exception;
327
+ }
328
+ const result = {
329
+ exists: false,
330
+ pjsonPath: jsonPath,
331
+ main: void 0,
332
+ name: void 0,
333
+ type: "none",
334
+ exports: void 0,
335
+ imports: void 0
336
+ };
337
+ if (string !== void 0) {
338
+ let parsed;
339
+ try {
340
+ parsed = JSON.parse(string);
341
+ } catch (error_) {
342
+ const error = new ERR_INVALID_PACKAGE_CONFIG(jsonPath, (base ? `"${specifier}" from ` : "") + _url.fileURLToPath.call(void 0, base || specifier), error_.message);
343
+ error.cause = error_;
344
+ throw error;
345
+ }
346
+ result.exists = true;
347
+ if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string")
348
+ result.name = parsed.name;
349
+ if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string")
350
+ result.main = parsed.main;
351
+ if (hasOwnProperty$1.call(parsed, "exports"))
352
+ result.exports = parsed.exports;
353
+ if (hasOwnProperty$1.call(parsed, "imports"))
354
+ result.imports = parsed.imports;
355
+ if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module"))
356
+ result.type = parsed.type;
357
+ }
358
+ cache.set(jsonPath, result);
359
+ return result;
360
+ }
361
+ function getPackageScopeConfig(resolved) {
362
+ let packageJSONUrl = new URL("package.json", resolved);
363
+ while (true) {
364
+ if (packageJSONUrl.pathname.endsWith("node_modules/package.json"))
365
+ break;
366
+ const packageConfig = read(_url.fileURLToPath.call(void 0, packageJSONUrl), { specifier: resolved });
367
+ if (packageConfig.exists)
368
+ return packageConfig;
369
+ const lastPackageJSONUrl = packageJSONUrl;
370
+ packageJSONUrl = new URL("../package.json", packageJSONUrl);
371
+ if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname)
372
+ break;
373
+ }
374
+ return {
375
+ pjsonPath: _url.fileURLToPath.call(void 0, packageJSONUrl),
376
+ exists: false,
377
+ type: "none"
378
+ };
379
+ }
380
+ var hasOwnProperty = {}.hasOwnProperty;
381
+ var extensionFormatMap = {
382
+ __proto__: null,
383
+ ".json": "json",
384
+ ".cjs": "commonjs",
385
+ ".cts": "commonjs",
386
+ ".js": "module",
387
+ ".ts": "module",
388
+ ".mts": "module",
389
+ ".mjs": "module"
390
+ };
391
+ var protocolHandlers = {
392
+ __proto__: null,
393
+ "data:": getDataProtocolModuleFormat,
394
+ "file:": getFileProtocolModuleFormat,
395
+ "node:": () => "builtin"
396
+ };
397
+ function mimeToFormat(mime) {
398
+ if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime))
399
+ return "module";
400
+ if (mime === "application/json")
401
+ return "json";
402
+ return null;
403
+ }
404
+ function getDataProtocolModuleFormat(parsed) {
405
+ const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
406
+ null,
407
+ null,
408
+ null
409
+ ];
410
+ return mimeToFormat(mime);
411
+ }
412
+ function extname(url) {
413
+ const pathname = url.pathname;
414
+ let index = pathname.length;
415
+ while (index--) {
416
+ const code = pathname.codePointAt(index);
417
+ if (code === 47)
418
+ return "";
419
+ if (code === 46)
420
+ return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
421
+ }
422
+ return "";
423
+ }
424
+ function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
425
+ const ext = extname(url);
426
+ if (ext === ".js") {
427
+ const { type: packageType } = getPackageScopeConfig(url);
428
+ if (packageType !== "none")
429
+ return packageType;
430
+ return "commonjs";
431
+ }
432
+ if (ext === "") {
433
+ const { type: packageType } = getPackageScopeConfig(url);
434
+ if (packageType === "none" || packageType === "commonjs")
435
+ return "commonjs";
436
+ return "module";
437
+ }
438
+ const format$1 = extensionFormatMap[ext];
439
+ if (format$1)
440
+ return format$1;
441
+ if (ignoreErrors)
442
+ return;
443
+ throw new ERR_UNKNOWN_FILE_EXTENSION(ext, _url.fileURLToPath.call(void 0, url));
444
+ }
445
+ function defaultGetFormatWithoutErrors(url, context) {
446
+ const protocol = url.protocol;
447
+ if (!hasOwnProperty.call(protocolHandlers, protocol))
448
+ return null;
449
+ return protocolHandlers[protocol](url, context, true) || null;
450
+ }
451
+ var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
452
+ var own = {}.hasOwnProperty;
453
+ var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
454
+ var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
455
+ var invalidPackageNameRegEx = /^\.|%|\\/;
456
+ var patternRegEx = /\*/g;
457
+ var encodedSeparatorRegEx = /%2f|%5c/i;
458
+ var emittedPackageWarnings = /* @__PURE__ */ new Set();
459
+ var doubleSlashRegEx = /[/\\]{2}/;
460
+ function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
461
+ if (_process2.default.noDeprecation)
462
+ return;
463
+ const pjsonPath = _url.fileURLToPath.call(void 0, packageJsonUrl);
464
+ const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
465
+ _process2.default.emitWarning(`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${_url.fileURLToPath.call(void 0, base)}` : ""}.`, "DeprecationWarning", "DEP0166");
466
+ }
467
+ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
468
+ if (_process2.default.noDeprecation)
469
+ return;
470
+ if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module")
471
+ return;
472
+ const urlPath = _url.fileURLToPath.call(void 0, url.href);
473
+ const packagePath = _url.fileURLToPath.call(void 0, new (0, _url.URL)(".", packageJsonUrl));
474
+ const basePath = _url.fileURLToPath.call(void 0, base);
475
+ if (!main)
476
+ _process2.default.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.
477
+ Default "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
478
+ else if (_path2.default.resolve(packagePath, main) !== urlPath)
479
+ _process2.default.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.
480
+ Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
481
+ }
482
+ function tryStatSync(path$1) {
483
+ try {
484
+ return _fs.statSync.call(void 0, path$1);
485
+ } catch (e) {
486
+ }
487
+ }
488
+ function fileExists(url) {
489
+ const stats = _fs.statSync.call(void 0, url, { throwIfNoEntry: false });
490
+ const isFile = stats ? stats.isFile() : void 0;
491
+ return isFile === null || isFile === void 0 ? false : isFile;
492
+ }
493
+ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
494
+ let guess;
495
+ if (packageConfig.main !== void 0) {
496
+ guess = new (0, _url.URL)(packageConfig.main, packageJsonUrl);
497
+ if (fileExists(guess))
498
+ return guess;
499
+ const tries$1 = [
500
+ `./${packageConfig.main}.js`,
501
+ `./${packageConfig.main}.json`,
502
+ `./${packageConfig.main}.node`,
503
+ `./${packageConfig.main}/index.js`,
504
+ `./${packageConfig.main}/index.json`,
505
+ `./${packageConfig.main}/index.node`
506
+ ];
507
+ let i$1 = -1;
508
+ while (++i$1 < tries$1.length) {
509
+ guess = new (0, _url.URL)(tries$1[i$1], packageJsonUrl);
510
+ if (fileExists(guess))
511
+ break;
512
+ guess = void 0;
513
+ }
514
+ if (guess) {
515
+ emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
516
+ return guess;
517
+ }
518
+ }
519
+ const tries = [
520
+ "./index.js",
521
+ "./index.json",
522
+ "./index.node"
523
+ ];
524
+ let i = -1;
525
+ while (++i < tries.length) {
526
+ guess = new (0, _url.URL)(tries[i], packageJsonUrl);
527
+ if (fileExists(guess))
528
+ break;
529
+ guess = void 0;
530
+ }
531
+ if (guess) {
532
+ emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
533
+ return guess;
534
+ }
535
+ throw new ERR_MODULE_NOT_FOUND(_url.fileURLToPath.call(void 0, new (0, _url.URL)(".", packageJsonUrl)), _url.fileURLToPath.call(void 0, base));
536
+ }
537
+ function finalizeResolution(resolved, base, preserveSymlinks) {
538
+ if (encodedSeparatorRegEx.exec(resolved.pathname) !== null)
539
+ throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, String.raw`must not include encoded "/" or "\" characters`, _url.fileURLToPath.call(void 0, base));
540
+ let filePath;
541
+ try {
542
+ filePath = _url.fileURLToPath.call(void 0, resolved);
543
+ } catch (error) {
544
+ Object.defineProperty(error, "input", { value: String(resolved) });
545
+ Object.defineProperty(error, "module", { value: String(base) });
546
+ throw error;
547
+ }
548
+ const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
549
+ if (stats && stats.isDirectory()) {
550
+ const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, _url.fileURLToPath.call(void 0, base));
551
+ error.url = String(resolved);
552
+ throw error;
553
+ }
554
+ if (!stats || !stats.isFile()) {
555
+ const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && _url.fileURLToPath.call(void 0, base), true);
556
+ error.url = String(resolved);
557
+ throw error;
558
+ }
559
+ if (!preserveSymlinks) {
560
+ const real = _fs.realpathSync.call(void 0, filePath);
561
+ const { search, hash } = resolved;
562
+ resolved = _url.pathToFileURL.call(void 0, real + (filePath.endsWith(_path2.default.sep) ? "/" : ""));
563
+ resolved.search = search;
564
+ resolved.hash = hash;
565
+ }
566
+ return resolved;
567
+ }
568
+ function importNotDefined(specifier, packageJsonUrl, base) {
569
+ return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && _url.fileURLToPath.call(void 0, new (0, _url.URL)(".", packageJsonUrl)), _url.fileURLToPath.call(void 0, base));
570
+ }
571
+ function exportsNotFound(subpath, packageJsonUrl, base) {
572
+ return new ERR_PACKAGE_PATH_NOT_EXPORTED(_url.fileURLToPath.call(void 0, new (0, _url.URL)(".", packageJsonUrl)), subpath, base && _url.fileURLToPath.call(void 0, base));
573
+ }
574
+ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
575
+ throw new ERR_INVALID_MODULE_SPECIFIER(request, `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${_url.fileURLToPath.call(void 0, packageJsonUrl)}`, base && _url.fileURLToPath.call(void 0, base));
576
+ }
577
+ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
578
+ target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
579
+ return new ERR_INVALID_PACKAGE_TARGET(_url.fileURLToPath.call(void 0, new (0, _url.URL)(".", packageJsonUrl)), subpath, target, internal, base && _url.fileURLToPath.call(void 0, base));
580
+ }
581
+ function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
582
+ if (subpath !== "" && !pattern && target.at(-1) !== "/")
583
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
584
+ if (!target.startsWith("./")) {
585
+ if (internal && !target.startsWith("../") && !target.startsWith("/")) {
586
+ let isURL = false;
587
+ try {
588
+ new (0, _url.URL)(target);
589
+ isURL = true;
590
+ } catch (e) {
591
+ }
592
+ if (!isURL)
593
+ return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
594
+ }
595
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
596
+ }
597
+ if (invalidSegmentRegEx.exec(target.slice(2)) !== null)
598
+ if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
599
+ if (!isPathMap) {
600
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
601
+ emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
602
+ }
603
+ } else
604
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
605
+ const resolved = new (0, _url.URL)(target, packageJsonUrl);
606
+ const resolvedPath = resolved.pathname;
607
+ const packagePath = new (0, _url.URL)(".", packageJsonUrl).pathname;
608
+ if (!resolvedPath.startsWith(packagePath))
609
+ throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
610
+ if (subpath === "")
611
+ return resolved;
612
+ if (invalidSegmentRegEx.exec(subpath) !== null) {
613
+ const request = pattern ? match.replace("*", () => subpath) : match + subpath;
614
+ if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
615
+ if (!isPathMap)
616
+ emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
617
+ } else
618
+ throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
619
+ }
620
+ if (pattern)
621
+ return new (0, _url.URL)(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
622
+ return new (0, _url.URL)(subpath, resolved);
623
+ }
624
+ function isArrayIndex(key) {
625
+ const keyNumber = Number(key);
626
+ if (`${keyNumber}` !== key)
627
+ return false;
628
+ return keyNumber >= 0 && keyNumber < 4294967295;
629
+ }
630
+ function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
631
+ if (typeof target === "string")
632
+ return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
633
+ if (Array.isArray(target)) {
634
+ const targetList = target;
635
+ if (targetList.length === 0)
636
+ return null;
637
+ let lastException;
638
+ let i = -1;
639
+ while (++i < targetList.length) {
640
+ const targetItem = targetList[i];
641
+ let resolveResult;
642
+ try {
643
+ resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
644
+ } catch (error) {
645
+ const exception = error;
646
+ lastException = exception;
647
+ if (exception.code === "ERR_INVALID_PACKAGE_TARGET")
648
+ continue;
649
+ throw error;
650
+ }
651
+ if (resolveResult === void 0)
652
+ continue;
653
+ if (resolveResult === null) {
654
+ lastException = null;
655
+ continue;
656
+ }
657
+ return resolveResult;
658
+ }
659
+ if (lastException === void 0 || lastException === null)
660
+ return null;
661
+ throw lastException;
662
+ }
663
+ if (typeof target === "object" && target !== null) {
664
+ const keys = Object.getOwnPropertyNames(target);
665
+ let i = -1;
666
+ while (++i < keys.length) {
667
+ const key = keys[i];
668
+ if (isArrayIndex(key))
669
+ throw new ERR_INVALID_PACKAGE_CONFIG(_url.fileURLToPath.call(void 0, packageJsonUrl), _url.fileURLToPath.call(void 0, base), '"exports" cannot contain numeric property keys.');
670
+ }
671
+ i = -1;
672
+ while (++i < keys.length) {
673
+ const key = keys[i];
674
+ if (key === "default" || conditions && conditions.has(key)) {
675
+ const conditionalTarget = target[key];
676
+ const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
677
+ if (resolveResult === void 0)
678
+ continue;
679
+ return resolveResult;
680
+ }
681
+ }
682
+ return null;
683
+ }
684
+ if (target === null)
685
+ return null;
686
+ throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
687
+ }
688
+ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
689
+ if (typeof exports === "string" || Array.isArray(exports))
690
+ return true;
691
+ if (typeof exports !== "object" || exports === null)
692
+ return false;
693
+ const keys = Object.getOwnPropertyNames(exports);
694
+ let isConditionalSugar = false;
695
+ let i = 0;
696
+ let keyIndex = -1;
697
+ while (++keyIndex < keys.length) {
698
+ const key = keys[keyIndex];
699
+ const currentIsConditionalSugar = key === "" || key[0] !== ".";
700
+ if (i++ === 0)
701
+ isConditionalSugar = currentIsConditionalSugar;
702
+ else if (isConditionalSugar !== currentIsConditionalSugar)
703
+ throw new ERR_INVALID_PACKAGE_CONFIG(_url.fileURLToPath.call(void 0, packageJsonUrl), _url.fileURLToPath.call(void 0, base), `"exports" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.`);
704
+ }
705
+ return isConditionalSugar;
706
+ }
707
+ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
708
+ if (_process2.default.noDeprecation)
709
+ return;
710
+ const pjsonPath = _url.fileURLToPath.call(void 0, pjsonUrl);
711
+ if (emittedPackageWarnings.has(pjsonPath + "|" + match))
712
+ return;
713
+ emittedPackageWarnings.add(pjsonPath + "|" + match);
714
+ _process2.default.emitWarning(`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${_url.fileURLToPath.call(void 0, base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`, "DeprecationWarning", "DEP0155");
715
+ }
716
+ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
717
+ let exports = packageConfig.exports;
718
+ if (isConditionalExportsMainSugar(exports, packageJsonUrl, base))
719
+ exports = { ".": exports };
720
+ if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
721
+ const target = exports[packageSubpath];
722
+ const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
723
+ if (resolveResult === null || resolveResult === void 0)
724
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
725
+ return resolveResult;
726
+ }
727
+ let bestMatch = "";
728
+ let bestMatchSubpath = "";
729
+ const keys = Object.getOwnPropertyNames(exports);
730
+ let i = -1;
731
+ while (++i < keys.length) {
732
+ const key = keys[i];
733
+ const patternIndex = key.indexOf("*");
734
+ if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
735
+ if (packageSubpath.endsWith("/"))
736
+ emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
737
+ const patternTrailer = key.slice(patternIndex + 1);
738
+ if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
739
+ bestMatch = key;
740
+ bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
741
+ }
742
+ }
743
+ }
744
+ if (bestMatch) {
745
+ const target = exports[bestMatch];
746
+ const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
747
+ if (resolveResult === null || resolveResult === void 0)
748
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
749
+ return resolveResult;
750
+ }
751
+ throw exportsNotFound(packageSubpath, packageJsonUrl, base);
752
+ }
753
+ function patternKeyCompare(a, b) {
754
+ const aPatternIndex = a.indexOf("*");
755
+ const bPatternIndex = b.indexOf("*");
756
+ const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
757
+ const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
758
+ if (baseLengthA > baseLengthB)
759
+ return -1;
760
+ if (baseLengthB > baseLengthA)
761
+ return 1;
762
+ if (aPatternIndex === -1)
763
+ return 1;
764
+ if (bPatternIndex === -1)
765
+ return -1;
766
+ if (a.length > b.length)
767
+ return -1;
768
+ if (b.length > a.length)
769
+ return 1;
770
+ return 0;
771
+ }
772
+ function packageImportsResolve(name, base, conditions) {
773
+ if (name === "#" || name.startsWith("#/") || name.endsWith("/"))
774
+ throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", _url.fileURLToPath.call(void 0, base));
775
+ let packageJsonUrl;
776
+ const packageConfig = getPackageScopeConfig(base);
777
+ if (packageConfig.exists) {
778
+ packageJsonUrl = _url.pathToFileURL.call(void 0, packageConfig.pjsonPath);
779
+ const imports = packageConfig.imports;
780
+ if (imports)
781
+ if (own.call(imports, name) && !name.includes("*")) {
782
+ const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
783
+ if (resolveResult !== null && resolveResult !== void 0)
784
+ return resolveResult;
785
+ } else {
786
+ let bestMatch = "";
787
+ let bestMatchSubpath = "";
788
+ const keys = Object.getOwnPropertyNames(imports);
789
+ let i = -1;
790
+ while (++i < keys.length) {
791
+ const key = keys[i];
792
+ const patternIndex = key.indexOf("*");
793
+ if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
794
+ const patternTrailer = key.slice(patternIndex + 1);
795
+ if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
796
+ bestMatch = key;
797
+ bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
798
+ }
799
+ }
800
+ }
801
+ if (bestMatch) {
802
+ const target = imports[bestMatch];
803
+ const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
804
+ if (resolveResult !== null && resolveResult !== void 0)
805
+ return resolveResult;
806
+ }
807
+ }
808
+ }
809
+ throw importNotDefined(name, packageJsonUrl, base);
810
+ }
811
+ function parsePackageName(specifier, base) {
812
+ let separatorIndex = specifier.indexOf("/");
813
+ let validPackageName = true;
814
+ let isScoped = false;
815
+ if (specifier[0] === "@") {
816
+ isScoped = true;
817
+ if (separatorIndex === -1 || specifier.length === 0)
818
+ validPackageName = false;
819
+ else
820
+ separatorIndex = specifier.indexOf("/", separatorIndex + 1);
821
+ }
822
+ const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
823
+ if (invalidPackageNameRegEx.exec(packageName) !== null)
824
+ validPackageName = false;
825
+ if (!validPackageName)
826
+ throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", _url.fileURLToPath.call(void 0, base));
827
+ return {
828
+ packageName,
829
+ packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
830
+ isScoped
831
+ };
832
+ }
833
+ function packageResolve(specifier, base, conditions) {
834
+ if (nodeBuiltins.includes(specifier))
835
+ return new (0, _url.URL)("node:" + specifier);
836
+ const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
837
+ const packageConfig = getPackageScopeConfig(base);
838
+ if (packageConfig.exists && packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null)
839
+ return packageExportsResolve(_url.pathToFileURL.call(void 0, packageConfig.pjsonPath), packageSubpath, packageConfig, base, conditions);
840
+ let packageJsonUrl = new (0, _url.URL)("./node_modules/" + packageName + "/package.json", base);
841
+ let packageJsonPath = _url.fileURLToPath.call(void 0, packageJsonUrl);
842
+ let lastPath;
843
+ do {
844
+ const stat = tryStatSync(packageJsonPath.slice(0, -13));
845
+ if (!stat || !stat.isDirectory()) {
846
+ lastPath = packageJsonPath;
847
+ packageJsonUrl = new (0, _url.URL)((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
848
+ packageJsonPath = _url.fileURLToPath.call(void 0, packageJsonUrl);
849
+ continue;
850
+ }
851
+ const packageConfig$1 = read(packageJsonPath, {
852
+ base,
853
+ specifier
854
+ });
855
+ if (packageConfig$1.exports !== void 0 && packageConfig$1.exports !== null)
856
+ return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig$1, base, conditions);
857
+ if (packageSubpath === ".")
858
+ return legacyMainResolve(packageJsonUrl, packageConfig$1, base);
859
+ return new (0, _url.URL)(packageSubpath, packageJsonUrl);
860
+ } while (packageJsonPath.length !== lastPath.length);
861
+ throw new ERR_MODULE_NOT_FOUND(packageName, _url.fileURLToPath.call(void 0, base), false);
862
+ }
863
+ function isRelativeSpecifier(specifier) {
864
+ if (specifier[0] === ".") {
865
+ if (specifier.length === 1 || specifier[1] === "/")
866
+ return true;
867
+ if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/"))
868
+ return true;
869
+ }
870
+ return false;
871
+ }
872
+ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
873
+ if (specifier === "")
874
+ return false;
875
+ if (specifier[0] === "/")
876
+ return true;
877
+ return isRelativeSpecifier(specifier);
878
+ }
879
+ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
880
+ const protocol = base.protocol;
881
+ const isData = protocol === "data:";
882
+ let resolved;
883
+ if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier))
884
+ try {
885
+ resolved = new (0, _url.URL)(specifier, base);
886
+ } catch (error_) {
887
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
888
+ error.cause = error_;
889
+ throw error;
890
+ }
891
+ else if (protocol === "file:" && specifier[0] === "#")
892
+ resolved = packageImportsResolve(specifier, base, conditions);
893
+ else
894
+ try {
895
+ resolved = new (0, _url.URL)(specifier);
896
+ } catch (error_) {
897
+ if (isData && !nodeBuiltins.includes(specifier)) {
898
+ const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
899
+ error.cause = error_;
900
+ throw error;
901
+ }
902
+ resolved = packageResolve(specifier, base, conditions);
903
+ }
904
+ _assert2.default.ok(resolved !== void 0, "expected to be defined");
905
+ if (resolved.protocol !== "file:")
906
+ return resolved;
907
+ return finalizeResolution(resolved, base, preserveSymlinks);
908
+ }
909
+ var DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
910
+ var isWindows = /* @__PURE__ */ (() => process.platform === "win32")();
911
+ var globalCache = /* @__PURE__ */ (() => globalThis["__EXSOLVE_CACHE__"] || (globalThis["__EXSOLVE_CACHE__"] = /* @__PURE__ */ new Map()))();
912
+ function resolveModuleURL(input, options) {
913
+ const parsedInput = _parseInput(input);
914
+ if ("external" in parsedInput)
915
+ return parsedInput.external;
916
+ const specifier = parsedInput.specifier;
917
+ let url = parsedInput.url;
918
+ let absolutePath = parsedInput.absolutePath;
919
+ let cacheKey;
920
+ let cacheObj;
921
+ if ((options == null ? void 0 : options.cache) !== false) {
922
+ cacheKey = _cacheKey(absolutePath || specifier, options);
923
+ cacheObj = (options == null ? void 0 : options.cache) && typeof (options == null ? void 0 : options.cache) === "object" ? options.cache : globalCache;
924
+ }
925
+ if (cacheObj) {
926
+ const cached = cacheObj.get(cacheKey);
927
+ if (typeof cached === "string")
928
+ return cached;
929
+ if (cached instanceof Error) {
930
+ if (options == null ? void 0 : options.try)
931
+ return;
932
+ throw cached;
933
+ }
934
+ }
935
+ if (absolutePath)
936
+ try {
937
+ const stat = _fs.lstatSync.call(void 0, absolutePath);
938
+ if (stat.isSymbolicLink()) {
939
+ absolutePath = _fs.realpathSync.call(void 0, absolutePath);
940
+ url = _url.pathToFileURL.call(void 0, absolutePath);
941
+ }
942
+ if (stat.isFile()) {
943
+ if (cacheObj)
944
+ cacheObj.set(cacheKey, url.href);
945
+ return url.href;
946
+ }
947
+ } catch (error) {
948
+ if ((error == null ? void 0 : error.code) !== "ENOENT") {
949
+ if (cacheObj)
950
+ cacheObj.set(cacheKey, error);
951
+ throw error;
952
+ }
953
+ }
954
+ const conditionsSet = (options == null ? void 0 : options.conditions) ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
955
+ const target = specifier || url.href;
956
+ const bases = _normalizeBases(options == null ? void 0 : options.from);
957
+ const suffixes = (options == null ? void 0 : options.suffixes) || [""];
958
+ const extensions = (options == null ? void 0 : options.extensions) ? ["", ...options.extensions] : [""];
959
+ let resolved;
960
+ for (const base of bases) {
961
+ for (const suffix of suffixes) {
962
+ let name = _join(target, suffix);
963
+ if (name === ".")
964
+ name += "/.";
965
+ for (const extension of extensions) {
966
+ resolved = _tryModuleResolve(name + extension, base, conditionsSet);
967
+ if (resolved)
968
+ break;
969
+ }
970
+ if (resolved)
971
+ break;
972
+ }
973
+ if (resolved)
974
+ break;
975
+ }
976
+ if (!resolved) {
977
+ const error = /* @__PURE__ */ new Error(`Cannot resolve module "${input}" (from: ${bases.map((u) => _fmtPath(u)).join(", ")})`);
978
+ error.code = "ERR_MODULE_NOT_FOUND";
979
+ if (cacheObj)
980
+ cacheObj.set(cacheKey, error);
981
+ if (options == null ? void 0 : options.try)
982
+ return;
983
+ throw error;
984
+ }
985
+ if (cacheObj)
986
+ cacheObj.set(cacheKey, resolved.href);
987
+ return resolved.href;
988
+ }
989
+ function resolveModulePath(id, options) {
990
+ const resolved = resolveModuleURL(id, options);
991
+ if (!resolved)
992
+ return;
993
+ if (!resolved.startsWith("file://") && (options == null ? void 0 : options.try))
994
+ return;
995
+ const absolutePath = _url.fileURLToPath.call(void 0, resolved);
996
+ return isWindows ? _normalizeWinPath(absolutePath) : absolutePath;
997
+ }
998
+ function _tryModuleResolve(specifier, base, conditions) {
999
+ try {
1000
+ return moduleResolve(specifier, base, conditions);
1001
+ } catch (e) {
1002
+ }
1003
+ }
1004
+ function _normalizeBases(inputs) {
1005
+ const urls = (Array.isArray(inputs) ? inputs : [inputs]).flatMap((input) => _normalizeBase(input));
1006
+ if (urls.length === 0)
1007
+ return [_url.pathToFileURL.call(void 0, "./")];
1008
+ return urls;
1009
+ }
1010
+ function _normalizeBase(input) {
1011
+ if (!input)
1012
+ return [];
1013
+ if (_isURL(input))
1014
+ return [input];
1015
+ if (typeof input !== "string")
1016
+ return [];
1017
+ if (/^(?:node|data|http|https|file):/.test(input))
1018
+ return new URL(input);
1019
+ try {
1020
+ if (input.endsWith("/") || _fs.statSync.call(void 0, input).isDirectory())
1021
+ return _url.pathToFileURL.call(void 0, input + "/");
1022
+ return _url.pathToFileURL.call(void 0, input);
1023
+ } catch (e) {
1024
+ return [_url.pathToFileURL.call(void 0, input + "/"), _url.pathToFileURL.call(void 0, input)];
1025
+ }
1026
+ }
1027
+ function _fmtPath(input) {
1028
+ try {
1029
+ return _url.fileURLToPath.call(void 0, input);
1030
+ } catch (e) {
1031
+ return input;
1032
+ }
1033
+ }
1034
+ function _cacheKey(id, opts) {
1035
+ return JSON.stringify([
1036
+ id,
1037
+ ((opts == null ? void 0 : opts.conditions) || ["node", "import"]).sort(),
1038
+ opts == null ? void 0 : opts.extensions,
1039
+ opts == null ? void 0 : opts.from,
1040
+ opts == null ? void 0 : opts.suffixes
1041
+ ]);
1042
+ }
1043
+ function _join(a, b) {
1044
+ if (!a || !b || b === "/")
1045
+ return a;
1046
+ return (a.endsWith("/") ? a : a + "/") + (b.startsWith("/") ? b.slice(1) : b);
1047
+ }
1048
+ function _normalizeWinPath(path$1) {
1049
+ return path$1.replace(/\\/g, "/").replace(/^[a-z]:\//, (r) => r.toUpperCase());
1050
+ }
1051
+ function _isURL(input) {
1052
+ var _a;
1053
+ return input instanceof URL || ((_a = input == null ? void 0 : input.constructor) == null ? void 0 : _a.name) === "URL";
1054
+ }
1055
+ function _parseInput(input) {
1056
+ if (typeof input === "string") {
1057
+ if (input.startsWith("file:")) {
1058
+ const url = new URL(input);
1059
+ return {
1060
+ url,
1061
+ absolutePath: _url.fileURLToPath.call(void 0, url)
1062
+ };
1063
+ }
1064
+ if (_path.isAbsolute.call(void 0, input))
1065
+ return {
1066
+ url: _url.pathToFileURL.call(void 0, input),
1067
+ absolutePath: input
1068
+ };
1069
+ if (/^(?:node|data|http|https):/.test(input))
1070
+ return { external: input };
1071
+ if (nodeBuiltins.includes(input) && !input.includes(":"))
1072
+ return { external: `node:${input}` };
1073
+ return { specifier: input };
1074
+ }
1075
+ if (_isURL(input)) {
1076
+ if (input.protocol === "file:")
1077
+ return {
1078
+ url: input,
1079
+ absolutePath: _url.fileURLToPath.call(void 0, input)
1080
+ };
1081
+ return { external: input.href };
1082
+ }
1083
+ throw new TypeError("id must be a `string` or `URL`");
1084
+ }
15
1085
 
16
1086
  // src/utils.ts
17
1087
 
@@ -130,11 +1200,13 @@ var ThirdPartyExtractor = class {
130
1200
  return dir;
131
1201
  } else {
132
1202
  const typedPkgName = getTypedName(pkg.name);
133
- const typedPkgJsonPath = _findpkg2.default.sync(
134
- _resolve2.default.sync(`${typedPkgName}/package.json`, {
135
- basedir: this.context
136
- })
137
- );
1203
+ const typedPkgJsonPath = _package.up.call(void 0, {
1204
+ cwd: _path2.default.dirname(
1205
+ resolveModulePath(`${typedPkgName}/package.json`, {
1206
+ from: this.context
1207
+ })
1208
+ )
1209
+ });
138
1210
  const typedDir = _path2.default.dirname(typedPkgJsonPath);
139
1211
  _fs.readFileSync.call(void 0, typedPkgJsonPath, "utf-8");
140
1212
  this.addPkgs(typedPkgName, typedDir);
package/dist/index.mjs CHANGED
@@ -7,11 +7,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
7
7
  });
8
8
 
9
9
  // src/ThirdPartyExtractor.ts
10
- import findPkg from "find-pkg";
10
+ import { up as findPkgUp } from "empathic/package";
11
11
  import { copyFile, lstat, mkdir, readdir } from "fs/promises";
12
12
  import { existsSync, readFileSync } from "fs";
13
13
  import path2 from "path";
14
- import resolve from "resolve";
14
+ import { resolveModulePath } from "exsolve";
15
15
 
16
16
  // src/utils.ts
17
17
  import path from "path";
@@ -130,11 +130,13 @@ var ThirdPartyExtractor = class {
130
130
  return dir;
131
131
  } else {
132
132
  const typedPkgName = getTypedName(pkg.name);
133
- const typedPkgJsonPath = findPkg.sync(
134
- resolve.sync(`${typedPkgName}/package.json`, {
135
- basedir: this.context
136
- })
137
- );
133
+ const typedPkgJsonPath = findPkgUp({
134
+ cwd: path2.dirname(
135
+ resolveModulePath(`${typedPkgName}/package.json`, {
136
+ from: this.context
137
+ })
138
+ )
139
+ });
138
140
  const typedDir = path2.dirname(typedPkgJsonPath);
139
141
  readFileSync(typedPkgJsonPath, "utf-8");
140
142
  this.addPkgs(typedPkgName, typedDir);
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"
@@ -32,20 +32,20 @@
32
32
  "author": "hanric <hanric.zhang@gmail.com>",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "find-pkg": "2.0.0",
36
- "resolve": "1.22.8"
35
+ "empathic": "2.0.0",
36
+ "exsolve": "1.0.8"
37
37
  },
38
38
  "devDependencies": {
39
+ "@rstest/core": "^0.10.6",
39
40
  "@types/node": "^20.19.5",
40
41
  "@types/react": "^18.3.11",
41
- "vitest": "1.6.0",
42
42
  "react": "^18",
43
43
  "tsup": "7.3.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
47
47
  "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
48
- "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
48
+ "test": "pnpm exec rstest --passWithNoTests",
49
49
  "pre-release": "pnpm run test && pnpm run build"
50
50
  }
51
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/third-party-dts-extractor",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "files": [
5
5
  "dist/",
6
6
  "README.md"
@@ -32,20 +32,20 @@
32
32
  "author": "hanric <hanric.zhang@gmail.com>",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "find-pkg": "2.0.0",
36
- "resolve": "1.22.8"
35
+ "empathic": "2.0.0",
36
+ "exsolve": "1.0.8"
37
37
  },
38
38
  "devDependencies": {
39
+ "@rstest/core": "^0.10.6",
39
40
  "@types/node": "^20.19.5",
40
41
  "@types/react": "^18.3.11",
41
- "vitest": "1.6.0",
42
42
  "react": "^18",
43
43
  "tsup": "7.3.0"
44
44
  },
45
45
  "scripts": {
46
46
  "build": "tsup --config tsup.config.ts --outDir dist && cp package.json dist && cp *.md dist",
47
47
  "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\"",
48
- "test": "pnpm exec vitest run --passWithNoTests --config vite.config.mts",
48
+ "test": "pnpm exec rstest --passWithNoTests",
49
49
  "pre-release": "pnpm run test && pnpm run build"
50
50
  }
51
51
  }