vite 6.0.3 → 6.0.5

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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -5,7 +5,7 @@ import path$d, { posix as posix$1, isAbsolute as isAbsolute$1, join as join$1, r
5
5
  import require$$1$1, { fileURLToPath as fileURLToPath$1, URL as URL$3, pathToFileURL as pathToFileURL$1 } from 'node:url';
6
6
  import { promisify as promisify$4, format as format$2, inspect, stripVTControlCharacters } from 'node:util';
7
7
  import { performance } from 'node:perf_hooks';
8
- import require$$0$5, { createRequire as createRequire$1, builtinModules } from 'node:module';
8
+ import require$$0$6, { createRequire as createRequire$1, builtinModules } from 'node:module';
9
9
  import esbuild, { transform as transform$1, formatMessages, build as build$b } from 'esbuild';
10
10
  import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, ENV_ENTRY, SPECIAL_QUERY_RE, DEP_VERSION_RE, DEV_PROD_CONDITION, JS_TYPES_RE, KNOWN_ASSET_TYPES, CSS_LANGS_RE, METADATA_FILENAME, ESBUILD_MODULES_TARGET, ERR_OPTIMIZE_DEPS_PROCESSING_ERROR, ERR_FILE_NOT_FOUND_IN_OPTIMIZED_DEP_DIR, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, ROLLUP_HOOKS, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES, DEFAULT_CLIENT_MAIN_FIELDS, DEFAULT_SERVER_MAIN_FIELDS, DEFAULT_CLIENT_CONDITIONS, DEFAULT_SERVER_CONDITIONS } from '../constants.js';
11
11
  import require$$0$2, { posix, win32, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join, sep } from 'path';
@@ -17,7 +17,7 @@ import require$$0$4 from 'tty';
17
17
  import require$$1 from 'util';
18
18
  import require$$4$1 from 'net';
19
19
  import require$$0$7 from 'events';
20
- import require$$0$6 from 'url';
20
+ import require$$0$5 from 'url';
21
21
  import require$$1$2 from 'http';
22
22
  import require$$0$8 from 'stream';
23
23
  import require$$2 from 'os';
@@ -35,7 +35,7 @@ import { EventEmitter as EventEmitter$4 } from 'node:events';
35
35
  import require$$3 from 'crypto';
36
36
  import assert$1 from 'node:assert';
37
37
  import v8 from 'node:v8';
38
- import { Worker as Worker$1 } from 'node:worker_threads';
38
+ import { Worker as Worker$1, MessageChannel } from 'node:worker_threads';
39
39
  import zlib$1 from 'zlib';
40
40
  import require$$0$9 from 'buffer';
41
41
  import require$$1$3 from 'https';
@@ -2544,7 +2544,7 @@ const attachScopes = function attachScopes(ast, propertyName = 'scope') {
2544
2544
  }
2545
2545
  let newScope;
2546
2546
  // create new function scope
