ts-swc-transform 2.7.10 → 2.8.1
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/cjs/compat.d.cts +1 -0
- package/dist/cjs/compat.d.ts +1 -0
- package/dist/cjs/compat.js +17 -0
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/lib/resolve-with-exports.d.cts +16 -0
- package/dist/cjs/lib/resolve-with-exports.d.ts +16 -0
- package/dist/cjs/lib/resolve-with-exports.js +157 -0
- package/dist/cjs/lib/resolve-with-exports.js.map +1 -0
- package/dist/cjs/resolveFileSync.js +3 -3
- package/dist/cjs/resolveFileSync.js.map +1 -1
- package/dist/cjs/toPath.js +5 -6
- package/dist/cjs/toPath.js.map +1 -1
- package/dist/esm/compat.d.ts +1 -0
- package/dist/esm/compat.js +14 -0
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/lib/resolve-with-exports.d.ts +16 -0
- package/dist/esm/lib/resolve-with-exports.js +140 -0
- package/dist/esm/lib/resolve-with-exports.js.map +1 -0
- package/dist/esm/resolveFileSync.js +3 -3
- package/dist/esm/resolveFileSync.js.map +1 -1
- package/dist/esm/toPath.js +3 -4
- package/dist/esm/toPath.js.map +1 -1
- package/package.json +19 -19
- package/assets/import-meta-resolve.cjs +0 -1481
- package/dist/cjs/lib/import-meta-resolve.d.cts +0 -1
- package/dist/cjs/lib/import-meta-resolve.d.ts +0 -1
- package/dist/cjs/lib/import-meta-resolve.js +0 -22
- package/dist/cjs/lib/import-meta-resolve.js.map +0 -1
- package/dist/esm/lib/import-meta-resolve.d.ts +0 -1
- package/dist/esm/lib/import-meta-resolve.js +0 -6
- package/dist/esm/lib/import-meta-resolve.js.map +0 -1
|
@@ -1,1481 +0,0 @@
|
|
|
1
|
-
// bail early
|
|
2
|
-
var useCJS = !require('module').createRequire;
|
|
3
|
-
if (useCJS) {
|
|
4
|
-
module.exports.moduleResolve = function () { return null };
|
|
5
|
-
module.exports.resolve = function () { return null };
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var assert = require('assert');
|
|
11
|
-
var fs = require('fs');
|
|
12
|
-
var process = require('process');
|
|
13
|
-
var url = require('url');
|
|
14
|
-
var path = require('path');
|
|
15
|
-
var module$1 = require('module');
|
|
16
|
-
var v8 = require('v8');
|
|
17
|
-
var util = require('util');
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @typedef ErrnoExceptionFields
|
|
21
|
-
* @property {number | undefined} [errnode]
|
|
22
|
-
* @property {string | undefined} [code]
|
|
23
|
-
* @property {string | undefined} [path]
|
|
24
|
-
* @property {string | undefined} [syscall]
|
|
25
|
-
* @property {string | undefined} [url]
|
|
26
|
-
*
|
|
27
|
-
* @typedef {Error & ErrnoExceptionFields} ErrnoException
|
|
28
|
-
*/ /**
|
|
29
|
-
* @typedef {(...parameters: Array<any>) => string} MessageFunction
|
|
30
|
-
*/ // Manually “tree shaken” from:
|
|
31
|
-
// <https://github.com/nodejs/node/blob/45f5c9b/lib/internal/errors.js>
|
|
32
|
-
// Last checked on: Nov 2, 2023.
|
|
33
|
-
function _type_of$1(obj) {
|
|
34
|
-
"@swc/helpers - typeof";
|
|
35
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
36
|
-
}
|
|
37
|
-
var own$1 = {}.hasOwnProperty;
|
|
38
|
-
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
39
|
-
// Sorted by a rough estimate on most frequently used entries.
|
|
40
|
-
var kTypes = new Set([
|
|
41
|
-
'string',
|
|
42
|
-
'function',
|
|
43
|
-
'number',
|
|
44
|
-
'object',
|
|
45
|
-
// Accept 'Function' and 'Object' as alternative to the lower cased version.
|
|
46
|
-
'Function',
|
|
47
|
-
'Object',
|
|
48
|
-
'boolean',
|
|
49
|
-
'bigint',
|
|
50
|
-
'symbol'
|
|
51
|
-
]);
|
|
52
|
-
var codes = {};
|
|
53
|
-
/**
|
|
54
|
-
* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
|
|
55
|
-
* We cannot use Intl.ListFormat because it's not available in
|
|
56
|
-
* --without-intl builds.
|
|
57
|
-
*
|
|
58
|
-
* @param {Array<string>} array
|
|
59
|
-
* An array of strings.
|
|
60
|
-
* @param {string} [type]
|
|
61
|
-
* The list type to be inserted before the last element.
|
|
62
|
-
* @returns {string}
|
|
63
|
-
*/ function formatList(array) {
|
|
64
|
-
var type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 'and';
|
|
65
|
-
return array.length < 3 ? array.join(" ".concat(type, " ")) : "".concat(array.slice(0, -1).join(', '), ", ").concat(type, " ").concat(array[array.length - 1]);
|
|
66
|
-
}
|
|
67
|
-
/** @type {Map<string, MessageFunction | string>} */ var messages = new Map();
|
|
68
|
-
var nodeInternalPrefix = '__node_internal_';
|
|
69
|
-
/** @type {number} */ var userStackTraceLimit;
|
|
70
|
-
codes.ERR_INVALID_ARG_TYPE = createError('ERR_INVALID_ARG_TYPE', /**
|
|
71
|
-
* @param {string} name
|
|
72
|
-
* @param {Array<string> | string} expected
|
|
73
|
-
* @param {unknown} actual
|
|
74
|
-
*/ function(name, expected, actual) {
|
|
75
|
-
assert(typeof name === 'string', "'name' must be a string");
|
|
76
|
-
if (!Array.isArray(expected)) {
|
|
77
|
-
expected = [
|
|
78
|
-
expected
|
|
79
|
-
];
|
|
80
|
-
}
|
|
81
|
-
var message = 'The ';
|
|
82
|
-
if (name.endsWith(' argument')) {
|
|
83
|
-
// For cases like 'first argument'
|
|
84
|
-
message += "".concat(name, " ");
|
|
85
|
-
} else {
|
|
86
|
-
var type = name.includes('.') ? 'property' : 'argument';
|
|
87
|
-
message += '"'.concat(name, '" ').concat(type, " ");
|
|
88
|
-
}
|
|
89
|
-
message += 'must be ';
|
|
90
|
-
/** @type {Array<string>} */ var types = [];
|
|
91
|
-
/** @type {Array<string>} */ var instances = [];
|
|
92
|
-
/** @type {Array<string>} */ var other = [];
|
|
93
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
94
|
-
try {
|
|
95
|
-
for(var _iterator = expected[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
96
|
-
var value = _step.value;
|
|
97
|
-
assert(typeof value === 'string', 'All expected entries have to be of type string');
|
|
98
|
-
if (kTypes.has(value)) {
|
|
99
|
-
types.push(value.toLowerCase());
|
|
100
|
-
} else if (classRegExp.exec(value) === null) {
|
|
101
|
-
assert(value !== 'object', 'The value "object" should be written as "Object"');
|
|
102
|
-
other.push(value);
|
|
103
|
-
} else {
|
|
104
|
-
instances.push(value);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
} catch (err) {
|
|
108
|
-
_didIteratorError = true;
|
|
109
|
-
_iteratorError = err;
|
|
110
|
-
} finally{
|
|
111
|
-
try {
|
|
112
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
113
|
-
_iterator.return();
|
|
114
|
-
}
|
|
115
|
-
} finally{
|
|
116
|
-
if (_didIteratorError) {
|
|
117
|
-
throw _iteratorError;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// Special handle `object` in case other instances are allowed to outline
|
|
122
|
-
// the differences between each other.
|
|
123
|
-
if (instances.length > 0) {
|
|
124
|
-
var pos = types.indexOf('object');
|
|
125
|
-
if (pos !== -1) {
|
|
126
|
-
types.slice(pos, 1);
|
|
127
|
-
instances.push('Object');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (types.length > 0) {
|
|
131
|
-
message += "".concat(types.length > 1 ? 'one of type' : 'of type', " ").concat(formatList(types, 'or'));
|
|
132
|
-
if (instances.length > 0 || other.length > 0) message += ' or ';
|
|
133
|
-
}
|
|
134
|
-
if (instances.length > 0) {
|
|
135
|
-
message += "an instance of ".concat(formatList(instances, 'or'));
|
|
136
|
-
if (other.length > 0) message += ' or ';
|
|
137
|
-
}
|
|
138
|
-
if (other.length > 0) {
|
|
139
|
-
if (other.length > 1) {
|
|
140
|
-
message += "one of ".concat(formatList(other, 'or'));
|
|
141
|
-
} else {
|
|
142
|
-
if (other[0].toLowerCase() !== other[0]) message += 'an ';
|
|
143
|
-
message += "".concat(other[0]);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
message += ". Received ".concat(determineSpecificType(actual));
|
|
147
|
-
return message;
|
|
148
|
-
}, TypeError);
|
|
149
|
-
codes.ERR_INVALID_MODULE_SPECIFIER = createError('ERR_INVALID_MODULE_SPECIFIER', /**
|
|
150
|
-
* @param {string} request
|
|
151
|
-
* @param {string} reason
|
|
152
|
-
* @param {string} [base]
|
|
153
|
-
*/ function(request, reason) {
|
|
154
|
-
var base = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : undefined;
|
|
155
|
-
return 'Invalid module "'.concat(request, '" ').concat(reason).concat(base ? " imported from ".concat(base) : '');
|
|
156
|
-
}, TypeError);
|
|
157
|
-
codes.ERR_INVALID_PACKAGE_CONFIG = createError('ERR_INVALID_PACKAGE_CONFIG', /**
|
|
158
|
-
* @param {string} path
|
|
159
|
-
* @param {string} [base]
|
|
160
|
-
* @param {string} [message]
|
|
161
|
-
*/ function(path, base, message) {
|
|
162
|
-
return "Invalid package config ".concat(path).concat(base ? " while importing ".concat(base) : '').concat(message ? ". ".concat(message) : '');
|
|
163
|
-
}, Error);
|
|
164
|
-
codes.ERR_INVALID_PACKAGE_TARGET = createError('ERR_INVALID_PACKAGE_TARGET', /**
|
|
165
|
-
* @param {string} packagePath
|
|
166
|
-
* @param {string} key
|
|
167
|
-
* @param {unknown} target
|
|
168
|
-
* @param {boolean} [isImport=false]
|
|
169
|
-
* @param {string} [base]
|
|
170
|
-
*/ function(packagePath, key, target) {
|
|
171
|
-
var isImport = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false, base = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : undefined;
|
|
172
|
-
var relatedError = typeof target === 'string' && !isImport && target.length > 0 && !target.startsWith('./');
|
|
173
|
-
if (key === '.') {
|
|
174
|
-
assert(isImport === false);
|
|
175
|
-
return 'Invalid "exports" main target '.concat(JSON.stringify(target), " defined ") + "in the package config ".concat(packagePath, "package.json").concat(base ? " imported from ".concat(base) : '').concat(relatedError ? '; targets must start with "./"' : '');
|
|
176
|
-
}
|
|
177
|
-
return 'Invalid "'.concat(isImport ? 'imports' : 'exports', '" target ').concat(JSON.stringify(target), " defined for '").concat(key, "' in the package config ").concat(packagePath, "package.json").concat(base ? " imported from ".concat(base) : '').concat(relatedError ? '; targets must start with "./"' : '');
|
|
178
|
-
}, Error);
|
|
179
|
-
codes.ERR_MODULE_NOT_FOUND = createError('ERR_MODULE_NOT_FOUND', /**
|
|
180
|
-
* @param {string} path
|
|
181
|
-
* @param {string} base
|
|
182
|
-
* @param {boolean} [exactUrl]
|
|
183
|
-
*/ function(path, base) {
|
|
184
|
-
var exactUrl = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
|
|
185
|
-
return "Cannot find ".concat(exactUrl ? 'module' : 'package', " '").concat(path, "' imported from ").concat(base);
|
|
186
|
-
}, Error);
|
|
187
|
-
codes.ERR_NETWORK_IMPORT_DISALLOWED = createError('ERR_NETWORK_IMPORT_DISALLOWED', "import of '%s' by %s is not supported: %s", Error);
|
|
188
|
-
codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError('ERR_PACKAGE_IMPORT_NOT_DEFINED', /**
|
|
189
|
-
* @param {string} specifier
|
|
190
|
-
* @param {string} packagePath
|
|
191
|
-
* @param {string} base
|
|
192
|
-
*/ function(specifier, packagePath, base) {
|
|
193
|
-
return 'Package import specifier "'.concat(specifier, '" is not defined').concat(packagePath ? " in package ".concat(packagePath, "package.json") : '', " imported from ").concat(base);
|
|
194
|
-
}, TypeError);
|
|
195
|
-
codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError('ERR_PACKAGE_PATH_NOT_EXPORTED', /**
|
|
196
|
-
* @param {string} packagePath
|
|
197
|
-
* @param {string} subpath
|
|
198
|
-
* @param {string} [base]
|
|
199
|
-
*/ function(packagePath, subpath) {
|
|
200
|
-
var base = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : undefined;
|
|
201
|
-
if (subpath === '.') return 'No "exports" main defined in '.concat(packagePath, "package.json").concat(base ? " imported from ".concat(base) : '');
|
|
202
|
-
return "Package subpath '".concat(subpath, '\' is not defined by "exports" in ').concat(packagePath, "package.json").concat(base ? " imported from ".concat(base) : '');
|
|
203
|
-
}, Error);
|
|
204
|
-
codes.ERR_UNSUPPORTED_DIR_IMPORT = createError('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " + 'resolving ES modules imported from %s', Error);
|
|
205
|
-
codes.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);
|
|
206
|
-
codes.ERR_UNKNOWN_FILE_EXTENSION = createError('ERR_UNKNOWN_FILE_EXTENSION', /**
|
|
207
|
-
* @param {string} extension
|
|
208
|
-
* @param {string} path
|
|
209
|
-
*/ function(extension, path) {
|
|
210
|
-
return 'Unknown file extension "'.concat(extension, '" for ').concat(path);
|
|
211
|
-
}, TypeError);
|
|
212
|
-
codes.ERR_INVALID_ARG_VALUE = createError('ERR_INVALID_ARG_VALUE', /**
|
|
213
|
-
* @param {string} name
|
|
214
|
-
* @param {unknown} value
|
|
215
|
-
* @param {string} [reason='is invalid']
|
|
216
|
-
*/ function(name, value) {
|
|
217
|
-
var reason = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 'is invalid';
|
|
218
|
-
var inspected = util.inspect(value);
|
|
219
|
-
if (inspected.length > 128) {
|
|
220
|
-
inspected = "".concat(inspected.slice(0, 128), "...");
|
|
221
|
-
}
|
|
222
|
-
var type = name.includes('.') ? 'property' : 'argument';
|
|
223
|
-
return "The ".concat(type, " '").concat(name, "' ").concat(reason, ". Received ").concat(inspected);
|
|
224
|
-
}, TypeError);
|
|
225
|
-
/**
|
|
226
|
-
* Utility function for registering the error codes. Only used here. Exported
|
|
227
|
-
* *only* to allow for testing.
|
|
228
|
-
* @param {string} sym
|
|
229
|
-
* @param {MessageFunction | string} value
|
|
230
|
-
* @param {ErrorConstructor} constructor
|
|
231
|
-
* @returns {new (...parameters: Array<any>) => Error}
|
|
232
|
-
*/ function createError(sym, value, constructor) {
|
|
233
|
-
// Special case for SystemError that formats the error message differently
|
|
234
|
-
// The SystemErrors only have SystemError as their base classes.
|
|
235
|
-
messages.set(sym, value);
|
|
236
|
-
return makeNodeErrorWithCode(constructor, sym);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* @param {ErrorConstructor} Base
|
|
240
|
-
* @param {string} key
|
|
241
|
-
* @returns {ErrorConstructor}
|
|
242
|
-
*/ function makeNodeErrorWithCode(Base, key) {
|
|
243
|
-
// @ts-expect-error It’s a Node error.
|
|
244
|
-
return NodeError;
|
|
245
|
-
/**
|
|
246
|
-
* @param {Array<unknown>} parameters
|
|
247
|
-
*/ function NodeError() {
|
|
248
|
-
for(var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++){
|
|
249
|
-
parameters[_key] = arguments[_key];
|
|
250
|
-
}
|
|
251
|
-
var limit = Error.stackTraceLimit;
|
|
252
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
253
|
-
var error = new Base();
|
|
254
|
-
// Reset the limit and setting the name property.
|
|
255
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
256
|
-
var message = getMessage(key, parameters, error);
|
|
257
|
-
Object.defineProperties(error, {
|
|
258
|
-
// Note: no need to implement `kIsNodeError` symbol, would be hard,
|
|
259
|
-
// probably.
|
|
260
|
-
message: {
|
|
261
|
-
value: message,
|
|
262
|
-
enumerable: false,
|
|
263
|
-
writable: true,
|
|
264
|
-
configurable: true
|
|
265
|
-
},
|
|
266
|
-
toString: {
|
|
267
|
-
/** @this {Error} */ value: function value() {
|
|
268
|
-
return "".concat(this.name, " [").concat(key, "]: ").concat(this.message);
|
|
269
|
-
},
|
|
270
|
-
enumerable: false,
|
|
271
|
-
writable: true,
|
|
272
|
-
configurable: true
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
captureLargerStackTrace(error);
|
|
276
|
-
// @ts-expect-error It’s a Node error.
|
|
277
|
-
error.code = key;
|
|
278
|
-
return error;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* @returns {boolean}
|
|
283
|
-
*/ function isErrorStackTraceLimitWritable() {
|
|
284
|
-
// Do no touch Error.stackTraceLimit as V8 would attempt to install
|
|
285
|
-
// it again during deserialization.
|
|
286
|
-
try {
|
|
287
|
-
if (v8.startupSnapshot.isBuildingSnapshot()) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
} catch (e) {}
|
|
291
|
-
var desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
|
|
292
|
-
if (desc === undefined) {
|
|
293
|
-
return Object.isExtensible(Error);
|
|
294
|
-
}
|
|
295
|
-
return own$1.call(desc, 'writable') && desc.writable !== undefined ? desc.writable : desc.set !== undefined;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* This function removes unnecessary frames from Node.js core errors.
|
|
299
|
-
* @template {(...parameters: unknown[]) => unknown} T
|
|
300
|
-
* @param {T} wrappedFunction
|
|
301
|
-
* @returns {T}
|
|
302
|
-
*/ function hideStackFrames(wrappedFunction) {
|
|
303
|
-
// We rename the functions that will be hidden to cut off the stacktrace
|
|
304
|
-
// at the outermost one
|
|
305
|
-
var hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
306
|
-
Object.defineProperty(wrappedFunction, 'name', {
|
|
307
|
-
value: hidden
|
|
308
|
-
});
|
|
309
|
-
return wrappedFunction;
|
|
310
|
-
}
|
|
311
|
-
var captureLargerStackTrace = hideStackFrames(/**
|
|
312
|
-
* @param {Error} error
|
|
313
|
-
* @returns {Error}
|
|
314
|
-
*/ // @ts-expect-error: fine
|
|
315
|
-
function(error) {
|
|
316
|
-
var stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
317
|
-
if (stackTraceLimitIsWritable) {
|
|
318
|
-
userStackTraceLimit = Error.stackTraceLimit;
|
|
319
|
-
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
320
|
-
}
|
|
321
|
-
Error.captureStackTrace(error);
|
|
322
|
-
// Reset the limit
|
|
323
|
-
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
324
|
-
return error;
|
|
325
|
-
});
|
|
326
|
-
/**
|
|
327
|
-
* @param {string} key
|
|
328
|
-
* @param {Array<unknown>} parameters
|
|
329
|
-
* @param {Error} self
|
|
330
|
-
* @returns {string}
|
|
331
|
-
*/ function getMessage(key, parameters, self) {
|
|
332
|
-
var message = messages.get(key);
|
|
333
|
-
assert(message !== undefined, 'expected `message` to be found');
|
|
334
|
-
if (typeof message === 'function') {
|
|
335
|
-
assert(message.length <= parameters.length, "Code: ".concat(key, "; The provided arguments length (").concat(parameters.length, ") does not ") + "match the required ones (".concat(message.length, ")."));
|
|
336
|
-
return Reflect.apply(message, self, parameters);
|
|
337
|
-
}
|
|
338
|
-
var regex = /%[dfijoOs]/g;
|
|
339
|
-
var expectedLength = 0;
|
|
340
|
-
while(regex.exec(message) !== null)expectedLength++;
|
|
341
|
-
assert(expectedLength === parameters.length, "Code: ".concat(key, "; The provided arguments length (").concat(parameters.length, ") does not ") + "match the required ones (".concat(expectedLength, ")."));
|
|
342
|
-
if (parameters.length === 0) return message;
|
|
343
|
-
parameters.unshift(message);
|
|
344
|
-
return Reflect.apply(util.format, null, parameters);
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Determine the specific type of a value for type-mismatch errors.
|
|
348
|
-
* @param {unknown} value
|
|
349
|
-
* @returns {string}
|
|
350
|
-
*/ function determineSpecificType(value) {
|
|
351
|
-
if (value === null || value === undefined) {
|
|
352
|
-
return String(value);
|
|
353
|
-
}
|
|
354
|
-
if (typeof value === 'function' && value.name) {
|
|
355
|
-
return "function ".concat(value.name);
|
|
356
|
-
}
|
|
357
|
-
if ((typeof value === "undefined" ? "undefined" : _type_of$1(value)) === 'object') {
|
|
358
|
-
if (value.constructor && value.constructor.name) {
|
|
359
|
-
return "an instance of ".concat(value.constructor.name);
|
|
360
|
-
}
|
|
361
|
-
return "".concat(util.inspect(value, {
|
|
362
|
-
depth: -1
|
|
363
|
-
}));
|
|
364
|
-
}
|
|
365
|
-
var inspected = util.inspect(value, {
|
|
366
|
-
colors: false
|
|
367
|
-
});
|
|
368
|
-
if (inspected.length > 28) {
|
|
369
|
-
inspected = "".concat(inspected.slice(0, 25), "...");
|
|
370
|
-
}
|
|
371
|
-
return "type ".concat(typeof value === "undefined" ? "undefined" : _type_of$1(value), " (").concat(inspected, ")");
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Manually “tree shaken” from:
|
|
375
|
-
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/package_json_reader.js>
|
|
376
|
-
// Last checked on: Apr 29, 2023.
|
|
377
|
-
// Removed the native dependency.
|
|
378
|
-
// Also: no need to cache, we do that in resolve already.
|
|
379
|
-
var hasOwnProperty$1 = {}.hasOwnProperty;
|
|
380
|
-
var ERR_INVALID_PACKAGE_CONFIG$1 = codes.ERR_INVALID_PACKAGE_CONFIG;
|
|
381
|
-
/** @type {Map<string, PackageConfig>} */ var cache = new Map();
|
|
382
|
-
/**
|
|
383
|
-
* @param {string} jsonPath
|
|
384
|
-
* @param {{specifier: URL | string, base?: URL}} options
|
|
385
|
-
* @returns {PackageConfig}
|
|
386
|
-
*/ function read(jsonPath, param) {
|
|
387
|
-
var base = param.base, specifier = param.specifier;
|
|
388
|
-
var existing = cache.get(jsonPath);
|
|
389
|
-
if (existing) {
|
|
390
|
-
return existing;
|
|
391
|
-
}
|
|
392
|
-
/** @type {string | undefined} */ var string;
|
|
393
|
-
try {
|
|
394
|
-
string = fs.readFileSync(path.toNamespacedPath(jsonPath), 'utf8');
|
|
395
|
-
} catch (error) {
|
|
396
|
-
var exception = /** @type {ErrnoException} */ error;
|
|
397
|
-
if (exception.code !== 'ENOENT') {
|
|
398
|
-
throw exception;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
/** @type {PackageConfig} */ var result = {
|
|
402
|
-
exists: false,
|
|
403
|
-
pjsonPath: jsonPath,
|
|
404
|
-
main: undefined,
|
|
405
|
-
name: undefined,
|
|
406
|
-
type: 'none',
|
|
407
|
-
exports: undefined,
|
|
408
|
-
imports: undefined
|
|
409
|
-
};
|
|
410
|
-
if (string !== undefined) {
|
|
411
|
-
/** @type {Record<string, unknown>} */ var parsed;
|
|
412
|
-
try {
|
|
413
|
-
parsed = JSON.parse(string);
|
|
414
|
-
} catch (error_) {
|
|
415
|
-
var cause = /** @type {ErrnoException} */ error_;
|
|
416
|
-
var _$error = new ERR_INVALID_PACKAGE_CONFIG$1(jsonPath, (base ? '"'.concat(specifier, '" from ') : '') + url.fileURLToPath(base || specifier), cause.message);
|
|
417
|
-
_$error.cause = cause;
|
|
418
|
-
throw _$error;
|
|
419
|
-
}
|
|
420
|
-
result.exists = true;
|
|
421
|
-
if (hasOwnProperty$1.call(parsed, 'name') && typeof parsed.name === 'string') {
|
|
422
|
-
result.name = parsed.name;
|
|
423
|
-
}
|
|
424
|
-
if (hasOwnProperty$1.call(parsed, 'main') && typeof parsed.main === 'string') {
|
|
425
|
-
result.main = parsed.main;
|
|
426
|
-
}
|
|
427
|
-
if (hasOwnProperty$1.call(parsed, 'exports')) {
|
|
428
|
-
// @ts-expect-error: assume valid.
|
|
429
|
-
result.exports = parsed.exports;
|
|
430
|
-
}
|
|
431
|
-
if (hasOwnProperty$1.call(parsed, 'imports')) {
|
|
432
|
-
// @ts-expect-error: assume valid.
|
|
433
|
-
result.imports = parsed.imports;
|
|
434
|
-
}
|
|
435
|
-
// Ignore unknown types for forwards compatibility
|
|
436
|
-
if (hasOwnProperty$1.call(parsed, 'type') && (parsed.type === 'commonjs' || parsed.type === 'module')) {
|
|
437
|
-
result.type = parsed.type;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
cache.set(jsonPath, result);
|
|
441
|
-
return result;
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* @param {URL | string} resolved
|
|
445
|
-
* @returns {PackageConfig}
|
|
446
|
-
*/ function getPackageScopeConfig(resolved) {
|
|
447
|
-
// Note: in Node, this is now a native module.
|
|
448
|
-
var packageJSONUrl = new URL('package.json', resolved);
|
|
449
|
-
while(true){
|
|
450
|
-
var packageJSONPath = packageJSONUrl.pathname;
|
|
451
|
-
if (packageJSONPath.endsWith('node_modules/package.json')) {
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
var packageConfig = read(url.fileURLToPath(packageJSONUrl), {
|
|
455
|
-
specifier: resolved
|
|
456
|
-
});
|
|
457
|
-
if (packageConfig.exists) {
|
|
458
|
-
return packageConfig;
|
|
459
|
-
}
|
|
460
|
-
var lastPackageJSONUrl = packageJSONUrl;
|
|
461
|
-
packageJSONUrl = new URL('../package.json', packageJSONUrl);
|
|
462
|
-
// Terminates at root where ../package.json equals ../../package.json
|
|
463
|
-
// (can't just check "/package.json" for Windows support).
|
|
464
|
-
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
var packageJSONPath1 = url.fileURLToPath(packageJSONUrl);
|
|
469
|
-
// ^^ Note: in Node, this is now a native module.
|
|
470
|
-
return {
|
|
471
|
-
pjsonPath: packageJSONPath1,
|
|
472
|
-
exists: false,
|
|
473
|
-
type: 'none'
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Returns the package type for a given URL.
|
|
478
|
-
* @param {URL} url - The URL to get the package type for.
|
|
479
|
-
* @returns {PackageType}
|
|
480
|
-
*/ function getPackageType(url) {
|
|
481
|
-
// To do @anonrig: Write a C++ function that returns only "type".
|
|
482
|
-
return getPackageScopeConfig(url).type;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// Manually “tree shaken” from:
|
|
486
|
-
// <https://github.com/nodejs/node/blob/7c3dce0/lib/internal/modules/esm/get_format.js>
|
|
487
|
-
// Last checked on: Apr 29, 2023.
|
|
488
|
-
var ERR_UNKNOWN_FILE_EXTENSION = codes.ERR_UNKNOWN_FILE_EXTENSION;
|
|
489
|
-
var hasOwnProperty = {}.hasOwnProperty;
|
|
490
|
-
/** @type {Record<string, string>} */ var extensionFormatMap = {
|
|
491
|
-
// @ts-expect-error: hush.
|
|
492
|
-
__proto__: null,
|
|
493
|
-
'.cjs': 'commonjs',
|
|
494
|
-
'.js': 'module',
|
|
495
|
-
'.json': 'json',
|
|
496
|
-
'.mjs': 'module'
|
|
497
|
-
};
|
|
498
|
-
/**
|
|
499
|
-
* @param {string | null} mime
|
|
500
|
-
* @returns {string | null}
|
|
501
|
-
*/ function mimeToFormat(mime) {
|
|
502
|
-
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return 'module';
|
|
503
|
-
if (mime === 'application/json') return 'json';
|
|
504
|
-
return null;
|
|
505
|
-
}
|
|
506
|
-
/**
|
|
507
|
-
* @callback ProtocolHandler
|
|
508
|
-
* @param {URL} parsed
|
|
509
|
-
* @param {{parentURL: string, source?: Buffer}} context
|
|
510
|
-
* @param {boolean} ignoreErrors
|
|
511
|
-
* @returns {string | null | void}
|
|
512
|
-
*/ /**
|
|
513
|
-
* @type {Record<string, ProtocolHandler>}
|
|
514
|
-
*/ var protocolHandlers = {
|
|
515
|
-
// @ts-expect-error: hush.
|
|
516
|
-
__proto__: null,
|
|
517
|
-
'data:': getDataProtocolModuleFormat,
|
|
518
|
-
'file:': getFileProtocolModuleFormat,
|
|
519
|
-
'http:': getHttpProtocolModuleFormat,
|
|
520
|
-
'https:': getHttpProtocolModuleFormat,
|
|
521
|
-
'node:': function() {
|
|
522
|
-
return 'builtin';
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
/**
|
|
526
|
-
* @param {URL} parsed
|
|
527
|
-
*/ function getDataProtocolModuleFormat(parsed) {
|
|
528
|
-
var _ref = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
|
|
529
|
-
null,
|
|
530
|
-
null,
|
|
531
|
-
null
|
|
532
|
-
], mime = _ref[1];
|
|
533
|
-
return mimeToFormat(mime);
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Returns the file extension from a URL.
|
|
537
|
-
*
|
|
538
|
-
* Should give similar result to
|
|
539
|
-
* `require('node:path').extname(require('node:url').fileURLToPath(url))`
|
|
540
|
-
* when used with a `file:` URL.
|
|
541
|
-
*
|
|
542
|
-
* @param {URL} url
|
|
543
|
-
* @returns {string}
|
|
544
|
-
*/ function extname(url) {
|
|
545
|
-
var pathname = url.pathname;
|
|
546
|
-
var index = pathname.length;
|
|
547
|
-
while(index--){
|
|
548
|
-
var code = pathname.codePointAt(index);
|
|
549
|
-
if (code === 47 /* `/` */ ) {
|
|
550
|
-
return '';
|
|
551
|
-
}
|
|
552
|
-
if (code === 46 /* `.` */ ) {
|
|
553
|
-
return pathname.codePointAt(index - 1) === 47 /* `/` */ ? '' : pathname.slice(index);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return '';
|
|
557
|
-
}
|
|
558
|
-
/**
|
|
559
|
-
* @type {ProtocolHandler}
|
|
560
|
-
*/ function getFileProtocolModuleFormat(url$1, _context, ignoreErrors) {
|
|
561
|
-
var value = extname(url$1);
|
|
562
|
-
if (value === '.js') {
|
|
563
|
-
var packageType = getPackageType(url$1);
|
|
564
|
-
if (packageType !== 'none') {
|
|
565
|
-
return packageType;
|
|
566
|
-
}
|
|
567
|
-
return 'commonjs';
|
|
568
|
-
}
|
|
569
|
-
if (value === '') {
|
|
570
|
-
var packageType1 = getPackageType(url$1);
|
|
571
|
-
// Legacy behavior
|
|
572
|
-
if (packageType1 === 'none' || packageType1 === 'commonjs') {
|
|
573
|
-
return 'commonjs';
|
|
574
|
-
}
|
|
575
|
-
// Note: we don’t implement WASM, so we don’t need
|
|
576
|
-
// `getFormatOfExtensionlessFile` from `formats`.
|
|
577
|
-
return 'module';
|
|
578
|
-
}
|
|
579
|
-
var format = extensionFormatMap[value];
|
|
580
|
-
if (format) return format;
|
|
581
|
-
// Explicit undefined return indicates load hook should rerun format check
|
|
582
|
-
if (ignoreErrors) {
|
|
583
|
-
return undefined;
|
|
584
|
-
}
|
|
585
|
-
var filepath = url.fileURLToPath(url$1);
|
|
586
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
|
|
587
|
-
}
|
|
588
|
-
function getHttpProtocolModuleFormat() {
|
|
589
|
-
// To do: HTTPS imports.
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* @param {URL} url
|
|
593
|
-
* @param {{parentURL: string}} context
|
|
594
|
-
* @returns {string | null}
|
|
595
|
-
*/ function defaultGetFormatWithoutErrors(url, context) {
|
|
596
|
-
var protocol = url.protocol;
|
|
597
|
-
if (!hasOwnProperty.call(protocolHandlers, protocol)) {
|
|
598
|
-
return null;
|
|
599
|
-
}
|
|
600
|
-
return protocolHandlers[protocol](url, context, true) || null;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// Manually “tree shaken” from:
|
|
604
|
-
// <https://github.com/nodejs/node/blob/81a9a97/lib/internal/modules/esm/utils.js>
|
|
605
|
-
// Last checked on: Apr 29, 2023.
|
|
606
|
-
var ERR_INVALID_ARG_VALUE = codes.ERR_INVALID_ARG_VALUE;
|
|
607
|
-
// In Node itself these values are populated from CLI arguments, before any
|
|
608
|
-
// user code runs.
|
|
609
|
-
// Here we just define the defaults.
|
|
610
|
-
var DEFAULT_CONDITIONS = Object.freeze([
|
|
611
|
-
'node',
|
|
612
|
-
'import'
|
|
613
|
-
]);
|
|
614
|
-
var DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
|
|
615
|
-
/**
|
|
616
|
-
* Returns the default conditions for ES module loading.
|
|
617
|
-
*/ function getDefaultConditions() {
|
|
618
|
-
return DEFAULT_CONDITIONS;
|
|
619
|
-
}
|
|
620
|
-
/**
|
|
621
|
-
* Returns the default conditions for ES module loading, as a Set.
|
|
622
|
-
*/ function getDefaultConditionsSet() {
|
|
623
|
-
return DEFAULT_CONDITIONS_SET;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* @param {Array<string>} [conditions]
|
|
627
|
-
* @returns {Set<string>}
|
|
628
|
-
*/ function getConditionsSet(conditions) {
|
|
629
|
-
if (conditions !== undefined && conditions !== getDefaultConditions()) {
|
|
630
|
-
if (!Array.isArray(conditions)) {
|
|
631
|
-
throw new ERR_INVALID_ARG_VALUE('conditions', conditions, 'expected an array');
|
|
632
|
-
}
|
|
633
|
-
return new Set(conditions);
|
|
634
|
-
}
|
|
635
|
-
return getDefaultConditionsSet();
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// Manually “tree shaken” from:
|
|
639
|
-
// <https://github.com/nodejs/node/blob/81a9a97/lib/internal/modules/esm/resolve.js>
|
|
640
|
-
// Last checked on: Apr 29, 2023.
|
|
641
|
-
/**
|
|
642
|
-
* @typedef {import('node:fs').Stats} Stats
|
|
643
|
-
* @typedef {import('./errors.js').ErrnoException} ErrnoException
|
|
644
|
-
* @typedef {import('./package-json-reader.js').PackageConfig} PackageConfig
|
|
645
|
-
*/ function _type_of(obj) {
|
|
646
|
-
"@swc/helpers - typeof";
|
|
647
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
648
|
-
}
|
|
649
|
-
var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
650
|
-
var ERR_NETWORK_IMPORT_DISALLOWED = codes.ERR_NETWORK_IMPORT_DISALLOWED, ERR_INVALID_MODULE_SPECIFIER = codes.ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_PACKAGE_CONFIG = codes.ERR_INVALID_PACKAGE_CONFIG, ERR_INVALID_PACKAGE_TARGET = codes.ERR_INVALID_PACKAGE_TARGET, ERR_MODULE_NOT_FOUND = codes.ERR_MODULE_NOT_FOUND, ERR_PACKAGE_IMPORT_NOT_DEFINED = codes.ERR_PACKAGE_IMPORT_NOT_DEFINED, ERR_PACKAGE_PATH_NOT_EXPORTED = codes.ERR_PACKAGE_PATH_NOT_EXPORTED, ERR_UNSUPPORTED_DIR_IMPORT = codes.ERR_UNSUPPORTED_DIR_IMPORT, ERR_UNSUPPORTED_RESOLVE_REQUEST = codes.ERR_UNSUPPORTED_RESOLVE_REQUEST;
|
|
651
|
-
var own = {}.hasOwnProperty;
|
|
652
|
-
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;
|
|
653
|
-
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;
|
|
654
|
-
var invalidPackageNameRegEx = /^\.|%|\\/;
|
|
655
|
-
var patternRegEx = /\*/g;
|
|
656
|
-
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
657
|
-
/** @type {Set<string>} */ var emittedPackageWarnings = new Set();
|
|
658
|
-
var doubleSlashRegEx = /[/\\]{2}/;
|
|
659
|
-
/**
|
|
660
|
-
*
|
|
661
|
-
* @param {string} target
|
|
662
|
-
* @param {string} request
|
|
663
|
-
* @param {string} match
|
|
664
|
-
* @param {URL} packageJsonUrl
|
|
665
|
-
* @param {boolean} internal
|
|
666
|
-
* @param {URL} base
|
|
667
|
-
* @param {boolean} isTarget
|
|
668
|
-
*/ function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
669
|
-
// @ts-expect-error: apparently it does exist, TS.
|
|
670
|
-
if (process.noDeprecation) {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
var pjsonPath = url.fileURLToPath(packageJsonUrl);
|
|
674
|
-
var double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
675
|
-
process.emitWarning("Use of deprecated ".concat(double ? 'double slash' : 'leading or trailing slash matching', ' resolving "').concat(target, '" for module ') + 'request "'.concat(request, '" ').concat(request === match ? '' : 'matched to "'.concat(match, '" '), 'in the "').concat(internal ? 'imports' : 'exports', '" field module resolution of the package at ').concat(pjsonPath).concat(base ? " imported from ".concat(url.fileURLToPath(base)) : '', "."), 'DeprecationWarning', 'DEP0166');
|
|
676
|
-
}
|
|
677
|
-
/**
|
|
678
|
-
* @param {URL} url
|
|
679
|
-
* @param {URL} packageJsonUrl
|
|
680
|
-
* @param {URL} base
|
|
681
|
-
* @param {string} [main]
|
|
682
|
-
* @returns {void}
|
|
683
|
-
*/ function emitLegacyIndexDeprecation(url$1, packageJsonUrl, base, main) {
|
|
684
|
-
// @ts-expect-error: apparently it does exist, TS.
|
|
685
|
-
if (process.noDeprecation) {
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
var format = defaultGetFormatWithoutErrors(url$1, {
|
|
689
|
-
parentURL: base.href
|
|
690
|
-
});
|
|
691
|
-
if (format !== 'module') return;
|
|
692
|
-
var urlPath = url.fileURLToPath(url$1.href);
|
|
693
|
-
var packagePath = url.fileURLToPath(new url.URL('.', packageJsonUrl));
|
|
694
|
-
var basePath = url.fileURLToPath(base);
|
|
695
|
-
if (!main) {
|
|
696
|
-
process.emitWarning('No "main" or "exports" field defined in the package.json for '.concat(packagePath, ' resolving the main entry point "').concat(urlPath.slice(packagePath.length), '", imported from ').concat(basePath, '.\nDefault "index" lookups for the main are deprecated for ES modules.'), 'DeprecationWarning', 'DEP0151');
|
|
697
|
-
} else if (path.resolve(packagePath, main) !== urlPath) {
|
|
698
|
-
process.emitWarning("Package ".concat(packagePath, ' has a "main" field set to "').concat(main, '", ') + 'excluding the full filename and extension to the resolved file at "'.concat(urlPath.slice(packagePath.length), '", imported from ').concat(basePath, '.\n Automatic extension resolution of the "main" field is ') + 'deprecated for ES modules.', 'DeprecationWarning', 'DEP0151');
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* @param {string} path
|
|
703
|
-
* @returns {Stats | undefined}
|
|
704
|
-
*/ function tryStatSync(path) {
|
|
705
|
-
// Note: from Node 15 onwards we can use `throwIfNoEntry: false` instead.
|
|
706
|
-
try {
|
|
707
|
-
return fs.statSync(path);
|
|
708
|
-
} catch (e) {
|
|
709
|
-
// Note: in Node code this returns `new Stats`,
|
|
710
|
-
// but in Node 22 that’s marked as a deprecated internal API.
|
|
711
|
-
// Which, well, we kinda are, but still to prevent that warning,
|
|
712
|
-
// just yield `undefined`.
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Legacy CommonJS main resolution:
|
|
717
|
-
* 1. let M = pkg_url + (json main field)
|
|
718
|
-
* 2. TRY(M, M.js, M.json, M.node)
|
|
719
|
-
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
720
|
-
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
721
|
-
* 5. NOT_FOUND
|
|
722
|
-
*
|
|
723
|
-
* @param {URL} url
|
|
724
|
-
* @returns {boolean}
|
|
725
|
-
*/ function fileExists(url) {
|
|
726
|
-
var stats = fs.statSync(url, {
|
|
727
|
-
throwIfNoEntry: false
|
|
728
|
-
});
|
|
729
|
-
var isFile = stats ? stats.isFile() : undefined;
|
|
730
|
-
return isFile === null || isFile === undefined ? false : isFile;
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* @param {URL} packageJsonUrl
|
|
734
|
-
* @param {PackageConfig} packageConfig
|
|
735
|
-
* @param {URL} base
|
|
736
|
-
* @returns {URL}
|
|
737
|
-
*/ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
738
|
-
/** @type {URL | undefined} */ var guess;
|
|
739
|
-
if (packageConfig.main !== undefined) {
|
|
740
|
-
guess = new url.URL(packageConfig.main, packageJsonUrl);
|
|
741
|
-
// Note: fs check redundances will be handled by Descriptor cache here.
|
|
742
|
-
if (fileExists(guess)) return guess;
|
|
743
|
-
var tries = [
|
|
744
|
-
"./".concat(packageConfig.main, ".js"),
|
|
745
|
-
"./".concat(packageConfig.main, ".json"),
|
|
746
|
-
"./".concat(packageConfig.main, ".node"),
|
|
747
|
-
"./".concat(packageConfig.main, "/index.js"),
|
|
748
|
-
"./".concat(packageConfig.main, "/index.json"),
|
|
749
|
-
"./".concat(packageConfig.main, "/index.node")
|
|
750
|
-
];
|
|
751
|
-
var i = -1;
|
|
752
|
-
while(++i < tries.length){
|
|
753
|
-
guess = new url.URL(tries[i], packageJsonUrl);
|
|
754
|
-
if (fileExists(guess)) break;
|
|
755
|
-
guess = undefined;
|
|
756
|
-
}
|
|
757
|
-
if (guess) {
|
|
758
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
759
|
-
return guess;
|
|
760
|
-
}
|
|
761
|
-
// Fallthrough.
|
|
762
|
-
}
|
|
763
|
-
var tries1 = [
|
|
764
|
-
'./index.js',
|
|
765
|
-
'./index.json',
|
|
766
|
-
'./index.node'
|
|
767
|
-
];
|
|
768
|
-
var i1 = -1;
|
|
769
|
-
while(++i1 < tries1.length){
|
|
770
|
-
guess = new url.URL(tries1[i1], packageJsonUrl);
|
|
771
|
-
if (fileExists(guess)) break;
|
|
772
|
-
guess = undefined;
|
|
773
|
-
}
|
|
774
|
-
if (guess) {
|
|
775
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
776
|
-
return guess;
|
|
777
|
-
}
|
|
778
|
-
// Not found.
|
|
779
|
-
throw new ERR_MODULE_NOT_FOUND(url.fileURLToPath(new url.URL('.', packageJsonUrl)), url.fileURLToPath(base));
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* @param {URL} resolved
|
|
783
|
-
* @param {URL} base
|
|
784
|
-
* @param {boolean} [preserveSymlinks]
|
|
785
|
-
* @returns {URL}
|
|
786
|
-
*/ function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
787
|
-
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
|
|
788
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, 'must not include encoded "/" or "\\" characters', url.fileURLToPath(base));
|
|
789
|
-
}
|
|
790
|
-
/** @type {string} */ var filePath;
|
|
791
|
-
try {
|
|
792
|
-
filePath = url.fileURLToPath(resolved);
|
|
793
|
-
} catch (error) {
|
|
794
|
-
var cause = /** @type {ErrnoException} */ error;
|
|
795
|
-
Object.defineProperty(cause, 'input', {
|
|
796
|
-
value: String(resolved)
|
|
797
|
-
});
|
|
798
|
-
Object.defineProperty(cause, 'module', {
|
|
799
|
-
value: String(base)
|
|
800
|
-
});
|
|
801
|
-
throw cause;
|
|
802
|
-
}
|
|
803
|
-
var stats = tryStatSync(filePath.endsWith('/') ? filePath.slice(-1) : filePath);
|
|
804
|
-
if (stats && stats.isDirectory()) {
|
|
805
|
-
var _$error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, url.fileURLToPath(base));
|
|
806
|
-
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
807
|
-
_$error.url = String(resolved);
|
|
808
|
-
throw _$error;
|
|
809
|
-
}
|
|
810
|
-
if (!stats || !stats.isFile()) {
|
|
811
|
-
var _$error1 = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && url.fileURLToPath(base), true);
|
|
812
|
-
// @ts-expect-error Add this for `import.meta.resolve`.
|
|
813
|
-
_$error1.url = String(resolved);
|
|
814
|
-
throw _$error1;
|
|
815
|
-
}
|
|
816
|
-
if (!preserveSymlinks) {
|
|
817
|
-
var real = fs.realpathSync(filePath);
|
|
818
|
-
var search = resolved.search, hash = resolved.hash;
|
|
819
|
-
resolved = url.pathToFileURL(real + (filePath.endsWith(path.sep) ? '/' : ''));
|
|
820
|
-
resolved.search = search;
|
|
821
|
-
resolved.hash = hash;
|
|
822
|
-
}
|
|
823
|
-
return resolved;
|
|
824
|
-
}
|
|
825
|
-
/**
|
|
826
|
-
* @param {string} specifier
|
|
827
|
-
* @param {URL | undefined} packageJsonUrl
|
|
828
|
-
* @param {URL} base
|
|
829
|
-
* @returns {Error}
|
|
830
|
-
*/ function importNotDefined(specifier, packageJsonUrl, base) {
|
|
831
|
-
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && url.fileURLToPath(new url.URL('.', packageJsonUrl)), url.fileURLToPath(base));
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* @param {string} subpath
|
|
835
|
-
* @param {URL} packageJsonUrl
|
|
836
|
-
* @param {URL} base
|
|
837
|
-
* @returns {Error}
|
|
838
|
-
*/ function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
839
|
-
return new ERR_PACKAGE_PATH_NOT_EXPORTED(url.fileURLToPath(new url.URL('.', packageJsonUrl)), subpath, base && url.fileURLToPath(base));
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* @param {string} request
|
|
843
|
-
* @param {string} match
|
|
844
|
-
* @param {URL} packageJsonUrl
|
|
845
|
-
* @param {boolean} internal
|
|
846
|
-
* @param {URL} [base]
|
|
847
|
-
* @returns {never}
|
|
848
|
-
*/ function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
849
|
-
var reason = 'request is not a valid match in pattern "'.concat(match, '" for the "').concat(internal ? 'imports' : 'exports', '" resolution of ').concat(url.fileURLToPath(packageJsonUrl));
|
|
850
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(request, reason, base && url.fileURLToPath(base));
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* @param {string} subpath
|
|
854
|
-
* @param {unknown} target
|
|
855
|
-
* @param {URL} packageJsonUrl
|
|
856
|
-
* @param {boolean} internal
|
|
857
|
-
* @param {URL} [base]
|
|
858
|
-
* @returns {Error}
|
|
859
|
-
*/ function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
860
|
-
target = (typeof target === "undefined" ? "undefined" : _type_of(target)) === 'object' && target !== null ? JSON.stringify(target, null, '') : "".concat(target);
|
|
861
|
-
return new ERR_INVALID_PACKAGE_TARGET(url.fileURLToPath(new url.URL('.', packageJsonUrl)), subpath, target, internal, base && url.fileURLToPath(base));
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
* @param {string} target
|
|
865
|
-
* @param {string} subpath
|
|
866
|
-
* @param {string} match
|
|
867
|
-
* @param {URL} packageJsonUrl
|
|
868
|
-
* @param {URL} base
|
|
869
|
-
* @param {boolean} pattern
|
|
870
|
-
* @param {boolean} internal
|
|
871
|
-
* @param {boolean} isPathMap
|
|
872
|
-
* @param {Set<string> | undefined} conditions
|
|
873
|
-
* @returns {URL}
|
|
874
|
-
*/ function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
875
|
-
if (subpath !== '' && !pattern && target[target.length - 1] !== '/') throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
876
|
-
if (!target.startsWith('./')) {
|
|
877
|
-
if (internal && !target.startsWith('../') && !target.startsWith('/')) {
|
|
878
|
-
var isURL = false;
|
|
879
|
-
try {
|
|
880
|
-
new url.URL(target);
|
|
881
|
-
isURL = true;
|
|
882
|
-
} catch (e) {
|
|
883
|
-
// Continue regardless of error.
|
|
884
|
-
}
|
|
885
|
-
if (!isURL) {
|
|
886
|
-
var exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, function() {
|
|
887
|
-
return subpath;
|
|
888
|
-
}) : target + subpath;
|
|
889
|
-
return packageResolve(exportTarget, packageJsonUrl, conditions);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
893
|
-
}
|
|
894
|
-
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
|
|
895
|
-
if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
896
|
-
if (!isPathMap) {
|
|
897
|
-
var request = pattern ? match.replace('*', function() {
|
|
898
|
-
return subpath;
|
|
899
|
-
}) : match + subpath;
|
|
900
|
-
var resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, function() {
|
|
901
|
-
return subpath;
|
|
902
|
-
}) : target;
|
|
903
|
-
emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJsonUrl, internal, base, true);
|
|
904
|
-
}
|
|
905
|
-
} else {
|
|
906
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
var resolved = new url.URL(target, packageJsonUrl);
|
|
910
|
-
var resolvedPath = resolved.pathname;
|
|
911
|
-
var packagePath = new url.URL('.', packageJsonUrl).pathname;
|
|
912
|
-
if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
913
|
-
if (subpath === '') return resolved;
|
|
914
|
-
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
915
|
-
var request1 = pattern ? match.replace('*', function() {
|
|
916
|
-
return subpath;
|
|
917
|
-
}) : match + subpath;
|
|
918
|
-
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
919
|
-
if (!isPathMap) {
|
|
920
|
-
var resolvedTarget1 = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, function() {
|
|
921
|
-
return subpath;
|
|
922
|
-
}) : target;
|
|
923
|
-
emitInvalidSegmentDeprecation(resolvedTarget1, request1, match, packageJsonUrl, internal, base, false);
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
throwInvalidSubpath(request1, match, packageJsonUrl, internal, base);
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
if (pattern) {
|
|
930
|
-
return new url.URL(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, function() {
|
|
931
|
-
return subpath;
|
|
932
|
-
}));
|
|
933
|
-
}
|
|
934
|
-
return new url.URL(subpath, resolved);
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* @param {string} key
|
|
938
|
-
* @returns {boolean}
|
|
939
|
-
*/ function isArrayIndex(key) {
|
|
940
|
-
var keyNumber = Number(key);
|
|
941
|
-
if ("".concat(keyNumber) !== key) return false;
|
|
942
|
-
return keyNumber >= 0 && keyNumber < 0xffffffff;
|
|
943
|
-
}
|
|
944
|
-
/**
|
|
945
|
-
* @param {URL} packageJsonUrl
|
|
946
|
-
* @param {unknown} target
|
|
947
|
-
* @param {string} subpath
|
|
948
|
-
* @param {string} packageSubpath
|
|
949
|
-
* @param {URL} base
|
|
950
|
-
* @param {boolean} pattern
|
|
951
|
-
* @param {boolean} internal
|
|
952
|
-
* @param {boolean} isPathMap
|
|
953
|
-
* @param {Set<string> | undefined} conditions
|
|
954
|
-
* @returns {URL | null}
|
|
955
|
-
*/ function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
956
|
-
if (typeof target === 'string') {
|
|
957
|
-
return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
|
|
958
|
-
}
|
|
959
|
-
if (Array.isArray(target)) {
|
|
960
|
-
/** @type {Array<unknown>} */ var targetList = target;
|
|
961
|
-
if (targetList.length === 0) return null;
|
|
962
|
-
/** @type {ErrnoException | null | undefined} */ var lastException;
|
|
963
|
-
var i = -1;
|
|
964
|
-
while(++i < targetList.length){
|
|
965
|
-
var targetItem = targetList[i];
|
|
966
|
-
/** @type {URL | null} */ var resolveResult = void 0;
|
|
967
|
-
try {
|
|
968
|
-
resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
969
|
-
} catch (error) {
|
|
970
|
-
var exception = /** @type {ErrnoException} */ error;
|
|
971
|
-
lastException = exception;
|
|
972
|
-
if (exception.code === 'ERR_INVALID_PACKAGE_TARGET') continue;
|
|
973
|
-
throw error;
|
|
974
|
-
}
|
|
975
|
-
if (resolveResult === undefined) continue;
|
|
976
|
-
if (resolveResult === null) {
|
|
977
|
-
lastException = null;
|
|
978
|
-
continue;
|
|
979
|
-
}
|
|
980
|
-
return resolveResult;
|
|
981
|
-
}
|
|
982
|
-
if (lastException === undefined || lastException === null) {
|
|
983
|
-
return null;
|
|
984
|
-
}
|
|
985
|
-
throw lastException;
|
|
986
|
-
}
|
|
987
|
-
if ((typeof target === "undefined" ? "undefined" : _type_of(target)) === 'object' && target !== null) {
|
|
988
|
-
var keys = Object.getOwnPropertyNames(target);
|
|
989
|
-
var i1 = -1;
|
|
990
|
-
while(++i1 < keys.length){
|
|
991
|
-
var key = keys[i1];
|
|
992
|
-
if (isArrayIndex(key)) {
|
|
993
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(url.fileURLToPath(packageJsonUrl), base, '"exports" cannot contain numeric property keys.');
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
i1 = -1;
|
|
997
|
-
while(++i1 < keys.length){
|
|
998
|
-
var key1 = keys[i1];
|
|
999
|
-
if (key1 === 'default' || conditions && conditions.has(key1)) {
|
|
1000
|
-
// @ts-expect-error: indexable.
|
|
1001
|
-
var conditionalTarget = /** @type {unknown} */ target[key1];
|
|
1002
|
-
var resolveResult1 = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
1003
|
-
if (resolveResult1 === undefined) continue;
|
|
1004
|
-
return resolveResult1;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
return null;
|
|
1008
|
-
}
|
|
1009
|
-
if (target === null) {
|
|
1010
|
-
return null;
|
|
1011
|
-
}
|
|
1012
|
-
throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* @param {unknown} exports
|
|
1016
|
-
* @param {URL} packageJsonUrl
|
|
1017
|
-
* @param {URL} base
|
|
1018
|
-
* @returns {boolean}
|
|
1019
|
-
*/ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
1020
|
-
if (typeof exports === 'string' || Array.isArray(exports)) return true;
|
|
1021
|
-
if ((typeof exports === "undefined" ? "undefined" : _type_of(exports)) !== 'object' || exports === null) return false;
|
|
1022
|
-
var keys = Object.getOwnPropertyNames(exports);
|
|
1023
|
-
var isConditionalSugar = false;
|
|
1024
|
-
var i = 0;
|
|
1025
|
-
var keyIndex = -1;
|
|
1026
|
-
while(++keyIndex < keys.length){
|
|
1027
|
-
var key = keys[keyIndex];
|
|
1028
|
-
var currentIsConditionalSugar = key === '' || key[0] !== '.';
|
|
1029
|
-
if (i++ === 0) {
|
|
1030
|
-
isConditionalSugar = currentIsConditionalSugar;
|
|
1031
|
-
} else if (isConditionalSugar !== currentIsConditionalSugar) {
|
|
1032
|
-
throw new ERR_INVALID_PACKAGE_CONFIG(url.fileURLToPath(packageJsonUrl), 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.');
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
return isConditionalSugar;
|
|
1036
|
-
}
|
|
1037
|
-
/**
|
|
1038
|
-
* @param {string} match
|
|
1039
|
-
* @param {URL} pjsonUrl
|
|
1040
|
-
* @param {URL} base
|
|
1041
|
-
*/ function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
1042
|
-
// @ts-expect-error: apparently it does exist, TS.
|
|
1043
|
-
if (process.noDeprecation) {
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
var pjsonPath = url.fileURLToPath(pjsonUrl);
|
|
1047
|
-
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) return;
|
|
1048
|
-
emittedPackageWarnings.add(pjsonPath + '|' + match);
|
|
1049
|
-
process.emitWarning('Use of deprecated trailing slash pattern mapping "'.concat(match, '" in the ') + '"exports" field module resolution of the package at '.concat(pjsonPath).concat(base ? " imported from ".concat(url.fileURLToPath(base)) : '', '. Mapping specifiers ending in "/" is no longer supported.'), 'DeprecationWarning', 'DEP0155');
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* @param {URL} packageJsonUrl
|
|
1053
|
-
* @param {string} packageSubpath
|
|
1054
|
-
* @param {Record<string, unknown>} packageConfig
|
|
1055
|
-
* @param {URL} base
|
|
1056
|
-
* @param {Set<string> | undefined} conditions
|
|
1057
|
-
* @returns {URL}
|
|
1058
|
-
*/ function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
1059
|
-
var exports = packageConfig.exports;
|
|
1060
|
-
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
|
|
1061
|
-
exports = {
|
|
1062
|
-
'.': exports
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
if (own.call(exports, packageSubpath) && !packageSubpath.includes('*') && !packageSubpath.endsWith('/')) {
|
|
1066
|
-
// @ts-expect-error: indexable.
|
|
1067
|
-
var target = exports[packageSubpath];
|
|
1068
|
-
var resolveResult = resolvePackageTarget(packageJsonUrl, target, '', packageSubpath, base, false, false, false, conditions);
|
|
1069
|
-
if (resolveResult === null || resolveResult === undefined) {
|
|
1070
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
1071
|
-
}
|
|
1072
|
-
return resolveResult;
|
|
1073
|
-
}
|
|
1074
|
-
var bestMatch = '';
|
|
1075
|
-
var bestMatchSubpath = '';
|
|
1076
|
-
var keys = Object.getOwnPropertyNames(exports);
|
|
1077
|
-
var i = -1;
|
|
1078
|
-
while(++i < keys.length){
|
|
1079
|
-
var key = keys[i];
|
|
1080
|
-
var patternIndex = key.indexOf('*');
|
|
1081
|
-
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
1082
|
-
// When this reaches EOL, this can throw at the top of the whole function:
|
|
1083
|
-
//
|
|
1084
|
-
// if (StringPrototypeEndsWith(packageSubpath, '/'))
|
|
1085
|
-
// throwInvalidSubpath(packageSubpath)
|
|
1086
|
-
//
|
|
1087
|
-
// To match "imports" and the spec.
|
|
1088
|
-
if (packageSubpath.endsWith('/')) {
|
|
1089
|
-
emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
|
|
1090
|
-
}
|
|
1091
|
-
var patternTrailer = key.slice(patternIndex + 1);
|
|
1092
|
-
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf('*') === patternIndex) {
|
|
1093
|
-
bestMatch = key;
|
|
1094
|
-
bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
if (bestMatch) {
|
|
1099
|
-
// @ts-expect-error: indexable.
|
|
1100
|
-
var target1 = /** @type {unknown} */ exports[bestMatch];
|
|
1101
|
-
var resolveResult1 = resolvePackageTarget(packageJsonUrl, target1, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith('/'), conditions);
|
|
1102
|
-
if (resolveResult1 === null || resolveResult1 === undefined) {
|
|
1103
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
1104
|
-
}
|
|
1105
|
-
return resolveResult1;
|
|
1106
|
-
}
|
|
1107
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* @param {string} a
|
|
1111
|
-
* @param {string} b
|
|
1112
|
-
*/ function patternKeyCompare(a, b) {
|
|
1113
|
-
var aPatternIndex = a.indexOf('*');
|
|
1114
|
-
var bPatternIndex = b.indexOf('*');
|
|
1115
|
-
var baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
1116
|
-
var baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
1117
|
-
if (baseLengthA > baseLengthB) return -1;
|
|
1118
|
-
if (baseLengthB > baseLengthA) return 1;
|
|
1119
|
-
if (aPatternIndex === -1) return 1;
|
|
1120
|
-
if (bPatternIndex === -1) return -1;
|
|
1121
|
-
if (a.length > b.length) return -1;
|
|
1122
|
-
if (b.length > a.length) return 1;
|
|
1123
|
-
return 0;
|
|
1124
|
-
}
|
|
1125
|
-
/**
|
|
1126
|
-
* @param {string} name
|
|
1127
|
-
* @param {URL} base
|
|
1128
|
-
* @param {Set<string>} [conditions]
|
|
1129
|
-
* @returns {URL}
|
|
1130
|
-
*/ function packageImportsResolve(name, base, conditions) {
|
|
1131
|
-
if (name === '#' || name.startsWith('#/') || name.endsWith('/')) {
|
|
1132
|
-
var reason = 'is not a valid internal imports specifier name';
|
|
1133
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, url.fileURLToPath(base));
|
|
1134
|
-
}
|
|
1135
|
-
/** @type {URL | undefined} */ var packageJsonUrl;
|
|
1136
|
-
var packageConfig = getPackageScopeConfig(base);
|
|
1137
|
-
if (packageConfig.exists) {
|
|
1138
|
-
packageJsonUrl = url.pathToFileURL(packageConfig.pjsonPath);
|
|
1139
|
-
var imports = packageConfig.imports;
|
|
1140
|
-
if (imports) {
|
|
1141
|
-
if (own.call(imports, name) && !name.includes('*')) {
|
|
1142
|
-
var resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], '', name, base, false, true, false, conditions);
|
|
1143
|
-
if (resolveResult !== null && resolveResult !== undefined) {
|
|
1144
|
-
return resolveResult;
|
|
1145
|
-
}
|
|
1146
|
-
} else {
|
|
1147
|
-
var bestMatch = '';
|
|
1148
|
-
var bestMatchSubpath = '';
|
|
1149
|
-
var keys = Object.getOwnPropertyNames(imports);
|
|
1150
|
-
var i = -1;
|
|
1151
|
-
while(++i < keys.length){
|
|
1152
|
-
var key = keys[i];
|
|
1153
|
-
var patternIndex = key.indexOf('*');
|
|
1154
|
-
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
1155
|
-
var patternTrailer = key.slice(patternIndex + 1);
|
|
1156
|
-
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf('*') === patternIndex) {
|
|
1157
|
-
bestMatch = key;
|
|
1158
|
-
bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
if (bestMatch) {
|
|
1163
|
-
var target = imports[bestMatch];
|
|
1164
|
-
var resolveResult1 = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
|
|
1165
|
-
if (resolveResult1 !== null && resolveResult1 !== undefined) {
|
|
1166
|
-
return resolveResult1;
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
throw importNotDefined(name, packageJsonUrl, base);
|
|
1173
|
-
}
|
|
1174
|
-
/**
|
|
1175
|
-
* @param {string} specifier
|
|
1176
|
-
* @param {URL} base
|
|
1177
|
-
*/ function parsePackageName(specifier, base) {
|
|
1178
|
-
var separatorIndex = specifier.indexOf('/');
|
|
1179
|
-
var validPackageName = true;
|
|
1180
|
-
var isScoped = false;
|
|
1181
|
-
if (specifier[0] === '@') {
|
|
1182
|
-
isScoped = true;
|
|
1183
|
-
if (separatorIndex === -1 || specifier.length === 0) {
|
|
1184
|
-
validPackageName = false;
|
|
1185
|
-
} else {
|
|
1186
|
-
separatorIndex = specifier.indexOf('/', separatorIndex + 1);
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
var packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
1190
|
-
// Package name cannot have leading . and cannot have percent-encoding or
|
|
1191
|
-
// \\ separators.
|
|
1192
|
-
if (invalidPackageNameRegEx.exec(packageName) !== null) {
|
|
1193
|
-
validPackageName = false;
|
|
1194
|
-
}
|
|
1195
|
-
if (!validPackageName) {
|
|
1196
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(specifier, 'is not a valid package name', url.fileURLToPath(base));
|
|
1197
|
-
}
|
|
1198
|
-
var packageSubpath = '.' + (separatorIndex === -1 ? '' : specifier.slice(separatorIndex));
|
|
1199
|
-
return {
|
|
1200
|
-
packageName: packageName,
|
|
1201
|
-
packageSubpath: packageSubpath,
|
|
1202
|
-
isScoped: isScoped
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* @param {string} specifier
|
|
1207
|
-
* @param {URL} base
|
|
1208
|
-
* @param {Set<string> | undefined} conditions
|
|
1209
|
-
* @returns {URL}
|
|
1210
|
-
*/ function packageResolve(specifier, base, conditions) {
|
|
1211
|
-
if (module$1.builtinModules.includes(specifier)) {
|
|
1212
|
-
return new url.URL('node:' + specifier);
|
|
1213
|
-
}
|
|
1214
|
-
var _parsePackageName = parsePackageName(specifier, base), packageName = _parsePackageName.packageName, packageSubpath = _parsePackageName.packageSubpath, isScoped = _parsePackageName.isScoped;
|
|
1215
|
-
// ResolveSelf
|
|
1216
|
-
var packageConfig = getPackageScopeConfig(base);
|
|
1217
|
-
// Can’t test.
|
|
1218
|
-
/* c8 ignore next 16 */ if (packageConfig.exists) {
|
|
1219
|
-
var packageJsonUrl = url.pathToFileURL(packageConfig.pjsonPath);
|
|
1220
|
-
if (packageConfig.name === packageName && packageConfig.exports !== undefined && packageConfig.exports !== null) {
|
|
1221
|
-
return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
var packageJsonUrl1 = new url.URL('./node_modules/' + packageName + '/package.json', base);
|
|
1225
|
-
var packageJsonPath = url.fileURLToPath(packageJsonUrl1);
|
|
1226
|
-
/** @type {string} */ var lastPath;
|
|
1227
|
-
do {
|
|
1228
|
-
var stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
1229
|
-
if (!stat || !stat.isDirectory()) {
|
|
1230
|
-
lastPath = packageJsonPath;
|
|
1231
|
-
packageJsonUrl1 = new url.URL((isScoped ? '../../../../node_modules/' : '../../../node_modules/') + packageName + '/package.json', packageJsonUrl1);
|
|
1232
|
-
packageJsonPath = url.fileURLToPath(packageJsonUrl1);
|
|
1233
|
-
continue;
|
|
1234
|
-
}
|
|
1235
|
-
// Package match.
|
|
1236
|
-
var packageConfig1 = read(packageJsonPath, {
|
|
1237
|
-
base: base,
|
|
1238
|
-
specifier: specifier
|
|
1239
|
-
});
|
|
1240
|
-
if (packageConfig1.exports !== undefined && packageConfig1.exports !== null) {
|
|
1241
|
-
return packageExportsResolve(packageJsonUrl1, packageSubpath, packageConfig1, base, conditions);
|
|
1242
|
-
}
|
|
1243
|
-
if (packageSubpath === '.') {
|
|
1244
|
-
return legacyMainResolve(packageJsonUrl1, packageConfig1, base);
|
|
1245
|
-
}
|
|
1246
|
-
return new url.URL(packageSubpath, packageJsonUrl1);
|
|
1247
|
-
// Cross-platform root check.
|
|
1248
|
-
}while (packageJsonPath.length !== lastPath.length);
|
|
1249
|
-
throw new ERR_MODULE_NOT_FOUND(packageName, url.fileURLToPath(base), false);
|
|
1250
|
-
}
|
|
1251
|
-
/**
|
|
1252
|
-
* @param {string} specifier
|
|
1253
|
-
* @returns {boolean}
|
|
1254
|
-
*/ function isRelativeSpecifier(specifier) {
|
|
1255
|
-
if (specifier[0] === '.') {
|
|
1256
|
-
if (specifier.length === 1 || specifier[1] === '/') return true;
|
|
1257
|
-
if (specifier[1] === '.' && (specifier.length === 2 || specifier[2] === '/')) {
|
|
1258
|
-
return true;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
return false;
|
|
1262
|
-
}
|
|
1263
|
-
/**
|
|
1264
|
-
* @param {string} specifier
|
|
1265
|
-
* @returns {boolean}
|
|
1266
|
-
*/ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
1267
|
-
if (specifier === '') return false;
|
|
1268
|
-
if (specifier[0] === '/') return true;
|
|
1269
|
-
return isRelativeSpecifier(specifier);
|
|
1270
|
-
}
|
|
1271
|
-
/**
|
|
1272
|
-
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
1273
|
-
* sync and slightly lower-level than `resolve`).
|
|
1274
|
-
*
|
|
1275
|
-
* @param {string} specifier
|
|
1276
|
-
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
1277
|
-
* @param {URL} base
|
|
1278
|
-
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
1279
|
-
* @param {Set<string>} [conditions]
|
|
1280
|
-
* Conditions.
|
|
1281
|
-
* @param {boolean} [preserveSymlinks]
|
|
1282
|
-
* Keep symlinks instead of resolving them.
|
|
1283
|
-
* @returns {URL}
|
|
1284
|
-
* A URL object to the found thing.
|
|
1285
|
-
*/ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
1286
|
-
// Note: The Node code supports `base` as a string (in this internal API) too,
|
|
1287
|
-
// we don’t.
|
|
1288
|
-
var protocol = base.protocol;
|
|
1289
|
-
var isData = protocol === 'data:';
|
|
1290
|
-
var isRemote = isData || protocol === 'http:' || protocol === 'https:';
|
|
1291
|
-
// Order swapped from spec for minor perf gain.
|
|
1292
|
-
// Ok since relative URLs cannot parse as URLs.
|
|
1293
|
-
/** @type {URL | undefined} */ var resolved;
|
|
1294
|
-
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
1295
|
-
try {
|
|
1296
|
-
resolved = new url.URL(specifier, base);
|
|
1297
|
-
} catch (error_) {
|
|
1298
|
-
var error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1299
|
-
error.cause = error_;
|
|
1300
|
-
throw error;
|
|
1301
|
-
}
|
|
1302
|
-
} else if (protocol === 'file:' && specifier[0] === '#') {
|
|
1303
|
-
resolved = packageImportsResolve(specifier, base, conditions);
|
|
1304
|
-
} else {
|
|
1305
|
-
try {
|
|
1306
|
-
resolved = new url.URL(specifier);
|
|
1307
|
-
} catch (error_) {
|
|
1308
|
-
// Note: actual code uses `canBeRequiredWithoutScheme`.
|
|
1309
|
-
if (isRemote && !module$1.builtinModules.includes(specifier)) {
|
|
1310
|
-
var error1 = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1311
|
-
error1.cause = error_;
|
|
1312
|
-
throw error1;
|
|
1313
|
-
}
|
|
1314
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
assert(resolved !== undefined, 'expected to be defined');
|
|
1318
|
-
if (resolved.protocol !== 'file:') {
|
|
1319
|
-
return resolved;
|
|
1320
|
-
}
|
|
1321
|
-
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* @param {string} specifier
|
|
1325
|
-
* @param {URL | undefined} parsed
|
|
1326
|
-
* @param {URL | undefined} parsedParentURL
|
|
1327
|
-
*/ function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {
|
|
1328
|
-
if (parsedParentURL) {
|
|
1329
|
-
// Avoid accessing the `protocol` property due to the lazy getters.
|
|
1330
|
-
var parentProtocol = parsedParentURL.protocol;
|
|
1331
|
-
if (parentProtocol === 'http:' || parentProtocol === 'https:') {
|
|
1332
|
-
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
1333
|
-
// Avoid accessing the `protocol` property due to the lazy getters.
|
|
1334
|
-
var parsedProtocol = parsed === null || parsed === void 0 ? void 0 : parsed.protocol;
|
|
1335
|
-
// `data:` and `blob:` disallowed due to allowing file: access via
|
|
1336
|
-
// indirection
|
|
1337
|
-
if (parsedProtocol && parsedProtocol !== 'https:' && parsedProtocol !== 'http:') {
|
|
1338
|
-
throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'remote imports cannot import from a local location.');
|
|
1339
|
-
}
|
|
1340
|
-
return {
|
|
1341
|
-
url: (parsed === null || parsed === void 0 ? void 0 : parsed.href) || ''
|
|
1342
|
-
};
|
|
1343
|
-
}
|
|
1344
|
-
if (module$1.builtinModules.includes(specifier)) {
|
|
1345
|
-
throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'remote imports cannot import from a local location.');
|
|
1346
|
-
}
|
|
1347
|
-
throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'only relative and absolute specifiers are supported.');
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
// Note: this is from:
|
|
1352
|
-
// <https://github.com/nodejs/node/blob/3e74590/lib/internal/url.js#L687>
|
|
1353
|
-
/**
|
|
1354
|
-
* Checks if a value has the shape of a WHATWG URL object.
|
|
1355
|
-
*
|
|
1356
|
-
* Using a symbol or instanceof would not be able to recognize URL objects
|
|
1357
|
-
* coming from other implementations (e.g. in Electron), so instead we are
|
|
1358
|
-
* checking some well known properties for a lack of a better test.
|
|
1359
|
-
*
|
|
1360
|
-
* We use `href` and `protocol` as they are the only properties that are
|
|
1361
|
-
* easy to retrieve and calculate due to the lazy nature of the getters.
|
|
1362
|
-
*
|
|
1363
|
-
* @template {unknown} Value
|
|
1364
|
-
* @param {Value} self
|
|
1365
|
-
* @returns {Value is URL}
|
|
1366
|
-
*/ function isURL(self) {
|
|
1367
|
-
return Boolean(self && (typeof self === "undefined" ? "undefined" : _type_of(self)) === 'object' && 'href' in self && typeof self.href === 'string' && 'protocol' in self && typeof self.protocol === 'string' && self.href && self.protocol);
|
|
1368
|
-
}
|
|
1369
|
-
/**
|
|
1370
|
-
* Validate user-input in `context` supplied by a custom loader.
|
|
1371
|
-
*
|
|
1372
|
-
* @param {unknown} parentURL
|
|
1373
|
-
* @returns {asserts parentURL is URL | string | undefined}
|
|
1374
|
-
*/ function throwIfInvalidParentURL(parentURL) {
|
|
1375
|
-
if (parentURL === undefined) {
|
|
1376
|
-
return; // Main entry point, so no parent
|
|
1377
|
-
}
|
|
1378
|
-
if (typeof parentURL !== 'string' && !isURL(parentURL)) {
|
|
1379
|
-
throw new codes.ERR_INVALID_ARG_TYPE('parentURL', [
|
|
1380
|
-
'string',
|
|
1381
|
-
'URL'
|
|
1382
|
-
], parentURL);
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* @param {string} specifier
|
|
1387
|
-
* @param {{parentURL?: string, conditions?: Array<string>}} context
|
|
1388
|
-
* @returns {{url: string, format?: string | null}}
|
|
1389
|
-
*/ function defaultResolve(specifier) {
|
|
1390
|
-
var context = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1391
|
-
var parentURL = context.parentURL;
|
|
1392
|
-
assert(parentURL !== undefined, 'expected `parentURL` to be defined');
|
|
1393
|
-
throwIfInvalidParentURL(parentURL);
|
|
1394
|
-
/** @type {URL | undefined} */ var parsedParentURL;
|
|
1395
|
-
if (parentURL) {
|
|
1396
|
-
try {
|
|
1397
|
-
parsedParentURL = new url.URL(parentURL);
|
|
1398
|
-
} catch (e) {
|
|
1399
|
-
// Ignore exception
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
/** @type {URL | undefined} */ var parsed;
|
|
1403
|
-
/** @type {string | undefined} */ var protocol;
|
|
1404
|
-
try {
|
|
1405
|
-
parsed = shouldBeTreatedAsRelativeOrAbsolutePath(specifier) ? new url.URL(specifier, parsedParentURL) : new url.URL(specifier);
|
|
1406
|
-
// Avoid accessing the `protocol` property due to the lazy getters.
|
|
1407
|
-
protocol = parsed.protocol;
|
|
1408
|
-
if (protocol === 'data:') {
|
|
1409
|
-
return {
|
|
1410
|
-
url: parsed.href,
|
|
1411
|
-
format: null
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
} catch (e) {
|
|
1415
|
-
// Ignore exception
|
|
1416
|
-
}
|
|
1417
|
-
// There are multiple deep branches that can either throw or return; instead
|
|
1418
|
-
// of duplicating that deeply nested logic for the possible returns, DRY and
|
|
1419
|
-
// check for a return. This seems the least gnarly.
|
|
1420
|
-
var maybeReturn = checkIfDisallowedImport(specifier, parsed, parsedParentURL);
|
|
1421
|
-
if (maybeReturn) return maybeReturn;
|
|
1422
|
-
// This must come after checkIfDisallowedImport
|
|
1423
|
-
if (protocol === undefined && parsed) {
|
|
1424
|
-
protocol = parsed.protocol;
|
|
1425
|
-
}
|
|
1426
|
-
if (protocol === 'node:') {
|
|
1427
|
-
return {
|
|
1428
|
-
url: specifier
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
// This must come after checkIfDisallowedImport
|
|
1432
|
-
if (parsed && parsed.protocol === 'node:') return {
|
|
1433
|
-
url: specifier
|
|
1434
|
-
};
|
|
1435
|
-
var conditions = getConditionsSet(context.conditions);
|
|
1436
|
-
var url$1 = moduleResolve(specifier, new url.URL(parentURL), conditions, false);
|
|
1437
|
-
return {
|
|
1438
|
-
// Do NOT cast `url` to a string: that will work even when there are real
|
|
1439
|
-
// problems, silencing them
|
|
1440
|
-
url: url$1.href,
|
|
1441
|
-
format: defaultGetFormatWithoutErrors(url$1, {
|
|
1442
|
-
parentURL: parentURL
|
|
1443
|
-
})
|
|
1444
|
-
};
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
/**
|
|
1448
|
-
* Match `import.meta.resolve` except that `parent` is required (you can pass
|
|
1449
|
-
* `import.meta.url`).
|
|
1450
|
-
*
|
|
1451
|
-
* @param {string} specifier
|
|
1452
|
-
* The module specifier to resolve relative to parent
|
|
1453
|
-
* (`/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`,
|
|
1454
|
-
* etc).
|
|
1455
|
-
* @param {string} parent
|
|
1456
|
-
* The absolute parent module URL to resolve from.
|
|
1457
|
-
* You must pass `import.meta.url` or something else.
|
|
1458
|
-
* @returns {string}
|
|
1459
|
-
* Returns a string to a full `file:`, `data:`, or `node:` URL
|
|
1460
|
-
* to the found thing.
|
|
1461
|
-
*/ function resolve(specifier, parent) {
|
|
1462
|
-
if (!parent) {
|
|
1463
|
-
throw new Error('Please pass `parent`: `import-meta-resolve` cannot ponyfill that');
|
|
1464
|
-
}
|
|
1465
|
-
try {
|
|
1466
|
-
return defaultResolve(specifier, {
|
|
1467
|
-
parentURL: parent
|
|
1468
|
-
}).url;
|
|
1469
|
-
} catch (error) {
|
|
1470
|
-
// See: <https://github.com/nodejs/node/blob/45f5c9b/lib/internal/modules/esm/initialize_import_meta.js#L34>
|
|
1471
|
-
var exception = /** @type {ErrnoException} */ error;
|
|
1472
|
-
if ((exception.code === 'ERR_UNSUPPORTED_DIR_IMPORT' || exception.code === 'ERR_MODULE_NOT_FOUND') && typeof exception.url === 'string') {
|
|
1473
|
-
return exception.url;
|
|
1474
|
-
}
|
|
1475
|
-
throw error;
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
exports.moduleResolve = moduleResolve;
|
|
1480
|
-
exports.resolve = resolve;
|
|
1481
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) { }; module.exports = exports.default; }
|