vitest 0.0.94 → 0.0.98

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/worker.js CHANGED
@@ -1,211 +1,18 @@
1
- import path, { resolve as resolve$3, dirname as dirname$3 } from 'path';
1
+ import { a as resolve, d as dirname$2 } from './index-1488b423.js';
2
2
  import { n as nanoid } from './index-9e71c815.js';
3
- import { c as distDir } from './constants-9cfa4d7b.js';
3
+ import { c as distDir } from './constants-e78c749a.js';
4
4
  import { builtinModules, createRequire } from 'module';
5
- import { pathToFileURL, fileURLToPath, URL as URL$1 } from 'url';
5
+ import { pathToFileURL, fileURLToPath as fileURLToPath$2, URL as URL$1 } from 'url';
6
6
  import vm from 'vm';
7
- import { s as slash } from './utils-576876dc.js';
8
- import fs, { realpathSync, statSync, Stats, promises } from 'fs';
7
+ import path from 'path';
8
+ import fs, { promises, realpathSync, statSync, Stats } from 'fs';
9
9
  import assert from 'assert';
10
- import { format as format$3, inspect } from 'util';
10
+ import { format as format$2, inspect } from 'util';
11
+ import { s as slash } from './utils-70b78878.js';
11
12
  import { s as send } from './rpc-7de86f29.js';
12
13
  import 'tty';
13
14
  import 'local-pkg';
14
15
 
15
- function normalizeWindowsPath$2(input = "") {
16
- if (!input.includes("\\")) {
17
- return input;
18
- }
19
- return input.replace(/\\/g, "/");
20
- }
21
-
22
- const _UNC_REGEX$2 = /^[/][/]/;
23
- const _UNC_DRIVE_REGEX$2 = /^[/][/]([.]{1,2}[/])?([a-zA-Z]):[/]/;
24
- const _IS_ABSOLUTE_RE$2 = /^\/|^\\|^[a-zA-Z]:[/\\]/;
25
- const sep$2 = "/";
26
- const delimiter$2 = ":";
27
- const normalize$2 = function(path2) {
28
- if (path2.length === 0) {
29
- return ".";
30
- }
31
- path2 = normalizeWindowsPath$2(path2);
32
- const isUNCPath = path2.match(_UNC_REGEX$2);
33
- const hasUNCDrive = isUNCPath && path2.match(_UNC_DRIVE_REGEX$2);
34
- const isPathAbsolute = isAbsolute$2(path2);
35
- const trailingSeparator = path2[path2.length - 1] === "/";
36
- path2 = normalizeString$2(path2, !isPathAbsolute);
37
- if (path2.length === 0) {
38
- if (isPathAbsolute) {
39
- return "/";
40
- }
41
- return trailingSeparator ? "./" : ".";
42
- }
43
- if (trailingSeparator) {
44
- path2 += "/";
45
- }
46
- if (isUNCPath) {
47
- if (hasUNCDrive) {
48
- return `//./${path2}`;
49
- }
50
- return `//${path2}`;
51
- }
52
- return isPathAbsolute && !isAbsolute$2(path2) ? `/${path2}` : path2;
53
- };
54
- const join$2 = function(...args) {
55
- if (args.length === 0) {
56
- return ".";
57
- }
58
- let joined;
59
- for (let i = 0; i < args.length; ++i) {
60
- const arg = args[i];
61
- if (arg.length > 0) {
62
- if (joined === void 0) {
63
- joined = arg;
64
- } else {
65
- joined += `/${arg}`;
66
- }
67
- }
68
- }
69
- if (joined === void 0) {
70
- return ".";
71
- }
72
- return normalize$2(joined);
73
- };
74
- const resolve = function(...args) {
75
- args = args.map((arg) => normalizeWindowsPath$2(arg));
76
- let resolvedPath = "";
77
- let resolvedAbsolute = false;
78
- for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
79
- const path2 = i >= 0 ? args[i] : process.cwd();
80
- if (path2.length === 0) {
81
- continue;
82
- }
83
- resolvedPath = `${path2}/${resolvedPath}`;
84
- resolvedAbsolute = isAbsolute$2(path2);
85
- }
86
- resolvedPath = normalizeString$2(resolvedPath, !resolvedAbsolute);
87
- if (resolvedAbsolute && !isAbsolute$2(resolvedPath)) {
88
- return `/${resolvedPath}`;
89
- }
90
- return resolvedPath.length > 0 ? resolvedPath : ".";
91
- };
92
- function normalizeString$2(path2, allowAboveRoot) {
93
- let res = "";
94
- let lastSegmentLength = 0;
95
- let lastSlash = -1;
96
- let dots = 0;
97
- let char = null;
98
- for (let i = 0; i <= path2.length; ++i) {
99
- if (i < path2.length) {
100
- char = path2[i];
101
- } else if (char === "/") {
102
- break;
103
- } else {
104
- char = "/";
105
- }
106
- if (char === "/") {
107
- if (lastSlash === i - 1 || dots === 1) ; else if (dots === 2) {
108
- if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
109
- if (res.length > 2) {
110
- const lastSlashIndex = res.lastIndexOf("/");
111
- if (lastSlashIndex === -1) {
112
- res = "";
113
- lastSegmentLength = 0;
114
- } else {
115
- res = res.slice(0, lastSlashIndex);
116
- lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
117
- }
118
- lastSlash = i;
119
- dots = 0;
120
- continue;
121
- } else if (res.length !== 0) {
122
- res = "";
123
- lastSegmentLength = 0;
124
- lastSlash = i;
125
- dots = 0;
126
- continue;
127
- }
128
- }
129
- if (allowAboveRoot) {
130
- res += res.length > 0 ? "/.." : "..";
131
- lastSegmentLength = 2;
132
- }
133
- } else {
134
- if (res.length > 0) {
135
- res += `/${path2.slice(lastSlash + 1, i)}`;
136
- } else {
137
- res = path2.slice(lastSlash + 1, i);
138
- }
139
- lastSegmentLength = i - lastSlash - 1;
140
- }
141
- lastSlash = i;
142
- dots = 0;
143
- } else if (char === "." && dots !== -1) {
144
- ++dots;
145
- } else {
146
- dots = -1;
147
- }
148
- }
149
- return res;
150
- }
151
- const isAbsolute$2 = function(p) {
152
- return _IS_ABSOLUTE_RE$2.test(p);
153
- };
154
- const toNamespacedPath$2 = function(p) {
155
- return normalizeWindowsPath$2(p);
156
- };
157
- const extname$2 = function(p) {
158
- return path.posix.extname(normalizeWindowsPath$2(p));
159
- };
160
- const relative$2 = function(from, to) {
161
- return path.posix.relative(normalizeWindowsPath$2(from), normalizeWindowsPath$2(to));
162
- };
163
- const dirname$2 = function(p) {
164
- return path.posix.dirname(normalizeWindowsPath$2(p));
165
- };
166
- const format$2 = function(p) {
167
- return normalizeWindowsPath$2(path.posix.format(p));
168
- };
169
- const basename$2 = function(p, ext) {
170
- return path.posix.basename(normalizeWindowsPath$2(p), ext);
171
- };
172
- const parse$e = function(p) {
173
- return path.posix.parse(normalizeWindowsPath$2(p));
174
- };
175
-
176
- const _path$2 = /*#__PURE__*/Object.freeze({
177
- __proto__: null,
178
- sep: sep$2,
179
- delimiter: delimiter$2,
180
- normalize: normalize$2,
181
- join: join$2,
182
- resolve: resolve,
183
- normalizeString: normalizeString$2,
184
- isAbsolute: isAbsolute$2,
185
- toNamespacedPath: toNamespacedPath$2,
186
- extname: extname$2,
187
- relative: relative$2,
188
- dirname: dirname$2,
189
- format: format$2,
190
- basename: basename$2,
191
- parse: parse$e
192
- });
193
-
194
- ({
195
- ..._path$2
196
- });
197
-
198
- /*---------------------------------------------------------------------------------------------
199
- * Copyright (c) Microsoft Corporation. All rights reserved.
200
- * Licensed under the MIT License. See License.txt in the project root for license information.
201
- *--------------------------------------------------------------------------------------------*/
202
- var ParseOptions$1;
203
- (function (ParseOptions) {
204
- ParseOptions.DEFAULT = {
205
- allowTrailingComma: false
206
- };
207
- })(ParseOptions$1 || (ParseOptions$1 = {}));
208
-
209
16
  const BUILTIN_MODULES$1 = new Set(builtinModules);
