vite 2.8.0 → 2.8.4

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.

@@ -1222,126 +1222,166 @@ const KNOWN_ASSET_TYPES = [
1222
1222
  const DEFAULT_ASSETS_RE = new RegExp(`\\.(` + KNOWN_ASSET_TYPES.join('|') + `)(\\?.*)?$`);
1223
1223
  const DEP_VERSION_RE = /[\?&](v=[\w\.-]+)\b/;
1224
1224
 
1225
- var charToInteger = {};
1226
- var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1227
- for (var i$2 = 0; i$2 < chars$1.length; i$2++) {
1228
- charToInteger[chars$1.charCodeAt(i$2)] = i$2;
1229
- }
1225
+ const comma = 44;
1226
+ const semicolon = 59;
1227
+ const chars$2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1228
+ const intToChar = new Uint8Array(65); // 65 possible chars.
1229
+ const charToInteger$1 = new Uint8Array(123); // z is 122 in ASCII
1230
+ for (let i = 0; i < chars$2.length; i++) {
1231
+ const c = chars$2.charCodeAt(i);
1232
+ charToInteger$1[c] = i;
1233
+ intToChar[i] = c;
1234
+ }
1235
+ // Provide a fallback for older environments.
1236
+ const td = typeof TextDecoder !== 'undefined'
1237
+ ? new TextDecoder()
1238
+ : typeof Buffer !== 'undefined'
1239
+ ? {
1240
+ decode(buf) {
1241
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
1242
+ return out.toString();
1243
+ },
1244
+ }
1245
+ : {
1246
+ decode(buf) {
1247
+ let out = '';
1248
+ for (let i = 0; i < buf.length; i++) {
1249
+ out += String.fromCharCode(buf[i]);
1250
+ }
1251
+ return out;
1252
+ },
1253
+ };
1230
1254
  function decode(mappings) {
1231
- var decoded = [];
1232
- var line = [];
1233
- var segment = [
1234
- 0,
1235
- 0,
1236
- 0,
1237
- 0,
1238
- 0,
1239
- ];
1240
- var j = 0;
1241
- for (var i = 0, shift = 0, value = 0; i < mappings.length; i++) {
1242
- var c = mappings.charCodeAt(i);
1243
- if (c === 44) { // ","
1244
- segmentify(line, segment, j);
1245
- j = 0;
1246
- }
1247
- else if (c === 59) { // ";"
1248
- segmentify(line, segment, j);
1249
- j = 0;
1255
+ const state = new Int32Array(5);
1256
+ const decoded = [];
1257
+ let line = [];
1258
+ let sorted = true;
1259
+ let lastCol = 0;
1260
+ for (let i = 0; i < mappings.length;) {
1261
+ const c = mappings.charCodeAt(i);
1262
+ if (c === comma) {
1263
+ i++;
1264
+ }
1265
+ else if (c === semicolon) {
1266
+ state[0] = lastCol = 0;
1267
+ if (!sorted)
1268
+ sort(line);
1269
+ sorted = true;
1250
1270
  decoded.push(line);
1251
1271
  line = [];
1252
- segment[0] = 0;
1272
+ i++;
1253
1273
  }
1254
1274
  else {
1255
- var integer = charToInteger[c];
1256
- if (integer === undefined) {
1257
- throw new Error('Invalid character (' + String.fromCharCode(c) + ')');
1258
- }
1259
- var hasContinuationBit = integer & 32;
1260
- integer &= 31;
1261
- value += integer << shift;
1262
- if (hasContinuationBit) {
1263
- shift += 5;
1275
+ i = decodeInteger(mappings, i, state, 0); // generatedCodeColumn
1276
+ const col = state[0];
1277
+ if (col < lastCol)
1278
+ sorted = false;
1279
+ lastCol = col;
1280
+ if (!hasMoreSegments(mappings, i)) {
1281
+ line.push([col]);
1282
+ continue;
1264
1283
  }
1265
- else {
1266
- var shouldNegate = value & 1;
1267
- value >>>= 1;
1268
- if (shouldNegate) {
1269
- value = value === 0 ? -0x80000000 : -value;
1270
- }
1271
- segment[j] += value;
1272
- j++;
1273
- value = shift = 0; // reset
1284
+ i = decodeInteger(mappings, i, state, 1); // sourceFileIndex
1285
+ i = decodeInteger(mappings, i, state, 2); // sourceCodeLine
1286
+ i = decodeInteger(mappings, i, state, 3); // sourceCodeColumn
1287
+ if (!hasMoreSegments(mappings, i)) {
1288
+ line.push([col, state[1], state[2], state[3]]);
1289
+ continue;
1274
1290
  }
1291
+ i = decodeInteger(mappings, i, state, 4); // nameIndex
1292
+ line.push([col, state[1], state[2], state[3], state[4]]);
1275
1293
  }
1276
1294
  }
1277
- segmentify(line, segment, j);
1295
+ if (!sorted)
1296
+ sort(line);
1278
1297
  decoded.push(line);
1279
1298
  return decoded;
1280
1299
  }
1281
- function segmentify(line, segment, j) {
1282
- // This looks ugly, but we're creating specialized arrays with a specific
1283
- // length. This is much faster than creating a new array (which v8 expands to
1284
- // a capacity of 17 after pushing the first item), or slicing out a subarray
1285
- // (which is slow). Length 4 is assumed to be the most frequent, followed by
1286
- // length 5 (since not everything will have an associated name), followed by
1287
- // length 1 (it's probably rare for a source substring to not have an
1288
- // associated segment data).
1289
- if (j === 4)
1290
- line.push([segment[0], segment[1], segment[2], segment[3]]);
1291
- else if (j === 5)
1292
- line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]);
1293
- else if (j === 1)
1294
- line.push([segment[0]]);
1300
+ function decodeInteger(mappings, pos, state, j) {
1301
+ let value = 0;
1302
+ let shift = 0;
1303
+ let integer = 0;
1304
+ do {
1305
+ const c = mappings.charCodeAt(pos++);
1306
+ integer = charToInteger$1[c];
1307
+ value |= (integer & 31) << shift;
1308
+ shift += 5;
1309
+ } while (integer & 32);
1310
+ const shouldNegate = value & 1;
1311
+ value >>>= 1;
1312
+ if (shouldNegate) {
1313
+ value = value === 0 ? -0x80000000 : -value;
1314
+ }
1315
+ state[j] += value;
1316
+ return pos;
1317
+ }
1318
+ function hasMoreSegments(mappings, i) {
1319
+ if (i >= mappings.length)
1320
+ return false;
1321
+ const c = mappings.charCodeAt(i);
1322
+ if (c === comma || c === semicolon)
1323
+ return false;
1324
+ return true;
1295
1325
  }
1296
- function encode(decoded) {
1297
- var sourceFileIndex = 0; // second field
1298
- var sourceCodeLine = 0; // third field
1299
- var sourceCodeColumn = 0; // fourth field
1300
- var nameIndex = 0; // fifth field
1301
- var mappings = '';
1302
- for (var i = 0; i < decoded.length; i++) {
1303
- var line = decoded[i];
1304
- if (i > 0)
1305
- mappings += ';';
1326
+ function sort(line) {
1327
+ line.sort(sortComparator$1);
1328
+ }
1329
+ function sortComparator$1(a, b) {
1330
+ return a[0] - b[0];
1331
+ }
1332
+ function encode$1(decoded) {
1333
+ const state = new Int32Array(5);
1334
+ let buf = new Uint8Array(1000);
1335
+ let pos = 0;
1336
+ for (let i = 0; i < decoded.length; i++) {
1337
+ const line = decoded[i];
1338
+ if (i > 0) {
1339
+ buf = reserve(buf, pos, 1);
1340
+ buf[pos++] = semicolon;
1341
+ }
1306
1342
  if (line.length === 0)
1307
1343
  continue;
1308
- var generatedCodeColumn = 0; // first field
1309
- var lineMappings = [];
1310
- for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
1311
- var segment = line_1[_i];
1312
- var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
1313
- generatedCodeColumn = segment[0];
1314
- if (segment.length > 1) {
1315
- segmentMappings +=
1316
- encodeInteger(segment[1] - sourceFileIndex) +
1317
- encodeInteger(segment[2] - sourceCodeLine) +
1318
- encodeInteger(segment[3] - sourceCodeColumn);
1319
- sourceFileIndex = segment[1];
1320
- sourceCodeLine = segment[2];
1321
- sourceCodeColumn = segment[3];
1322
- }
1323
- if (segment.length === 5) {
1324
- segmentMappings += encodeInteger(segment[4] - nameIndex);
1325
- nameIndex = segment[4];
1326
- }
1327
- lineMappings.push(segmentMappings);
1344
+ state[0] = 0;
1345
+ for (let j = 0; j < line.length; j++) {
1346
+ const segment = line[j];
1347
+ // We can push up to 5 ints, each int can take at most 7 chars, and we
1348
+ // may push a comma.
1349
+ buf = reserve(buf, pos, 36);
1350
+ if (j > 0)
1351
+ buf[pos++] = comma;
1352
+ pos = encodeInteger$1(buf, pos, state, segment, 0); // generatedCodeColumn
1353
+ if (segment.length === 1)
1354
+ continue;
1355
+ pos = encodeInteger$1(buf, pos, state, segment, 1); // sourceFileIndex
1356
+ pos = encodeInteger$1(buf, pos, state, segment, 2); // sourceCodeLine
1357
+ pos = encodeInteger$1(buf, pos, state, segment, 3); // sourceCodeColumn
1358
+ if (segment.length === 4)
1359
+ continue;
1360
+ pos = encodeInteger$1(buf, pos, state, segment, 4); // nameIndex
1328
1361
  }
1329
- mappings += lineMappings.join(',');
1330
1362
  }
1331
- return mappings;
1363
+ return td.decode(buf.subarray(0, pos));
1332
1364
  }
1333
- function encodeInteger(num) {
1334
- var result = '';
1365
+ function reserve(buf, pos, count) {
1366
+ if (buf.length > pos + count)
1367
+ return buf;
1368
+ const swap = new Uint8Array(buf.length * 2);
1369
+ swap.set(buf);
1370
+ return swap;
1371
+ }
1372
+ function encodeInteger$1(buf, pos, state, segment, j) {
1373
+ const next = segment[j];
1374
+ let num = next - state[j];
1375
+ state[j] = next;
1335
1376
  num = num < 0 ? (-num << 1) | 1 : num << 1;
1336
1377
  do {
1337
- var clamped = num & 31;
1378
+ let clamped = num & 31;
1338
1379
  num >>>= 5;
1339
- if (num > 0) {
1380
+ if (num > 0)
1340
1381
  clamped |= 32;
1341
- }
1342
- result += chars$1[clamped];
1382
+ buf[pos++] = intToChar[clamped];
1343
1383
  } while (num > 0);
1344
- return result;
1384
+ return pos;
1345
1385
  }
1346
1386
 
1347
1387
  // Matches the scheme of a URL, eg "http://"
@@ -1519,199 +1559,82 @@ function resolve$3(input, base) {
1519
1559
  return `${url.scheme}//${url.user}${url.host}${url.port}${url.path}`;
1520
1560
  }
1521
1561
 
1522
- /**
1523
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1524
- *
1525
- * Licensed under the Apache License, Version 2.0 (the "License");
1526
- * you may not use this file except in compliance with the License.
1527
- * You may obtain a copy of the License at
1528
- *
1529
- * http://www.apache.org/licenses/LICENSE-2.0
1530
- *
1531
- * Unless required by applicable law or agreed to in writing, software
1532
- * distributed under the License is distributed on an "AS IS" BASIS,
1533
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1534
- * See the License for the specific language governing permissions and
1535
- * limitations under the License.
1536
- */
1537
- /**
1538
- * Creates a brand new (prototype-less) object with the enumerable-own
1539
- * properties of `target`. Any enumerable-own properties from `source` which
1540
- * are not present on `target` will be copied as well.
1541
- */
1542
- function defaults(target, source) {
1543
- return Object.assign(Object.create(null), source, target);
1562
+ function resolve$2(input, base) {
1563
+ // The base is always treated as a directory, if it's not empty.
1564
+ // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
1565
+ // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
1566
+ if (base && !base.endsWith('/'))
1567
+ base += '/';
1568
+ return resolve$3(input, base);
1544
1569
  }
1545
1570
 
1546
1571
  /**
1547
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1548
- *
1549
- * Licensed under the Apache License, Version 2.0 (the "License");
1550
- * you may not use this file except in compliance with the License.
1551
- * You may obtain a copy of the License at
1552
- *
1553
- * http://www.apache.org/licenses/LICENSE-2.0
1554
- *
1555
- * Unless required by applicable law or agreed to in writing, software
1556
- * distributed under the License is distributed on an "AS IS" BASIS,
1557
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1558
- * See the License for the specific language governing permissions and
1559
- * limitations under the License.
1560
- */
1561
- /**
1562
- * Decodes an input sourcemap into a `DecodedSourceMap` sourcemap object.
1563
- *
1564
- * Valid input maps include a `DecodedSourceMap`, a `RawSourceMap`, or JSON
1565
- * representations of either type.
1572
+ * Removes everything after the last "/", but leaves the slash.
1566
1573
  */
1567
- function decodeSourceMap(map) {
1568
- if (typeof map === 'string') {
1569
- map = JSON.parse(map);
1570
- }
1571
- let { mappings } = map;
1572
- if (typeof mappings === 'string') {
1573
- mappings = sortMappings(decode(mappings), true);
1574
- }
1575
- else {
1576
- // Clone the Line so that we can sort it. We don't want to mutate an array
1577
- // that we don't own directly.
1578
- mappings = sortMappings(mappings, false);
1579
- }
1580
- return defaults({ mappings }, map);
1581
- }
1582
- function firstUnsortedSegmentLine(mappings) {
1583
- for (let i = 0; i < mappings.length; i++) {
1584
- const segments = mappings[i];
1585
- for (let j = 1; j < segments.length; j++) {
1586
- if (segments[j][0] < segments[j - 1][0]) {
1587
- return i;
1588
- }
1589
- }
1590
- }
1591
- return mappings.length;
1574
+ function stripFilename(path) {
1575
+ if (!path)
1576
+ return '';
1577
+ const index = path.lastIndexOf('/');
1578
+ return path.slice(0, index + 1);
1592
1579
  }
1593
- function sortMappings(mappings, owned) {
1594
- const unosrtedIndex = firstUnsortedSegmentLine(mappings);
1595
- if (unosrtedIndex === mappings.length)
1580
+
1581
+ function maybeSort(mappings, owned) {
1582
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
1583
+ if (unsortedIndex === mappings.length)
1596
1584
  return mappings;
1585
+ // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
1586
+ // not, we do not want to modify the consumer's input array.
1597
1587
  if (!owned)
1598
1588
  mappings = mappings.slice();
1599
- for (let i = unosrtedIndex; i < mappings.length; i++) {
1589
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
1600
1590
  mappings[i] = sortSegments(mappings[i], owned);
1601
1591
  }
1602
1592
  return mappings;
1603
1593
  }
1604
- function sortSegments(segments, owned) {
1605
- if (!owned)
1606
- segments = segments.slice();
1607
- return segments.sort(segmentComparator);
1608
- }
1609
- function segmentComparator(a, b) {
1610
- return a[0] - b[0];
1611
- }
1612
-
1613
- /**
1614
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1615
- *
1616
- * Licensed under the Apache License, Version 2.0 (the "License");
1617
- * you may not use this file except in compliance with the License.
1618
- * You may obtain a copy of the License at
1619
- *
1620
- * http://www.apache.org/licenses/LICENSE-2.0
1621
- *
1622
- * Unless required by applicable law or agreed to in writing, software
1623
- * distributed under the License is distributed on an "AS IS" BASIS,
1624
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1625
- * See the License for the specific language governing permissions and
1626
- * limitations under the License.
1627
- */
1628
- /**
1629
- * A "leaf" node in the sourcemap tree, representing an original, unmodified
1630
- * source file. Recursive segment tracing ends at the `OriginalSource`.
1631
- */
1632
- class OriginalSource {
1633
- constructor(filename, content) {
1634
- this.filename = filename;
1635
- this.content = content;
1594
+ function nextUnsortedSegmentLine(mappings, start) {
1595
+ for (let i = start; i < mappings.length; i++) {
1596
+ if (!isSorted(mappings[i]))
1597
+ return i;
1636
1598
  }
1637
- /**
1638
- * Tracing a `SourceMapSegment` ends when we get to an `OriginalSource`,
1639
- * meaning this line/column location originated from this source file.
1640
- */
1641
- traceSegment(line, column, name) {
1642
- return { column, line, name, source: this };
1599
+ return mappings.length;
1600
+ }
1601
+ function isSorted(line) {
1602
+ for (let j = 1; j < line.length; j++) {
1603
+ if (line[j][0] < line[j - 1][0]) {
1604
+ return false;
1605
+ }
1643
1606
  }
1607
+ return true;
1644
1608
  }
1645
-
1646
- /**
1647
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1648
- *
1649
- * Licensed under the Apache License, Version 2.0 (the "License");
1650
- * you may not use this file except in compliance with the License.
1651
- * You may obtain a copy of the License at
1652
- *
1653
- * http://www.apache.org/licenses/LICENSE-2.0
1654
- *
1655
- * Unless required by applicable law or agreed to in writing, software
1656
- * distributed under the License is distributed on an "AS IS" BASIS,
1657
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1658
- * See the License for the specific language governing permissions and
1659
- * limitations under the License.
1660
- */
1661
- function resolve$2(input, base) {
1662
- // The base is always treated as a directory, if it's not empty.
1663
- // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
1664
- // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
1665
- if (base && !base.endsWith('/'))
1666
- base += '/';
1667
- return resolve$3(input, base);
1609
+ function sortSegments(line, owned) {
1610
+ if (!owned)
1611
+ line = line.slice();
1612
+ return line.sort(sortComparator);
1613
+ }
1614
+ function sortComparator(a, b) {
1615
+ return a[0] - b[0];
1668
1616
  }
1669
1617
 
1670
1618
  /**
1671
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1672
- *
1673
- * Licensed under the Apache License, Version 2.0 (the "License");
1674
- * you may not use this file except in compliance with the License.
1675
- * You may obtain a copy of the License at
1676
- *
1677
- * http://www.apache.org/licenses/LICENSE-2.0
1678
- *
1679
- * Unless required by applicable law or agreed to in writing, software
1680
- * distributed under the License is distributed on an "AS IS" BASIS,
1681
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1682
- * See the License for the specific language governing permissions and
1683
- * limitations under the License.
1684
- */
1685
- /**
1686
- * A binary search implementation that returns the index if a match is found,
1687
- * or the negated index of where the `needle` should be inserted.
1688
- *
1689
- * The `comparator` callback receives both the `item` under comparison and the
1690
- * needle we are searching for. It must return `0` if the `item` is a match,
1691
- * any negative number if `item` is too small (and we must search after it), or
1692
- * any positive number if the `item` is too large (and we must search before
1693
- * it).
1694
- *
1695
- * If no match is found, a negated index of where to insert the `needle` is
1696
- * returned. This negated index is guaranteed to be less than 0. To insert an
1697
- * item, negate it (again) and splice:
1619
+ * A binary search implementation that returns the index if a match is found.
1620
+ * If no match is found, then the left-index (the index associated with the item that comes just
1621
+ * before the desired index) is returned. To maintain proper sort order, a splice would happen at
1622
+ * the next index:
1698
1623
  *
1699
1624
  * ```js
1700
1625
  * const array = [1, 3];
1701
1626
  * const needle = 2;
1702
1627
  * const index = binarySearch(array, needle, (item, needle) => item - needle);
1703
1628
  *
1704
- * assert.equal(index, -2);
1705
- * assert.equal(~index, 1);
1706
- * array.splice(~index, 0, needle);
1629
+ * assert.equal(index, 0);
1630
+ * array.splice(index + 1, 0, needle);
1707
1631
  * assert.deepEqual(array, [1, 2, 3]);
1708
1632
  * ```
1709
1633
  */
1710
- function binarySearch$2(haystack, needle, comparator, low, high) {
1711
- low = Math.max(low, 0);
1634
+ function binarySearch$2(haystack, needle, low, high) {
1712
1635
  while (low <= high) {
1713
1636
  const mid = low + ((high - low) >> 1);
1714
- const cmp = comparator(haystack[mid], needle);
1637
+ const cmp = haystack[mid][0] - needle;
1715
1638
  if (cmp === 0) {
1716
1639
  return mid;
1717
1640
  }
@@ -1722,24 +1645,147 @@ function binarySearch$2(haystack, needle, comparator, low, high) {
1722
1645
  high = mid - 1;
1723
1646
  }
1724
1647
  }
1725
- return ~low;
1648
+ return low - 1;
1649
+ }
1650
+ function memoizedState() {
1651
+ return {
1652
+ lastKey: -1,
1653
+ lastNeedle: -1,
1654
+ lastIndex: -1,
1655
+ };
1656
+ }
1657
+ /**
1658
+ * This overly complicated beast is just to record the last tested line/column and the resulting
1659
+ * index, allowing us to skip a few tests if mappings are monotonically increasing.
1660
+ */
1661
+ function memoizedBinarySearch(haystack, needle, state, key) {
1662
+ const { lastKey, lastNeedle, lastIndex } = state;
1663
+ let low = 0;
1664
+ let high = haystack.length - 1;
1665
+ if (key === lastKey) {
1666
+ if (needle === lastNeedle) {
1667
+ return lastIndex;
1668
+ }
1669
+ if (needle >= lastNeedle) {
1670
+ // lastIndex may be -1 if the previous needle was not found.
1671
+ low = Math.max(lastIndex, 0);
1672
+ }
1673
+ else {
1674
+ high = lastIndex;
1675
+ }
1676
+ }
1677
+ state.lastKey = key;
1678
+ state.lastNeedle = needle;
1679
+ return (state.lastIndex = binarySearch$2(haystack, needle, low, high));
1726
1680
  }
1727
1681
 
1682
+ Object.freeze({
1683
+ source: null,
1684
+ line: null,
1685
+ column: null,
1686
+ name: null,
1687
+ });
1728
1688
  /**
1729
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1730
- *
1731
- * Licensed under the Apache License, Version 2.0 (the "License");
1732
- * you may not use this file except in compliance with the License.
1733
- * You may obtain a copy of the License at
1734
- *
1735
- * http://www.apache.org/licenses/LICENSE-2.0
1736
- *
1737
- * Unless required by applicable law or agreed to in writing, software
1738
- * distributed under the License is distributed on an "AS IS" BASIS,
1739
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1740
- * See the License for the specific language governing permissions and
1741
- * limitations under the License.
1689
+ * Returns the encoded (VLQ string) form of the SourceMap's mappings field.
1690
+ */
1691
+ let encodedMappings;
1692
+ /**
1693
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
1694
+ */
1695
+ let decodedMappings;
1696
+ /**
1697
+ * A low-level API to find the segment associated with a generated line/column (think, from a
1698
+ * stack trace). Line and column here are 0-based, unlike `originalPositionFor`.
1699
+ */
1700
+ let traceSegment;
1701
+ /**
1702
+ * A helper that skips sorting of the input map's mappings array, which can be expensive for larger
1703
+ * maps.
1704
+ */
1705
+ let presortedDecodedMap;
1706
+ class TraceMap {
1707
+ constructor(map, mapUrl) {
1708
+ this._binarySearchMemo = memoizedState();
1709
+ const isString = typeof map === 'string';
1710
+ const parsed = isString ? JSON.parse(map) : map;
1711
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
1712
+ this.version = version;
1713
+ this.file = file;
1714
+ this.names = names;
1715
+ this.sourceRoot = sourceRoot;
1716
+ this.sources = sources;
1717
+ this.sourcesContent = sourcesContent;
1718
+ if (sourceRoot || mapUrl) {
1719
+ const from = resolve$2(sourceRoot || '', stripFilename(mapUrl));
1720
+ this.resolvedSources = sources.map((s) => resolve$2(s || '', from));
1721
+ }
1722
+ else {
1723
+ this.resolvedSources = sources;
1724
+ }
1725
+ const { mappings } = parsed;
1726
+ if (typeof mappings === 'string') {
1727
+ this._encoded = mappings;
1728
+ this._decoded = decode(mappings);
1729
+ }
1730
+ else {
1731
+ this._encoded = undefined;
1732
+ this._decoded = maybeSort(mappings, isString);
1733
+ }
1734
+ }
1735
+ }
1736
+ (() => {
1737
+ encodedMappings = (map) => {
1738
+ var _a;
1739
+ return ((_a = map._encoded) !== null && _a !== void 0 ? _a : (map._encoded = encode$1(map._decoded)));
1740
+ };
1741
+ decodedMappings = (map) => {
1742
+ return map._decoded;
1743
+ };
1744
+ traceSegment = (map, line, column) => {
1745
+ const decoded = map._decoded;
1746
+ // It's common for parent source maps to have pointers to lines that have no
1747
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
1748
+ if (line >= decoded.length)
1749
+ return null;
1750
+ const segments = decoded[line];
1751
+ const index = memoizedBinarySearch(segments, column, map._binarySearchMemo, line);
1752
+ // we come before any mapped segment
1753
+ if (index < 0)
1754
+ return null;
1755
+ return segments[index];
1756
+ };
1757
+ presortedDecodedMap = (map, mapUrl) => {
1758
+ const clone = Object.assign({}, map);
1759
+ clone.mappings = [];
1760
+ const tracer = new TraceMap(clone, mapUrl);
1761
+ tracer._decoded = map.mappings;
1762
+ return tracer;
1763
+ };
1764
+ })();
1765
+
1766
+ /**
1767
+ * A "leaf" node in the sourcemap tree, representing an original, unmodified
1768
+ * source file. Recursive segment tracing ends at the `OriginalSource`.
1742
1769
  */
1770
+ class OriginalSource {
1771
+ constructor(source, content) {
1772
+ this.source = source;
1773
+ this.content = content;
1774
+ }
1775
+ /**
1776
+ * Tracing a `SourceMapSegment` ends when we get to an `OriginalSource`,
1777
+ * meaning this line/column location originated from this source file.
1778
+ */
1779
+ originalPositionFor(line, column, name) {
1780
+ return { column, line, name, source: this.source, content: this.content };
1781
+ }
1782
+ }
1783
+
1784
+ /**
1785
+ * Puts `key` into the backing array, if it is not already present. Returns
1786
+ * the index of the `key` in the backing array.
1787
+ */
1788
+ let put;
1743
1789
  /**
1744
1790
  * FastStringArray acts like a `Set` (allowing only one occurrence of a string
1745
1791
  * `key`), but provides the index of the `key` in the backing array.
@@ -1753,12 +1799,10 @@ class FastStringArray {
1753
1799
  this.indexes = Object.create(null);
1754
1800
  this.array = [];
1755
1801
  }
1756
- /**
1757
- * Puts `key` into the backing array, if it is not already present. Returns
1758
- * the index of the `key` in the backing array.
1759
- */
1760
- put(key) {
1761
- const { array, indexes } = this;
1802
+ }
1803
+ (() => {
1804
+ put = (strarr, key) => {
1805
+ const { array, indexes } = strarr;
1762
1806
  // The key may or may not be present. If it is present, it's a number.
1763
1807
  let index = indexes[key];
1764
1808
  // If it's not yet present, we need to insert it and track the index in the
@@ -1768,24 +1812,16 @@ class FastStringArray {
1768
1812
  array.push(key);
1769
1813
  }
1770
1814
  return index;
1771
- }
1772
- }
1815
+ };
1816
+ })();
1773
1817
 
1818
+ const INVALID_MAPPING = undefined;
1819
+ const SOURCELESS_MAPPING = null;
1774
1820
  /**
1775
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1776
- *
1777
- * Licensed under the Apache License, Version 2.0 (the "License");
1778
- * you may not use this file except in compliance with the License.
1779
- * You may obtain a copy of the License at
1780
- *
1781
- * http://www.apache.org/licenses/LICENSE-2.0
1782
- *
1783
- * Unless required by applicable law or agreed to in writing, software
1784
- * distributed under the License is distributed on an "AS IS" BASIS,
1785
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1786
- * See the License for the specific language governing permissions and
1787
- * limitations under the License.
1821
+ * traceMappings is only called on the root level SourceMapTree, and begins the process of
1822
+ * resolving each mapping in terms of the original source files.
1788
1823
  */
1824
+ let traceMappings;
1789
1825
  /**
1790
1826
  * SourceMapTree represents a single sourcemap, with the ability to trace
1791
1827
  * mappings into its child nodes (which may themselves be SourceMapTrees).
@@ -1794,166 +1830,105 @@ class SourceMapTree {
1794
1830
  constructor(map, sources) {
1795
1831
  this.map = map;
1796
1832
  this.sources = sources;
1797
- this.lastLine = 0;
1798
- this.lastColumn = 0;
1799
- this.lastIndex = 0;
1800
1833
  }
1801
1834
  /**
1802
- * traceMappings is only called on the root level SourceMapTree, and begins
1803
- * the process of resolving each mapping in terms of the original source
1804
- * files.
1835
+ * originalPositionFor is only called on children SourceMapTrees. It recurses down
1836
+ * into its own child SourceMapTrees, until we find the original source map.
1805
1837
  */
1806
- traceMappings() {
1838
+ originalPositionFor(line, column, name) {
1839
+ const segment = traceSegment(this.map, line, column);
1840
+ // If we couldn't find a segment, then this doesn't exist in the sourcemap.
1841
+ if (segment == null)
1842
+ return INVALID_MAPPING;
1843
+ // 1-length segments only move the current generated column, there's no source information
1844
+ // to gather from it.
1845
+ if (segment.length === 1)
1846
+ return SOURCELESS_MAPPING;
1847
+ const source = this.sources[segment[1]];
1848
+ return source.originalPositionFor(segment[2], segment[3], segment.length === 5 ? this.map.names[segment[4]] : name);
1849
+ }
1850
+ }
1851
+ (() => {
1852
+ traceMappings = (tree) => {
1807
1853
  const mappings = [];
1808
1854
  const names = new FastStringArray();
1809
1855
  const sources = new FastStringArray();
1810
1856
  const sourcesContent = [];
1811
- const { mappings: rootMappings, names: rootNames } = this.map;
1857
+ const { sources: rootSources, map } = tree;
1858
+ const rootNames = map.names;
1859
+ const rootMappings = decodedMappings(map);
1860
+ let lastLineWithSegment = -1;
1812
1861
  for (let i = 0; i < rootMappings.length; i++) {
1813
1862
  const segments = rootMappings[i];
1814
1863
  const tracedSegments = [];
1815
- let lastTraced = undefined;
1864
+ let lastSourcesIndex = -1;
1865
+ let lastSourceLine = -1;
1866
+ let lastSourceColumn = -1;
1816
1867
  for (let j = 0; j < segments.length; j++) {
1817
1868
  const segment = segments[j];
1818
- // 1-length segments only move the current generated column, there's no
1819
- // source information to gather from it.
1820
- if (segment.length === 1)
1821
- continue;
1822
- const source = this.sources[segment[1]];
1823
- const traced = source.traceSegment(segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : '');
1824
- if (!traced)
1869
+ let traced = SOURCELESS_MAPPING;
1870
+ // 1-length segments only move the current generated column, there's no source information
1871
+ // to gather from it.
1872
+ if (segment.length !== 1) {
1873
+ const source = rootSources[segment[1]];
1874
+ traced = source.originalPositionFor(segment[2], segment[3], segment.length === 5 ? rootNames[segment[4]] : '');
1875
+ // If the trace is invalid, then the trace ran into a sourcemap that doesn't contain a
1876
+ // respective segment into an original source.
1877
+ if (traced === INVALID_MAPPING)
1878
+ continue;
1879
+ }
1880
+ const genCol = segment[0];
1881
+ if (traced === SOURCELESS_MAPPING) {
1882
+ if (lastSourcesIndex === -1) {
1883
+ // This is a consecutive source-less segment, which doesn't carry any new information.
1884
+ continue;
1885
+ }
1886
+ lastSourcesIndex = lastSourceLine = lastSourceColumn = -1;
1887
+ tracedSegments.push([genCol]);
1825
1888
  continue;
1889
+ }
1826
1890
  // So we traced a segment down into its original source file. Now push a
1827
1891
  // new segment pointing to this location.
1828
- const { column, line, name } = traced;
1829
- const { content, filename } = traced.source;
1892
+ const { column, line, name, content, source } = traced;
1830
1893
  // Store the source location, and ensure we keep sourcesContent up to
1831
1894
  // date with the sources array.
1832
- const sourceIndex = sources.put(filename);
1833
- sourcesContent[sourceIndex] = content;
1834
- if (lastTraced &&
1835
- lastTraced[1] === sourceIndex &&
1836
- lastTraced[2] === line &&
1837
- lastTraced[3] === column) {
1838
- // This is a duplicate mapping pointing at the exact same starting point in the source file.
1839
- // It doesn't provide any new information, and only bloats the sourcemap.
1895
+ const sourcesIndex = put(sources, source);
1896
+ sourcesContent[sourcesIndex] = content;
1897
+ if (lastSourcesIndex === sourcesIndex &&
1898
+ lastSourceLine === line &&
1899
+ lastSourceColumn === column) {
1900
+ // This is a duplicate mapping pointing at the exact same starting point in the source
1901
+ // file. It doesn't carry any new information, and only bloats the sourcemap.
1840
1902
  continue;
1841
1903
  }
1842
- // This looks like unnecessary duplication, but it noticeably increases
1843
- // performance. If we were to push the nameIndex onto length-4 array, v8
1844
- // would internally allocate 22 slots! That's 68 wasted bytes! Array
1845
- // literals have the same capacity as their length, saving memory.
1846
- if (name) {
1847
- lastTraced = [segment[0], sourceIndex, line, column, names.put(name)];
1848
- }
1849
- else {
1850
- lastTraced = [segment[0], sourceIndex, line, column];
1851
- }
1852
- tracedSegments.push(lastTraced);
1904
+ lastLineWithSegment = i;
1905
+ lastSourcesIndex = sourcesIndex;
1906
+ lastSourceLine = line;
1907
+ lastSourceColumn = column;
1908
+ // This looks like unnecessary duplication, but it noticeably increases performance. If we
1909
+ // were to push the nameIndex onto length-4 array, v8 would internally allocate 22 slots!
1910
+ // That's 68 wasted bytes! Array literals have the same capacity as their length, saving
1911
+ // memory.
1912
+ tracedSegments.push(name
1913
+ ? [genCol, sourcesIndex, line, column, put(names, name)]
1914
+ : [genCol, sourcesIndex, line, column]);
1853
1915
  }
1854
1916
  mappings.push(tracedSegments);
1855
1917
  }
1856
- // TODO: Make all sources relative to the sourceRoot.
1857
- return defaults({
1918
+ if (mappings.length > lastLineWithSegment + 1) {
1919
+ mappings.length = lastLineWithSegment + 1;
1920
+ }
1921
+ return presortedDecodedMap(Object.assign({}, tree.map, {
1858
1922
  mappings,
1923
+ // TODO: Make all sources relative to the sourceRoot.
1924
+ sourceRoot: undefined,
1859
1925
  names: names.array,
1860
1926
  sources: sources.array,
1861
1927
  sourcesContent,
1862
- }, this.map);
1863
- }
1864
- /**
1865
- * traceSegment is only called on children SourceMapTrees. It recurses down
1866
- * into its own child SourceMapTrees, until we find the original source map.
1867
- */
1868
- traceSegment(line, column, name) {
1869
- const { mappings, names } = this.map;
1870
- // It's common for parent sourcemaps to have pointers to lines that have no
1871
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
1872
- if (line >= mappings.length)
1873
- return null;
1874
- const segments = mappings[line];
1875
- if (segments.length === 0)
1876
- return null;
1877
- let low = 0;
1878
- let high = segments.length - 1;
1879
- if (line === this.lastLine) {
1880
- if (column >= this.lastColumn) {
1881
- low = this.lastIndex;
1882
- }
1883
- else {
1884
- high = this.lastIndex;
1885
- }
1886
- }
1887
- let index = binarySearch$2(segments, column, segmentComparator$1, low, high);
1888
- this.lastLine = line;
1889
- this.lastColumn = column;
1890
- if (index === -1) {
1891
- this.lastIndex = index;
1892
- return null; // we come before any mapped segment
1893
- }
1894
- // If we can't find a segment that lines up to this column, we use the
1895
- // segment before.
1896
- if (index < 0) {
1897
- index = ~index - 1;
1898
- }
1899
- this.lastIndex = index;
1900
- const segment = segments[index];
1901
- // 1-length segments only move the current generated column, there's no
1902
- // source information to gather from it.
1903
- if (segment.length === 1)
1904
- return null;
1905
- const source = this.sources[segment[1]];
1906
- // So now we can recurse down, until we hit the original source file.
1907
- return source.traceSegment(segment[2], segment[3],
1908
- // A child map's recorded name for this segment takes precedence over the
1909
- // parent's mapped name. Imagine a mangler changing the name over, etc.
1910
- segment.length === 5 ? names[segment[4]] : name);
1911
- }
1912
- }
1913
- function segmentComparator$1(segment, column) {
1914
- return segment[0] - column;
1915
- }
1916
-
1917
- /**
1918
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1919
- *
1920
- * Licensed under the Apache License, Version 2.0 (the "License");
1921
- * you may not use this file except in compliance with the License.
1922
- * You may obtain a copy of the License at
1923
- *
1924
- * http://www.apache.org/licenses/LICENSE-2.0
1925
- *
1926
- * Unless required by applicable law or agreed to in writing, software
1927
- * distributed under the License is distributed on an "AS IS" BASIS,
1928
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1929
- * See the License for the specific language governing permissions and
1930
- * limitations under the License.
1931
- */
1932
- /**
1933
- * Removes the filename from a path.
1934
- */
1935
- function stripFilename(path) {
1936
- if (!path)
1937
- return '';
1938
- const index = path.lastIndexOf('/');
1939
- return path.slice(0, index + 1);
1940
- }
1928
+ }));
1929
+ };
1930
+ })();
1941
1931
 
1942
- /**
1943
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
1944
- *
1945
- * Licensed under the Apache License, Version 2.0 (the "License");
1946
- * you may not use this file except in compliance with the License.
1947
- * You may obtain a copy of the License at
1948
- *
1949
- * http://www.apache.org/licenses/LICENSE-2.0
1950
- *
1951
- * Unless required by applicable law or agreed to in writing, software
1952
- * distributed under the License is distributed on an "AS IS" BASIS,
1953
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1954
- * See the License for the specific language governing permissions and
1955
- * limitations under the License.
1956
- */
1957
1932
  function asArray(value) {
1958
1933
  if (Array.isArray(value))
1959
1934
  return value;
@@ -1970,8 +1945,8 @@ function asArray(value) {
1970
1945
  * does not have an associated sourcemap, it is considered an original,
1971
1946
  * unmodified source file.
1972
1947
  */
1973
- function buildSourceMapTree(input, loader, relativeRoot) {
1974
- const maps = asArray(input).map(decodeSourceMap);
1948
+ function buildSourceMapTree(input, loader) {
1949
+ const maps = asArray(input).map((m) => new TraceMap(m, ''));
1975
1950
  const map = maps.pop();
1976
1951
  for (let i = 0; i < maps.length; i++) {
1977
1952
  if (maps[i].sources.length > 1) {
@@ -1979,48 +1954,43 @@ function buildSourceMapTree(input, loader, relativeRoot) {
1979
1954
  'Did you specify these with the most recent transformation maps first?');
1980
1955
  }
1981
1956
  }
1982
- const { sourceRoot, sources, sourcesContent } = map;
1983
- const children = sources.map((sourceFile, i) => {
1984
- // Each source file is loaded relative to the sourcemap's own sourceRoot,
1985
- // which is itself relative to the sourcemap's parent.
1986
- const uri = resolve$2(sourceFile || '', resolve$2(sourceRoot || '', stripFilename(relativeRoot)));
1957
+ let tree = build$2(map, '', loader);
1958
+ for (let i = maps.length - 1; i >= 0; i--) {
1959
+ tree = new SourceMapTree(maps[i], [tree]);
1960
+ }
1961
+ return tree;
1962
+ }
1963
+ function build$2(map, importer, loader) {
1964
+ const { resolvedSources, sourcesContent } = map;
1965
+ const children = resolvedSources.map((sourceFile, i) => {
1966
+ // The loading context gives the loader more information about why this file is being loaded
1967
+ // (eg, from which importer). It also allows the loader to override the location of the loaded
1968
+ // sourcemap/original source, or to override the content in the sourcesContent field if it's
1969
+ // an unmodified source file.
1970
+ const ctx = {
1971
+ importer,
1972
+ source: sourceFile || '',
1973
+ content: undefined,
1974
+ };
1987
1975
  // Use the provided loader callback to retrieve the file's sourcemap.
1988
1976
  // TODO: We should eventually support async loading of sourcemap files.
1989
- const sourceMap = loader(uri);
1977
+ const sourceMap = loader(ctx.source, ctx);
1978
+ const { source, content } = ctx;
1990
1979
  // If there is no sourcemap, then it is an unmodified source file.
1991
1980
  if (!sourceMap) {
1992
- // The source file's actual contents must be included in the sourcemap
1993
- // (done when generating the sourcemap) for it to be included as a
1994
- // sourceContent in the output sourcemap.
1995
- const sourceContent = sourcesContent ? sourcesContent[i] : null;
1996
- return new OriginalSource(uri, sourceContent);
1981
+ // The contents of this unmodified source file can be overridden via the loader context,
1982
+ // allowing it to be explicitly null or a string. If it remains undefined, we fall back to
1983
+ // the importing sourcemap's `sourcesContent` field.
1984
+ const sourceContent = content !== undefined ? content : sourcesContent ? sourcesContent[i] : null;
1985
+ return new OriginalSource(source, sourceContent);
1997
1986
  }
1998
1987
  // Else, it's a real sourcemap, and we need to recurse into it to load its
1999
1988
  // source files.
2000
- return buildSourceMapTree(decodeSourceMap(sourceMap), loader, uri);
1989
+ return build$2(new TraceMap(sourceMap, source), source, loader);
2001
1990
  });
2002
- let tree = new SourceMapTree(map, children);
2003
- for (let i = maps.length - 1; i >= 0; i--) {
2004
- tree = new SourceMapTree(maps[i], [tree]);
2005
- }
2006
- return tree;
1991
+ return new SourceMapTree(map, children);
2007
1992
  }
2008
1993
 
2009
- /**
2010
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
2011
- *
2012
- * Licensed under the Apache License, Version 2.0 (the "License");
2013
- * you may not use this file except in compliance with the License.
2014
- * You may obtain a copy of the License at
2015
- *
2016
- * http://www.apache.org/licenses/LICENSE-2.0
2017
- *
2018
- * Unless required by applicable law or agreed to in writing, software
2019
- * distributed under the License is distributed on an "AS IS" BASIS,
2020
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2021
- * See the License for the specific language governing permissions and
2022
- * limitations under the License.
2023
- */
2024
1994
  /**
2025
1995
  * A SourceMap v3 compatible sourcemap, which only includes fields that were
2026
1996
  * provided to it.
@@ -2028,13 +1998,10 @@ function buildSourceMapTree(input, loader, relativeRoot) {
2028
1998
  class SourceMap$1 {
2029
1999
  constructor(map, options) {
2030
2000
  this.version = 3; // SourceMap spec says this should be first.
2031
- if ('file' in map)
2032
- this.file = map.file;
2033
- this.mappings = options.decodedMappings ? map.mappings : encode(map.mappings);
2001
+ this.file = map.file;
2002
+ this.mappings = options.decodedMappings ? decodedMappings(map) : encodedMappings(map);
2034
2003
  this.names = map.names;
2035
- // TODO: We first need to make all source URIs relative to the sourceRoot
2036
- // before we can support a sourceRoot.
2037
- // if ('sourceRoot' in map) this.sourceRoot = map.sourceRoot;
2004
+ this.sourceRoot = map.sourceRoot;
2038
2005
  this.sources = map.sources;
2039
2006
  if (!options.excludeContent && 'sourcesContent' in map) {
2040
2007
  this.sourcesContent = map.sourcesContent;
@@ -2045,21 +2012,6 @@ class SourceMap$1 {
2045
2012
  }
2046
2013
  }
2047
2014
 
2048
- /**
2049
- * Copyright 2019 The AMP HTML Authors. All Rights Reserved.
2050
- *
2051
- * Licensed under the Apache License, Version 2.0 (the "License");
2052
- * you may not use this file except in compliance with the License.
2053
- * You may obtain a copy of the License at
2054
- *
2055
- * http://www.apache.org/licenses/LICENSE-2.0
2056
- *
2057
- * Unless required by applicable law or agreed to in writing, software
2058
- * distributed under the License is distributed on an "AS IS" BASIS,
2059
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2060
- * See the License for the specific language governing permissions and
2061
- * limitations under the License.
2062
- */
2063
2015
  /**
2064
2016
  * Traces through all the mappings in the root sourcemap, through the sources
2065
2017
  * (and their sourcemaps), all the way back to the original source location.
@@ -2077,8 +2029,8 @@ class SourceMap$1 {
2077
2029
  */
2078
2030
  function remapping(input, loader, options) {
2079
2031
  const opts = typeof options === 'object' ? options : { excludeContent: !!options, decodedMappings: false };
2080
- const graph = buildSourceMapTree(input, loader);
2081
- return new SourceMap$1(graph.traceMappings(), opts);
2032
+ const tree = buildSourceMapTree(input, loader);
2033
+ return new SourceMap$1(traceMappings(tree), opts);
2082
2034
  }
2083
2035
 
2084
2036
  function slash$1(p) {
@@ -2225,7 +2177,7 @@ function injectQuery(url, queryToInject) {
2225
2177
  pathname = pathname.slice(1);
2226
2178
  }
2227
2179
  pathname = decodeURIComponent(pathname);
2228
- return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${hash || ''}`;
2180
+ return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ''}${hash !== null && hash !== void 0 ? hash : ''}`;
2229
2181
  }
2230
2182
  const timestampRE = /\bt=\d{13}&?\b/;
2231
2183
  function removeTimestampQuery(url) {
@@ -2386,8 +2338,8 @@ function writeFile(filename, content) {
2386
2338
  */
2387
2339
  function isFileReadable(filename) {
2388
2340
  try {
2389
- fs__default.accessSync(filename, fs__default.constants.R_OK);
2390
- return true;
2341
+ const stat = fs__default.statSync(filename, { throwIfNoEntry: false });
2342
+ return !!stat;
2391
2343
  }
2392
2344
  catch {
2393
2345
  return false;
@@ -2463,7 +2415,7 @@ async function processSrcSet(srcs, replacer) {
2463
2415
  };
2464
2416
  }));
2465
2417
  return ret.reduce((prev, { url, descriptor }, index) => {
2466
- descriptor = descriptor || '';
2418
+ descriptor !== null && descriptor !== void 0 ? descriptor : (descriptor = '');
2467
2419
  return (prev +=
2468
2420
  url + ` ${descriptor}${index === ret.length - 1 ? '' : ', '}`);
2469
2421
  }, '');
@@ -2858,6 +2810,62 @@ function throttle(fn) {
2858
2810
  };
2859
2811
  }
2860
2812
 
2813
+ var charToInteger = {};
2814
+ var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
2815
+ for (var i$2 = 0; i$2 < chars$1.length; i$2++) {
2816
+ charToInteger[chars$1.charCodeAt(i$2)] = i$2;
2817
+ }
2818
+ function encode(decoded) {
2819
+ var sourceFileIndex = 0; // second field
2820
+ var sourceCodeLine = 0; // third field
2821
+ var sourceCodeColumn = 0; // fourth field
2822
+ var nameIndex = 0; // fifth field
2823
+ var mappings = '';
2824
+ for (var i = 0; i < decoded.length; i++) {
2825
+ var line = decoded[i];
2826
+ if (i > 0)
2827
+ mappings += ';';
2828
+ if (line.length === 0)
2829
+ continue;
2830
+ var generatedCodeColumn = 0; // first field
2831
+ var lineMappings = [];
2832
+ for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
2833
+ var segment = line_1[_i];
2834
+ var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
2835
+ generatedCodeColumn = segment[0];
2836
+ if (segment.length > 1) {
2837
+ segmentMappings +=
2838
+ encodeInteger(segment[1] - sourceFileIndex) +
2839
+ encodeInteger(segment[2] - sourceCodeLine) +
2840
+ encodeInteger(segment[3] - sourceCodeColumn);
2841
+ sourceFileIndex = segment[1];
2842
+ sourceCodeLine = segment[2];
2843
+ sourceCodeColumn = segment[3];
2844
+ }
2845
+ if (segment.length === 5) {
2846
+ segmentMappings += encodeInteger(segment[4] - nameIndex);
2847
+ nameIndex = segment[4];
2848
+ }
2849
+ lineMappings.push(segmentMappings);
2850
+ }
2851
+ mappings += lineMappings.join(',');
2852
+ }
2853
+ return mappings;
2854
+ }
2855
+ function encodeInteger(num) {
2856
+ var result = '';
2857
+ num = num < 0 ? (-num << 1) | 1 : num << 1;
2858
+ do {
2859
+ var clamped = num & 31;
2860
+ num >>>= 5;
2861
+ if (num > 0) {
2862
+ clamped |= 32;
2863
+ }
2864
+ result += chars$1[clamped];
2865
+ } while (num > 0);
2866
+ return result;
2867
+ }
2868
+
2861
2869
  var BitSet = function BitSet(arg) {
2862
2870
  this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
2863
2871
  };
@@ -5660,7 +5668,7 @@ const append$1 = (queue = '', stash = '', enclose = false) => {
5660
5668
  return utils$g.flatten(result);
5661
5669
  };
5662
5670
 
5663
- const expand$4 = (ast, options = {}) => {
5671
+ const expand$3 = (ast, options = {}) => {
5664
5672
  let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
5665
5673
 
5666
5674
  let walk = (node, parent = {}) => {
@@ -5740,7 +5748,7 @@ const expand$4 = (ast, options = {}) => {
5740
5748
  return utils$g.flatten(walk(ast));
5741
5749
  };
5742
5750
 
5743
- var expand_1$1 = expand$4;
5751
+ var expand_1 = expand$3;
5744
5752
 
5745
5753
  var constants$6 = {
5746
5754
  MAX_LENGTH: 1024 * 64,
@@ -6129,7 +6137,7 @@ var parse_1$2 = parse$m;
6129
6137
 
6130
6138
  const stringify$4 = stringify$8;
6131
6139
  const compile = compile_1;
6132
- const expand$3 = expand_1$1;
6140
+ const expand$2 = expand_1;
6133
6141
  const parse$l = parse_1$2;
6134
6142
 
6135
6143
  /**
@@ -6249,7 +6257,7 @@ braces$2.expand = (input, options = {}) => {
6249
6257
  input = braces$2.parse(input, options);
6250
6258
  }
6251
6259
 
6252
- let result = expand$3(input, options);
6260
+ let result = expand$2(input, options);
6253
6261
 
6254
6262
  // filter out empty strings if specified
6255
6263
  if (options.noempty === true) {
@@ -18858,7 +18866,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
18858
18866
  const postcssOptions = (postcssConfig && postcssConfig.options) || {};
18859
18867
  const postcssPlugins = postcssConfig && postcssConfig.plugins ? postcssConfig.plugins.slice() : [];
18860
18868
  if (needInlineImport) {
18861
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-0ebab0df.js'); }).then(function (n) { return n.index; })).default({
18869
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-ec2e68f4.js'); }).then(function (n) { return n.index; })).default({
18862
18870
  async resolve(id, basedir) {
18863
18871
  const resolved = await atImportResolvers.css(id, path__default.join(basedir, '*'));
18864
18872
  if (resolved) {
@@ -18872,7 +18880,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
18872
18880
  replacer: urlReplacer
18873
18881
  }));
18874
18882
  if (isModule) {
18875
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-752d5fd3.js'); }).then(function (n) { return n.index; })).default({
18883
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-32e0ec2c.js'); }).then(function (n) { return n.index; })).default({
18876
18884
  ...modulesOptions,
18877
18885
  getJSON(cssFileName, _modules, outputFileName) {
18878
18886
  modules = _modules;
@@ -18913,7 +18921,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
18913
18921
  // record CSS dependencies from @imports
18914
18922
  for (const message of postcssResult.messages) {
18915
18923
  if (message.type === 'dependency') {
18916
- deps.add(message.file);
18924
+ deps.add(normalizePath$4(message.file));
18917
18925
  }
18918
18926
  else if (message.type === 'dir-dependency') {
18919
18927
  // https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#3-dependencies
@@ -21295,7 +21303,7 @@ const assetAttrsConfig = {
21295
21303
  const isAsyncScriptMap = new WeakMap();
21296
21304
  async function traverseHtml(html, filePath, visitor) {
21297
21305
  // lazy load compiler
21298
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-9e561a04.js'); }).then(function (n) { return n.compilerDom_cjs; });
21306
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-4e686eeb.js'); }).then(function (n) { return n.compilerDom_cjs; });
21299
21307
  // @vue/compiler-core doesn't like lowercase doctypes
21300
21308
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21301
21309
  try {
@@ -22780,7 +22788,9 @@ function manifestPlugin(config) {
22780
22788
  const outputLength = Array.isArray(output) ? output.length : 1;
22781
22789
  if (outputCount >= outputLength) {
22782
22790
  this.emitFile({
22783
- fileName: `manifest.json`,
22791
+ fileName: typeof config.build.manifest === 'string'
22792
+ ? config.build.manifest
22793
+ : 'manifest.json',
22784
22794
  type: 'asset',
22785
22795
  source: JSON.stringify(manifest, null, 2)
22786
22796
  });
@@ -23682,7 +23692,7 @@ function expandTop(str) {
23682
23692
  str = '\\{\\}' + str.substr(2);
23683
23693
  }
23684
23694
 
23685
- return expand$2(escapeBraces(str), true).map(unescapeBraces);
23695
+ return expand$1(escapeBraces(str), true).map(unescapeBraces);
23686
23696
  }
23687
23697
 
23688
23698
  function embrace(str) {
@@ -23699,7 +23709,7 @@ function gte(i, y) {
23699
23709
  return i >= y;
23700
23710
  }
23701
23711
 
23702
- function expand$2(str, isTop) {
23712
+ function expand$1(str, isTop) {
23703
23713
  var expansions = [];
23704
23714
 
23705
23715
  var m = balanced('{', '}', str);
@@ -23713,7 +23723,7 @@ function expand$2(str, isTop) {
23713
23723
  // {a},b}
23714
23724
  if (m.post.match(/,.*\}/)) {
23715
23725
  str = m.pre + '{' + m.body + escClose + m.post;
23716
- return expand$2(str);
23726
+ return expand$1(str);
23717
23727
  }
23718
23728
  return [str];
23719
23729
  }
@@ -23725,10 +23735,10 @@ function expand$2(str, isTop) {
23725
23735
  n = parseCommaParts(m.body);
23726
23736
  if (n.length === 1) {
23727
23737
  // x{{a,b}}y ==> x{a}y x{b}y
23728
- n = expand$2(n[0], false).map(embrace);
23738
+ n = expand$1(n[0], false).map(embrace);
23729
23739
  if (n.length === 1) {
23730
23740
  var post = m.post.length
23731
- ? expand$2(m.post, false)
23741
+ ? expand$1(m.post, false)
23732
23742
  : [''];
23733
23743
  return post.map(function(p) {
23734
23744
  return m.pre + n[0] + p;
@@ -23743,7 +23753,7 @@ function expand$2(str, isTop) {
23743
23753
  // no need to expand pre, since it is guaranteed to be free of brace-sets
23744
23754
  var pre = m.pre;
23745
23755
  var post = m.post.length
23746
- ? expand$2(m.post, false)
23756
+ ? expand$1(m.post, false)
23747
23757
  : [''];
23748
23758
 
23749
23759
  var N;
@@ -23787,7 +23797,7 @@ function expand$2(str, isTop) {
23787
23797
  N.push(c);
23788
23798
  }
23789
23799
  } else {
23790
- N = concatMap(n, function(el) { return expand$2(el, false) });
23800
+ N = concatMap(n, function(el) { return expand$1(el, false) });
23791
23801
  }
23792
23802
 
23793
23803
  for (var j = 0; j < N.length; j++) {
@@ -23810,7 +23820,7 @@ try {
23810
23820
  } catch (er) {}
23811
23821
 
23812
23822
  var GLOBSTAR$1 = minimatch$3.GLOBSTAR = Minimatch$1.GLOBSTAR = {};
23813
- var expand$1 = braceExpansion;
23823
+ var expand = braceExpansion;
23814
23824
 
23815
23825
  var plTypes = {
23816
23826
  '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
@@ -24055,7 +24065,7 @@ function braceExpand (pattern, options) {
24055
24065
  return [pattern]
24056
24066
  }
24057
24067
 
24058
- return expand$1(pattern)
24068
+ return expand(pattern)
24059
24069
  }
24060
24070
 
24061
24071
  // parse a component of the expanded set.
@@ -29778,6 +29788,7 @@ function ssrManifestPlugin(config) {
29778
29788
  return {
29779
29789
  name: 'vite:ssr-manifest',
29780
29790
  generateBundle(_options, bundle) {
29791
+ var _a;
29781
29792
  for (const file in bundle) {
29782
29793
  const chunk = bundle[file];
29783
29794
  if (chunk.type === 'chunk') {
@@ -29789,7 +29800,7 @@ function ssrManifestPlugin(config) {
29789
29800
  const assetFiles = chunkToEmittedAssetsMap.get(chunk);
29790
29801
  for (const id in chunk.modules) {
29791
29802
  const normalizedId = normalizePath$4(path$r.relative(config.root, id));
29792
- const mappedChunks = ssrManifest[normalizedId] || (ssrManifest[normalizedId] = []);
29803
+ const mappedChunks = (_a = ssrManifest[normalizedId]) !== null && _a !== void 0 ? _a : (ssrManifest[normalizedId] = []);
29793
29804
  if (!chunk.isEntry) {
29794
29805
  mappedChunks.push(base + chunk.fileName);
29795
29806
  }
@@ -29851,7 +29862,9 @@ function ssrManifestPlugin(config) {
29851
29862
  }
29852
29863
  }
29853
29864
  this.emitFile({
29854
- fileName: 'ssr-manifest.json',
29865
+ fileName: typeof config.build.ssrManifest === 'string'
29866
+ ? config.build.ssrManifest
29867
+ : 'ssr-manifest.json',
29855
29868
  type: 'asset',
29856
29869
  source: JSON.stringify(ssrManifest, null, 2)
29857
29870
  });
@@ -38538,7 +38551,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
38538
38551
  loader,
38539
38552
  contents: localContent
38540
38553
  };
38541
- js += `import '${virtualModulePrefix}${path}';\n`;
38554
+ js += `import ${JSON.stringify(virtualModulePrefix + path)}\n`;
38542
38555
  }
38543
38556
  else {
38544
38557
  js += content + '\n';
@@ -39234,7 +39247,7 @@ function onRollupWarning(warning, warn, config) {
39234
39247
  }
39235
39248
  }
39236
39249
  function resolveExternal(ssrExternals, user) {
39237
- return ((id, parentId, isResolved) => {
39250
+ return (id, parentId, isResolved) => {
39238
39251
  if (shouldExternalizeForSSR(id, ssrExternals)) {
39239
39252
  return true;
39240
39253
  }
@@ -39249,7 +39262,7 @@ function resolveExternal(ssrExternals, user) {
39249
39262
  return isExternal(id, user);
39250
39263
  }
39251
39264
  }
39252
- });
39265
+ };
39253
39266
  }
39254
39267
  function isExternal(id, test) {
39255
39268
  if (typeof test === 'string') {
@@ -39259,10 +39272,10 @@ function isExternal(id, test) {
39259
39272
  return test.test(id);
39260
39273
  }
39261
39274
  }
39262
- function injectSsrFlagToHooks(p) {
39263
- const { resolveId, load, transform } = p;
39275
+ function injectSsrFlagToHooks(plugin) {
39276
+ const { resolveId, load, transform } = plugin;
39264
39277
  return {
39265
- ...p,
39278
+ ...plugin,
39266
39279
  resolveId: wrapSsrResolveId(resolveId),
39267
39280
  load: wrapSsrLoad(load),
39268
39281
  transform: wrapSsrTransform(transform)
@@ -39278,21 +39291,21 @@ function wrapSsrResolveId(fn) {
39278
39291
  function wrapSsrLoad(fn) {
39279
39292
  if (!fn)
39280
39293
  return;
39281
- // Receiving options param to be future-proof if Rollup adds it
39282
39294
  return function (id, ...args) {
39295
+ // @ts-expect-error: Receiving options param to be future-proof if Rollup adds it
39283
39296
  return fn.call(this, id, injectSsrFlag(args[0]));
39284
39297
  };
39285
39298
  }
39286
39299
  function wrapSsrTransform(fn) {
39287
39300
  if (!fn)
39288
39301
  return;
39289
- // Receiving options param to be future-proof if Rollup adds it
39290
39302
  return function (code, importer, ...args) {
39303
+ // @ts-expect-error: Receiving options param to be future-proof if Rollup adds it
39291
39304
  return fn.call(this, code, importer, injectSsrFlag(args[0]));
39292
39305
  };
39293
39306
  }
39294
- function injectSsrFlag(options = {}) {
39295
- return { ...options, ssr: true };
39307
+ function injectSsrFlag(options) {
39308
+ return { ...(options !== null && options !== void 0 ? options : {}), ssr: true };
39296
39309
  }
39297
39310
 
39298
39311
  var build$1 = {
@@ -45036,7 +45049,7 @@ async function getCertificate(cacheDir) {
45036
45049
  return content;
45037
45050
  }
45038
45051
  catch {
45039
- const content = (await Promise.resolve().then(function () { return require('./dep-6a30742f.js'); })).createCertificate();
45052
+ const content = (await Promise.resolve().then(function () { return require('./dep-98e8af53.js'); })).createCertificate();
45040
45053
  fs$n.promises
45041
45054
  .mkdir(cacheDir, { recursive: true })
45042
45055
  .then(() => fs$n.promises.writeFile(cachePath, content))
@@ -48221,6 +48234,45 @@ function initAsClient(websocket, address, protocols, options) {
48221
48234
  opts.path = parts[1];
48222
48235
  }
48223
48236
 
48237
+ if (opts.followRedirects) {
48238
+ if (websocket._redirects === 0) {
48239
+ websocket._originalHost = parsedUrl.host;
48240
+
48241
+ const headers = options && options.headers;
48242
+
48243
+ //
48244
+ // Shallow copy the user provided options so that headers can be changed
48245
+ // without mutating the original object.
48246
+ //
48247
+ options = { ...options, headers: {} };
48248
+
48249
+ if (headers) {
48250
+ for (const [key, value] of Object.entries(headers)) {
48251
+ options.headers[key.toLowerCase()] = value;
48252
+ }
48253
+ }
48254
+ } else if (parsedUrl.host !== websocket._originalHost) {
48255
+ //
48256
+ // Match curl 7.77.0 behavior and drop the following headers. These
48257
+ // headers are also dropped when following a redirect to a subdomain.
48258
+ //
48259
+ delete opts.headers.authorization;
48260
+ delete opts.headers.cookie;
48261
+ delete opts.headers.host;
48262
+ opts.auth = undefined;
48263
+ }
48264
+
48265
+ //
48266
+ // Match curl 7.77.0 behavior and make the first `Authorization` header win.
48267
+ // If the `Authorization` header is set, then there is nothing to do as it
48268
+ // will take precedence.
48269
+ //
48270
+ if (opts.auth && !options.headers.authorization) {
48271
+ options.headers.authorization =
48272
+ 'Basic ' + Buffer.from(opts.auth).toString('base64');
48273
+ }
48274
+ }
48275
+
48224
48276
  let req = (websocket._req = get(opts));
48225
48277
 
48226
48278
  if (opts.timeout) {
@@ -48786,6 +48838,8 @@ class WebSocketServer extends EventEmitter {
48786
48838
  * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
48787
48839
  * not to skip UTF-8 validation for text and close messages
48788
48840
  * @param {Function} [options.verifyClient] A hook to reject connections
48841
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
48842
+ * class to use. It must be the `WebSocket` class or class that extends it
48789
48843
  * @param {Function} [callback] A listener for the `listening` event
48790
48844
  */
48791
48845
  constructor(options, callback) {
@@ -48804,6 +48858,7 @@ class WebSocketServer extends EventEmitter {
48804
48858
  host: null,
48805
48859
  path: null,
48806
48860
  port: null,
48861
+ WebSocket,
48807
48862
  ...options
48808
48863
  };
48809
48864
 
@@ -49093,7 +49148,7 @@ class WebSocketServer extends EventEmitter {
49093
49148
  `Sec-WebSocket-Accept: ${digest}`
49094
49149
  ];
49095
49150
 
49096
- const ws = new WebSocket(null);
49151
+ const ws = new this.options.WebSocket(null);
49097
49152
 
49098
49153
  if (protocols.size) {
49099
49154
  //
@@ -55902,7 +55957,7 @@ function ssrRewriteStacktrace(stack, moduleGraph) {
55902
55957
  .split('\n')
55903
55958
  .map((line) => {
55904
55959
  return line.replace(/^ {4}at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?)\)?/, (input, varName, url, line, column) => {
55905
- var _a;
55960
+ var _a, _b, _c;
55906
55961
  if (!url)
55907
55962
  return input;
55908
55963
  const mod = moduleGraph.urlToModuleMap.get(url);
@@ -55919,7 +55974,7 @@ function ssrRewriteStacktrace(stack, moduleGraph) {
55919
55974
  if (!pos.source) {
55920
55975
  return input;
55921
55976
  }
55922
- const source = `${pos.source}:${pos.line || 0}:${pos.column || 0}`;
55977
+ const source = `${pos.source}:${(_b = pos.line) !== null && _b !== void 0 ? _b : 0}:${(_c = pos.column) !== null && _c !== void 0 ? _c : 0}`;
55923
55978
  if (!varName || varName === 'eval') {
55924
55979
  return ` at ${source}`;
55925
55980
  }
@@ -69490,6 +69545,12 @@ async function preview(inlineConfig) {
69490
69545
  };
69491
69546
  }
69492
69547
 
69548
+ var preview$1 = {
69549
+ __proto__: null,
69550
+ resolvePreviewOptions: resolvePreviewOptions,
69551
+ preview: preview
69552
+ };
69553
+
69493
69554
  function matches(pattern, importee) {
69494
69555
  if (pattern instanceof RegExp) {
69495
69556
  return pattern.test(importee);
@@ -70128,7 +70189,7 @@ const normalizedEnvEntry = normalizePath$4(ENV_ENTRY);
70128
70189
  function clientInjectionsPlugin(config) {
70129
70190
  return {
70130
70191
  name: 'vite:client-inject',
70131
- transform(code, id) {
70192
+ transform(code, id, options) {
70132
70193
  if (id === normalizedClientEntry || id === normalizedEnvEntry) {
70133
70194
  let options = config.server.hmr;
70134
70195
  options = options && typeof options !== 'boolean' ? options : {};
@@ -70163,8 +70224,10 @@ function clientInjectionsPlugin(config) {
70163
70224
  .replace(`__HMR_TIMEOUT__`, JSON.stringify(timeout))
70164
70225
  .replace(`__HMR_ENABLE_OVERLAY__`, JSON.stringify(overlay));
70165
70226
  }
70166
- else if (code.includes('process.env.NODE_ENV')) {
70167
- // replace process.env.NODE_ENV
70227
+ else if (!(options === null || options === void 0 ? void 0 : options.ssr) && code.includes('process.env.NODE_ENV')) {
70228
+ // replace process.env.NODE_ENV instead of defining a global
70229
+ // for it to avoid shimming a `process` object during dev,
70230
+ // avoiding inconsistencies between dev and build
70168
70231
  return code.replace(/\bprocess\.env\.NODE_ENV\b/g, JSON.stringify(config.mode));
70169
70232
  }
70170
70233
  }
@@ -70565,7 +70628,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
70565
70628
  ].filter(Boolean);
70566
70629
  }
70567
70630
 
70568
- var main = {exports: {}};
70631
+ var main$1 = {exports: {}};
70569
70632
 
70570
70633
  const fs = fs__default;
70571
70634
  const path = path__default;
@@ -70706,70 +70769,56 @@ const DotenvModule = {
70706
70769
  parse
70707
70770
  };
70708
70771
 
70709
- main.exports.config = DotenvModule.config;
70710
- main.exports.parse = DotenvModule.parse;
70711
- main.exports = DotenvModule;
70772
+ main$1.exports.config = DotenvModule.config;
70773
+ main$1.exports.parse = DotenvModule.parse;
70774
+ main$1.exports = DotenvModule;
70712
70775
 
70713
- var dotenv = main.exports;
70776
+ var dotenv = main$1.exports;
70714
70777
 
70715
- function _interpolate (envValue, environment, config) {
70716
- const matches = envValue.match(/(.?\${*[\w]*(?::-)?[\w]*}*)/g) || [];
70778
+ var dotenvExpand = function (config) {
70779
+ // if ignoring process.env, use a blank object
70780
+ var environment = config.ignoreProcessEnv ? {} : process.env;
70717
70781
 
70718
- return matches.reduce(function (newEnv, match, index) {
70719
- const parts = /(.?)\${*([\w]*(?::-)?[\w]*)?}*/g.exec(match);
70720
- if (!parts || parts.length === 0) {
70721
- return newEnv
70722
- }
70782
+ var interpolate = function (envValue) {
70783
+ var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || [];
70723
70784
 
70724
- const prefix = parts[1];
70785
+ return matches.reduce(function (newEnv, match) {
70786
+ var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match);
70787
+ var prefix = parts[1];
70725
70788
 
70726
- let value, replacePart;
70789
+ var value, replacePart;
70727
70790
 
70728
- if (prefix === '\\') {
70729
- replacePart = parts[0];
70730
- value = replacePart.replace('\\$', '$');
70731
- } else {
70732
- const keyParts = parts[2].split(':-');
70733
- const key = keyParts[0];
70734
- replacePart = parts[0].substring(prefix.length);
70735
- // process.env value 'wins' over .env file's value
70736
- value = Object.prototype.hasOwnProperty.call(environment, key)
70737
- ? environment[key]
70738
- : (config.parsed[key] || keyParts[1] || '');
70739
-
70740
- // If the value is found, remove nested expansions.
70741
- if (keyParts.length > 1 && value) {
70742
- const replaceNested = matches[index + 1];
70743
- matches[index + 1] = '';
70744
-
70745
- newEnv = newEnv.replace(replaceNested, '');
70746
- }
70747
- // Resolve recursive interpolations
70748
- value = _interpolate(value, environment, config);
70749
- }
70791
+ if (prefix === '\\') {
70792
+ replacePart = parts[0];
70793
+ value = replacePart.replace('\\$', '$');
70794
+ } else {
70795
+ var key = parts[2];
70796
+ replacePart = parts[0].substring(prefix.length);
70797
+ // process.env value 'wins' over .env file's value
70798
+ value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '');
70750
70799
 
70751
- return newEnv.replace(replacePart, value)
70752
- }, envValue)
70753
- }
70800
+ // Resolve recursive interpolations
70801
+ value = interpolate(value);
70802
+ }
70754
70803
 
70755
- function expand (config) {
70756
- // if ignoring process.env, use a blank object
70757
- const environment = config.ignoreProcessEnv ? {} : process.env;
70804
+ return newEnv.replace(replacePart, value)
70805
+ }, envValue)
70806
+ };
70758
70807
 
70759
- for (const configKey in config.parsed) {
70760
- const value = Object.prototype.hasOwnProperty.call(environment, configKey) ? environment[configKey] : config.parsed[configKey];
70808
+ for (var configKey in config.parsed) {
70809
+ var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey];
70761
70810
 
70762
- config.parsed[configKey] = _interpolate(value, environment, config);
70811
+ config.parsed[configKey] = interpolate(value);
70763
70812
  }
70764
70813
 
70765
- for (const processKey in config.parsed) {
70814
+ for (var processKey in config.parsed) {
70766
70815
  environment[processKey] = config.parsed[processKey];
70767
70816
  }
70768
70817
 
70769
70818
  return config
70770
- }
70819
+ };
70771
70820
 
70772
- var expand_1 = expand;
70821
+ var main = dotenvExpand;
70773
70822
 
70774
70823
  const debug = createDebugger('vite:config');
70775
70824
  /**
@@ -71383,7 +71432,7 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
71383
71432
  debug: ((_a = process.env.DEBUG) === null || _a === void 0 ? void 0 : _a.includes('vite:dotenv')) || undefined
71384
71433
  });
71385
71434
  // let environment variables use each other
71386
- expand_1({
71435
+ main({
71387
71436
  parsed,
71388
71437
  // prevent process.env mutation
71389
71438
  ignoreProcessEnv: true
@@ -71429,6 +71478,7 @@ exports.mergeConfig = mergeConfig;
71429
71478
  exports.normalizePath = normalizePath$4;
71430
71479
  exports.optimizeDeps = optimizeDeps;
71431
71480
  exports.preview = preview;
71481
+ exports.preview$1 = preview$1;
71432
71482
  exports.printHttpServerUrls = printHttpServerUrls;
71433
71483
  exports.resolveConfig = resolveConfig;
71434
71484
  exports.resolveEnvPrefix = resolveEnvPrefix;