@vitejs/plugin-legacy 6.0.2 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -164,7 +164,7 @@ function joinUrlSegments(a, b) {
164
164
  if (!a || !b) {
165
165
  return a || b || "";
166
166
  }
167
- if (a[a.length - 1] === "/") {
167
+ if (a.endsWith("/")) {
168
168
  a = a.substring(0, a.length - 1);
169
169
  }
170
170
  if (b[0] !== "/") {
@@ -209,6 +209,7 @@ function viteLegacyPlugin(options = {}) {
209
209
  }
210
210
  const debugFlags = (process.env.DEBUG || "").split(",");
211
211
  const isDebug = debugFlags.includes("vite:*") || debugFlags.includes("vite:legacy");
212
+ const assumptions = options.assumptions || {};
212
213
  const facadeToLegacyChunkMap = /* @__PURE__ */ new Map();
213
214
  const facadeToLegacyPolyfillMap = /* @__PURE__ */ new Map();
214
215
  const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
@@ -345,6 +346,7 @@ function viteLegacyPlugin(options = {}) {
345
346
  await detectPolyfills(
346
347
  `Promise.resolve(); Promise.all();`,
347
348
  targets,
349
+ assumptions,
348
350
  legacyPolyfills
349
351
  );
350
352
  }
@@ -454,7 +456,12 @@ function viteLegacyPlugin(options = {}) {
454
456
  }
455
457
  if (!isLegacyChunk(chunk, opts)) {
456
458
  if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
457
- await detectPolyfills(raw, modernTargets, polyfillsDiscovered.modern);
459
+ await detectPolyfills(
460
+ raw,
461
+ modernTargets,
462
+ assumptions,
463
+ polyfillsDiscovered.modern
464
+ );
458
465
  }
459
466
  const ms = new MagicString__default(raw);
460
467
  if (genLegacy && chunk.isEntry) {
@@ -496,6 +503,7 @@ function viteLegacyPlugin(options = {}) {
496
503
  compact: !!config.build.minify,
497
504
  sourceMaps,
498
505
  inputSourceMap: void 0,
506
+ assumptions,
499
507
  presets: [
500
508
  // forcing our plugin to run before preset-env by wrapping it in a
501
509
  // preset so we can catch the injected import statements...
@@ -649,13 +657,14 @@ function viteLegacyPlugin(options = {}) {
649
657
  };
650
658
  return [legacyConfigPlugin, legacyGenerateBundlePlugin, legacyPostPlugin];
651
659
  }
652
- async function detectPolyfills(code, targets, list) {
660
+ async function detectPolyfills(code, targets, assumptions, list) {
653
661
  const babel2 = await loadBabel();
654
662
  const result = babel2.transform(code, {
655
663
  ast: true,
656
664
  babelrc: false,
657
665
  configFile: false,
658
666
  compact: false,
667
+ assumptions,
659
668
  presets: [
660
669
  [
661
670
  (await import('@babel/preset-env')).default,
@@ -712,7 +721,8 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
712
721
  output: {
713
722
  format,
714
723
  hashCharacters: rollupOutputOptions.hashCharacters,
715
- entryFileNames: rollupOutputOptions.entryFileNames
724
+ entryFileNames: rollupOutputOptions.entryFileNames,
725
+ sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl
716
726
  }
717
727
  }
718
728
  },
package/dist/index.d.cts CHANGED
@@ -31,10 +31,17 @@ interface Options {
31
31
  * default: true
32
32
  */
33
33
  renderModernChunks?: boolean;
34
+ /**
35
+ * @see https://babeljs.io/docs/assumptions
36
+ *
37
+ * default: {}
38
+ */
39
+ assumptions?: Record<string, boolean>;
34
40
  }
35
41
 
36
42
  declare function viteLegacyPlugin(options?: Options): Plugin[];
37
- declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
43
+ declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
38
44
  declare const cspHashes: string[];
39
45
 
40
- export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
46
+ export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
47
+ export type { Options };
package/dist/index.d.mts CHANGED
@@ -31,10 +31,17 @@ interface Options {
31
31
  * default: true
32
32
  */
33
33
  renderModernChunks?: boolean;
34
+ /**
35
+ * @see https://babeljs.io/docs/assumptions
36
+ *
37
+ * default: {}
38
+ */
39
+ assumptions?: Record<string, boolean>;
34
40
  }
35
41
 
36
42
  declare function viteLegacyPlugin(options?: Options): Plugin[];
37
- declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
43
+ declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
38
44
  declare const cspHashes: string[];
39
45
 
40
- export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
46
+ export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
47
+ export type { Options };
package/dist/index.d.ts CHANGED
@@ -31,10 +31,17 @@ interface Options {
31
31
  * default: true
32
32
  */
33
33
  renderModernChunks?: boolean;
34
+ /**
35
+ * @see https://babeljs.io/docs/assumptions
36
+ *
37
+ * default: {}
38
+ */
39
+ assumptions?: Record<string, boolean>;
34
40
  }
35
41
 
36
42
  declare function viteLegacyPlugin(options?: Options): Plugin[];
37
- declare function detectPolyfills(code: string, targets: any, list: Set<string>): Promise<void>;
43
+ declare function detectPolyfills(code: string, targets: any, assumptions: Record<string, boolean>, list: Set<string>): Promise<void>;
38
44
  declare const cspHashes: string[];
39
45
 
40
- export { type Options, cspHashes, viteLegacyPlugin as default, detectPolyfills };
46
+ export { cspHashes, viteLegacyPlugin as default, detectPolyfills };
47
+ export type { Options };
package/dist/index.mjs CHANGED
@@ -152,7 +152,7 @@ function joinUrlSegments(a, b) {
152
152
  if (!a || !b) {
153
153
  return a || b || "";
154
154
  }
155
- if (a[a.length - 1] === "/") {
155
+ if (a.endsWith("/")) {
156
156
  a = a.substring(0, a.length - 1);
157
157
  }
158
158
  if (b[0] !== "/") {
@@ -197,6 +197,7 @@ function viteLegacyPlugin(options = {}) {
197
197
  }
198
198
  const debugFlags = (process.env.DEBUG || "").split(",");
199
199
  const isDebug = debugFlags.includes("vite:*") || debugFlags.includes("vite:legacy");
200
+ const assumptions = options.assumptions || {};
200
201
  const facadeToLegacyChunkMap = /* @__PURE__ */ new Map();
201
202
  const facadeToLegacyPolyfillMap = /* @__PURE__ */ new Map();
202
203
  const facadeToModernPolyfillMap = /* @__PURE__ */ new Map();
@@ -333,6 +334,7 @@ function viteLegacyPlugin(options = {}) {
333
334
  await detectPolyfills(
334
335
  `Promise.resolve(); Promise.all();`,
335
336
  targets,
337
+ assumptions,
336
338
  legacyPolyfills
337
339
  );
338
340
  }
@@ -442,7 +444,12 @@ function viteLegacyPlugin(options = {}) {
442
444
  }
443
445
  if (!isLegacyChunk(chunk, opts)) {
444
446
  if (options.modernPolyfills && !Array.isArray(options.modernPolyfills) && genModern) {
445
- await detectPolyfills(raw, modernTargets, polyfillsDiscovered.modern);
447
+ await detectPolyfills(
448
+ raw,
449
+ modernTargets,
450
+ assumptions,
451
+ polyfillsDiscovered.modern
452
+ );
446
453
  }
447
454
  const ms = new MagicString(raw);
448
455
  if (genLegacy && chunk.isEntry) {
@@ -484,6 +491,7 @@ function viteLegacyPlugin(options = {}) {
484
491
  compact: !!config.build.minify,
485
492
  sourceMaps,
486
493
  inputSourceMap: void 0,
494
+ assumptions,
487
495
  presets: [
488
496
  // forcing our plugin to run before preset-env by wrapping it in a
489
497
  // preset so we can catch the injected import statements...
@@ -637,13 +645,14 @@ function viteLegacyPlugin(options = {}) {
637
645
  };
638
646
  return [legacyConfigPlugin, legacyGenerateBundlePlugin, legacyPostPlugin];
639
647
  }
640
- async function detectPolyfills(code, targets, list) {
648
+ async function detectPolyfills(code, targets, assumptions, list) {
641
649
  const babel2 = await loadBabel();
642
650
  const result = babel2.transform(code, {
643
651
  ast: true,
644
652
  babelrc: false,
645
653
  configFile: false,
646
654
  compact: false,
655
+ assumptions,
647
656
  presets: [
648
657
  [
649
658
  (await import('@babel/preset-env')).default,
@@ -700,7 +709,8 @@ async function buildPolyfillChunk(mode, imports, bundle, facadeToChunkMap, build
700
709
  output: {
701
710
  format,
702
711
  hashCharacters: rollupOutputOptions.hashCharacters,
703
- entryFileNames: rollupOutputOptions.entryFileNames
712
+ entryFileNames: rollupOutputOptions.entryFileNames,
713
+ sourcemapBaseUrl: rollupOutputOptions.sourcemapBaseUrl
704
714
  }
705
715
  }
706
716
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "6.0.2",
3
+ "version": "6.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -36,11 +36,11 @@
36
36
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
37
37
  "funding": "https://github.com/vitejs/vite?sponsor=1",
38
38
  "dependencies": {
39
- "@babel/core": "^7.26.9",
39
+ "@babel/core": "^7.26.10",
40
40
  "@babel/preset-env": "^7.26.9",
41
41
  "browserslist": "^4.24.4",
42
42
  "browserslist-to-esbuild": "^2.1.1",
43
- "core-js": "^3.40.0",
43
+ "core-js": "^3.41.0",
44
44
  "magic-string": "^0.30.17",
45
45
  "regenerator-runtime": "^0.14.1",
46
46
  "systemjs": "^6.15.1"
@@ -50,10 +50,10 @@
50
50
  "vite": "^6.0.0"
51
51
  },
52
52
  "devDependencies": {
53
- "acorn": "^8.14.0",
53
+ "acorn": "^8.14.1",
54
54
  "picocolors": "^1.1.1",
55
- "unbuild": "^3.3.1",
56
- "vite": "6.2.0"
55
+ "unbuild": "3.4.2",
56
+ "vite": "6.3.3"
57
57
  },
58
58
  "scripts": {
59
59
  "dev": "unbuild --stub",