210
17
  function normalizeSlash$1(str) {
211
18
  return str.replace(/\\/g, "/");
@@ -223,12 +30,17 @@ function perr$1(_err) {
223
30
  Error.captureStackTrace(err, pcall$1);
224
31
  return Promise.reject(err);
225
32
  }
33
+ const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
34
+ function getProtocol(id) {
35
+ const proto = id.match(ProtocolRegex);
36
+ return proto ? proto.groups.proto : null;
37
+ }
226
38
 
227
39
  function fileURLToPath$1(id) {
228
40
  if (typeof id === "string" && !id.startsWith("file://")) {
229
41
  return normalizeSlash$1(id);
230
42
  }
231
- return normalizeSlash$1(fileURLToPath(id));
43
+ return normalizeSlash$1(fileURLToPath$2(id));
232
44
  }
233
45
  function normalizeid$1(id) {
234
46
  if (typeof id !== "string") {
@@ -3641,7 +3453,7 @@ function getMessage$1(key, args, self) {
3641
3453
  if (args.length === 0) return message
3642
3454
 
3643
3455
  args.unshift(message);
3644
- return Reflect.apply(format$3, null, args)
3456
+ return Reflect.apply(format$2, null, args)
3645
3457
  }
3646
3458
 
3647
3459
  // Manually “tree shaken” from:
@@ -3685,7 +3497,7 @@ function defaultGetFormat$1(url) {
3685
3497
  }
3686
3498
 
3687
3499
  if (!format) {
3688
- throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath(url))
3500
+ throw new ERR_UNKNOWN_FILE_EXTENSION$1(ext, fileURLToPath$2(url))
3689
3501
  }
3690
3502
 
3691
3503
  return {format: format || null}
@@ -3730,7 +3542,7 @@ const packageJsonCache$1 = new Map();
3730
3542
  * @returns {void}
3731
3543
  */
3732
3544
  function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
3733
- const pjsonPath = fileURLToPath(pjsonUrl);
3545
+ const pjsonPath = fileURLToPath$2(pjsonUrl);
3734
3546
 
3735
3547
  if (emittedPackageWarnings$1.has(pjsonPath + '|' + match)) return
3736
3548
  emittedPackageWarnings$1.add(pjsonPath + '|' + match);
@@ -3738,7 +3550,7 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
3738
3550
  `Use of deprecated folder mapping "${match}" in the ${
3739
3551
  isExports ? '"exports"' : '"imports"'
3740
3552
  } field module resolution of the package at ${pjsonPath}${
3741
- base ? ` imported from ${fileURLToPath(base)}` : ''
3553
+ base ? ` imported from ${fileURLToPath$2(base)}` : ''
3742
3554
  }.\n` +
3743
3555
  `Update this package.json to use a subpath pattern like "${match}*".`,
3744
3556
  'DeprecationWarning',
@@ -3756,9 +3568,9 @@ function emitFolderMapDeprecation$1(match, pjsonUrl, isExports, base) {
3756
3568
  function emitLegacyIndexDeprecation$1(url, packageJsonUrl, base, main) {
3757
3569
  const {format} = defaultGetFormat$1(url.href);
3758
3570
  if (format !== 'module') return
3759
- const path = fileURLToPath(url.href);
3760
- const pkgPath = fileURLToPath(new URL$1('.', packageJsonUrl));
3761
- const basePath = fileURLToPath(base);
3571
+ const path = fileURLToPath$2(url.href);
3572
+ const pkgPath = fileURLToPath$2(new URL$1('.', packageJsonUrl));
3573
+ const basePath = fileURLToPath$2(base);
3762
3574
  if (main)
3763
3575
  process.emitWarning(
3764
3576
  `Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, ` +
@@ -3828,7 +3640,7 @@ function getPackageConfig$1(path, specifier, base) {
3828
3640
  } catch (error) {
3829
3641
  throw new ERR_INVALID_PACKAGE_CONFIG$1(
3830
3642
  path,
3831
- (base ? `"${specifier}" from ` : '') + fileURLToPath(base || specifier),
3643
+ (base ? `"${specifier}" from ` : '') + fileURLToPath$2(base || specifier),
3832
3644
  error.message
3833
3645
  )
3834
3646
  }
@@ -3864,7 +3676,7 @@ function getPackageScopeConfig$1(resolved) {
3864
3676
  if (packageJsonPath.endsWith('node_modules/package.json')) break
3865
3677
 
3866
3678
  const packageConfig = getPackageConfig$1(
3867
- fileURLToPath(packageJsonUrl),
3679
+ fileURLToPath$2(packageJsonUrl),
3868
3680
  resolved
3869
3681
  );
3870
3682
  if (packageConfig.exists) return packageConfig
@@ -3877,7 +3689,7 @@ function getPackageScopeConfig$1(resolved) {
3877
3689
  if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break
3878
3690
  }
3879
3691
 
3880
- const packageJsonPath = fileURLToPath(packageJsonUrl);
3692
+ const packageJsonPath = fileURLToPath$2(packageJsonUrl);
3881
3693
  /** @type {PackageConfig} */
3882
3694
  const packageConfig = {
3883
3695
  pjsonPath: packageJsonPath,
@@ -3904,7 +3716,7 @@ function getPackageScopeConfig$1(resolved) {
3904
3716
  * @returns {boolean}
3905
3717
  */
3906
3718
  function fileExists$1(url) {
3907
- return tryStatSync$1(fileURLToPath(url)).isFile()
3719
+ return tryStatSync$1(fileURLToPath$2(url)).isFile()
3908
3720
  }
3909
3721
 
3910
3722
  /**
@@ -3965,8 +3777,8 @@ function legacyMainResolve$1(packageJsonUrl, packageConfig, base) {
3965
3777
 
3966
3778
  // Not found.
3967
3779
  throw new ERR_MODULE_NOT_FOUND$1(
3968
- fileURLToPath(new URL$1('.', packageJsonUrl)),
3969
- fileURLToPath(base)
3780
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
3781
+ fileURLToPath$2(base)
3970
3782
  )
3971
3783
  }
3972
3784
 
@@ -3980,15 +3792,15 @@ function finalizeResolution$1(resolved, base) {
3980
3792
  throw new ERR_INVALID_MODULE_SPECIFIER$1(
3981
3793
  resolved.pathname,
3982
3794
  'must not include encoded "/" or "\\" characters',
3983
- fileURLToPath(base)
3795
+ fileURLToPath$2(base)
3984
3796
  )
3985
3797
 
3986
- const path = fileURLToPath(resolved);
3798
+ const path = fileURLToPath$2(resolved);
3987
3799
 
3988
3800
  const stats = tryStatSync$1(path.endsWith('/') ? path.slice(-1) : path);
3989
3801
 
3990
3802
  if (stats.isDirectory()) {
3991
- const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath(base));
3803
+ const error = new ERR_UNSUPPORTED_DIR_IMPORT$1(path, fileURLToPath$2(base));
3992
3804
  // @ts-expect-error Add this for `import.meta.resolve`.
3993
3805
  error.url = String(resolved);
3994
3806
  throw error
@@ -3997,7 +3809,7 @@ function finalizeResolution$1(resolved, base) {
3997
3809
  if (!stats.isFile()) {
3998
3810
  throw new ERR_MODULE_NOT_FOUND$1(
3999
3811
  path || resolved.pathname,
4000
- base && fileURLToPath(base),
3812
+ base && fileURLToPath$2(base),
4001
3813
  'module'
4002
3814
  )
4003
3815
  }
@@ -4014,8 +3826,8 @@ function finalizeResolution$1(resolved, base) {
4014
3826
  function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
4015
3827
  throw new ERR_PACKAGE_IMPORT_NOT_DEFINED$1(
4016
3828
  specifier,
4017
- packageJsonUrl && fileURLToPath(new URL$1('.', packageJsonUrl)),
4018
- fileURLToPath(base)
3829
+ packageJsonUrl && fileURLToPath$2(new URL$1('.', packageJsonUrl)),
3830
+ fileURLToPath$2(base)
4019
3831
  )
4020
3832
  }
4021
3833
 
@@ -4027,9 +3839,9 @@ function throwImportNotDefined$1(specifier, packageJsonUrl, base) {
4027
3839
  */
4028
3840
  function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
4029
3841
  throw new ERR_PACKAGE_PATH_NOT_EXPORTED$1(
4030
- fileURLToPath(new URL$1('.', packageJsonUrl)),
3842
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
4031
3843
  subpath,
4032
- base && fileURLToPath(base)
3844
+ base && fileURLToPath$2(base)
4033
3845
  )
4034
3846
  }
4035
3847
 
@@ -4043,12 +3855,12 @@ function throwExportsNotFound$1(subpath, packageJsonUrl, base) {
4043
3855
  function throwInvalidSubpath$1(subpath, packageJsonUrl, internal, base) {
4044
3856
  const reason = `request is not a valid subpath for the "${
4045
3857
  internal ? 'imports' : 'exports'
4046
- }" resolution of ${fileURLToPath(packageJsonUrl)}`;
3858
+ }" resolution of ${fileURLToPath$2(packageJsonUrl)}`;
4047
3859
 
4048
3860
  throw new ERR_INVALID_MODULE_SPECIFIER$1(
4049
3861
  subpath,
4050
3862
  reason,
4051
- base && fileURLToPath(base)
3863
+ base && fileURLToPath$2(base)
4052
3864
  )
4053
3865
  }
4054
3866
 
@@ -4073,11 +3885,11 @@ function throwInvalidPackageTarget$1(
4073
3885
  : `${target}`;
4074
3886
 
4075
3887
  throw new ERR_INVALID_PACKAGE_TARGET$1(
4076
- fileURLToPath(new URL$1('.', packageJsonUrl)),
3888
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
4077
3889
  subpath,
4078
3890
  target,
4079
3891
  internal,
4080
- base && fileURLToPath(base)
3892
+ base && fileURLToPath$2(base)
4081
3893
  )
4082
3894
  }
4083
3895
 
@@ -4246,7 +4058,7 @@ function resolvePackageTarget$1(
4246
4058
  const key = keys[i];
4247
4059
  if (isArrayIndex$1(key)) {
4248
4060
  throw new ERR_INVALID_PACKAGE_CONFIG$1(
4249
- fileURLToPath(packageJsonUrl),
4061
+ fileURLToPath$2(packageJsonUrl),
4250
4062
  base,
4251
4063
  '"exports" cannot contain numeric property keys.'
4252
4064
  )
@@ -4312,7 +4124,7 @@ function isConditionalExportsMainSugar$1(exports, packageJsonUrl, base) {
4312
4124
  isConditionalSugar = curIsConditionalSugar;
4313
4125
  } else if (isConditionalSugar !== curIsConditionalSugar) {
4314
4126
  throw new ERR_INVALID_PACKAGE_CONFIG$1(
4315
- fileURLToPath(packageJsonUrl),
4127
+ fileURLToPath$2(packageJsonUrl),
4316
4128
  base,
4317
4129
  '"exports" cannot contain some keys starting with \'.\' and some not.' +
4318
4130
  ' The exports object must either be an object of package subpath keys' +
@@ -4415,7 +4227,7 @@ function packageExportsResolve$1(
4415
4227
  function packageImportsResolve$1(name, base, conditions) {
4416
4228
  if (name === '#' || name.startsWith('#/')) {
4417
4229
  const reason = 'is not a valid internal imports specifier name';
4418
- throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath(base))
4230
+ throw new ERR_INVALID_MODULE_SPECIFIER$1(name, reason, fileURLToPath$2(base))
4419
4231
  }
4420
4232
 
4421
4233
  /** @type {URL} */
@@ -4533,7 +4345,7 @@ function parsePackageName$1(specifier, base) {
4533
4345
  throw new ERR_INVALID_MODULE_SPECIFIER$1(
4534
4346
  specifier,
4535
4347
  'is not a valid package name',
4536
- fileURLToPath(base)
4348
+ fileURLToPath$2(base)
4537
4349
  )
4538
4350
  }
4539
4351
 
@@ -4581,7 +4393,7 @@ function packageResolve$1(specifier, base, conditions) {
4581
4393
  './node_modules/' + packageName + '/package.json',
4582
4394
  base
4583
4395
  );
4584
- let packageJsonPath = fileURLToPath(packageJsonUrl);
4396
+ let packageJsonPath = fileURLToPath$2(packageJsonUrl);
4585
4397
  /** @type {string} */
4586
4398
  let lastPath;
4587
4399
  do {
@@ -4594,7 +4406,7 @@ function packageResolve$1(specifier, base, conditions) {
4594
4406
  '/package.json',
4595
4407
  packageJsonUrl
4596
4408
  );
4597
- packageJsonPath = fileURLToPath(packageJsonUrl);
4409
+ packageJsonPath = fileURLToPath$2(packageJsonUrl);
4598
4410
  continue
4599
4411
  }
4600
4412
 
@@ -4614,7 +4426,7 @@ function packageResolve$1(specifier, base, conditions) {
4614
4426
  // Cross-platform root check.
4615
4427
  } while (packageJsonPath.length !== lastPath.length)
4616
4428
 
4617
- throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath(base))
4429
+ throw new ERR_MODULE_NOT_FOUND$1(packageName, fileURLToPath$2(base))
4618
4430
  }
4619
4431
 
4620
4432
  /**
@@ -4761,6 +4573,43 @@ var ParseOptions;
4761
4573
  };
4762
4574
  })(ParseOptions || (ParseOptions = {}));
4763
4575
 
4576
+ const BUILTIN_MODULES = new Set(builtinModules);
4577
+ function normalizeSlash(str) {
4578
+ return str.replace(/\\/g, "/");
4579
+ }
4580
+ function pcall(fn, ...args) {
4581
+ try {
4582
+ return Promise.resolve(fn(...args)).catch((err) => perr(err));
4583
+ } catch (err) {
4584
+ return perr(err);
4585
+ }
4586
+ }
4587
+ function perr(_err) {
4588
+ const err = new Error(_err);
4589
+ err.code = _err.code;
4590
+ Error.captureStackTrace(err, pcall);
4591
+ return Promise.reject(err);
4592
+ }
4593
+
4594
+ function fileURLToPath(id) {
4595
+ if (typeof id === "string" && !id.startsWith("file://")) {
4596
+ return normalizeSlash(id);
4597
+ }
4598
+ return normalizeSlash(fileURLToPath$2(id));
4599
+ }
4600
+ function normalizeid(id) {
4601
+ if (typeof id !== "string") {
4602
+ id = id.toString();
4603
+ }
4604
+ if (/(node|data|http|https|file):/.test(id)) {
4605
+ return id;
4606
+ }
4607
+ if (BUILTIN_MODULES.has(id)) {
4608
+ return "node:" + id;
4609
+ }
4610
+ return "file://" + normalizeSlash(id);
4611
+ }
4612
+
4764
4613
  function normalizeWindowsPath(input = "") {
4765
4614
  if (!input.includes("\\")) {
4766
4615
  return input;
@@ -7776,10 +7625,49 @@ var builtins = function ({
7776
7625
 
7777
7626
  // Manually “tree shaken” from:
7778
7627
 
7628
+ const reader = {read};
7629
+ const packageJsonReader = reader;
7630
+
7631
+ /**
7632
+ * @param {string} jsonPath
7633
+ * @returns {{string: string}}
7634
+ */
7635
+ function read(jsonPath) {
7636
+ return find(path.dirname(jsonPath))
7637
+ }
7638
+
7639
+ /**
7640
+ * @param {string} dir
7641
+ * @returns {{string: string}}
7642
+ */
7643
+ function find(dir) {
7644
+ try {
7645
+ const string = fs.readFileSync(
7646
+ path.toNamespacedPath(path.join(dir, 'package.json')),
7647
+ 'utf8'
7648
+ );
7649
+ return {string}
7650
+ } catch (error) {
7651
+ if (error.code === 'ENOENT') {
7652
+ const parent = path.dirname(dir);
7653
+ if (dir !== parent) return find(parent)
7654
+ return {string: undefined}
7655
+ // Throw all other errors.
7656
+ /* c8 ignore next 4 */
7657
+ }
7658
+
7659
+ throw error
7660
+ }
7661
+ }
7662
+
7663
+ // Manually “tree shaken” from:
7664
+
7779
7665
  const isWindows$2 = process.platform === 'win32';
7780
7666
 
7781
7667
  const own$1 = {}.hasOwnProperty;
7782
7668
 
7669
+ const codes = {};
7670
+
7783
7671
  /**
7784
7672
  * @typedef {(...args: unknown[]) => string} MessageFunction
7785
7673
  */
@@ -7790,7 +7678,7 @@ const nodeInternalPrefix = '__node_internal_';
7790
7678
  /** @type {number} */
7791
7679
  let userStackTraceLimit;
7792
7680
 
7793
- createError(
7681
+ codes.ERR_INVALID_MODULE_SPECIFIER = createError(
7794
7682
  'ERR_INVALID_MODULE_SPECIFIER',
7795
7683
  /**
7796
7684
  * @param {string} request
@@ -7805,7 +7693,7 @@ createError(
7805
7693
  TypeError
7806
7694
  );
7807
7695
 
7808
- createError(
7696
+ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
7809
7697
  'ERR_INVALID_PACKAGE_CONFIG',
7810
7698
  /**
7811
7699
  * @param {string} path
@@ -7820,7 +7708,7 @@ createError(
7820
7708
  Error
7821
7709
  );
7822
7710
 
7823
- createError(
7711
+ codes.ERR_INVALID_PACKAGE_TARGET = createError(
7824
7712
  'ERR_INVALID_PACKAGE_TARGET',
7825
7713
  /**
7826
7714
  * @param {string} pkgPath
@@ -7856,7 +7744,7 @@ createError(
7856
7744
  Error
7857
7745
  );
7858
7746
 
7859
- createError(
7747
+ codes.ERR_MODULE_NOT_FOUND = createError(
7860
7748
  'ERR_MODULE_NOT_FOUND',
7861
7749
  /**
7862
7750
  * @param {string} path
@@ -7869,7 +7757,7 @@ createError(
7869
7757
  Error
7870
7758
  );
7871
7759
 
7872
- createError(
7760
+ codes.ERR_PACKAGE_IMPORT_NOT_DEFINED = createError(
7873
7761
  'ERR_PACKAGE_IMPORT_NOT_DEFINED',
7874
7762
  /**
7875
7763
  * @param {string} specifier
@@ -7884,7 +7772,7 @@ createError(
7884
7772
  TypeError
7885
7773
  );
7886
7774
 
7887
- createError(
7775
+ codes.ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
7888
7776
  'ERR_PACKAGE_PATH_NOT_EXPORTED',
7889
7777
  /**
7890
7778
  * @param {string} pkgPath
@@ -7903,20 +7791,20 @@ createError(
7903
7791
  Error
7904
7792
  );
7905
7793
 
7906
- createError(
7794
+ codes.ERR_UNSUPPORTED_DIR_IMPORT = createError(
7907
7795
  'ERR_UNSUPPORTED_DIR_IMPORT',
7908
7796
  "Directory import '%s' is not supported " +
7909
7797
  'resolving ES modules imported from %s',
7910
7798
  Error
7911
7799
  );
7912
7800
 
7913
- createError(
7801
+ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
7914
7802
  'ERR_UNKNOWN_FILE_EXTENSION',
7915
7803
  'Unknown file extension "%s" for %s',
7916
7804
  TypeError
7917
7805
  );
7918
7806
 
7919
- createError(
7807
+ codes.ERR_INVALID_ARG_VALUE = createError(
7920
7808
  'ERR_INVALID_ARG_VALUE',
7921
7809
  /**
7922
7810
  * @param {string} name
@@ -7939,7 +7827,7 @@ createError(
7939
7827
  // , RangeError
7940
7828
  );
7941
7829
 
7942
- createError(
7830
+ codes.ERR_UNSUPPORTED_ESM_URL_SCHEME = createError(
7943
7831
  'ERR_UNSUPPORTED_ESM_URL_SCHEME',
7944
7832
  /**
7945
7833
  * @param {URL} url
@@ -8116,112 +8004,1196 @@ function getMessage(key, args, self) {
8116
8004
  if (args.length === 0) return message
8117
8005
 
8118
8006
  args.unshift(message);
8119
- return Reflect.apply(format$3, null, args)
8007
+ return Reflect.apply(format$2, null, args)
8120
8008
  }
8121
8009
 
8122
8010
  // Manually “tree shaken” from:
8123
8011
 
8124
- builtins();
8125
-
8126
- Object.freeze(['node', 'import']);
8127
- pathToFileURL(process.cwd());
8128
- const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
8129
- function hasCJSSyntax(code) {
8130
- return CJS_RE.test(code);
8131
- }
8012
+ const {ERR_UNKNOWN_FILE_EXTENSION} = codes;
8132
8013
 
8133
- const defaultFindOptions = {
8134
- startingFrom: ".",
8135
- rootPattern: /^node_modules$/,
8136
- test: (filePath) => {
8137
- try {
8138
- if (statSync(filePath).isFile()) {
8139
- return true;
8140
- }
8141
- } catch {
8142
- }
8143
- return null;
8144
- }
8014
+ const extensionFormatMap = {
8015
+ __proto__: null,
8016
+ '.cjs': 'commonjs',
8017
+ '.js': 'module',
8018
+ '.mjs': 'module'
8145
8019
  };
8146
- async function findNearestFile(filename, _options = {}) {
8147
- const options = { ...defaultFindOptions, ..._options };
8148
- const basePath = resolve(options.startingFrom);
8149
- const leadingSlash = basePath[0] === "/";
8150
- const segments = basePath.split("/").filter(Boolean);
8151
- if (leadingSlash) {
8152
- segments[0] = "/" + segments[0];
8153
- }
8154
- let root = segments.findIndex((r) => r.match(options.rootPattern));
8155
- if (root === -1)
8156
- root = 0;
8157
- for (let i = segments.length; i > root; i--) {
8158
- const filePath = join$2(...segments.slice(0, i), filename);
8159
- if (await options.test(filePath)) {
8160
- return filePath;
8161
- }
8020
+
8021
+ /**
8022
+ * @param {string} url
8023
+ * @returns {{format: string|null}}
8024
+ */
8025
+ function defaultGetFormat(url) {
8026
+ if (url.startsWith('node:')) {
8027
+ return {format: 'builtin'}
8162
8028
  }
8163
- throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
8164
- }
8165
- async function readPackageJSON(id, opts = {}) {
8166
- const resolvedPath = await resolvePackageJSON(id, opts);
8167
- const blob = await promises.readFile(resolvedPath, "utf-8");
8168
- return JSON.parse(blob);
8169
- }
8170
- async function resolvePackageJSON(id = process.cwd(), opts = {}) {
8171
- const resolvedPath = isAbsolute$2(id) ? id : await resolvePath$1(id, opts);
8172
- return findNearestFile("package.json", { startingFrom: resolvedPath, ...opts });
8173
- }
8174
8029
 
8175
- var __defProp = Object.defineProperty;
8176
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8177
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8178
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
8179
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8180
- var __spreadValues = (a, b) => {
8181
- for (var prop in b || (b = {}))
8182
- if (__hasOwnProp.call(b, prop))
8183
- __defNormalProp(a, prop, b[prop]);
8184
- if (__getOwnPropSymbols)
8185
- for (var prop of __getOwnPropSymbols(b)) {
8186
- if (__propIsEnum.call(b, prop))
8187
- __defNormalProp(a, prop, b[prop]);
8188
- }
8189
- return a;
8190
- };
8191
- const ProtocolRegex = /^(?<proto>.{2,}):.+$/;
8192
- function getProtocol(id) {
8193
- const proto = id.match(ProtocolRegex);
8194
- return proto ? proto.groups.proto : null;
8030
+ const parsed = new URL$1(url);
8031
+
8032
+ if (parsed.protocol === 'data:') {
8033
+ const {1: mime} = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(
8034
+ parsed.pathname
8035
+ ) || [null, null];
8036
+ const format = mime === 'text/javascript' ? 'module' : null;
8037
+ return {format}
8038
+ }
8039
+
8040
+ if (parsed.protocol === 'file:') {
8041
+ const ext = path.extname(parsed.pathname);
8042
+ /** @type {string} */
8043
+ let format;
8044
+ if (ext === '.js') {
8045
+ format = getPackageType(parsed.href) === 'module' ? 'module' : 'commonjs';
8046
+ } else {
8047
+ format = extensionFormatMap[ext];
8048
+ }
8049
+
8050
+ if (!format) {
8051
+ throw new ERR_UNKNOWN_FILE_EXTENSION(ext, fileURLToPath$2(url))
8052
+ }
8053
+
8054
+ return {format: format || null}
8055
+ }
8056
+
8057
+ return {format: null}
8058
+ }
8059
+
8060
+ // Manually “tree shaken” from:
8061
+
8062
+ builtins();
8063
+
8064
+ const {
8065
+ ERR_INVALID_MODULE_SPECIFIER,
8066
+ ERR_INVALID_PACKAGE_CONFIG,
8067
+ ERR_INVALID_PACKAGE_TARGET,
8068
+ ERR_MODULE_NOT_FOUND,
8069
+ ERR_PACKAGE_IMPORT_NOT_DEFINED,
8070
+ ERR_PACKAGE_PATH_NOT_EXPORTED,
8071
+ ERR_UNSUPPORTED_DIR_IMPORT,
8072
+ ERR_UNSUPPORTED_ESM_URL_SCHEME,
8073
+ ERR_INVALID_ARG_VALUE
8074
+ } = codes;
8075
+
8076
+ const own = {}.hasOwnProperty;
8077
+
8078
+ Object.freeze(['node', 'import']);
8079
+
8080
+ const invalidSegmentRegEx = /(^|\\|\/)(\.\.?|node_modules)(\\|\/|$)/;
8081
+ const patternRegEx = /\*/g;
8082
+ const encodedSepRegEx = /%2f|%2c/i;
8083
+ /** @type {Set<string>} */
8084
+ const emittedPackageWarnings = new Set();
8085
+ /** @type {Map<string, PackageConfig>} */
8086
+ const packageJsonCache = new Map();
8087
+
8088
+ /**
8089
+ * @param {string} match
8090
+ * @param {URL} pjsonUrl
8091
+ * @param {boolean} isExports
8092
+ * @param {URL} base
8093
+ * @returns {void}
8094
+ */
8095
+ function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) {
8096
+ const pjsonPath = fileURLToPath$2(pjsonUrl);
8097
+
8098
+ if (emittedPackageWarnings.has(pjsonPath + '|' + match)) return
8099
+ emittedPackageWarnings.add(pjsonPath + '|' + match);
8100
+ process.emitWarning(
8101
+ `Use of deprecated folder mapping "${match}" in the ${
8102
+ isExports ? '"exports"' : '"imports"'
8103
+ } field module resolution of the package at ${pjsonPath}${
8104
+ base ? ` imported from ${fileURLToPath$2(base)}` : ''
8105
+ }.\n` +
8106
+ `Update this package.json to use a subpath pattern like "${match}*".`,
8107
+ 'DeprecationWarning',
8108
+ 'DEP0148'
8109
+ );
8110
+ }
8111
+
8112
+ /**
8113
+ * @param {URL} url
8114
+ * @param {URL} packageJsonUrl
8115
+ * @param {URL} base
8116
+ * @param {unknown} [main]
8117
+ * @returns {void}
8118
+ */
8119
+ function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
8120
+ const {format} = defaultGetFormat(url.href);
8121
+ if (format !== 'module') return
8122
+ const path = fileURLToPath$2(url.href);
8123
+ const pkgPath = fileURLToPath$2(new URL$1('.', packageJsonUrl));
8124
+ const basePath = fileURLToPath$2(base);
8125
+ if (main)
8126
+ process.emitWarning(
8127
+ `Package ${pkgPath} has a "main" field set to ${JSON.stringify(main)}, ` +
8128
+ `excluding the full filename and extension to the resolved file at "${path.slice(
8129
+ pkgPath.length
8130
+ )}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is` +
8131
+ 'deprecated for ES modules.',
8132
+ 'DeprecationWarning',
8133
+ 'DEP0151'
8134
+ );
8135
+ else
8136
+ process.emitWarning(
8137
+ `No "main" or "exports" field defined in the package.json for ${pkgPath} resolving the main entry point "${path.slice(
8138
+ pkgPath.length
8139
+ )}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`,
8140
+ 'DeprecationWarning',
8141
+ 'DEP0151'
8142
+ );
8143
+ }
8144
+
8145
+ /**
8146
+ * @param {string} path
8147
+ * @returns {Stats}
8148
+ */
8149
+ function tryStatSync(path) {
8150
+ // Note: from Node 15 onwards we can use `throwIfNoEntry: false` instead.
8151
+ try {
8152
+ return statSync(path)
8153
+ } catch {
8154
+ return new Stats()
8155
+ }
8156
+ }
8157
+
8158
+ /**
8159
+ * @param {string} path
8160
+ * @param {string|URL} specifier Note: `specifier` is actually optional, not base.
8161
+ * @param {URL} [base]
8162
+ * @returns {PackageConfig}
8163
+ */
8164
+ function getPackageConfig(path, specifier, base) {
8165
+ const existing = packageJsonCache.get(path);
8166
+ if (existing !== undefined) {
8167
+ return existing
8168
+ }
8169
+
8170
+ const source = packageJsonReader.read(path).string;
8171
+
8172
+ if (source === undefined) {
8173
+ /** @type {PackageConfig} */
8174
+ const packageConfig = {
8175
+ pjsonPath: path,
8176
+ exists: false,
8177
+ main: undefined,
8178
+ name: undefined,
8179
+ type: 'none',
8180
+ exports: undefined,
8181
+ imports: undefined
8182
+ };
8183
+ packageJsonCache.set(path, packageConfig);
8184
+ return packageConfig
8185
+ }
8186
+
8187
+ /** @type {Object.<string, unknown>} */
8188
+ let packageJson;
8189
+ try {
8190
+ packageJson = JSON.parse(source);
8191
+ } catch (error) {
8192
+ throw new ERR_INVALID_PACKAGE_CONFIG(
8193
+ path,
8194
+ (base ? `"${specifier}" from ` : '') + fileURLToPath$2(base || specifier),
8195
+ error.message
8196
+ )
8197
+ }
8198
+
8199
+ const {exports, imports, main, name, type} = packageJson;
8200
+
8201
+ /** @type {PackageConfig} */
8202
+ const packageConfig = {
8203
+ pjsonPath: path,
8204
+ exists: true,
8205
+ main: typeof main === 'string' ? main : undefined,
8206
+ name: typeof name === 'string' ? name : undefined,
8207
+ type: type === 'module' || type === 'commonjs' ? type : 'none',
8208
+ // @ts-expect-error Assume `Object.<string, unknown>`.
8209
+ exports,
8210
+ // @ts-expect-error Assume `Object.<string, unknown>`.
8211
+ imports: imports && typeof imports === 'object' ? imports : undefined
8212
+ };
8213
+ packageJsonCache.set(path, packageConfig);
8214
+ return packageConfig
8215
+ }
8216
+
8217
+ /**
8218
+ * @param {URL|string} resolved
8219
+ * @returns {PackageConfig}
8220
+ */
8221
+ function getPackageScopeConfig(resolved) {
8222
+ let packageJsonUrl = new URL$1('./package.json', resolved);
8223
+
8224
+ while (true) {
8225
+ const packageJsonPath = packageJsonUrl.pathname;
8226
+
8227
+ if (packageJsonPath.endsWith('node_modules/package.json')) break
8228
+
8229
+ const packageConfig = getPackageConfig(
8230
+ fileURLToPath$2(packageJsonUrl),
8231
+ resolved
8232
+ );
8233
+ if (packageConfig.exists) return packageConfig
8234
+
8235
+ const lastPackageJsonUrl = packageJsonUrl;
8236
+ packageJsonUrl = new URL$1('../package.json', packageJsonUrl);
8237
+
8238
+ // Terminates at root where ../package.json equals ../../package.json
8239
+ // (can't just check "/package.json" for Windows support).
8240
+ if (packageJsonUrl.pathname === lastPackageJsonUrl.pathname) break
8241
+ }
8242
+
8243
+ const packageJsonPath = fileURLToPath$2(packageJsonUrl);
8244
+ /** @type {PackageConfig} */
8245
+ const packageConfig = {
8246
+ pjsonPath: packageJsonPath,
8247
+ exists: false,
8248
+ main: undefined,
8249
+ name: undefined,
8250
+ type: 'none',
8251
+ exports: undefined,
8252
+ imports: undefined
8253
+ };
8254
+ packageJsonCache.set(packageJsonPath, packageConfig);
8255
+ return packageConfig
8256
+ }
8257
+
8258
+ /**
8259
+ * Legacy CommonJS main resolution:
8260
+ * 1. let M = pkg_url + (json main field)
8261
+ * 2. TRY(M, M.js, M.json, M.node)
8262
+ * 3. TRY(M/index.js, M/index.json, M/index.node)
8263
+ * 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
8264
+ * 5. NOT_FOUND
8265
+ *
8266
+ * @param {URL} url
8267
+ * @returns {boolean}
8268
+ */
8269
+ function fileExists(url) {
8270
+ return tryStatSync(fileURLToPath$2(url)).isFile()
8271
+ }
8272
+
8273
+ /**
8274
+ * @param {URL} packageJsonUrl
8275
+ * @param {PackageConfig} packageConfig
8276
+ * @param {URL} base
8277
+ * @returns {URL}
8278
+ */
8279
+ function legacyMainResolve(packageJsonUrl, packageConfig, base) {
8280
+ /** @type {URL} */
8281
+ let guess;
8282
+ if (packageConfig.main !== undefined) {
8283
+ guess = new URL$1(`./${packageConfig.main}`, packageJsonUrl);
8284
+ // Note: fs check redundances will be handled by Descriptor cache here.
8285
+ if (fileExists(guess)) return guess
8286
+
8287
+ const tries = [
8288
+ `./${packageConfig.main}.js`,
8289
+ `./${packageConfig.main}.json`,
8290
+ `./${packageConfig.main}.node`,
8291
+ `./${packageConfig.main}/index.js`,
8292
+ `./${packageConfig.main}/index.json`,
8293
+ `./${packageConfig.main}/index.node`
8294
+ ];
8295
+ let i = -1;
8296
+
8297
+ while (++i < tries.length) {
8298
+ guess = new URL$1(tries[i], packageJsonUrl);
8299
+ if (fileExists(guess)) break
8300
+ guess = undefined;
8301
+ }
8302
+
8303
+ if (guess) {
8304
+ emitLegacyIndexDeprecation(
8305
+ guess,
8306
+ packageJsonUrl,
8307
+ base,
8308
+ packageConfig.main
8309
+ );
8310
+ return guess
8311
+ }
8312
+ // Fallthrough.
8313
+ }
8314
+
8315
+ const tries = ['./index.js', './index.json', './index.node'];
8316
+ let i = -1;
8317
+
8318
+ while (++i < tries.length) {
8319
+ guess = new URL$1(tries[i], packageJsonUrl);
8320
+ if (fileExists(guess)) break
8321
+ guess = undefined;
8322
+ }
8323
+
8324
+ if (guess) {
8325
+ emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
8326
+ return guess
8327
+ }
8328
+
8329
+ // Not found.
8330
+ throw new ERR_MODULE_NOT_FOUND(
8331
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
8332
+ fileURLToPath$2(base)
8333
+ )
8334
+ }
8335
+
8336
+ /**
8337
+ * @param {URL} resolved
8338
+ * @param {URL} base
8339
+ * @returns {URL}
8340
+ */
8341
+ function finalizeResolution(resolved, base) {
8342
+ if (encodedSepRegEx.test(resolved.pathname))
8343
+ throw new ERR_INVALID_MODULE_SPECIFIER(
8344
+ resolved.pathname,
8345
+ 'must not include encoded "/" or "\\" characters',
8346
+ fileURLToPath$2(base)
8347
+ )
8348
+
8349
+ const path = fileURLToPath$2(resolved);
8350
+
8351
+ const stats = tryStatSync(path.endsWith('/') ? path.slice(-1) : path);
8352
+
8353
+ if (stats.isDirectory()) {
8354
+ const error = new ERR_UNSUPPORTED_DIR_IMPORT(path, fileURLToPath$2(base));
8355
+ // @ts-expect-error Add this for `import.meta.resolve`.
8356
+ error.url = String(resolved);
8357
+ throw error
8358
+ }
8359
+
8360
+ if (!stats.isFile()) {
8361
+ throw new ERR_MODULE_NOT_FOUND(
8362
+ path || resolved.pathname,
8363
+ base && fileURLToPath$2(base),
8364
+ 'module'
8365
+ )
8366
+ }
8367
+
8368
+ return resolved
8369
+ }
8370
+
8371
+ /**
8372
+ * @param {string} specifier
8373
+ * @param {URL?} packageJsonUrl
8374
+ * @param {URL} base
8375
+ * @returns {never}
8376
+ */
8377
+ function throwImportNotDefined(specifier, packageJsonUrl, base) {
8378
+ throw new ERR_PACKAGE_IMPORT_NOT_DEFINED(
8379
+ specifier,
8380
+ packageJsonUrl && fileURLToPath$2(new URL$1('.', packageJsonUrl)),
8381
+ fileURLToPath$2(base)
8382
+ )
8383
+ }
8384
+
8385
+ /**
8386
+ * @param {string} subpath
8387
+ * @param {URL} packageJsonUrl
8388
+ * @param {URL} base
8389
+ * @returns {never}
8390
+ */
8391
+ function throwExportsNotFound(subpath, packageJsonUrl, base) {
8392
+ throw new ERR_PACKAGE_PATH_NOT_EXPORTED(
8393
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
8394
+ subpath,
8395
+ base && fileURLToPath$2(base)
8396
+ )
8397
+ }
8398
+
8399
+ /**
8400
+ * @param {string} subpath
8401
+ * @param {URL} packageJsonUrl
8402
+ * @param {boolean} internal
8403
+ * @param {URL} [base]
8404
+ * @returns {never}
8405
+ */
8406
+ function throwInvalidSubpath(subpath, packageJsonUrl, internal, base) {
8407
+ const reason = `request is not a valid subpath for the "${
8408
+ internal ? 'imports' : 'exports'
8409
+ }" resolution of ${fileURLToPath$2(packageJsonUrl)}`;
8410
+
8411
+ throw new ERR_INVALID_MODULE_SPECIFIER(
8412
+ subpath,
8413
+ reason,
8414
+ base && fileURLToPath$2(base)
8415
+ )
8416
+ }
8417
+
8418
+ /**
8419
+ * @param {string} subpath
8420
+ * @param {unknown} target
8421
+ * @param {URL} packageJsonUrl
8422
+ * @param {boolean} internal
8423
+ * @param {URL} [base]
8424
+ * @returns {never}
8425
+ */
8426
+ function throwInvalidPackageTarget(
8427
+ subpath,
8428
+ target,
8429
+ packageJsonUrl,
8430
+ internal,
8431
+ base
8432
+ ) {
8433
+ target =
8434
+ typeof target === 'object' && target !== null
8435
+ ? JSON.stringify(target, null, '')
8436
+ : `${target}`;
8437
+
8438
+ throw new ERR_INVALID_PACKAGE_TARGET(
8439
+ fileURLToPath$2(new URL$1('.', packageJsonUrl)),
8440
+ subpath,
8441
+ target,
8442
+ internal,
8443
+ base && fileURLToPath$2(base)
8444
+ )
8445
+ }
8446
+
8447
+ /**
8448
+ * @param {string} target
8449
+ * @param {string} subpath
8450
+ * @param {string} match
8451
+ * @param {URL} packageJsonUrl
8452
+ * @param {URL} base
8453
+ * @param {boolean} pattern
8454
+ * @param {boolean} internal
8455
+ * @param {Set<string>} conditions
8456
+ * @returns {URL}
8457
+ */
8458
+ function resolvePackageTargetString(
8459
+ target,
8460
+ subpath,
8461
+ match,
8462
+ packageJsonUrl,
8463
+ base,
8464
+ pattern,
8465
+ internal,
8466
+ conditions
8467
+ ) {
8468
+ if (subpath !== '' && !pattern && target[target.length - 1] !== '/')
8469
+ throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
8470
+
8471
+ if (!target.startsWith('./')) {
8472
+ if (internal && !target.startsWith('../') && !target.startsWith('/')) {
8473
+ let isURL = false;
8474
+
8475
+ try {
8476
+ new URL$1(target);
8477
+ isURL = true;
8478
+ } catch {}
8479
+
8480
+ if (!isURL) {
8481
+ const exportTarget = pattern
8482
+ ? target.replace(patternRegEx, subpath)
8483
+ : target + subpath;
8484
+
8485
+ return packageResolve(exportTarget, packageJsonUrl, conditions)
8486
+ }
8487
+ }
8488
+
8489
+ throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
8490
+ }
8491
+
8492
+ if (invalidSegmentRegEx.test(target.slice(2)))
8493
+ throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
8494
+
8495
+ const resolved = new URL$1(target, packageJsonUrl);
8496
+ const resolvedPath = resolved.pathname;
8497
+ const packagePath = new URL$1('.', packageJsonUrl).pathname;
8498
+
8499
+ if (!resolvedPath.startsWith(packagePath))
8500
+ throwInvalidPackageTarget(match, target, packageJsonUrl, internal, base);
8501
+
8502
+ if (subpath === '') return resolved
8503
+
8504
+ if (invalidSegmentRegEx.test(subpath))
8505
+ throwInvalidSubpath(match + subpath, packageJsonUrl, internal, base);
8506
+
8507
+ if (pattern) return new URL$1(resolved.href.replace(patternRegEx, subpath))
8508
+ return new URL$1(subpath, resolved)
8509
+ }
8510
+
8511
+ /**
8512
+ * @param {string} key
8513
+ * @returns {boolean}
8514
+ */
8515
+ function isArrayIndex(key) {
8516
+ const keyNumber = Number(key);
8517
+ if (`${keyNumber}` !== key) return false
8518
+ return keyNumber >= 0 && keyNumber < 0xffff_ffff
8519
+ }
8520
+
8521
+ /**
8522
+ * @param {URL} packageJsonUrl
8523
+ * @param {unknown} target
8524
+ * @param {string} subpath
8525
+ * @param {string} packageSubpath
8526
+ * @param {URL} base
8527
+ * @param {boolean} pattern
8528
+ * @param {boolean} internal
8529
+ * @param {Set<string>} conditions
8530
+ * @returns {URL}
8531
+ */
8532
+ function resolvePackageTarget(
8533
+ packageJsonUrl,
8534
+ target,
8535
+ subpath,
8536
+ packageSubpath,
8537
+ base,
8538
+ pattern,
8539
+ internal,
8540
+ conditions
8541
+ ) {
8542
+ if (typeof target === 'string') {
8543
+ return resolvePackageTargetString(
8544
+ target,
8545
+ subpath,
8546
+ packageSubpath,
8547
+ packageJsonUrl,
8548
+ base,
8549
+ pattern,
8550
+ internal,
8551
+ conditions
8552
+ )
8553
+ }
8554
+
8555
+ if (Array.isArray(target)) {
8556
+ /** @type {unknown[]} */
8557
+ const targetList = target;
8558
+ if (targetList.length === 0) return null
8559
+
8560
+ /** @type {Error} */
8561
+ let lastException;
8562
+ let i = -1;
8563
+
8564
+ while (++i < targetList.length) {
8565
+ const targetItem = targetList[i];
8566
+ /** @type {URL} */
8567
+ let resolved;
8568
+ try {
8569
+ resolved = resolvePackageTarget(
8570
+ packageJsonUrl,
8571
+ targetItem,
8572
+ subpath,
8573
+ packageSubpath,
8574
+ base,
8575
+ pattern,
8576
+ internal,
8577
+ conditions
8578
+ );
8579
+ } catch (error) {
8580
+ lastException = error;
8581
+ if (error.code === 'ERR_INVALID_PACKAGE_TARGET') continue
8582
+ throw error
8583
+ }
8584
+
8585
+ if (resolved === undefined) continue
8586
+
8587
+ if (resolved === null) {
8588
+ lastException = null;
8589
+ continue
8590
+ }
8591
+
8592
+ return resolved
8593
+ }
8594
+
8595
+ if (lastException === undefined || lastException === null) {
8596
+ // @ts-expect-error The diff between `undefined` and `null` seems to be
8597
+ // intentional
8598
+ return lastException
8599
+ }
8600
+
8601
+ throw lastException
8602
+ }
8603
+
8604
+ if (typeof target === 'object' && target !== null) {
8605
+ const keys = Object.getOwnPropertyNames(target);
8606
+ let i = -1;
8607
+
8608
+ while (++i < keys.length) {
8609
+ const key = keys[i];
8610
+ if (isArrayIndex(key)) {
8611
+ throw new ERR_INVALID_PACKAGE_CONFIG(
8612
+ fileURLToPath$2(packageJsonUrl),
8613
+ base,
8614
+ '"exports" cannot contain numeric property keys.'
8615
+ )
8616
+ }
8617
+ }
8618
+
8619
+ i = -1;
8620
+
8621
+ while (++i < keys.length) {
8622
+ const key = keys[i];
8623
+ if (key === 'default' || (conditions && conditions.has(key))) {
8624
+ /** @type {unknown} */
8625
+ const conditionalTarget = target[key];
8626
+ const resolved = resolvePackageTarget(
8627
+ packageJsonUrl,
8628
+ conditionalTarget,
8629
+ subpath,
8630
+ packageSubpath,
8631
+ base,
8632
+ pattern,
8633
+ internal,
8634
+ conditions
8635
+ );
8636
+ if (resolved === undefined) continue
8637
+ return resolved
8638
+ }
8639
+ }
8640
+
8641
+ return undefined
8642
+ }
8643
+
8644
+ if (target === null) {
8645
+ return null
8646
+ }
8647
+
8648
+ throwInvalidPackageTarget(
8649
+ packageSubpath,
8650
+ target,
8651
+ packageJsonUrl,
8652
+ internal,
8653
+ base
8654
+ );
8655
+ }
8656
+
8657
+ /**
8658
+ * @param {unknown} exports
8659
+ * @param {URL} packageJsonUrl
8660
+ * @param {URL} base
8661
+ * @returns {boolean}
8662
+ */
8663
+ function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
8664
+ if (typeof exports === 'string' || Array.isArray(exports)) return true
8665
+ if (typeof exports !== 'object' || exports === null) return false
8666
+
8667
+ const keys = Object.getOwnPropertyNames(exports);
8668
+ let isConditionalSugar = false;
8669
+ let i = 0;
8670
+ let j = -1;
8671
+ while (++j < keys.length) {
8672
+ const key = keys[j];
8673
+ const curIsConditionalSugar = key === '' || key[0] !== '.';
8674
+ if (i++ === 0) {
8675
+ isConditionalSugar = curIsConditionalSugar;
8676
+ } else if (isConditionalSugar !== curIsConditionalSugar) {
8677
+ throw new ERR_INVALID_PACKAGE_CONFIG(
8678
+ fileURLToPath$2(packageJsonUrl),
8679
+ base,
8680
+ '"exports" cannot contain some keys starting with \'.\' and some not.' +
8681
+ ' The exports object must either be an object of package subpath keys' +
8682
+ ' or an object of main entry condition name keys only.'
8683
+ )
8684
+ }
8685
+ }
8686
+
8687
+ return isConditionalSugar
8688
+ }
8689
+
8690
+ /**
8691
+ * @param {URL} packageJsonUrl
8692
+ * @param {string} packageSubpath
8693
+ * @param {Object.<string, unknown>} packageConfig
8694
+ * @param {URL} base
8695
+ * @param {Set<string>} conditions
8696
+ * @returns {ResolveObject}
8697
+ */
8698
+ function packageExportsResolve(
8699
+ packageJsonUrl,
8700
+ packageSubpath,
8701
+ packageConfig,
8702
+ base,
8703
+ conditions
8704
+ ) {
8705
+ let exports = packageConfig.exports;
8706
+ if (isConditionalExportsMainSugar(exports, packageJsonUrl, base))
8707
+ exports = {'.': exports};
8708
+
8709
+ if (own.call(exports, packageSubpath)) {
8710
+ const target = exports[packageSubpath];
8711
+ const resolved = resolvePackageTarget(
8712
+ packageJsonUrl,
8713
+ target,
8714
+ '',
8715
+ packageSubpath,
8716
+ base,
8717
+ false,
8718
+ false,
8719
+ conditions
8720
+ );
8721
+ if (resolved === null || resolved === undefined)
8722
+ throwExportsNotFound(packageSubpath, packageJsonUrl, base);
8723
+ return {resolved, exact: true}
8724
+ }
8725
+
8726
+ let bestMatch = '';
8727
+ const keys = Object.getOwnPropertyNames(exports);
8728
+ let i = -1;
8729
+
8730
+ while (++i < keys.length) {
8731
+ const key = keys[i];
8732
+ if (
8733
+ key[key.length - 1] === '*' &&
8734
+ packageSubpath.startsWith(key.slice(0, -1)) &&
8735
+ packageSubpath.length >= key.length &&
8736
+ key.length > bestMatch.length
8737
+ ) {
8738
+ bestMatch = key;
8739
+ } else if (
8740
+ key[key.length - 1] === '/' &&
8741
+ packageSubpath.startsWith(key) &&
8742
+ key.length > bestMatch.length
8743
+ ) {
8744
+ bestMatch = key;
8745
+ }
8746
+ }
8747
+
8748
+ if (bestMatch) {
8749
+ const target = exports[bestMatch];
8750
+ const pattern = bestMatch[bestMatch.length - 1] === '*';
8751
+ const subpath = packageSubpath.slice(bestMatch.length - (pattern ? 1 : 0));
8752
+ const resolved = resolvePackageTarget(
8753
+ packageJsonUrl,
8754
+ target,
8755
+ subpath,
8756
+ bestMatch,
8757
+ base,
8758
+ pattern,
8759
+ false,
8760
+ conditions
8761
+ );
8762
+ if (resolved === null || resolved === undefined)
8763
+ throwExportsNotFound(packageSubpath, packageJsonUrl, base);
8764
+ if (!pattern)
8765
+ emitFolderMapDeprecation(bestMatch, packageJsonUrl, true, base);
8766
+ return {resolved, exact: pattern}
8767
+ }
8768
+
8769
+ throwExportsNotFound(packageSubpath, packageJsonUrl, base);
8770
+ }
8771
+
8772
+ /**
8773
+ * @param {string} name
8774
+ * @param {URL} base
8775
+ * @param {Set<string>} [conditions]
8776
+ * @returns {ResolveObject}
8777
+ */
8778
+ function packageImportsResolve(name, base, conditions) {
8779
+ if (name === '#' || name.startsWith('#/')) {
8780
+ const reason = 'is not a valid internal imports specifier name';
8781
+ throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath$2(base))
8782
+ }
8783
+
8784
+ /** @type {URL} */
8785
+ let packageJsonUrl;
8786
+
8787
+ const packageConfig = getPackageScopeConfig(base);
8788
+
8789
+ if (packageConfig.exists) {
8790
+ packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
8791
+ const imports = packageConfig.imports;
8792
+ if (imports) {
8793
+ if (own.call(imports, name)) {
8794
+ const resolved = resolvePackageTarget(
8795
+ packageJsonUrl,
8796
+ imports[name],
8797
+ '',
8798
+ name,
8799
+ base,
8800
+ false,
8801
+ true,
8802
+ conditions
8803
+ );
8804
+ if (resolved !== null) return {resolved, exact: true}
8805
+ } else {
8806
+ let bestMatch = '';
8807
+ const keys = Object.getOwnPropertyNames(imports);
8808
+ let i = -1;
8809
+
8810
+ while (++i < keys.length) {
8811
+ const key = keys[i];
8812
+
8813
+ if (
8814
+ key[key.length - 1] === '*' &&
8815
+ name.startsWith(key.slice(0, -1)) &&
8816
+ name.length >= key.length &&
8817
+ key.length > bestMatch.length
8818
+ ) {
8819
+ bestMatch = key;
8820
+ } else if (
8821
+ key[key.length - 1] === '/' &&
8822
+ name.startsWith(key) &&
8823
+ key.length > bestMatch.length
8824
+ ) {
8825
+ bestMatch = key;
8826
+ }
8827
+ }
8828
+
8829
+ if (bestMatch) {
8830
+ const target = imports[bestMatch];
8831
+ const pattern = bestMatch[bestMatch.length - 1] === '*';
8832
+ const subpath = name.slice(bestMatch.length - (pattern ? 1 : 0));
8833
+ const resolved = resolvePackageTarget(
8834
+ packageJsonUrl,
8835
+ target,
8836
+ subpath,
8837
+ bestMatch,
8838
+ base,
8839
+ pattern,
8840
+ true,
8841
+ conditions
8842
+ );
8843
+ if (resolved !== null) {
8844
+ if (!pattern)
8845
+ emitFolderMapDeprecation(bestMatch, packageJsonUrl, false, base);
8846
+ return {resolved, exact: pattern}
8847
+ }
8848
+ }
8849
+ }
8850
+ }
8851
+ }
8852
+
8853
+ throwImportNotDefined(name, packageJsonUrl, base);
8854
+ }
8855
+
8856
+ /**
8857
+ * @param {string} url
8858
+ * @returns {PackageType}
8859
+ */
8860
+ function getPackageType(url) {
8861
+ const packageConfig = getPackageScopeConfig(url);
8862
+ return packageConfig.type
8863
+ }
8864
+
8865
+ /**
8866
+ * @param {string} specifier
8867
+ * @param {URL} base
8868
+ */
8869
+ function parsePackageName(specifier, base) {
8870
+ let separatorIndex = specifier.indexOf('/');
8871
+ let validPackageName = true;
8872
+ let isScoped = false;
8873
+ if (specifier[0] === '@') {
8874
+ isScoped = true;
8875
+ if (separatorIndex === -1 || specifier.length === 0) {
8876
+ validPackageName = false;
8877
+ } else {
8878
+ separatorIndex = specifier.indexOf('/', separatorIndex + 1);
8879
+ }
8880
+ }
8881
+
8882
+ const packageName =
8883
+ separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
8884
+
8885
+ // Package name cannot have leading . and cannot have percent-encoding or
8886
+ // separators.
8887
+ let i = -1;
8888
+ while (++i < packageName.length) {
8889
+ if (packageName[i] === '%' || packageName[i] === '\\') {
8890
+ validPackageName = false;
8891
+ break
8892
+ }
8893
+ }
8894
+
8895
+ if (!validPackageName) {
8896
+ throw new ERR_INVALID_MODULE_SPECIFIER(
8897
+ specifier,
8898
+ 'is not a valid package name',
8899
+ fileURLToPath$2(base)
8900
+ )
8901
+ }
8902
+
8903
+ const packageSubpath =
8904
+ '.' + (separatorIndex === -1 ? '' : specifier.slice(separatorIndex));
8905
+
8906
+ return {packageName, packageSubpath, isScoped}
8907
+ }
8908
+
8909
+ /**
8910
+ * @param {string} specifier
8911
+ * @param {URL} base
8912
+ * @param {Set<string>} conditions
8913
+ * @returns {URL}
8914
+ */
8915
+ function packageResolve(specifier, base, conditions) {
8916
+ const {packageName, packageSubpath, isScoped} = parsePackageName(
8917
+ specifier,
8918
+ base
8919
+ );
8920
+
8921
+ // ResolveSelf
8922
+ const packageConfig = getPackageScopeConfig(base);
8923
+
8924
+ // Can’t test.
8925
+ /* c8 ignore next 16 */
8926
+ if (packageConfig.exists) {
8927
+ const packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
8928
+ if (
8929
+ packageConfig.name === packageName &&
8930
+ packageConfig.exports !== undefined &&
8931
+ packageConfig.exports !== null
8932
+ ) {
8933
+ return packageExportsResolve(
8934
+ packageJsonUrl,
8935
+ packageSubpath,
8936
+ packageConfig,
8937
+ base,
8938
+ conditions
8939
+ ).resolved
8940
+ }
8941
+ }
8942
+
8943
+ let packageJsonUrl = new URL$1(
8944
+ './node_modules/' + packageName + '/package.json',
8945
+ base
8946
+ );
8947
+ let packageJsonPath = fileURLToPath$2(packageJsonUrl);
8948
+ /** @type {string} */
8949
+ let lastPath;
8950
+ do {
8951
+ const stat = tryStatSync(packageJsonPath.slice(0, -13));
8952
+ if (!stat.isDirectory()) {
8953
+ lastPath = packageJsonPath;
8954
+ packageJsonUrl = new URL$1(
8955
+ (isScoped ? '../../../../node_modules/' : '../../../node_modules/') +
8956
+ packageName +
8957
+ '/package.json',
8958
+ packageJsonUrl
8959
+ );
8960
+ packageJsonPath = fileURLToPath$2(packageJsonUrl);
8961
+ continue
8962
+ }
8963
+
8964
+ // Package match.
8965
+ const packageConfig = getPackageConfig(packageJsonPath, specifier, base);
8966
+ if (packageConfig.exports !== undefined && packageConfig.exports !== null)
8967
+ return packageExportsResolve(
8968
+ packageJsonUrl,
8969
+ packageSubpath,
8970
+ packageConfig,
8971
+ base,
8972
+ conditions
8973
+ ).resolved
8974
+ if (packageSubpath === '.')
8975
+ return legacyMainResolve(packageJsonUrl, packageConfig, base)
8976
+ return new URL$1(packageSubpath, packageJsonUrl)
8977
+ // Cross-platform root check.
8978
+ } while (packageJsonPath.length !== lastPath.length)
8979
+
8980
+ throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath$2(base))
8981
+ }
8982
+
8983
+ /**
8984
+ * @param {string} specifier
8985
+ * @returns {boolean}
8986
+ */
8987
+ function isRelativeSpecifier(specifier) {
8988
+ if (specifier[0] === '.') {
8989
+ if (specifier.length === 1 || specifier[1] === '/') return true
8990
+ if (
8991
+ specifier[1] === '.' &&
8992
+ (specifier.length === 2 || specifier[2] === '/')
8993
+ ) {
8994
+ return true
8995
+ }
8996
+ }
8997
+
8998
+ return false
8999
+ }
9000
+
9001
+ /**
9002
+ * @param {string} specifier
9003
+ * @returns {boolean}
9004
+ */
9005
+ function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
9006
+ if (specifier === '') return false
9007
+ if (specifier[0] === '/') return true
9008
+ return isRelativeSpecifier(specifier)
9009
+ }
9010
+
9011
+ /**
9012
+ * The “Resolver Algorithm Specification” as detailed in the Node docs (which is
9013
+ * sync and slightly lower-level than `resolve`).
9014
+ *
9015
+ *
9016
+ *
9017
+ * @param {string} specifier
9018
+ * @param {URL} base
9019
+ * @param {Set<string>} [conditions]
9020
+ * @returns {URL}
9021
+ */
9022
+ function moduleResolve(specifier, base, conditions) {
9023
+ // Order swapped from spec for minor perf gain.
9024
+ // Ok since relative URLs cannot parse as URLs.
9025
+ /** @type {URL} */
9026
+ let resolved;
9027
+
9028
+ if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
9029
+ resolved = new URL$1(specifier, base);
9030
+ } else if (specifier[0] === '#') {
9031
+ ({resolved} = packageImportsResolve(specifier, base, conditions));
9032
+ } else {
9033
+ try {
9034
+ resolved = new URL$1(specifier);
9035
+ } catch {
9036
+ resolved = packageResolve(specifier, base, conditions);
9037
+ }
9038
+ }
9039
+
9040
+ return finalizeResolution(resolved, base)
9041
+ }
9042
+
9043
+ const DEFAULT_CONDITIONS_SET = new Set(["node", "import"]);
9044
+ const DEFAULT_URL = pathToFileURL(process.cwd());
9045
+ const DEFAULT_EXTENSIONS = [".mjs", ".cjs", ".js", ".json"];
9046
+ const NOT_FOUND_ERRORS = new Set(["ERR_MODULE_NOT_FOUND", "ERR_UNSUPPORTED_DIR_IMPORT", "MODULE_NOT_FOUND"]);
9047
+ function _tryModuleResolve(id, url, conditions) {
9048
+ try {
9049
+ return moduleResolve(id, url, conditions);
9050
+ } catch (err) {
9051
+ if (!NOT_FOUND_ERRORS.has(err.code)) {
9052
+ throw err;
9053
+ }
9054
+ return null;
9055
+ }
9056
+ }
9057
+ function _resolve(id, opts = {}) {
9058
+ if (/(node|data|http|https):/.test(id)) {
9059
+ return id;
9060
+ }
9061
+ if (BUILTIN_MODULES.has(id)) {
9062
+ return "node:" + id;
9063
+ }
9064
+ if (isAbsolute(id)) {
9065
+ return id;
9066
+ }
9067
+ const conditionsSet = opts.conditions ? new Set(opts.conditions) : DEFAULT_CONDITIONS_SET;
9068
+ const _urls = (Array.isArray(opts.url) ? opts.url : [opts.url]).filter(Boolean).map((u) => new URL(normalizeid(u.toString())));
9069
+ if (!_urls.length) {
9070
+ _urls.push(DEFAULT_URL);
9071
+ }
9072
+ const urls = [..._urls];
9073
+ for (const url of _urls) {
9074
+ if (url.protocol === "file:" && !url.pathname.includes("node_modules")) {
9075
+ const newURL = new URL(url);
9076
+ newURL.pathname += "/node_modules";
9077
+ urls.push(newURL);
9078
+ }
9079
+ }
9080
+ let resolved;
9081
+ for (const url of urls) {
9082
+ resolved = _tryModuleResolve(id, url, conditionsSet);
9083
+ if (resolved) {
9084
+ break;
9085
+ }
9086
+ for (const prefix of ["", "/index"]) {
9087
+ for (const ext of opts.extensions || DEFAULT_EXTENSIONS) {
9088
+ resolved = _tryModuleResolve(id + prefix + ext, url, conditionsSet);
9089
+ if (resolved) {
9090
+ break;
9091
+ }
9092
+ }
9093
+ if (resolved) {
9094
+ break;
9095
+ }
9096
+ }
9097
+ }
9098
+ if (!resolved) {
9099
+ const err = new Error(`Cannot find module ${id} imported from ${urls.join(", ")}`);
9100
+ err.code = "ERR_MODULE_NOT_FOUND";
9101
+ throw err;
9102
+ }
9103
+ const realPath = realpathSync(fileURLToPath(resolved));
9104
+ return pathToFileURL(realPath).toString();
9105
+ }
9106
+ function resolveSync(id, opts) {
9107
+ return _resolve(id, opts);
9108
+ }
9109
+ function resolvePathSync(id, opts) {
9110
+ return fileURLToPath(resolveSync(id, opts));
9111
+ }
9112
+ function resolvePath(id, opts) {
9113
+ return pcall(resolvePathSync, id, opts);
9114
+ }
9115
+
9116
+ const defaultFindOptions = {
9117
+ startingFrom: ".",
9118
+ rootPattern: /^node_modules$/,
9119
+ test: (filePath) => {
9120
+ try {
9121
+ if (statSync(filePath).isFile()) {
9122
+ return true;
9123
+ }
9124
+ } catch {
9125
+ }
9126
+ return null;
9127
+ }
9128
+ };
9129
+ async function findNearestFile(filename, _options = {}) {
9130
+ const options = { ...defaultFindOptions, ..._options };
9131
+ const basePath = resolve$2(options.startingFrom);
9132
+ const leadingSlash = basePath[0] === "/";
9133
+ const segments = basePath.split("/").filter(Boolean);
9134
+ if (leadingSlash) {
9135
+ segments[0] = "/" + segments[0];
9136
+ }
9137
+ let root = segments.findIndex((r) => r.match(options.rootPattern));
9138
+ if (root === -1)
9139
+ root = 0;
9140
+ for (let i = segments.length; i > root; i--) {
9141
+ const filePath = join$1(...segments.slice(0, i), filename);
9142
+ if (await options.test(filePath)) {
9143
+ return filePath;
9144
+ }
9145
+ }
9146
+ throw new Error(`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`);
9147
+ }
9148
+ async function readPackageJSON(id, opts = {}) {
9149
+ const resolvedPath = await resolvePackageJSON(id, opts);
9150
+ const blob = await promises.readFile(resolvedPath, "utf-8");
9151
+ return JSON.parse(blob);
9152
+ }
9153
+ async function resolvePackageJSON(id = process.cwd(), opts = {}) {
9154
+ const resolvedPath = isAbsolute$1(id) ? id : await resolvePath(id, opts);
9155
+ return findNearestFile("package.json", { startingFrom: resolvedPath });
8195
9156
  }
9157
+
8196
9158
  const ESM_RE = /([\s;]|^)(import[\w,{}\s*]*from|import\s*['"*{]|export\b\s*(?:[*{]|default|type|function|const|var|let|async function)|import\.meta\b)/m;
8197
- const BUILTIN_EXTENSIONS = /* @__PURE__ */ new Set([".mjs", ".cjs", ".node", ".wasm"]);
9159
+ const BUILTIN_EXTENSIONS = new Set([".mjs", ".cjs", ".node", ".wasm"]);
8198
9160
  function hasESMSyntax(code) {
8199
9161
  return ESM_RE.test(code);
8200
9162
  }
9163
+ const CJS_RE = /([\s;]|^)(module.exports\b|exports\.\w|require\s*\(|global\.\w)/m;
9164
+ function hasCJSSyntax(code) {
9165
+ return CJS_RE.test(code);
9166
+ }
8201
9167
  const validNodeImportDefaults = {
8202
9168
  allowedProtocols: ["node", "file", "data"]
8203
9169
  };
8204
9170
  async function isValidNodeImport(id, _opts = {}) {
8205
- var _a;
8206
- if (isNodeBuiltin(id))
9171
+ if (isNodeBuiltin(id)) {
8207
9172
  return true;
8208
- const opts = __spreadValues(__spreadValues({}, validNodeImportDefaults), _opts);
9173
+ }
9174
+ const opts = { ...validNodeImportDefaults, ..._opts };
8209
9175
  const proto = getProtocol(id);
8210
- if (proto && !((_a = opts.allowedProtocols) == null ? void 0 : _a.includes(proto)))
9176
+ if (proto && !opts.allowedProtocols.includes(proto)) {
8211
9177
  return false;
8212
- if (proto === "data")
9178
+ }
9179
+ if (proto === "data") {
8213
9180
  return true;
9181
+ }
8214
9182
  const resolvedPath = await resolvePath$1(id, opts);
8215
- const extension = extname$2(resolvedPath);
8216
- if (BUILTIN_EXTENSIONS.has(extension))
9183
+ const extension = extname$1(resolvedPath);
9184
+ if (BUILTIN_EXTENSIONS.has(extension)) {
8217
9185
  return true;
8218
- if (extension !== ".js")
9186
+ }
9187
+ if (extension !== ".js") {
8219
9188
  return false;
8220
- if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/))
9189
+ }
9190
+ if (resolvedPath.match(/\.(\w+-)?esm?(-\w+)?\.js$/)) {
8221
9191
  return false;
9192
+ }
8222
9193
  const pkg = await readPackageJSON(resolvedPath).catch(() => null);
8223
- if ((pkg == null ? void 0 : pkg.type) === "module")
9194
+ if (pkg?.type === "module") {
8224
9195
  return true;
9196
+ }
8225
9197
  const code = opts.code || await promises.readFile(resolvedPath, "utf-8").catch(() => null) || "";
8226
9198
  return hasCJSSyntax(code) || !hasESMSyntax(code);
8227
9199
  }
@@ -8255,18 +9227,21 @@ const stubRequests = {
8255
9227
  };
8256
9228
  async function interpretedImport(path, interpretDefault) {
8257
9229
  const mod = await import(path);
8258
- if (interpretDefault && "__esModule" in mod && "default" in mod) {
8259
- const defaultExport = mod.default;
8260
- if (!("default" in defaultExport)) {
8261
- Object.defineProperty(defaultExport, "default", {
8262
- enumerable: true,
8263
- configurable: true,
8264
- get() {
8265
- return defaultExport;
8266
- }
8267
- });
8268
- }
8269
- return defaultExport;
9230
+ if (interpretDefault && "default" in mod) {
9231
+ return new Proxy(mod, {
9232
+ get(target, key, receiver) {
9233
+ return Reflect.get(target, key, receiver) || Reflect.get(target.default, key, receiver);
9234
+ },
9235
+ set(target, key, value, receiver) {
9236
+ return Reflect.set(target, key, value, receiver) || Reflect.set(target.default, key, value, receiver);
9237
+ },
9238
+ has(target, key) {
9239
+ return Reflect.has(target, key) || Reflect.has(target.default, key);
9240
+ },
9241
+ deleteProperty(target, key) {
9242
+ return Reflect.deleteProperty(target, key) || Reflect.deleteProperty(target.default, key);
9243
+ }
9244
+ });
8270
9245
  }
8271
9246
  return mod;
8272
9247
  }
@@ -8276,7 +9251,7 @@ async function executeInViteNode(options) {
8276
9251
  builtinModules.forEach((m) => externalCache.set(m, true));
8277
9252
  const result = [];
8278
9253
  for (const file of files)
8279
- result.push(await cachedRequest(`/@fs/${slash(resolve$3(file))}`, []));
9254
+ result.push(await cachedRequest(`/@fs/${slash(resolve(file))}`, []));
8280
9255
  return result;
8281
9256
  async function directRequest(id, fsPath, callstack) {
8282
9257
  callstack = [...callstack, id];
@@ -8300,7 +9275,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
8300
9275
  const url = pathToFileURL(fsPath).href;
8301
9276
  const exports = {};
8302
9277
  setCache(fsPath, { code: transformed, exports });
8303
- const __filename = fileURLToPath(url);
9278
+ const __filename = fileURLToPath$2(url);
8304
9279
  const moduleProxy = {
8305
9280
  set exports(value) {
8306
9281
  exportAll(exports, value);
@@ -8320,10 +9295,10 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
8320
9295
  exports,
8321
9296
  module: moduleProxy,
8322
9297
  __filename,
8323
- __dirname: dirname$3(__filename)
9298
+ __dirname: dirname$2(__filename)
8324
9299
  };
8325
- const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{${transformed}
8326
- }`, {
9300
+ const fn = vm.runInThisContext(`async (${Object.keys(context).join(",")})=>{{${transformed}
9301
+ }}`, {
8327
9302
  filename: fsPath,
8328
9303
  lineOffset: 0
8329
9304
  });
@@ -8340,7 +9315,7 @@ ${[...callstack, dep].reverse().map((p) => `- ${p}`).join("\n")}`);
8340
9315
  var _a, _b;
8341
9316
  const id = normalizeId(rawId);
8342
9317
  if (externalCache.get(id))
8343
- return interpretedImport(id, options.interpretDefault);
9318
+ return interpretedImport(patchWindowsImportPath(id), options.interpretDefault);
8344
9319
  const fsPath = toFilePath(id, root);
8345
9320
  const importPath = patchWindowsImportPath(fsPath);
8346
9321
  if (!externalCache.has(importPath))
@@ -8385,10 +9360,10 @@ async function shouldExternalize(id, config) {
8385
9360
  return id.includes("/node_modules/") && await isValidNodeImport(id);
8386
9361
  }
8387
9362
  function toFilePath(id, root) {
8388
- let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$3(root)) ? id : id.startsWith("/") ? slash(resolve$3(root, id.slice(1))) : id;
9363
+ let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname$2(root)) ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
8389
9364
  if (absolute.startsWith("//"))
8390
9365
  absolute = absolute.slice(1);
8391
- return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
9366
+ return isWindows && absolute.startsWith("/") ? fileURLToPath$2(pathToFileURL(absolute.slice(1)).href) : absolute;
8392
9367
  }
8393
9368
  function matchExternalizePattern(id, patterns) {
8394
9369
  for (const ex of patterns) {
@@ -8405,6 +9380,8 @@ function matchExternalizePattern(id, patterns) {
8405
9380
  function patchWindowsImportPath(path) {
8406
9381
  if (path.match(/^\w:\\/))
8407
9382
  return `file:///${slash(path)}`;
9383
+ else if (path.match(/^\w:\//))
9384
+ return `file:///${path}`;
8408
9385
  else
8409
9386
  return path;
8410
9387
  }
@@ -8426,7 +9403,7 @@ async function startViteNode(ctx) {
8426
9403
  const { run: run2, collect: collect2 } = (await executeInViteNode({
8427
9404
  root: config.root,
8428
9405
  files: [
8429
- resolve$3(distDir, "entry.js")
9406
+ resolve(distDir, "entry.js")
8430
9407
  ],
8431
9408
  fetch(id) {
8432
9409
  return process.__vitest_worker__.rpc("fetch", id);