2547
- if (/Function/.test(node.type)) {
2547
+ if (node.type.includes('Function')) {
2548
2548
  const func = node;
2549
2549
  newScope = new Scope({
2550
2550
  parent: scope,
@@ -2565,7 +2565,7 @@ const attachScopes = function attachScopes(ast, propertyName = 'scope') {
2565
2565
  });
2566
2566
  }
2567
2567
  // create new block scope
2568
- if (node.type === 'BlockStatement' && !/Function/.test(parent.type)) {
2568
+ if (node.type === 'BlockStatement' && !parent.type.includes('Function')) {
2569
2569
  newScope = new Scope({
2570
2570
  parent: scope,
2571
2571
  block: true
@@ -2652,11 +2652,17 @@ const createFilter$1 = function createFilter(include, exclude, options) {
2652
2652
  const pathId = normalizePath$6(id);
2653
2653
  for (let i = 0; i < excludeMatchers.length; ++i) {
2654
2654
  const matcher = excludeMatchers[i];
2655
+ if (matcher instanceof RegExp) {
2656
+ matcher.lastIndex = 0;
2657
+ }
2655
2658
  if (matcher.test(pathId))
2656
2659
  return false;
2657
2660
  }
2658
2661
  for (let i = 0; i < includeMatchers.length; ++i) {
2659
2662
  const matcher = includeMatchers[i];
2663
+ if (matcher instanceof RegExp) {
2664
+ matcher.lastIndex = 0;
2665
+ }
2660
2666
  if (matcher.test(pathId))
2661
2667
  return true;
2662
2668
  }
@@ -3880,7 +3886,7 @@ class Chunk {
3880
3886
  // ' test'.trim()
3881
3887
  // split -> ' ' + 'test'
3882
3888
  // ✔️ edit -> '' + 'test'
3883
- // ✖️ edit -> 'test' + ''
3889
+ // ✖️ edit -> 'test' + ''
3884
3890
  // TODO is this block necessary?...
3885
3891
  newChunk.edit('', false);
3886
3892
  this.content = '';
@@ -4127,6 +4133,7 @@ class Mappings {
4127
4133
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
4128
4134
  this.generatedCodeColumn = 0;
4129
4135
  first = true;
4136
+ charInHiresBoundary = false;
4130
4137
  } else {
4131
4138
  if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
4132
4139
  const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
@@ -4204,6 +4211,7 @@ class MagicString {
4204
4211
  storedNames: { writable: true, value: {} },
4205
4212
  indentStr: { writable: true, value: undefined },
4206
4213
  ignoreList: { writable: true, value: options.ignoreList },
4214
+ offset: { writable: true, value: options.offset || 0 },
4207
4215
  });
4208
4216
 
4209
4217
  this.byStart[0] = chunk;
@@ -4222,6 +4230,8 @@ class MagicString {
4222
4230
  }
4223
4231
 
4224
4232
  appendLeft(index, content) {
4233
+ index = index + this.offset;
4234
+
4225
4235
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
4226
4236
 
4227
4237
  this._split(index);
@@ -4237,6 +4247,8 @@ class MagicString {
4237
4247
  }
4238
4248
 
4239
4249
  appendRight(index, content) {
4250
+ index = index + this.offset;
4251
+
4240
4252
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
4241
4253
 
4242
4254
  this._split(index);
@@ -4252,7 +4264,7 @@ class MagicString {
4252
4264
  }
4253
4265
 
4254
4266
  clone() {
4255
- const cloned = new MagicString(this.original, { filename: this.filename });
4267
+ const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
4256
4268
 
4257
4269
  let originalChunk = this.firstChunk;
4258
4270
  let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
@@ -4450,7 +4462,7 @@ class MagicString {
4450
4462
  if (!warned.insertLeft) {
4451
4463
  console.warn(
4452
4464
  'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
4453
- ); // eslint-disable-line no-console
4465
+ );
4454
4466
  warned.insertLeft = true;
4455
4467
  }
4456
4468
 
@@ -4461,7 +4473,7 @@ class MagicString {
4461
4473
  if (!warned.insertRight) {
4462
4474
  console.warn(
4463
4475
  'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
4464
- ); // eslint-disable-line no-console
4476
+ );
4465
4477
  warned.insertRight = true;
4466
4478
  }
4467
4479
 
@@ -4469,6 +4481,10 @@ class MagicString {
4469
4481
  }
4470
4482
 
4471
4483
  move(start, end, index) {
4484
+ start = start + this.offset;
4485
+ end = end + this.offset;
4486
+ index = index + this.offset;
4487
+
4472
4488
  if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
4473
4489
 
4474
4490
  this._split(start);
@@ -4511,6 +4527,9 @@ class MagicString {
4511
4527
  }
4512
4528
 
4513
4529
  update(start, end, content, options) {
4530
+ start = start + this.offset;
4531
+ end = end + this.offset;
4532
+
4514
4533
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
4515
4534
 
4516
4535
  if (this.original.length !== 0) {
@@ -4531,7 +4550,7 @@ class MagicString {
4531
4550
  if (!warned.storeName) {
4532
4551
  console.warn(
4533
4552
  'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
4534
- ); // eslint-disable-line no-console
4553
+ );
4535
4554
  warned.storeName = true;
4536
4555
  }
4537
4556
 
@@ -4582,6 +4601,8 @@ class MagicString {
4582
4601
  }
4583
4602
 
4584
4603
  prependLeft(index, content) {
4604
+ index = index + this.offset;
4605
+
4585
4606
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
4586
4607
 
4587
4608
  this._split(index);
@@ -4597,6 +4618,8 @@ class MagicString {
4597
4618
  }
4598
4619
 
4599
4620
  prependRight(index, content) {
4621
+ index = index + this.offset;
4622
+
4600
4623
  if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
4601
4624
 
4602
4625
  this._split(index);
@@ -4612,6 +4635,9 @@ class MagicString {
4612
4635
  }
4613
4636
 
4614
4637
  remove(start, end) {
4638
+ start = start + this.offset;
4639
+ end = end + this.offset;
4640
+
4615
4641
  if (this.original.length !== 0) {
4616
4642
  while (start < 0) start += this.original.length;
4617
4643
  while (end < 0) end += this.original.length;
@@ -4638,6 +4664,9 @@ class MagicString {
4638
4664
  }
4639
4665
 
4640
4666
  reset(start, end) {
4667
+ start = start + this.offset;
4668
+ end = end + this.offset;
4669
+
4641
4670
  if (this.original.length !== 0) {
4642
4671
  while (start < 0) start += this.original.length;
4643
4672
  while (end < 0) end += this.original.length;
@@ -4702,7 +4731,10 @@ class MagicString {
4702
4731
  return this.intro + lineStr;
4703
4732
  }
4704
4733
 
4705
- slice(start = 0, end = this.original.length) {
4734
+ slice(start = 0, end = this.original.length - this.offset) {
4735
+ start = start + this.offset;
4736
+ end = end + this.offset;
4737
+
4706
4738
  if (this.original.length !== 0) {
4707
4739
  while (start < 0) start += this.original.length;
4708
4740
  while (end < 0) end += this.original.length;
@@ -4938,11 +4970,7 @@ class MagicString {
4938
4970
  if (match.index != null) {
4939
4971
  const replacement = getReplacement(match, this.original);
4940
4972
  if (replacement !== match[0]) {
4941
- this.overwrite(
4942
- match.index,
4943
- match.index + match[0].length,
4944
- replacement
4945
- );
4973
+ this.overwrite(match.index, match.index + match[0].length, replacement);
4946
4974
  }
4947
4975
  }
4948
4976
  });
@@ -4951,11 +4979,7 @@ class MagicString {
4951
4979
  if (match && match.index != null) {
4952
4980
  const replacement = getReplacement(match, this.original);
4953
4981
  if (replacement !== match[0]) {
4954
- this.overwrite(
4955
- match.index,
4956
- match.index + match[0].length,
4957
- replacement
4958
- );
4982
+ this.overwrite(match.index, match.index + match[0].length, replacement);
4959
4983
  }
4960
4984
  }
4961
4985
  }
@@ -4990,8 +5014,7 @@ class MagicString {
4990
5014
  index = original.indexOf(string, index + stringLength)
4991
5015
  ) {
4992
5016
  const previous = original.slice(index, index + stringLength);
4993
- if (previous !== replacement)
4994
- this.overwrite(index, index + stringLength, replacement);
5017
+ if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
4995
5018
  }
4996
5019
 
4997
5020
  return this;
@@ -5042,7 +5065,7 @@ function isReference(node, parent) {
5042
5065
  return false;
5043
5066
  }
5044
5067
 
5045
- var version$2 = "28.0.1";
5068
+ var version$2 = "28.0.2";
5046
5069
  var peerDependencies = {
5047
5070
  rollup: "^2.68.0||^3.0.0||^4.0.0"
5048
5071
  };
@@ -8638,24 +8661,62 @@ function requireCommon () {
8638
8661
  createDebug.names = [];
8639
8662
  createDebug.skips = [];
8640
8663
 
8641
- let i;
8642
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
8643
- const len = split.length;
8664
+ const split = (typeof namespaces === 'string' ? namespaces : '')
8665
+ .trim()
8666
+ .replace(' ', ',')
8667
+ .split(',')
8668
+ .filter(Boolean);
8644
8669
 
8645
- for (i = 0; i < len; i++) {
8646
- if (!split[i]) {
8647
- // ignore empty strings
8648
- continue;
8670
+ for (const ns of split) {
8671
+ if (ns[0] === '-') {
8672
+ createDebug.skips.push(ns.slice(1));
8673
+ } else {
8674
+ createDebug.names.push(ns);
8649
8675
  }
8676
+ }
8677
+ }
8650
8678
 
8651
- namespaces = split[i].replace(/\*/g, '.*?');
8652
-
8653
- if (namespaces[0] === '-') {
8654
- createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
8679
+ /**
8680
+ * Checks if the given string matches a namespace template, honoring
8681
+ * asterisks as wildcards.
8682
+ *
8683
+ * @param {String} search
8684
+ * @param {String} template
8685
+ * @return {Boolean}
8686
+ */
8687
+ function matchesTemplate(search, template) {
8688
+ let searchIndex = 0;
8689
+ let templateIndex = 0;
8690
+ let starIndex = -1;
8691
+ let matchIndex = 0;
8692
+
8693
+ while (searchIndex < search.length) {
8694
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
8695
+ // Match character or proceed with wildcard
8696
+ if (template[templateIndex] === '*') {
8697
+ starIndex = templateIndex;
8698
+ matchIndex = searchIndex;
8699
+ templateIndex++; // Skip the '*'
8700
+ } else {
8701
+ searchIndex++;
8702
+ templateIndex++;
8703
+ }
8704
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
8705
+ // Backtrack to the last '*' and try to match more characters
8706
+ templateIndex = starIndex + 1;
8707
+ matchIndex++;
8708
+ searchIndex = matchIndex;
8655
8709
  } else {
8656
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
8710
+ return false; // No match
8657
8711
  }
8658
8712
  }
8713
+
8714
+ // Handle trailing '*' in template
8715
+ while (templateIndex < template.length && template[templateIndex] === '*') {
8716
+ templateIndex++;
8717
+ }
8718
+
8719
+ return templateIndex === template.length;
8659
8720
  }
8660
8721
 
8661
8722
  /**
@@ -8666,8 +8727,8 @@ function requireCommon () {
8666
8727
  */
8667
8728
  function disable() {
8668
8729
  const namespaces = [
8669
- ...createDebug.names.map(toNamespace),
8670
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
8730
+ ...createDebug.names,
8731
+ ...createDebug.skips.map(namespace => '-' + namespace)
8671
8732
  ].join(',');
8672
8733
  createDebug.enable('');
8673
8734
  return namespaces;
@@ -8681,21 +8742,14 @@ function requireCommon () {
8681
8742
  * @api public
8682
8743
  */
8683
8744
  function enabled(name) {
8684
- if (name[name.length - 1] === '*') {
8685
- return true;
8686
- }
8687
-
8688
- let i;
8689
- let len;
8690
-
8691
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
8692
- if (createDebug.skips[i].test(name)) {
8745
+ for (const skip of createDebug.skips) {
8746
+ if (matchesTemplate(name, skip)) {
8693
8747
  return false;
8694
8748
  }
8695
8749
  }
8696
8750
 
8697
- for (i = 0, len = createDebug.names.length; i < len; i++) {
8698
- if (createDebug.names[i].test(name)) {
8751
+ for (const ns of createDebug.names) {
8752
+ if (matchesTemplate(name, ns)) {
8699
8753
  return true;
8700
8754
  }
8701
8755
  }
@@ -8703,19 +8757,6 @@ function requireCommon () {
8703
8757
  return false;
8704
8758
  }
8705
8759
 
8706
- /**
8707
- * Convert regexp to namespace
8708
- *
8709
- * @param {RegExp} regxep
8710
- * @return {String} namespace
8711
- * @api private
8712
- */
8713
- function toNamespace(regexp) {
8714
- return regexp.toString()
8715
- .substring(2, regexp.toString().length - 2)
8716
- .replace(/\.\*\?$/, '*');
8717
- }
8718
-
8719
8760
  /**
8720
8761
  * Coerce `val`.
8721
8762
  *
@@ -8884,6 +8925,7 @@ function requireBrowser$1 () {
8884
8925
 
8885
8926
  // Is webkit? http://stackoverflow.com/a/16459606/376773
8886
8927
  // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
8928
+ // eslint-disable-next-line no-return-assign
8887
8929
  return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
8888
8930
  // Is firebug? http://stackoverflow.com/a/398120/376773
8889
8931
  (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
@@ -12382,8 +12424,18 @@ async function reloadOnTsconfigChange(server, changedFile) {
12382
12424
  }
12383
12425
  }
12384
12426
 
12427
+ // src/realWorker.ts
12428
+
12429
+ // src/utils.ts
12430
+ var AsyncFunction = async function() {
12431
+ }.constructor;
12432
+ var codeToDataUrl = (code) => `data:application/javascript,${encodeURIComponent(code + "\n//# sourceURL=[worker-eval(artichokie)]")}`;
12433
+ var viteSsrDynamicImport = "__vite_ssr_dynamic_import__";
12434
+
12385
12435
  // src/realWorker.ts
12386
12436
  var Worker = class {
12437
+ /** @internal */
12438
+ _isModule;
12387
12439
  /** @internal */
12388
12440
  _code;
12389
12441
  /** @internal */
@@ -12397,7 +12449,12 @@ var Worker = class {
12397
12449
  /** @internal */
12398
12450
  _queue;
12399
12451
  constructor(fn, options = {}) {
12400
- this._code = genWorkerCode(fn, options.parentFunctions ?? {});
12452
+ this._isModule = options.type === "module";
12453
+ this._code = genWorkerCode(
12454
+ fn,
12455
+ this._isModule,
12456
+ options.parentFunctions ?? {}
12457
+ );
12401
12458
  this._parentFunctions = options.parentFunctions ?? {};
12402
12459
  const defaultMax = Math.max(
12403
12460
  1,
@@ -12414,7 +12471,7 @@ var Worker = class {
12414
12471
  return new Promise((resolve, reject) => {
12415
12472
  worker.currentResolve = resolve;
12416
12473
  worker.currentReject = reject;
12417
- worker.postMessage({ type: "run", args });
12474
+ worker.postMessage({ args });
12418
12475
  });
12419
12476
  }
12420
12477
  stop() {
@@ -12429,51 +12486,70 @@ var Worker = class {
12429
12486
  this._queue = [];
12430
12487
  }
12431
12488
  /** @internal */
12489
+ _createWorker(parentFunctionSyncMessagePort, parentFunctionAsyncMessagePort, lockState) {
12490
+ const options = {
12491
+ workerData: [
12492
+ parentFunctionSyncMessagePort,
12493
+ parentFunctionAsyncMessagePort,
12494
+ lockState
12495
+ ],
12496
+ transferList: [
12497
+ parentFunctionSyncMessagePort,
12498
+ parentFunctionAsyncMessagePort
12499
+ ]
12500
+ };
12501
+ if (this._isModule) {
12502
+ return new Worker$1(
12503
+ new URL(codeToDataUrl(this._code)),
12504
+ options
12505
+ );
12506
+ }
12507
+ return new Worker$1(this._code, {
12508
+ ...options,
12509
+ eval: true
12510
+ });
12511
+ }
12512
+ /** @internal */
12432
12513
  async _getAvailableWorker() {
12433
12514
  if (this._idlePool.length) {
12434
12515
  return this._idlePool.shift();
12435
12516
  }
12436
12517
  if (this._pool.length < this._max) {
12437
- const worker = new Worker$1(this._code, { eval: true });
12518
+ const parentFunctionResponder = createParentFunctionResponder(
12519
+ this._parentFunctions
12520
+ );
12521
+ const worker = this._createWorker(
12522
+ parentFunctionResponder.workerPorts.sync,
12523
+ parentFunctionResponder.workerPorts.async,
12524
+ parentFunctionResponder.lockState
12525
+ );
12438
12526
  worker.on("message", async (args) => {
12439
- if (args.type === "run") {
12440
- if ("result" in args) {
12441
- worker.currentResolve && worker.currentResolve(args.result);
12442
- worker.currentResolve = null;
12443
- } else {
12444
- if (args.error instanceof ReferenceError) {
12445
- args.error.message += ". Maybe you forgot to pass the function to parentFunction?";
12446
- }
12447
- worker.currentReject && worker.currentReject(args.error);
12448
- worker.currentReject = null;
12449
- }
12450
- this._assignDoneWorker(worker);
12451
- } else if (args.type === "parentFunction") {
12452
- try {
12453
- const result = await this._parentFunctions[args.name](...args.args);
12454
- worker.postMessage({ type: "parentFunction", id: args.id, result });
12455
- } catch (e) {
12456
- worker.postMessage({
12457
- type: "parentFunction",
12458
- id: args.id,
12459
- error: e
12460
- });
12527
+ if ("result" in args) {
12528
+ worker.currentResolve?.(args.result);
12529
+ worker.currentResolve = null;
12530
+ } else {
12531
+ if (args.error instanceof ReferenceError) {
12532
+ args.error.message += ". Maybe you forgot to pass the function to parentFunction?";
12461
12533
  }
12534
+ worker.currentReject?.(args.error);
12535
+ worker.currentReject = null;
12462
12536
  }
12537
+ this._assignDoneWorker(worker);
12463
12538
  });
12464
12539
  worker.on("error", (err) => {
12465
- worker.currentReject && worker.currentReject(err);
12540
+ worker.currentReject?.(err);
12466
12541
  worker.currentReject = null;
12542
+ parentFunctionResponder.close();
12467
12543
  });
12468
12544
  worker.on("exit", (code) => {
12469
12545
  const i = this._pool.indexOf(worker);
12470
- if (i > -1)
12471
- this._pool.splice(i, 1);
12546
+ if (i > -1) this._pool.splice(i, 1);
12472
12547
  if (code !== 0 && worker.currentReject) {
12473
12548
  worker.currentReject(
12474
12549
  new Error(`Worker stopped with non-0 exit code ${code}`)
12475
12550
  );
12476
12551
  worker.currentReject = null;
12552
+ parentFunctionResponder.close();
12477
12553
  }
12478
12554
  });
12479
12555
  this._pool.push(worker);
@@ -12498,22 +12574,99 @@ var Worker = class {
12498
12574
  this._idlePool.push(worker);
12499
12575
  }
12500
12576
  };
12501
- function genWorkerCode(fn, parentFunctions) {
12502
- const createParentFunctionCaller = (parentPort) => {
12577
+ function createParentFunctionResponder(parentFunctions) {
12578
+ const lockState = new Int32Array(new SharedArrayBuffer(4));
12579
+ const unlock = () => {
12580
+ Atomics.store(lockState, 0, 0);
12581
+ Atomics.notify(lockState, 0);
12582
+ };
12583
+ const parentFunctionSyncMessageChannel = new MessageChannel();
12584
+ const parentFunctionAsyncMessageChannel = new MessageChannel();
12585
+ const parentFunctionSyncMessagePort = parentFunctionSyncMessageChannel.port1;
12586
+ const parentFunctionAsyncMessagePort = parentFunctionAsyncMessageChannel.port1;
12587
+ const syncResponse = (data) => {
12588
+ parentFunctionSyncMessagePort.postMessage(data);
12589
+ unlock();
12590
+ };
12591
+ parentFunctionSyncMessagePort.on("message", async (args) => {
12592
+ let syncResult;
12593
+ try {
12594
+ syncResult = parentFunctions[args.name](...args.args);
12595
+ } catch (error) {
12596
+ syncResponse({ id: args.id, error });
12597
+ return;
12598
+ }
12599
+ if (!(typeof syncResult === "object" && syncResult !== null && "then" in syncResult && typeof syncResult.then === "function")) {
12600
+ syncResponse({
12601
+ id: args.id,
12602
+ result: syncResult
12603
+ });
12604
+ return;
12605
+ }
12606
+ syncResponse({
12607
+ id: args.id,
12608
+ isAsync: true
12609
+ });
12610
+ try {
12611
+ const result = await syncResult;
12612
+ parentFunctionAsyncMessagePort.postMessage({ id: args.id, result });
12613
+ } catch (error) {
12614
+ parentFunctionAsyncMessagePort.postMessage({ id: args.id, error });
12615
+ }
12616
+ });
12617
+ parentFunctionSyncMessagePort.unref();
12618
+ return {
12619
+ close: () => {
12620
+ parentFunctionSyncMessagePort.close();
12621
+ parentFunctionAsyncMessagePort.close();
12622
+ },
12623
+ lockState,
12624
+ workerPorts: {
12625
+ sync: parentFunctionSyncMessageChannel.port2,
12626
+ async: parentFunctionAsyncMessageChannel.port2
12627
+ }
12628
+ };
12629
+ }
12630
+ function genWorkerCode(fn, isModule, parentFunctions) {
12631
+ const createLock = (lockState) => {
12632
+ return {
12633
+ lock: () => {
12634
+ Atomics.store(lockState, 0, 1);
12635
+ },
12636
+ waitUnlock: () => {
12637
+ const status = Atomics.wait(lockState, 0, 1, 10 * 1e3);
12638
+ if (status === "timed-out") {
12639
+ throw new Error(status);
12640
+ }
12641
+ }
12642
+ };
12643
+ };
12644
+ const createParentFunctionRequester = (syncPort, asyncPort, receive, lock) => {
12503
12645
  let id = 0;
12504
12646
  const resolvers = /* @__PURE__ */ new Map();
12505
- const call = (key) => async (...args) => {
12647
+ const call = (key) => (...args) => {
12506
12648
  id++;
12507
- let resolve, reject;
12508
- const promise = new Promise((res, rej) => {
12509
- resolve = res;
12510
- reject = rej;
12511
- });
12512
- resolvers.set(id, { resolve, reject });
12513
- parentPort.postMessage({ type: "parentFunction", id, name: key, args });
12514
- return await promise;
12649
+ lock.lock();
12650
+ syncPort.postMessage({ id, name: key, args });
12651
+ lock.waitUnlock();
12652
+ const resArgs = receive(syncPort).message;
12653
+ if (resArgs.isAsync) {
12654
+ let resolve, reject;
12655
+ const promise = new Promise((res, rej) => {
12656
+ resolve = res;
12657
+ reject = rej;
12658
+ });
12659
+ resolvers.set(id, { resolve, reject });
12660
+ return promise;
12661
+ }
12662
+ if ("error" in resArgs) {
12663
+ throw resArgs.error;
12664
+ } else {
12665
+ return resArgs.result;
12666
+ }
12515
12667
  };
12516
- const receive = (id2, args) => {
12668
+ asyncPort.on("message", (args) => {
12669
+ const id2 = args.id;
12517
12670
  if (resolvers.has(id2)) {
12518
12671
  const { resolve, reject } = resolvers.get(id2);
12519
12672
  resolvers.delete(id2);
@@ -12523,48 +12676,64 @@ function genWorkerCode(fn, parentFunctions) {
12523
12676
  reject(args.error);
12524
12677
  }
12525
12678
  }
12526
- };
12527
- return { call, receive };
12679
+ });
12680
+ return { call };
12528
12681
  };
12682
+ const fnString = fn.toString().replaceAll(viteSsrDynamicImport, "import");
12529
12683
  return `
12530
- const { parentPort } = require('worker_threads')
12531
- const parentFunctionCaller = (${createParentFunctionCaller.toString()})(parentPort)
12684
+ ${isModule ? "import { parentPort, receiveMessageOnPort, workerData } from 'worker_threads'" : "const { parentPort, receiveMessageOnPort, workerData } = require('worker_threads')"}
12685
+ const [parentFunctionSyncMessagePort, parentFunctionAsyncMessagePort, lockState] = workerData
12686
+ const createLock = ${createLock.toString()}
12687
+ const parentFunctionRequester = (${createParentFunctionRequester.toString()})(
12688
+ parentFunctionSyncMessagePort,
12689
+ parentFunctionAsyncMessagePort,
12690
+ receiveMessageOnPort,
12691
+ createLock(lockState)
12692
+ )
12532
12693
 
12533
- const doWork = (() => {
12694
+ const doWorkPromise = (async () => {
12534
12695
  ${Object.keys(parentFunctions).map(
12535
- (key) => `const ${key} = parentFunctionCaller.call(${JSON.stringify(key)});`
12696
+ (key) => `const ${key} = parentFunctionRequester.call(${JSON.stringify(key)});`
12536
12697
  ).join("\n")}
12537
- return (${fn.toString()})()
12698
+ return await (${fnString})()
12538
12699
  })()
12700
+ let doWork
12539
12701
 
12540
12702
  parentPort.on('message', async (args) => {
12541
- if (args.type === 'run') {
12542
- try {
12543
- const res = await doWork(...args.args)
12544
- parentPort.postMessage({ type: 'run', result: res })
12545
- } catch (e) {
12546
- parentPort.postMessage({ type: 'run', error: e })
12547
- }
12548
- } else if (args.type === 'parentFunction') {
12549
- parentFunctionCaller.receive(args.id, args)
12703
+ doWork ||= await doWorkPromise
12704
+
12705
+ try {
12706
+ const res = await doWork(...args.args)
12707
+ parentPort.postMessage({ result: res })
12708
+ } catch (e) {
12709
+ parentPort.postMessage({ error: e })
12550
12710
  }
12551
12711
  })
12552
12712
  `;
12553
12713
  }
12714
+ var importRe = /\bimport\s*\(/;
12715
+ var internalImportName = "__artichokie_local_import__";
12554
12716
  var FakeWorker = class {
12555
12717
  /** @internal */
12556
12718
  _fn;
12557
12719
  constructor(fn, options = {}) {
12720
+ const declareRequire = options.type !== "module";
12558
12721
  const argsAndCode = genFakeWorkerArgsAndCode(
12559
12722
  fn,
12723
+ declareRequire,
12560
12724
  options.parentFunctions ?? {}
12561
12725
  );
12562
- const require2 = createRequire$1(import.meta.url);
12563
- this._fn = new Function(...argsAndCode)(require2, options.parentFunctions);
12726
+ const localImport = (specifier) => import(specifier);
12727
+ const args = [
12728
+ ...declareRequire ? [createRequire$1(import.meta.url)] : [],
12729
+ localImport,
12730
+ options.parentFunctions
12731
+ ];
12732
+ this._fn = new AsyncFunction(...argsAndCode)(...args);
12564
12733
  }
12565
12734
  async run(...args) {
12566
12735
  try {
12567
- return await this._fn(...args);
12736
+ return await (await this._fn)(...args);
12568
12737
  } catch (err) {
12569
12738
  if (err instanceof ReferenceError) {
12570
12739
  err.message += ". Maybe you forgot to pass the function to parentFunction?";
@@ -12575,13 +12744,15 @@ var FakeWorker = class {
12575
12744
  stop() {
12576
12745
  }
12577
12746
  };
12578
- function genFakeWorkerArgsAndCode(fn, parentFunctions) {
12747
+ function genFakeWorkerArgsAndCode(fn, declareRequire, parentFunctions) {
12748
+ const fnString = fn.toString().replace(importRe, `${internalImportName}(`).replaceAll(viteSsrDynamicImport, internalImportName);
12579
12749
  return [
12580
- "require",
12750
+ ...declareRequire ? ["require"] : [],
12751
+ internalImportName,
12581
12752
  "parentFunctions",
12582
12753
  `
12583
12754
  ${Object.keys(parentFunctions).map((key) => `const ${key} = parentFunctions[${JSON.stringify(key)}];`).join("\n")}
12584
- return (${fn.toString()})()
12755
+ return await (${fnString})()
12585
12756
  `
12586
12757
  ];
12587
12758
  }
@@ -12633,12 +12804,15 @@ ${e.message}`);
12633
12804
  };
12634
12805
  function terserPlugin(config) {
12635
12806
  const { maxWorkers, ...terserOptions } = config.build.terserOptions;
12636
- const makeWorker = () => new Worker(
12807
+ const makeWorker = () => new WorkerWithFallback(
12637
12808
  () => async (terserPath2, code, options) => {
12638
12809
  const terser = require(terserPath2);
12639
12810
  return terser.minify(code, options);
12640
12811
  },
12641
12812
  {
12813
+ shouldUseFake(_terserPath, _code, options) {
12814
+ return !!(typeof options.mangle === "object" && (options.mangle.nth_identifier?.get || typeof options.mangle.properties === "object" && options.mangle.properties.nth_identifier?.get) || typeof options.format?.comments === "function" || typeof options.output?.comments === "function");
12815
+ },
12642
12816
  max: maxWorkers
12643
12817
  }
12644
12818
  );
@@ -13505,7 +13679,7 @@ function manifestPlugin() {
13505
13679
  const { root } = this.environment.config;
13506
13680
  const buildOptions = this.environment.config.build;
13507
13681
  function getChunkName(chunk) {
13508
- return getChunkOriginalFileName(chunk, root, format) ?? `_` + path$d.basename(chunk.fileName);
13682
+ return getChunkOriginalFileName(chunk, root, format) ?? `_${path$d.basename(chunk.fileName)}`;
13509
13683
  }
13510
13684
  function getInternalImports(imports) {
13511
13685
  const filteredImports = [];
@@ -13568,19 +13742,17 @@ function manifestPlugin() {
13568
13742
  } catch {
13569
13743
  }
13570
13744
  }
13571
- const fileNameToAsset = /* @__PURE__ */ new Map();
13572
13745
  for (const file in bundle) {
13573
13746
  const chunk = bundle[file];
13574
13747
  if (chunk.type === "chunk") {
13575
13748
  manifest[getChunkName(chunk)] = createChunk(chunk);
13576
13749
  } else if (chunk.type === "asset" && chunk.names.length > 0) {
13577
- const src = chunk.originalFileNames.length > 0 ? chunk.originalFileNames[0] : "_" + path$d.basename(chunk.fileName);
13750
+ const src = chunk.originalFileNames.length > 0 ? chunk.originalFileNames[0] : `_${path$d.basename(chunk.fileName)}`;
13578
13751
  const isEntry = entryCssAssetFileNames.has(chunk.fileName);
13579
13752
  const asset = createAsset(chunk, src, isEntry);
13580
13753
  const file2 = manifest[src]?.file;
13581
13754
  if (!(file2 && endsWithJSRE.test(file2))) {
13582
13755
  manifest[src] = asset;
13583
- fileNameToAsset.set(chunk.fileName, asset);
13584
13756
  }
13585
13757
  for (const originalFileName of chunk.originalFileNames.slice(1)) {
13586
13758
  const file3 = manifest[originalFileName]?.file;
@@ -13609,7 +13781,7 @@ function getChunkOriginalFileName(chunk, root, format) {
13609
13781
  if (format === "system" && !chunk.name.includes("-legacy")) {
13610
13782
  const ext = path$d.extname(name);
13611
13783
  const endPos = ext.length !== 0 ? -ext.length : void 0;
13612
- name = name.slice(0, endPos) + `-legacy` + ext;
13784
+ name = `${name.slice(0, endPos)}-legacy${ext}`;
13613
13785
  }
13614
13786
  return name.replace(/\0/g, "");
13615
13787
  }
@@ -14016,6 +14188,7 @@ var src$2 = {};
14016
14188
  const path$b = require$$0$2;
14017
14189
  const fs$7 = require$$0$3;
14018
14190
  const os$2 = require$$2;
14191
+ const url$4 = require$$0$5;
14019
14192
 
14020
14193
  const fsReadFileAsync = fs$7.promises.readFile;
14021
14194
 
@@ -14054,7 +14227,8 @@ function parentDir(p) {
14054
14227
  /** @type {import('./index').LoaderSync} */
14055
14228
  const jsonLoader = (_, content) => JSON.parse(content);
14056
14229
  // Use plain require in webpack context for dynamic import
14057
- const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
14230
+ const requireFunc =
14231
+ typeof __webpack_require__ === 'function' ? __non_webpack_require__ : __require;
14058
14232
  /** @type {import('./index').LoadersSync} */
14059
14233
  const defaultLoadersSync = Object.freeze({
14060
14234
  '.js': requireFunc,
@@ -14067,7 +14241,8 @@ src$2.defaultLoadersSync = defaultLoadersSync;
14067
14241
  /** @type {import('./index').Loader} */
14068
14242
  const dynamicImport = async id => {
14069
14243
  try {
14070
- const mod = await import(/* webpackIgnore: true */ id);
14244
+ const fileUrl = url$4.pathToFileURL(id).href;
14245
+ const mod = await import(/* webpackIgnore: true */ fileUrl);
14071
14246
 
14072
14247
  return mod.default;
14073
14248
  } catch (e) {
@@ -14471,7 +14646,7 @@ src$2.lilconfigSync = function lilconfigSync(name, options) {
14471
14646
  };
14472
14647
 
14473
14648
  // @ts-check
14474
- const { createRequire } = require$$0$5;
14649
+ const { createRequire } = require$$0$6;
14475
14650
  const { fileURLToPath, pathToFileURL } = require$$1$1;
14476
14651
 
14477
14652
  const TS_EXT_RE = /\.[mc]?ts$/;
@@ -15105,7 +15280,7 @@ function alias$1(options = {}) {
15105
15280
  };
15106
15281
  }
15107
15282
 
15108
- function e(e,n,r){throw new Error(r?`No known conditions for "${n}" specifier in "${e}" package`:`Missing "${n}" specifier in "${e}" package`)}function n(n,i,o,f){let s,u,l=r(n,o),c=function(e){let n=new Set(["default",...e.conditions||[]]);return e.unsafe||n.add(e.require?"require":"import"),e.unsafe||n.add(e.browser?"browser":"node"),n}(f||{}),a=i[l];if(void 0===a){let e,n,r,t;for(t in i)n&&t.length<n.length||("/"===t[t.length-1]&&l.startsWith(t)?(u=l.substring(t.length),n=t):t.length>1&&(r=t.indexOf("*",1),~r&&(e=RegExp("^"+t.substring(0,r)+"(.*)"+t.substring(1+r)).exec(l),e&&e[1]&&(u=e[1],n=t))));a=i[n];}return a||e(n,l),s=t(a,c),s||e(n,l,1),u&&function(e,n){let r,t=0,i=e.length,o=/[*]/g,f=/[/]$/;for(;t<i;t++)e[t]=o.test(r=e[t])?r.replace(o,n):f.test(r)?r+n:r;}(s,u),s}function r(e,n,r){if(e===n||"."===n)return ".";let t=e+"/",i=t.length,o=n.slice(0,i)===t,f=o?n.slice(i):n;return "#"===f[0]?f:o||!r?"./"===f.slice(0,2)?f:"./"+f:f}function t(e,n,r){if(e){if("string"==typeof e)return r&&r.add(e),[e];let i,o;if(Array.isArray(e)){for(o=r||new Set,i=0;i<e.length;i++)t(e[i],n,o);if(!r&&o.size)return [...o]}else for(i in e)if(n.has(i))return t(e[i],n,r)}}function o(e,r,t){let i,o=e.exports;if(o){if("string"==typeof o)o={".":o};else for(i in o){"."!==i[0]&&(o={".":o});break}return n(e.name,o,r||".",t)}}function f(e,r,t){if(e.imports)return n(e.name,e.imports,r,t)}
15283
+ function e(e,n,r){throw new Error(r?`No known conditions for "${n}" specifier in "${e}" package`:`Missing "${n}" specifier in "${e}" package`)}function n(n,i,o,f){let s,u,l=r(n,o),c=function(e){let n=new Set(["default",...e.conditions||[]]);return e.unsafe||n.add(e.require?"require":"import"),e.unsafe||n.add(e.browser?"browser":"node"),n}(f||{}),a=i[l];if(void 0===a){let e,n,r,t;for(t in i)n&&t.length<n.length||("/"===t[t.length-1]&&l.startsWith(t)?(u=l.substring(t.length),n=t):t.length>1&&(r=t.indexOf("*",1),~r&&(e=RegExp("^"+t.substring(0,r)+"(.*)"+t.substring(1+r)+"$").exec(l),e&&e[1]&&(u=e[1],n=t))));a=i[n];}return a||e(n,l),s=t(a,c),s||e(n,l,1),u&&function(e,n){let r,t=0,i=e.length,o=/[*]/g,f=/[/]$/;for(;t<i;t++)e[t]=o.test(r=e[t])?r.replace(o,n):f.test(r)?r+n:r;}(s,u),s}function r(e,n,r){if(e===n||"."===n)return ".";let t=e+"/",i=t.length,o=n.slice(0,i)===t,f=o?n.slice(i):n;return "#"===f[0]?f:o||!r?"./"===f.slice(0,2)?f:"./"+f:f}function t(e,n,r){if(e){if("string"==typeof e)return r&&r.add(e),[e];let i,o;if(Array.isArray(e)){for(o=r||new Set,i=0;i<e.length;i++)t(e[i],n,o);if(!r&&o.size)return [...o]}else for(i in e)if(n.has(i))return t(e[i],n,r)}}function o(e,r,t){let i,o=e.exports;if(o){if("string"==typeof o)o={".":o};else for(i in o){"."!==i[0]&&(o={".":o});break}return n(e.name,o,r||".",t)}}function f(e,r,t){if(e.imports)return n(e.name,e.imports,r,t)}
15109
15284
 
15110
15285
  const HASH_RE = /#/g;
15111
15286
  const AMPERSAND_RE = /&/g;
@@ -18777,9 +18952,11 @@ async function prepareEsbuildOptimizerRun(environment, depsInfo, processingCache
18777
18952
  );
18778
18953
  if (optimizerContext.cancelled) return { context: void 0, idToExports };
18779
18954
  const define = {
18780
- "process.env.NODE_ENV": JSON.stringify(
18781
- process.env.NODE_ENV || environment.config.mode
18782
- )
18955
+ "process.env.NODE_ENV": environment.config.keepProcessEnv ? (
18956
+ // define process.env.NODE_ENV even for keepProcessEnv === true
18957
+ // as esbuild will replace it automatically when `platform` is `'browser'`
18958
+ "process.env.NODE_ENV"
18959
+ ) : JSON.stringify(process.env.NODE_ENV || environment.config.mode)
18783
18960
  };
18784
18961
  const platform = optimizeDeps2.esbuildOptions?.platform ?? // We generally don't want to use platform 'neutral', as esbuild has custom handling
18785
18962
  // when the platform is 'node' or 'browser' that can't be emulated by using mainFields
@@ -19101,7 +19278,7 @@ function getConfigHash(environment) {
19101
19278
  const { optimizeDeps: optimizeDeps2 } = config;
19102
19279
  const content = JSON.stringify(
19103
19280
  {
19104
- mode: process.env.NODE_ENV || config.mode,
19281
+ define: !config.keepProcessEnv ? process.env.NODE_ENV || config.mode : null,
19105
19282
  root: config.root,
19106
19283
  resolve: config.resolve,
19107
19284
  assetsInclude: config.assetsInclude,
@@ -19405,7 +19582,7 @@ function throwFileNotFoundInOptimizedDep(id) {
19405
19582
  var main$1 = {exports: {}};
19406
19583
 
19407
19584
  var name = "dotenv";
19408
- var version$1 = "16.4.5";
19585
+ var version$1 = "16.4.7";
19409
19586
  var description = "Loads environment variables from .env file";
19410
19587
  var main = "lib/main.js";
19411
19588
  var types = "lib/main.d.ts";
@@ -19426,10 +19603,9 @@ var exports = {
19426
19603
  var scripts = {
19427
19604
  "dts-check": "tsc --project tests/types/tsconfig.json",
19428
19605
  lint: "standard",
19429
- "lint-readme": "standard-markdown",
19430
19606
  pretest: "npm run lint && npm run dts-check",
19431
- test: "tap tests/*.js --100 -Rspec",
19432
- "test:coverage": "tap --coverage-report=lcov",
19607
+ test: "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
19608
+ "test:coverage": "tap run --show-full-coverage --timeout=60000 --coverage-report=lcov",
19433
19609
  prerelease: "npm test",
19434
19610
  release: "standard-version"
19435
19611
  };
@@ -19450,15 +19626,12 @@ var keywords = [
19450
19626
  var readmeFilename = "README.md";
19451
19627
  var license = "BSD-2-Clause";
19452
19628
  var devDependencies = {
19453
- "@definitelytyped/dtslint": "^0.0.133",
19454
19629
  "@types/node": "^18.11.3",
19455
- decache: "^4.6.1",
19630
+ decache: "^4.6.2",
19456
19631
  sinon: "^14.0.1",
19457
19632
  standard: "^17.0.0",
19458
- "standard-markdown": "^7.1.0",
19459
19633
  "standard-version": "^9.5.0",
19460
- tap: "^16.3.0",
19461
- tar: "^6.1.11",
19634
+ tap: "^19.2.0",
19462
19635
  typescript: "^4.8.4"
19463
19636
  };
19464
19637
  var engines = {
@@ -21427,7 +21600,7 @@ var parseurl$1 = {exports: {}};
21427
21600
  * @private
21428
21601
  */
21429
21602
 
21430
- var url$3 = require$$0$6;
21603
+ var url$3 = require$$0$5;
21431
21604
  var parse$c = url$3.parse;
21432
21605
  var Url = url$3.Url;
21433
21606
 
@@ -30281,7 +30454,7 @@ function launchEditor (file, specifiedEditor, onErrorCallback) {
30281
30454
 
30282
30455
  var launchEditor_1 = launchEditor;
30283
30456
 
30284
- const url$2 = require$$0$6;
30457
+ const url$2 = require$$0$5;
30285
30458
  const path$3 = require$$0$2;
30286
30459
  const launch = launchEditor_1;
30287
30460
 
@@ -35481,7 +35654,7 @@ const http$3 = require$$1$2;
35481
35654
  const net = require$$4$1;
35482
35655
  const tls = require$$4$2;
35483
35656
  const { randomBytes, createHash: createHash$1 } = require$$3;
35484
- const { URL: URL$2 } = require$$0$6;
35657
+ const { URL: URL$2 } = require$$0$5;
35485
35658
 
35486
35659
  const PerMessageDeflate$1 = permessageDeflate;
35487
35660
  const Receiver = receiver;
@@ -38147,7 +38320,7 @@ var requiresPort = function required(port, protocol) {
38147
38320
 
38148
38321
  (function (exports) {
38149
38322
  var common = exports,
38150
- url = require$$0$6,
38323
+ url = require$$0$5,
38151
38324
  required = requiresPort;
38152
38325
 
38153
38326
  var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i,
@@ -38394,7 +38567,7 @@ var requiresPort = function required(port, protocol) {
38394
38567
  return !!~host.indexOf(':');
38395
38568
  }} (common$3));
38396
38569
 
38397
- var url$1 = require$$0$6,
38570
+ var url$1 = require$$0$5,
38398
38571
  common$2 = common$3;
38399
38572
 
38400
38573
 
@@ -38560,7 +38733,7 @@ var debug_1 = function () {
38560
38733
  debug$7.apply(null, arguments);
38561
38734
  };
38562
38735
 
38563
- var url = require$$0$6;
38736
+ var url = require$$0$5;
38564
38737
  var URL$1 = url.URL;
38565
38738
  var http$1 = require$$1$2;
38566
38739
  var https$1 = require$$1$3;
@@ -39609,7 +39782,7 @@ var wsIncoming = {
39609
39782
 
39610
39783
  (function (module) {
39611
39784
  var httpProxy = module.exports,
39612
- parse_url = require$$0$6.parse,
39785
+ parse_url = require$$0$5.parse,
39613
39786
  EE3 = eventemitter3Exports,
39614
39787
  http = require$$1$2,
39615
39788
  https = require$$1$3,
@@ -42701,6 +42874,7 @@ function timeMiddleware(root) {
42701
42874
  };
42702
42875
  }
42703
42876
 
42877
+ const EMPTY_OBJECT$1 = Object.freeze({});
42704
42878
  class ModuleNode {
42705
42879
  _moduleGraph;
42706
42880
  _clientModule;
@@ -42749,6 +42923,41 @@ class ModuleNode {
42749
42923
  }
42750
42924
  return importedModules;
42751
42925
  }
42926
+ _getModuleInfoUnion(prop) {
42927
+ const _clientValue = this._clientModule?.[prop];
42928
+ const _ssrValue = this._ssrModule?.[prop];
42929
+ if (_clientValue == null && _ssrValue == null) return void 0;
42930
+ return new Proxy({}, {
42931
+ get: (_, key) => {
42932
+ if (key === "meta") {
42933
+ return this.meta || EMPTY_OBJECT$1;
42934
+ }
42935
+ if (_clientValue) {
42936
+ if (key in _clientValue) {
42937
+ return _clientValue[key];
42938
+ }
42939
+ }
42940
+ if (_ssrValue) {
42941
+ if (key in _ssrValue) {
42942
+ return _ssrValue[key];
42943
+ }
42944
+ }
42945
+ }
42946
+ });
42947
+ }
42948
+ _getModuleObjectUnion(prop) {
42949
+ const _clientValue = this._clientModule?.[prop];
42950
+ const _ssrValue = this._ssrModule?.[prop];
42951
+ if (_clientValue == null && _ssrValue == null) return void 0;
42952
+ const info = {};
42953
+ if (_ssrValue) {
42954
+ Object.assign(info, _ssrValue);
42955
+ }
42956
+ if (_clientValue) {
42957
+ Object.assign(info, _clientValue);
42958
+ }
42959
+ return info;
42960
+ }
42752
42961
  get url() {
42753
42962
  return this._get("url");
42754
42963
  }
@@ -42770,11 +42979,13 @@ class ModuleNode {
42770
42979
  get type() {
42771
42980
  return this._get("type");
42772
42981
  }
42982
+ // `info` needs special care as it's defined as a proxy in `pluginContainer`,
42983
+ // so we also merge it as a proxy too
42773
42984
  get info() {
42774
- return this._get("info");
42985
+ return this._getModuleInfoUnion("info");
42775
42986
  }
42776
42987
  get meta() {
42777
- return this._get("meta");
42988
+ return this._getModuleObjectUnion("meta");
42778
42989
  }
42779
42990
  get importers() {
42780
42991
  return this._getModuleSetUnion("importers");
@@ -43520,6 +43731,7 @@ async function _createServer(inlineConfig = {}, options) {
43520
43731
  server._ssrCompatModuleRunner?.close()
43521
43732
  ]);
43522
43733
  server.resolvedUrls = null;
43734
+ server._ssrCompatModuleRunner = void 0;
43523
43735
  },
43524
43736
  printUrls() {
43525
43737
  if (server.resolvedUrls) {
@@ -43931,7 +44143,7 @@ const normalizeHotChannel = (channel, enableHmr, normalizeClient = true) => {
43931
44143
  const handleInvoke = async (payload) => {
43932
44144
  if (!invokeHandlers) {
43933
44145
  return {
43934
- e: {
44146
+ error: {
43935
44147
  name: "TransportError",
43936
44148
  message: "invokeHandlers is not set",
43937
44149
  stack: new Error().stack
@@ -43943,10 +44155,10 @@ const normalizeHotChannel = (channel, enableHmr, normalizeClient = true) => {
43943
44155
  try {
43944
44156
  const invokeHandler = invokeHandlers[name];
43945
44157
  const result = await invokeHandler(...args);
43946
- return { r: result };
44158
+ return { result };
43947
44159
  } catch (error2) {
43948
44160
  return {
43949
- e: {
44161
+ error: {
43950
44162
  name: error2.name,
43951
44163
  message: error2.message,
43952
44164
  stack: error2.stack,
@@ -44025,13 +44237,7 @@ const normalizeHotChannel = (channel, enableHmr, normalizeClient = true) => {
44025
44237
  };
44026
44238
  channel.on?.("vite:invoke", listenerForInvokeHandler);
44027
44239
  },
44028
- handleInvoke: async (payload) => {
44029
- const data = await handleInvoke(payload);
44030
- if (data.e) {
44031
- return { error: data.e };
44032
- }
44033
- return { result: data.r };
44034
- },
44240
+ handleInvoke,
44035
44241
  send: (...args) => {
44036
44242
  let payload;
44037
44243
  if (typeof args[0] === "string") {
@@ -46907,16 +47113,23 @@ class EnvironmentPluginContainer {
46907
47113
  await this._buildStartPromise;
46908
47114
  }
46909
47115
  const skip = options?.skip;
47116
+ const skipCalls = options?.skipCalls;
46910
47117
  const scan = !!options?.scan;
46911
47118
  const ssr = this.environment.config.consumer === "server";
46912
- const ctx = new ResolveIdContext(this, skip, scan);
47119
+ const ctx = new ResolveIdContext(this, skip, skipCalls, scan);
47120
+ const mergedSkip = new Set(skip);
47121
+ for (const call of skipCalls ?? []) {
47122
+ if (call.id === rawId && call.importer === importer) {
47123
+ mergedSkip.add(call.plugin);
47124
+ }
47125
+ }
46913
47126
  const resolveStart = debugResolve ? performance.now() : 0;
46914
47127
  let id = null;
46915
47128
  const partial = {};
46916
47129
  for (const plugin of this.getSortedPlugins("resolveId")) {
46917
47130
  if (this._closed && this.environment.config.dev.recoverable)
46918
47131
  throwClosedServerError();
46919
- if (skip?.has(plugin)) continue;
47132
+ if (mergedSkip?.has(plugin)) continue;
46920
47133
  ctx._plugin = plugin;
46921
47134
  const pluginResolveStart = debugPluginResolve ? performance.now() : 0;
46922
47135
  const handler = getHookHandler(plugin.resolveId);
@@ -47067,22 +47280,23 @@ class PluginContext {
47067
47280
  _activeId = null;
47068
47281
  _activeCode = null;
47069
47282
  _resolveSkips;
47283
+ _resolveSkipCalls;
47070
47284
  meta;
47071
47285
  environment;
47072
47286
  parse(code, opts) {
47073
47287
  return parseAst(code, opts);
47074
47288
  }
47075
47289
  async resolve(id, importer, options) {
47076
- let skip;
47077
- if (options?.skipSelf !== false) {
47078
- skip = new Set(this._resolveSkips);
47079
- skip.add(this._plugin);
47080
- }
47290
+ const skipCalls = options?.skipSelf === false ? this._resolveSkipCalls : [
47291
+ ...this._resolveSkipCalls || [],
47292
+ { id, importer, plugin: this._plugin }
47293
+ ];
47081
47294
  let out = await this._container.resolveId(id, importer, {
47082
47295
  attributes: options?.attributes,
47083
47296
  custom: options?.custom,
47084
47297
  isEntry: !!options?.isEntry,
47085
- skip,
47298
+ skip: this._resolveSkips,
47299
+ skipCalls,
47086
47300
  scan: this._scan
47087
47301
  });
47088
47302
  if (typeof out === "string") out = { id: out };
@@ -47251,9 +47465,10 @@ ${err2.stack || err2.message}
47251
47465
  }
47252
47466
  }
47253
47467
  class ResolveIdContext extends PluginContext {
47254
- constructor(container, skip, scan) {
47468
+ constructor(container, skip, skipCalls, scan) {
47255
47469
  super(null, container);
47256
47470
  this._resolveSkips = skip;
47471
+ this._resolveSkipCalls = skipCalls;
47257
47472
  this._scan = scan;
47258
47473
  }
47259
47474
  }
@@ -47364,9 +47579,33 @@ class PluginContainer {
47364
47579
  return this._getEnvironment(options).pluginContainer;
47365
47580
  }
47366
47581
  getModuleInfo(id) {
47367
- return this.environments.client.pluginContainer.getModuleInfo(id) || this.environments.ssr.pluginContainer.getModuleInfo(
47368
- id
47369
- );
47582
+ const clientModuleInfo = this.environments.client.pluginContainer.getModuleInfo(id);
47583
+ const ssrModuleInfo = this.environments.ssr.pluginContainer.getModuleInfo(id);
47584
+ if (clientModuleInfo == null && ssrModuleInfo == null) return null;
47585
+ return new Proxy({}, {
47586
+ get: (_, key) => {
47587
+ if (key === "meta") {
47588
+ const meta = {};
47589
+ if (ssrModuleInfo) {
47590
+ Object.assign(meta, ssrModuleInfo.meta);
47591
+ }
47592
+ if (clientModuleInfo) {
47593
+ Object.assign(meta, clientModuleInfo.meta);
47594
+ }
47595
+ return meta;
47596
+ }
47597
+ if (clientModuleInfo) {
47598
+ if (key in clientModuleInfo) {
47599
+ return clientModuleInfo[key];
47600
+ }
47601
+ }
47602
+ if (ssrModuleInfo) {
47603
+ if (key in ssrModuleInfo) {
47604
+ return ssrModuleInfo[key];
47605
+ }
47606
+ }
47607
+ }
47608
+ });
47370
47609
  }
47371
47610
  get options() {
47372
47611
  return this.environments.client.pluginContainer.options;
@@ -48130,7 +48369,12 @@ function createCSSResolvers(config) {
48130
48369
  });
48131
48370
  sassResolve = async (...args) => {
48132
48371
  if (args[1].startsWith("file://")) {
48133
- args[1] = fileURLToPath$1(args[1]);
48372
+ args[1] = fileURLToPath$1(args[1], {
48373
+ windows: (
48374
+ // file:///foo cannot be converted to path with windows mode
48375
+ isWindows$3 && args[1].startsWith("file:///") ? false : void 0
48376
+ )
48377
+ });
48134
48378
  }
48135
48379
  return resolver(...args);
48136
48380
  };
@@ -48433,8 +48677,8 @@ function createCachedImport(imp) {
48433
48677
  return cached;
48434
48678
  };
48435
48679
  }
48436
- const importPostcssImport = createCachedImport(() => import('./dep-CjE1AkI6.js').then(function (n) { return n.i; }));
48437
- const importPostcssModules = createCachedImport(() => import('./dep-BiVmWRQp.js').then(function (n) { return n.i; }));
48680
+ const importPostcssImport = createCachedImport(() => import('./dep-CrWUFq3l.js').then(function (n) { return n.i; }));
48681
+ const importPostcssModules = createCachedImport(() => import('./dep-pSQn2Hds.js').then(function (n) { return n.i; }));
48438
48682
  const importPostcss = createCachedImport(() => import('postcss'));
48439
48683
  const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
48440
48684
  let alwaysFakeWorkerWorkerControllerCache;
@@ -48919,7 +49163,15 @@ const makeModernScssWorker = (environment, resolvers, alias, maxWorkers) => {
48919
49163
  async canonicalize(url, context) {
48920
49164
  const importer = context.containingUrl ? fileURLToPath2(context.containingUrl) : options.filename;
48921
49165
  const resolved = await internalCanonicalize(url, importer);
48922
- return resolved ? pathToFileURL2(resolved) : null;
49166
+ if (resolved && // only limit to these extensions because:
49167
+ // - for the `@import`/`@use`s written in file loaded by `load` function,
49168
+ // the `canonicalize` function of that `importer` is called first
49169
+ // - the `load` function of an importer is only called for the importer
49170
+ // that returned a non-null result from its `canonicalize` function
49171
+ (resolved.endsWith(".css") || resolved.endsWith(".scss") || resolved.endsWith(".sass"))) {
49172
+ return pathToFileURL2(resolved);
49173
+ }
49174
+ return null;
48923
49175
  },
48924
49176
  async load(canonicalUrl) {
48925
49177
  const ext = path2.extname(canonicalUrl.pathname);
@@ -48980,7 +49232,10 @@ const makeModernCompilerScssWorker = (environment, resolvers, alias, _maxWorkers
48980
49232
  url,
48981
49233
  cleanScssBugUrl(importer)
48982
49234
  );
48983
- return resolved ? pathToFileURL$1(resolved) : null;
49235
+ if (resolved && (resolved.endsWith(".css") || resolved.endsWith(".scss") || resolved.endsWith(".sass"))) {
49236
+ return pathToFileURL$1(resolved);
49237
+ }
49238
+ return null;
48984
49239
  },
48985
49240
  async load(canonicalUrl) {
48986
49241
  const ext = path$d.extname(canonicalUrl.pathname);
@@ -49517,21 +49772,24 @@ async function compileLightningCSS(id, src, environment, urlReplacer) {
49517
49772
  let css = decoder.decode(res.code);
49518
49773
  for (const dep of res.dependencies) {
49519
49774
  switch (dep.type) {
49520
- case "url":
49775
+ case "url": {
49776
+ let replaceUrl;
49521
49777
  if (skipUrlReplacer(dep.url)) {
49522
- css = css.replace(dep.placeholder, () => dep.url);
49523
- break;
49524
- }
49525
- if (urlReplacer) {
49526
- const replaceUrl = await urlReplacer(
49527
- dep.url,
49528
- toAbsolute(dep.loc.filePath)
49529
- );
49530
- css = css.replace(dep.placeholder, () => replaceUrl);
49778
+ replaceUrl = dep.url;
49779
+ } else if (urlReplacer) {
49780
+ replaceUrl = await urlReplacer(dep.url, toAbsolute(dep.loc.filePath));
49531
49781
  } else {
49532
- css = css.replace(dep.placeholder, () => dep.url);
49533
- }
49782
+ replaceUrl = dep.url;
49783
+ }
49784
+ css = css.replace(
49785
+ dep.placeholder,
49786
+ // lightningcss always generates `url("placeholder")`
49787
+ // (`url('placeholder')`, `url(placeholder)` is not generated)
49788
+ // so escape double quotes
49789
+ () => replaceUrl.replaceAll('"', '\\"')
49790
+ );
49534
49791
  break;
49792
+ }
49535
49793
  default:
49536
49794
  throw new Error(`Unsupported dependency type: ${dep.type}`);
49537
49795
  }