df54938d66a0c2340df787d14fb576fc965cbe20b096adc60d62d4e37ea7f39ebd64bb92f80b166bb04f5c062d033892a2b72e4e078cc7cf050a0e10ec61fd 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.moduleResolve = moduleResolve;
  6. exports.resolve = resolve;
  7. function _assert() {
  8. const data = require("assert");
  9. _assert = function () {
  10. return data;
  11. };
  12. return data;
  13. }
  14. function _fs() {
  15. const data = _interopRequireWildcard(require("fs"), true);
  16. _fs = function () {
  17. return data;
  18. };
  19. return data;
  20. }
  21. function _process() {
  22. const data = require("process");
  23. _process = function () {
  24. return data;
  25. };
  26. return data;
  27. }
  28. function _url() {
  29. const data = require("url");
  30. _url = function () {
  31. return data;
  32. };
  33. return data;
  34. }
  35. function _path() {
  36. const data = require("path");
  37. _path = function () {
  38. return data;
  39. };
  40. return data;
  41. }
  42. function _module() {
  43. const data = require("module");
  44. _module = function () {
  45. return data;
  46. };
  47. return data;
  48. }
  49. function _v() {
  50. const data = require("v8");
  51. _v = function () {
  52. return data;
  53. };
  54. return data;
  55. }
  56. function _util() {
  57. const data = require("util");
  58. _util = function () {
  59. return data;
  60. };
  61. return data;
  62. }
  63. function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
  64. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
  65. const own$1 = {}.hasOwnProperty;
  66. const classRegExp = /^([A-Z][a-z\d]*)+$/;
  67. const kTypes = new Set(['string', 'function', 'number', 'object', 'Function', 'Object', 'boolean', 'bigint', 'symbol']);
  68. const codes = {};
  69. function formatList(array, type = 'and') {
  70. return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(', ')}, ${type} ${array[array.length - 1]}`;
  71. }
  72. const messages = new Map();
  73. const nodeInternalPrefix = '__node_internal_';
  74. let userStackTraceLimit;
  75. codes.ERR_INVALID_ARG_TYPE = createError('ERR_INVALID_ARG_TYPE', (name, expected, actual) => {
  76. _assert()(typeof name === 'string', "'name' must be a string");
  77. if (!Array.isArray(expected)) {
  78. expected = [expected];
  79. }
  80. let message = 'The ';
  81. if (name.endsWith(' argument')) {
  82. message += `${name} `;
  83. } else {
  84. const type = name.includes('.') ? 'property' : 'argument';
  85. message += `"${name}" ${type} `;
  86. }
  87. message += 'must be ';
  88. const types = [];
  89. const instances = [];
  90. const other = [];
  91. for (const value of expected) {
  92. _assert()(typeof value === 'string', 'All expected entries have to be of type string');
  93. if (kTypes.has(value)) {
  94. types.push(value.toLowerCase());
  95. } else if (classRegExp.exec(value) === null) {
  96. _assert()(value !== 'object', 'The value "object" should be written as "Object"');
  97. other.push(value);
  98. } else {
  99. instances.push(value);
  100. }
  101. }
  102. if (instances.length > 0) {
  103. const pos = types.indexOf('object');
  104. if (pos !== -1) {
  105. types.slice(pos, 1);
  106. instances.push('Object');
  107. }
  108. }
  109. if (types.length > 0) {
  110. message += `${types.length > 1 ? 'one of type' : 'of type'} ${formatList(types, 'or')}`;
  111. if (instances.length > 0 || other.length > 0) message += ' or ';
  112. }
  113. if (instances.length > 0) {
  114. message += `an instance of ${formatList(instances, 'or')}`;
  115. if (other.length > 0) message += ' or ';
  116. }
  117. if (other.length > 0) {
  118. if (other.length > 1) {
  119. message += `one of ${formatList(other, 'or')}`;
  120. } else {
  121. if (other[0].toLowerCase() !== other[0]) message += 'an ';
  122. message += `${other[0]}`;
  123. }
  124. }
  125. message += `. Received ${determineSpecificType(actual)}`;
  126. return message;
  127. }, TypeError);
  128. codes.ERR_INVALID_MODULE_SPECIFIER = createError('ERR_INVALID_MODULE_SPECIFIER', (request, reason, base = undefined) => {
  129. return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ''}`;
  130. }, TypeError);
  131. codes.ERR_INVALID_PACKAGE_CONFIG = createError('ERR_INVALID_PACKAGE_CONFIG', (path, base, message) => {
  132. return `Invalid package config ${path}${base ? ` while importing ${base}` : ''}${message ? `. ${message}` : ''}`;
  133. }, Error);
  134. codes.ERR_INVALID_PACKAGE_TARGET = createError('ERR_INVALID_PACKAGE_TARGET', (packagePath, key, target, isImport = false, base = undefined) => {
  135. const relatedError = typeof target === 'string' && !isImport && target.length > 0 && !target.startsWith('./');
  136. if (key === '.') {
  137. _assert()(isImport === false);
  138. 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 "./"' : ''}`;
  139. }
  140. 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 "./"' : ''}`;
  141. }, Error);
  142. codes.ERR_MODULE_NOT_FOUND = createError('ERR_MODULE_NOT_FOUND', (path, base, exactUrl = false) => {
  143. return `Cannot find ${exactUrl ? 'module' : 'package'} '${path}' imported from ${base}`;
  144. }, Error);
  145. codes.ERR_NETWORK_IMPORT_DISALLOWED = createError('ERR_NETWORK_IMPORT_DISALLOWED', "import of '%s' by %s is not supported: %s", Error);
  146. codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError('ERR_PACKAGE_IMPORT_NOT_DEFINED', (specifier, packagePath, base) => {
  147. return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath}package.json` : ''} imported from ${base}`;
  148. }, TypeError);
  149. codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError('ERR_PACKAGE_PATH_NOT_EXPORTED', (packagePath, subpath, base = undefined) => {
  150. if (subpath === '.') return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ''}`;
  151. return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ''}`;
  152. }, Error);
  153. codes.ERR_UNSUPPORTED_DIR_IMPORT = createError('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " + 'resolving ES modules imported from %s', Error);
  154. 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);
  155. codes.ERR_UNKNOWN_FILE_EXTENSION = createError('ERR_UNKNOWN_FILE_EXTENSION', (extension, path) => {
  156. return `Unknown file extension "${extension}" for ${path}`;
  157. }, TypeError);
  158. codes.ERR_INVALID_ARG_VALUE = createError('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
  159. let inspected = (0, _util().inspect)(value);
  160. if (inspected.length > 128) {
  161. inspected = `${inspected.slice(0, 128)}...`;
  162. }
  163. const type = name.includes('.') ? 'property' : 'argument';
  164. return `The ${type} '${name}' ${reason}. Received ${inspected}`;
  165. }, TypeError);
  166. function createError(sym, value, constructor) {
  167. messages.set(sym, value);
  168. return makeNodeErrorWithCode(constructor, sym);
  169. }
  170. function makeNodeErrorWithCode(Base, key) {
  171. return NodeError;
  172. function NodeError(...parameters) {
  173. const limit = Error.stackTraceLimit;
  174. if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
  175. const error = new Base();
  176. if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
  177. const message = getMessage(key, parameters, error);
  178. Object.defineProperties(error, {
  179. message: {
  180. value: message,
  181. enumerable: false,
  182. writable: true,
  183. configurable: true
  184. },
  185. toString: {
  186. value() {
  187. return `${this.name} [${key}]: ${this.message}`;
  188. },
  189. enumerable: false,
  190. writable: true,
  191. configurable: true
  192. }
  193. });
  194. captureLargerStackTrace(error);
  195. error.code = key;
  196. return error;
  197. }
  198. }
  199. function isErrorStackTraceLimitWritable() {
  200. try {
  201. if (_v().startupSnapshot.isBuildingSnapshot()) {
  202. return false;
  203. }
  204. } catch (_unused) {}
  205. const desc = Object.getOwnPropertyDescriptor(Error, 'stackTraceLimit');
  206. if (desc === undefined) {
  207. return Object.isExtensible(Error);
  208. }
  209. return own$1.call(desc, 'writable') && desc.writable !== undefined ? desc.writable : desc.set !== undefined;
  210. }
  211. function hideStackFrames(wrappedFunction) {
  212. const hidden = nodeInternalPrefix + wrappedFunction.name;
  213. Object.defineProperty(wrappedFunction, 'name', {
  214. value: hidden
  215. });
  216. return wrappedFunction;
  217. }
  218. const captureLargerStackTrace = hideStackFrames(function (error) {
  219. const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
  220. if (stackTraceLimitIsWritable) {
  221. userStackTraceLimit = Error.stackTraceLimit;
  222. Error.stackTraceLimit = Number.POSITIVE_INFINITY;
  223. }
  224. Error.captureStackTrace(error);
  225. if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
  226. return error;
  227. });
  228. function getMessage(key, parameters, self) {
  229. const message = messages.get(key);
  230. _assert()(message !== undefined, 'expected `message` to be found');
  231. if (typeof message === 'function') {
  232. _assert()(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not ` + `match the required ones (${message.length}).`);
  233. return Reflect.apply(message, self, parameters);
  234. }
  235. const regex = /%[dfijoOs]/g;
  236. let expectedLength = 0;
  237. while (regex.exec(message) !== null) expectedLength++;
  238. _assert()(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not ` + `match the required ones (${expectedLength}).`);
  239. if (parameters.length === 0) return message;
  240. parameters.unshift(message);
  241. return Reflect.apply(_util().format, null, parameters);
  242. }
  243. function determineSpecificType(value) {
  244. if (value === null || value === undefined) {
  245. return String(value);
  246. }
  247. if (typeof value === 'function' && value.name) {
  248. return `function ${value.name}`;
  249. }
  250. if (typeof value === 'object') {
  251. if (value.constructor && value.constructor.name) {
  252. return `an instance of ${value.constructor.name}`;
  253. }
  254. return `${(0, _util().inspect)(value, {
  255. depth: -1
  256. })}`;
  257. }
  258. let inspected = (0, _util().inspect)(value, {
  259. colors: false
  260. });
  261. if (inspected.length > 28) {
  262. inspected = `${inspected.slice(0, 25)}...`;
  263. }
  264. return `type ${typeof value} (${inspected})`;
  265. }
  266. const hasOwnProperty$1 = {}.hasOwnProperty;
  267. const {
  268. ERR_INVALID_PACKAGE_CONFIG: ERR_INVALID_PACKAGE_CONFIG$1
  269. } = codes;
  270. const cache = new Map();
  271. function read(jsonPath, {
  272. base,
  273. specifier
  274. }) {
  275. const existing = cache.get(jsonPath);
  276. if (existing) {
  277. return existing;
  278. }
  279. let string;
  280. try {
  281. string = _fs().default.readFileSync(_path().toNamespacedPath(jsonPath), 'utf8');
  282. } catch (error) {
  283. const exception = error;
  284. if (exception.code !== 'ENOENT') {
  285. throw exception;
  286. }
  287. }
  288. const result = {
  289. exists: false,
  290. pjsonPath: jsonPath,
  291. main: undefined,
  292. name: undefined,
  293. type: 'none',
  294. exports: undefined,
  295. imports: undefined
  296. };
  297. if (string !== undefined) {
  298. let parsed;
  299. try {
  300. parsed = JSON.parse(string);
  301. } catch (error_) {
  302. const cause = error_;
  303. const error = new ERR_INVALID_PACKAGE_CONFIG$1(jsonPath, (base ? `"${specifier}" from ` : '') + (0, _url().fileURLToPath)(base || specifier), cause.message);
  304. error.cause = cause;
  305. throw error;
  306. }
  307. result.exists = true;
  308. if (hasOwnProperty$1.call(parsed, 'name') && typeof parsed.name === 'string') {
  309. result.name = parsed.name;
  310. }
  311. if (hasOwnProperty$1.call(parsed, 'main') && typeof parsed.main === 'string') {
  312. result.main = parsed.main;
  313. }
  314. if (hasOwnProperty$1.call(parsed, 'exports')) {
  315. result.exports = parsed.exports;
  316. }
  317. if (hasOwnProperty$1.call(parsed, 'imports')) {
  318. result.imports = parsed.imports;
  319. }
  320. if (hasOwnProperty$1.call(parsed, 'type') && (parsed.type === 'commonjs' || parsed.type === 'module')) {
  321. result.type = parsed.type;
  322. }
  323. }
  324. cache.set(jsonPath, result);
  325. return result;
  326. }
  327. function getPackageScopeConfig(resolved) {
  328. let packageJSONUrl = new URL('package.json', resolved);
  329. while (true) {
  330. const packageJSONPath = packageJSONUrl.pathname;
  331. if (packageJSONPath.endsWith('node_modules/package.json')) {
  332. break;
  333. }
  334. const packageConfig = read((0, _url().fileURLToPath)(packageJSONUrl), {
  335. specifier: resolved
  336. });
  337. if (packageConfig.exists) {
  338. return packageConfig;
  339. }
  340. const lastPackageJSONUrl = packageJSONUrl;
  341. packageJSONUrl = new URL('../package.json', packageJSONUrl);
  342. if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) {
  343. break;
  344. }
  345. }
  346. const packageJSONPath = (0, _url().fileURLToPath)(packageJSONUrl);
  347. return {
  348. pjsonPath: packageJSONPath,
  349. exists: false,
  350. type: 'none'
  351. };
  352. }
  353. function getPackageType(url) {
  354. return getPackageScopeConfig(url).type;
  355. }
  356. const {
  357. ERR_UNKNOWN_FILE_EXTENSION
  358. } = codes;
  359. const hasOwnProperty = {}.hasOwnProperty;
  360. const extensionFormatMap = {
  361. __proto__: null,
  362. '.cjs': 'commonjs',
  363. '.js': 'module',
  364. '.json': 'json',
  365. '.mjs': 'module'
  366. };
  367. function mimeToFormat(mime) {
  368. if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return 'module';
  369. if (mime === 'application/json') return 'json';
  370. return null;
  371. }
  372. const protocolHandlers = {
  373. __proto__: null,
  374. 'data:': getDataProtocolModuleFormat,
  375. 'file:': getFileProtocolModuleFormat,
  376. 'http:': getHttpProtocolModuleFormat,
  377. 'https:': getHttpProtocolModuleFormat,
  378. 'node:'() {
  379. return 'builtin';
  380. }
  381. };
  382. function getDataProtocolModuleFormat(parsed) {
  383. const {
  384. 1: mime
  385. } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [null, null, null];
  386. return mimeToFormat(mime);
  387. }
  388. function extname(url) {
  389. const pathname = url.pathname;
  390. let index = pathname.length;
  391. while (index--) {
  392. const code = pathname.codePointAt(index);
  393. if (code === 47) {
  394. return '';
  395. }
  396. if (code === 46) {
  397. return pathname.codePointAt(index - 1) === 47 ? '' : pathname.slice(index);
  398. }
  399. }
  400. return '';
  401. }
  402. function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
  403. const value = extname(url);
  404. if (value === '.js') {
  405. const packageType = getPackageType(url);
  406. if (packageType !== 'none') {
  407. return packageType;
  408. }
  409. return 'commonjs';
  410. }
  411. if (value === '') {
  412. const packageType = getPackageType(url);
  413. if (packageType === 'none' || packageType === 'commonjs') {
  414. return 'commonjs';
  415. }
  416. return 'module';
  417. }
  418. const format = extensionFormatMap[value];
  419. if (format) return format;
  420. if (ignoreErrors) {
  421. return undefined;
  422. }
  423. const filepath = (0, _url().fileURLToPath)(url);
  424. throw new ERR_UNKNOWN_FILE_EXTENSION(value, filepath);
  425. }
  426. function getHttpProtocolModuleFormat() {}
  427. function defaultGetFormatWithoutErrors(url, context) {
  428. const protocol = url.protocol;
  429. if (!hasOwnProperty.call(protocolHandlers, protocol)) {
  430. return null;
  431. }
  432. return protocolHandlers[protocol](url, context, true) || null;
  433. }
  434. const {
  435. ERR_INVALID_ARG_VALUE
  436. } = codes;
  437. const DEFAULT_CONDITIONS = Object.freeze(['node', 'import']);
  438. const DEFAULT_CONDITIONS_SET = new Set(DEFAULT_CONDITIONS);
  439. function getDefaultConditions() {
  440. return DEFAULT_CONDITIONS;
  441. }
  442. function getDefaultConditionsSet() {
  443. return DEFAULT_CONDITIONS_SET;
  444. }
  445. function getConditionsSet(conditions) {
  446. if (conditions !== undefined && conditions !== getDefaultConditions()) {
  447. if (!Array.isArray(conditions)) {
  448. throw new ERR_INVALID_ARG_VALUE('conditions', conditions, 'expected an array');
  449. }
  450. return new Set(conditions);
  451. }
  452. return getDefaultConditionsSet();
  453. }
  454. const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
  455. const {
  456. ERR_NETWORK_IMPORT_DISALLOWED,
  457. ERR_INVALID_MODULE_SPECIFIER,
  458. ERR_INVALID_PACKAGE_CONFIG,
  459. ERR_INVALID_PACKAGE_TARGET,
  460. ERR_MODULE_NOT_FOUND,
  461. ERR_PACKAGE_IMPORT_NOT_DEFINED,
  462. ERR_PACKAGE_PATH_NOT_EXPORTED,
  463. ERR_UNSUPPORTED_DIR_IMPORT,
  464. ERR_UNSUPPORTED_RESOLVE_REQUEST
  465. } = codes;
  466. const own = {}.hasOwnProperty;
  467. const 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;
  468. const 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;
  469. const invalidPackageNameRegEx = /^\.|%|\\/;
  470. const patternRegEx = /\*/g;
  471. const encodedSeparatorRegEx = /%2f|%5c/i;
  472. const emittedPackageWarnings = new Set();
  473. const doubleSlashRegEx = /[/\\]{2}/;
  474. function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
  475. if (_process().noDeprecation) {
  476. return;
  477. }
  478. const pjsonPath = (0, _url().fileURLToPath)(packageJsonUrl);
  479. const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
  480. _process().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 ${(0, _url().fileURLToPath)(base)}` : ''}.`, 'DeprecationWarning', 'DEP0166');
  481. }
  482. function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
  483. if (_process().noDeprecation) {
  484. return;
  485. }
  486. const format = defaultGetFormatWithoutErrors(url, {
  487. parentURL: base.href
  488. });
  489. if (format !== 'module') return;
  490. const urlPath = (0, _url().fileURLToPath)(url.href);
  491. const packagePath = (0, _url().fileURLToPath)(new (_url().URL)('.', packageJsonUrl));
  492. const basePath = (0, _url().fileURLToPath)(base);
  493. if (!main) {
  494. _process().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}.\nDefault "index" lookups for the main are deprecated for ES modules.`, 'DeprecationWarning', 'DEP0151');
  495. } else if (_path().resolve(packagePath, main) !== urlPath) {
  496. _process().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}.\n Automatic extension resolution of the "main" field is ` + 'deprecated for ES modules.', 'DeprecationWarning', 'DEP0151');
  497. }
  498. }
  499. function tryStatSync(path) {
  500. try {
  501. return (0, _fs().statSync)(path);
  502. } catch (_unused2) {}
  503. }
  504. function fileExists(url) {
  505. const stats = (0, _fs().statSync)(url, {
  506. throwIfNoEntry: false
  507. });
  508. const isFile = stats ? stats.isFile() : undefined;
  509. return isFile === null || isFile === undefined ? false : isFile;
  510. }
  511. function legacyMainResolve(packageJsonUrl, packageConfig, base) {
  512. let guess;
  513. if (packageConfig.main !== undefined) {
  514. guess = new (_url().URL)(packageConfig.main, packageJsonUrl);
  515. if (fileExists(guess)) return guess;
  516. const tries = [`./${packageConfig.main}.js`, `./${packageConfig.main}.json`, `./${packageConfig.main}.node`, `./${packageConfig.main}/index.js`, `./${packageConfig.main}/index.json`, `./${packageConfig.main}/index.node`];
  517. let i = -1;
  518. while (++i < tries.length) {
  519. guess = new (_url().URL)(tries[i], packageJsonUrl);
  520. if (fileExists(guess)) break;
  521. guess = undefined;
  522. }
  523. if (guess) {
  524. emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
  525. return guess;
  526. }
  527. }
  528. const tries = ['./index.js', './index.json', './index.node'];
  529. let i = -1;
  530. while (++i < tries.length) {
  531. guess = new (_url().URL)(tries[i], packageJsonUrl);
  532. if (fileExists(guess)) break;
  533. guess = undefined;
  534. }
  535. if (guess) {
  536. emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
  537. return guess;
  538. }
  539. throw new ERR_MODULE_NOT_FOUND((0, _url().fileURLToPath)(new (_url().URL)('.', packageJsonUrl)), (0, _url().fileURLToPath)(base));
  540. }
  541. function finalizeResolution(resolved, base, preserveSymlinks) {
  542. if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) {
  543. throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, 'must not include encoded "/" or "\\" characters', (0, _url().fileURLToPath)(base));
  544. }
  545. let filePath;
  546. try {
  547. filePath = (0, _url().fileURLToPath)(resolved);
  548. } catch (error) {
  549. const cause = error;
  550. Object.defineProperty(cause, 'input', {
  551. value: String(resolved)
  552. });
  553. Object.defineProperty(cause, 'module', {
  554. value: String(base)
  555. });
  556. throw cause;
  557. }
  558. const stats = tryStatSync(filePath.endsWith('/') ? filePath.slice(-1) : filePath);
  559. if (stats && stats.isDirectory()) {
  560. const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, (0, _url().fileURLToPath)(base));
  561. error.url = String(resolved);
  562. throw error;
  563. }
  564. if (!stats || !stats.isFile()) {
  565. const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && (0, _url().fileURLToPath)(base), true);
  566. error.url = String(resolved);
  567. throw error;
  568. }
  569. if (!preserveSymlinks) {
  570. const real = (0, _fs().realpathSync)(filePath);
  571. const {
  572. search,
  573. hash
  574. } = resolved;
  575. resolved = (0, _url().pathToFileURL)(real + (filePath.endsWith(_path().sep) ? '/' : ''));
  576. resolved.search = search;
  577. resolved.hash = hash;
  578. }
  579. return resolved;
  580. }
  581. function importNotDefined(specifier, packageJsonUrl, base) {
  582. return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && (0, _url().fileURLToPath)(new (_url().URL)('.', packageJsonUrl)), (0, _url().fileURLToPath)(base));
  583. }
  584. function exportsNotFound(subpath, packageJsonUrl, base) {
  585. return new ERR_PACKAGE_PATH_NOT_EXPORTED((0, _url().fileURLToPath)(new (_url().URL)('.', packageJsonUrl)), subpath, base && (0, _url().fileURLToPath)(base));
  586. }
  587. function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
  588. const reason = `request is not a valid match in pattern "${match}" for the "${internal ? 'imports' : 'exports'}" resolution of ${(0, _url().fileURLToPath)(packageJsonUrl)}`;
  589. throw new ERR_INVALID_MODULE_SPECIFIER(request, reason, base && (0, _url().fileURLToPath)(base));
  590. }
  591. function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
  592. target = typeof target === 'object' && target !== null ? JSON.stringify(target, null, '') : `${target}`;
  593. return new ERR_INVALID_PACKAGE_TARGET((0, _url().fileURLToPath)(new (_url().URL)('.', packageJsonUrl)), subpath, target, internal, base && (0, _url().fileURLToPath)(base));
  594. }
  595. function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
  596. if (subpath !== '' && !pattern && target[target.length - 1] !== '/') throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
  597. if (!target.startsWith('./')) {
  598. if (internal && !target.startsWith('../') && !target.startsWith('/')) {
  599. let isURL = false;
  600. try {
  601. new (_url().URL)(target);
  602. isURL = true;
  603. } catch (_unused3) {}
  604. if (!isURL) {
  605. const exportTarget = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath;
  606. return packageResolve(exportTarget, packageJsonUrl, conditions);
  607. }
  608. }
  609. throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
  610. }
  611. if (invalidSegmentRegEx.exec(target.slice(2)) !== null) {
  612. if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
  613. if (!isPathMap) {
  614. const request = pattern ? match.replace('*', () => subpath) : match + subpath;
  615. const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target;
  616. emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJsonUrl, internal, base, true);
  617. }
  618. } else {
  619. throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
  620. }
  621. }
  622. const resolved = new (_url().URL)(target, packageJsonUrl);
  623. const resolvedPath = resolved.pathname;
  624. const packagePath = new (_url().URL)('.', packageJsonUrl).pathname;
  625. if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
  626. if (subpath === '') return resolved;
  627. if (invalidSegmentRegEx.exec(subpath) !== null) {
  628. const request = pattern ? match.replace('*', () => subpath) : match + subpath;
  629. if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
  630. if (!isPathMap) {
  631. const resolvedTarget = pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target;
  632. emitInvalidSegmentDeprecation(resolvedTarget, request, match, packageJsonUrl, internal, base, false);
  633. }
  634. } else {
  635. throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
  636. }
  637. }
  638. if (pattern) {
  639. return new (_url().URL)(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
  640. }
  641. return new (_url().URL)(subpath, resolved);
  642. }
  643. function isArrayIndex(key) {
  644. const keyNumber = Number(key);
  645. if (`${keyNumber}` !== key) return false;
  646. return keyNumber >= 0 && keyNumber < 0xffffffff;
  647. }
  648. function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
  649. if (typeof target === 'string') {
  650. return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
  651. }
  652. if (Array.isArray(target)) {
  653. const targetList = target;
  654. if (targetList.length === 0) return null;
  655. let lastException;
  656. let i = -1;
  657. while (++i < targetList.length) {
  658. const targetItem = targetList[i];
  659. let resolveResult;
  660. try {
  661. resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
  662. } catch (error) {
  663. const exception = error;
  664. lastException = exception;
  665. if (exception.code === 'ERR_INVALID_PACKAGE_TARGET') continue;
  666. throw error;
  667. }
  668. if (resolveResult === undefined) continue;
  669. if (resolveResult === null) {
  670. lastException = null;
  671. continue;
  672. }
  673. return resolveResult;
  674. }
  675. if (lastException === undefined || lastException === null) {
  676. return null;
  677. }
  678. throw lastException;
  679. }
  680. if (typeof target === 'object' && target !== null) {
  681. const keys = Object.getOwnPropertyNames(target);
  682. let i = -1;
  683. while (++i < keys.length) {
  684. const key = keys[i];
  685. if (isArrayIndex(key)) {
  686. throw new ERR_INVALID_PACKAGE_CONFIG((0, _url().fileURLToPath)(packageJsonUrl), base, '"exports" cannot contain numeric property keys.');
  687. }
  688. }
  689. i = -1;
  690. while (++i < keys.length) {
  691. const key = keys[i];
  692. if (key === 'default' || conditions && conditions.has(key)) {
  693. const conditionalTarget = target[key];
  694. const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
  695. if (resolveResult === undefined) continue;
  696. return resolveResult;
  697. }
  698. }
  699. return null;
  700. }
  701. if (target === null) {
  702. return null;
  703. }
  704. throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
  705. }
  706. function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
  707. if (typeof exports === 'string' || Array.isArray(exports)) return true;
  708. if (typeof exports !== 'object' || exports === null) return false;
  709. const keys = Object.getOwnPropertyNames(exports);
  710. let isConditionalSugar = false;
  711. let i = 0;
  712. let keyIndex = -1;
  713. while (++keyIndex < keys.length) {
  714. const key = keys[keyIndex];
  715. const currentIsConditionalSugar = key === '' || key[0] !== '.';
  716. if (i++ === 0) {
  717. isConditionalSugar = currentIsConditionalSugar;
  718. } else if (isConditionalSugar !== currentIsConditionalSugar) {
  719. throw new ERR_INVALID_PACKAGE_CONFIG((0, _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.');
  720. }
  721. }
  722. return isConditionalSugar;
  723. }
  724. function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
  725. if (_process().noDeprecation) {
  726. return;
  727. }
  728. const pjsonPath = (0, _url().fileURLToPath)(pjsonUrl);
  729. if (emittedPackageWarnings.has(pjsonPath + '|' + match)) return;
  730. emittedPackageWarnings.add(pjsonPath + '|' + match);
  731. _process().emitWarning(`Use of deprecated trailing slash pattern mapping "${match}" in the ` + `"exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${(0, _url().fileURLToPath)(base)}` : ''}. Mapping specifiers ending in "/" is no longer supported.`, 'DeprecationWarning', 'DEP0155');
  732. }
  733. function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
  734. let exports = packageConfig.exports;
  735. if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) {
  736. exports = {
  737. '.': exports
  738. };
  739. }
  740. if (own.call(exports, packageSubpath) && !packageSubpath.includes('*') && !packageSubpath.endsWith('/')) {
  741. const target = exports[packageSubpath];
  742. const resolveResult = resolvePackageTarget(packageJsonUrl, target, '', packageSubpath, base, false, false, false, conditions);
  743. if (resolveResult === null || resolveResult === undefined) {
  744. throw exportsNotFound(packageSubpath, packageJsonUrl, base);
  745. }
  746. return resolveResult;
  747. }
  748. let bestMatch = '';
  749. let bestMatchSubpath = '';
  750. const keys = Object.getOwnPropertyNames(exports);
  751. let i = -1;
  752. while (++i < keys.length) {
  753. const key = keys[i];
  754. const patternIndex = key.indexOf('*');
  755. if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
  756. if (packageSubpath.endsWith('/')) {
  757. emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
  758. }
  759. const patternTrailer = key.slice(patternIndex + 1);
  760. if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf('*') === patternIndex) {
  761. bestMatch = key;
  762. bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
  763. }
  764. }
  765. }
  766. if (bestMatch) {
  767. const target = exports[bestMatch];
  768. const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith('/'), conditions);
  769. if (resolveResult === null || resolveResult === undefined) {
  770. throw exportsNotFound(packageSubpath, packageJsonUrl, base);
  771. }
  772. return resolveResult;
  773. }
  774. throw exportsNotFound(packageSubpath, packageJsonUrl, base);
  775. }
  776. function patternKeyCompare(a, b) {
  777. const aPatternIndex = a.indexOf('*');
  778. const bPatternIndex = b.indexOf('*');
  779. const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
  780. const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
  781. if (baseLengthA > baseLengthB) return -1;
  782. if (baseLengthB > baseLengthA) return 1;
  783. if (aPatternIndex === -1) return 1;
  784. if (bPatternIndex === -1) return -1;
  785. if (a.length > b.length) return -1;
  786. if (b.length > a.length) return 1;
  787. return 0;
  788. }
  789. function packageImportsResolve(name, base, conditions) {
  790. if (name === '#' || name.startsWith('#/') || name.endsWith('/')) {
  791. const reason = 'is not a valid internal imports specifier name';
  792. throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, (0, _url().fileURLToPath)(base));
  793. }
  794. let packageJsonUrl;
  795. const packageConfig = getPackageScopeConfig(base);
  796. if (packageConfig.exists) {
  797. packageJsonUrl = (0, _url().pathToFileURL)(packageConfig.pjsonPath);
  798. const imports = packageConfig.imports;
  799. if (imports) {
  800. if (own.call(imports, name) && !name.includes('*')) {
  801. const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], '', name, base, false, true, false, conditions);
  802. if (resolveResult !== null && resolveResult !== undefined) {
  803. return resolveResult;
  804. }
  805. } else {
  806. let bestMatch = '';
  807. let bestMatchSubpath = '';
  808. const keys = Object.getOwnPropertyNames(imports);
  809. let i = -1;
  810. while (++i < keys.length) {
  811. const key = keys[i];
  812. const patternIndex = key.indexOf('*');
  813. if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
  814. const patternTrailer = key.slice(patternIndex + 1);
  815. if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf('*') === patternIndex) {
  816. bestMatch = key;
  817. bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
  818. }
  819. }
  820. }
  821. if (bestMatch) {
  822. const target = imports[bestMatch];
  823. const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
  824. if (resolveResult !== null && resolveResult !== undefined) {
  825. return resolveResult;
  826. }
  827. }
  828. }
  829. }
  830. }
  831. throw importNotDefined(name, packageJsonUrl, base);
  832. }
  833. function parsePackageName(specifier, base) {
  834. let separatorIndex = specifier.indexOf('/');
  835. let validPackageName = true;
  836. let isScoped = false;
  837. if (specifier[0] === '@') {
  838. isScoped = true;
  839. if (separatorIndex === -1 || specifier.length === 0) {
  840. validPackageName = false;
  841. } else {
  842. separatorIndex = specifier.indexOf('/', separatorIndex + 1);
  843. }
  844. }
  845. const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
  846. if (invalidPackageNameRegEx.exec(packageName) !== null) {
  847. validPackageName = false;
  848. }
  849. if (!validPackageName) {
  850. throw new ERR_INVALID_MODULE_SPECIFIER(specifier, 'is not a valid package name', (0, _url().fileURLToPath)(base));
  851. }
  852. const packageSubpath = '.' + (separatorIndex === -1 ? '' : specifier.slice(separatorIndex));
  853. return {
  854. packageName,
  855. packageSubpath,
  856. isScoped
  857. };
  858. }
  859. function packageResolve(specifier, base, conditions) {
  860. if (_module().builtinModules.includes(specifier)) {
  861. return new (_url().URL)('node:' + specifier);
  862. }
  863. const {
  864. packageName,
  865. packageSubpath,
  866. isScoped
  867. } = parsePackageName(specifier, base);
  868. const packageConfig = getPackageScopeConfig(base);
  869. if (packageConfig.exists) {
  870. const packageJsonUrl = (0, _url().pathToFileURL)(packageConfig.pjsonPath);
  871. if (packageConfig.name === packageName && packageConfig.exports !== undefined && packageConfig.exports !== null) {
  872. return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
  873. }
  874. }
  875. let packageJsonUrl = new (_url().URL)('./node_modules/' + packageName + '/package.json', base);
  876. let packageJsonPath = (0, _url().fileURLToPath)(packageJsonUrl);
  877. let lastPath;
  878. do {
  879. const stat = tryStatSync(packageJsonPath.slice(0, -13));
  880. if (!stat || !stat.isDirectory()) {
  881. lastPath = packageJsonPath;
  882. packageJsonUrl = new (_url().URL)((isScoped ? '../../../../node_modules/' : '../../../node_modules/') + packageName + '/package.json', packageJsonUrl);
  883. packageJsonPath = (0, _url().fileURLToPath)(packageJsonUrl);
  884. continue;
  885. }
  886. const packageConfig = read(packageJsonPath, {
  887. base,
  888. specifier
  889. });
  890. if (packageConfig.exports !== undefined && packageConfig.exports !== null) {
  891. return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
  892. }
  893. if (packageSubpath === '.') {
  894. return legacyMainResolve(packageJsonUrl, packageConfig, base);
  895. }
  896. return new (_url().URL)(packageSubpath, packageJsonUrl);
  897. } while (packageJsonPath.length !== lastPath.length);
  898. throw new ERR_MODULE_NOT_FOUND(packageName, (0, _url().fileURLToPath)(base), false);
  899. }
  900. function isRelativeSpecifier(specifier) {
  901. if (specifier[0] === '.') {
  902. if (specifier.length === 1 || specifier[1] === '/') return true;
  903. if (specifier[1] === '.' && (specifier.length === 2 || specifier[2] === '/')) {
  904. return true;
  905. }
  906. }
  907. return false;
  908. }
  909. function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
  910. if (specifier === '') return false;
  911. if (specifier[0] === '/') return true;
  912. return isRelativeSpecifier(specifier);
  913. }
  914. function moduleResolve(specifier, base, conditions, preserveSymlinks) {
  915. const protocol = base.protocol;
  916. const isData = protocol === 'data:';
  917. const isRemote = isData || protocol === 'http:' || protocol === 'https:';
  918. let resolved;
  919. if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
  920. try {
  921. resolved = new (_url().URL)(specifier, base);
  922. } catch (error_) {
  923. const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
  924. error.cause = error_;
  925. throw error;
  926. }
  927. } else if (protocol === 'file:' && specifier[0] === '#') {
  928. resolved = packageImportsResolve(specifier, base, conditions);
  929. } else {
  930. try {
  931. resolved = new (_url().URL)(specifier);
  932. } catch (error_) {
  933. if (isRemote && !_module().builtinModules.includes(specifier)) {
  934. const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
  935. error.cause = error_;
  936. throw error;
  937. }
  938. resolved = packageResolve(specifier, base, conditions);
  939. }
  940. }
  941. _assert()(resolved !== undefined, 'expected to be defined');
  942. if (resolved.protocol !== 'file:') {
  943. return resolved;
  944. }
  945. return finalizeResolution(resolved, base, preserveSymlinks);
  946. }
  947. function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {
  948. if (parsedParentURL) {
  949. const parentProtocol = parsedParentURL.protocol;
  950. if (parentProtocol === 'http:' || parentProtocol === 'https:') {
  951. if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
  952. const parsedProtocol = parsed == null ? void 0 : parsed.protocol;
  953. if (parsedProtocol && parsedProtocol !== 'https:' && parsedProtocol !== 'http:') {
  954. throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'remote imports cannot import from a local location.');
  955. }
  956. return {
  957. url: (parsed == null ? void 0 : parsed.href) || ''
  958. };
  959. }
  960. if (_module().builtinModules.includes(specifier)) {
  961. throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'remote imports cannot import from a local location.');
  962. }
  963. throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, 'only relative and absolute specifiers are supported.');
  964. }
  965. }
  966. }
  967. function isURL(self) {
  968. return Boolean(self && typeof self === 'object' && 'href' in self && typeof self.href === 'string' && 'protocol' in self && typeof self.protocol === 'string' && self.href && self.protocol);
  969. }
  970. function throwIfInvalidParentURL(parentURL) {
  971. if (parentURL === undefined) {
  972. return;
  973. }
  974. if (typeof parentURL !== 'string' && !isURL(parentURL)) {
  975. throw new codes.ERR_INVALID_ARG_TYPE('parentURL', ['string', 'URL'], parentURL);
  976. }
  977. }
  978. function defaultResolve(specifier, context = {}) {
  979. const {
  980. parentURL
  981. } = context;
  982. _assert()(parentURL !== undefined, 'expected `parentURL` to be defined');
  983. throwIfInvalidParentURL(parentURL);
  984. let parsedParentURL;
  985. if (parentURL) {
  986. try {
  987. parsedParentURL = new (_url().URL)(parentURL);
  988. } catch (_unused4) {}
  989. }
  990. let parsed;
  991. let protocol;
  992. try {
  993. parsed = shouldBeTreatedAsRelativeOrAbsolutePath(specifier) ? new (_url().URL)(specifier, parsedParentURL) : new (_url().URL)(specifier);
  994. protocol = parsed.protocol;
  995. if (protocol === 'data:') {
  996. return {
  997. url: parsed.href,
  998. format: null
  999. };
  1000. }
  1001. } catch (_unused5) {}
  1002. const maybeReturn = checkIfDisallowedImport(specifier, parsed, parsedParentURL);
  1003. if (maybeReturn) return maybeReturn;
  1004. if (protocol === undefined && parsed) {
  1005. protocol = parsed.protocol;
  1006. }
  1007. if (protocol === 'node:') {
  1008. return {
  1009. url: specifier
  1010. };
  1011. }
  1012. if (parsed && parsed.protocol === 'node:') return {
  1013. url: specifier
  1014. };
  1015. const conditions = getConditionsSet(context.conditions);
  1016. const url = moduleResolve(specifier, new (_url().URL)(parentURL), conditions, false);
  1017. return {
  1018. url: url.href,
  1019. format: defaultGetFormatWithoutErrors(url, {
  1020. parentURL
  1021. })
  1022. };
  1023. }
  1024. function resolve(specifier, parent) {
  1025. if (!parent) {
  1026. throw new Error('Please pass `parent`: `import-meta-resolve` cannot ponyfill that');
  1027. }
  1028. try {
  1029. return defaultResolve(specifier, {
  1030. parentURL: parent
  1031. }).url;
  1032. } catch (error) {
  1033. const exception = error;
  1034. if ((exception.code === 'ERR_UNSUPPORTED_DIR_IMPORT' || exception.code === 'ERR_MODULE_NOT_FOUND') && typeof exception.url === 'string') {
  1035. return exception.url;
  1036. }
  1037. throw error;
  1038. }
  1039. }
  1040. 0 && 0;
  1041. //# sourceMappingURL=import-meta-resolve.js.map