@vitejs/plugin-legacy 8.0.0-beta.0 → 8.0.0-beta.2

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -37
  2. package/package.json +21 -10
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { build, normalizePath } from "vite";
6
6
  import MagicString from "magic-string";
7
7
  import browserslist from "browserslist";
8
8
 
9
- //#region rolldown:runtime
9
+ //#region \0rolldown/runtime.js
10
10
  var __create = Object.create;
11
11
  var __defProp = Object.defineProperty;
12
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -151,7 +151,7 @@ function joinUrlSegments(a, b) {
151
151
  }
152
152
  function toAssetPathFromHtml(filename, htmlPath, config) {
153
153
  const relativeUrlPath = normalizePath(path.relative(config.root, htmlPath));
154
- const toRelative = (filename$1, _hostId) => getBaseInHTML(relativeUrlPath, config) + filename$1;
154
+ const toRelative = (filename, _hostId) => getBaseInHTML(relativeUrlPath, config) + filename;
155
155
  return toOutputFilePathInHtml(filename, "asset", htmlPath, "html", config, toRelative);
156
156
  }
157
157
  const legacyEnvVarMarker = `__VITE_IS_LEGACY__`;
@@ -202,26 +202,26 @@ function viteLegacyPlugin(options = {}) {
202
202
  return [
203
203
  {
204
204
  name: "vite:legacy-config",
205
- async config(config$1, env$1) {
206
- if (env$1.command === "build" && !config$1.build?.ssr) {
207
- if (!config$1.build) config$1.build = {};
208
- if (genLegacy && !config$1.build.cssTarget) config$1.build.cssTarget = "chrome61";
205
+ async config(config, env) {
206
+ if (env.command === "build" && !config.build?.ssr) {
207
+ if (!config.build) config.build = {};
208
+ if (genLegacy && !config.build.cssTarget) config.build.cssTarget = "chrome61";
209
209
  if (genLegacy) {
210
- overriddenBuildTarget = config$1.build.target !== void 0;
210
+ overriddenBuildTarget = config.build.target !== void 0;
211
211
  overriddenDefaultModernTargets = options.modernTargets !== void 0;
212
- } else overriddenBuildTargetOnlyModern = config$1.build.target !== void 0;
212
+ } else overriddenBuildTargetOnlyModern = config.build.target !== void 0;
213
213
  if (options.modernTargets) {
214
214
  const { default: browserslistToEsbuild } = await import("browserslist-to-esbuild");
215
- config$1.build.target = browserslistToEsbuild(options.modernTargets);
216
- } else config$1.build.target = modernTargetsEsbuild;
215
+ config.build.target = browserslistToEsbuild(options.modernTargets);
216
+ } else config.build.target = modernTargetsEsbuild;
217
217
  }
218
- return { define: { "import.meta.env.LEGACY": env$1.command === "serve" || config$1.build?.ssr ? false : legacyEnvVarMarker } };
218
+ return { define: { "import.meta.env.LEGACY": env.command === "serve" || config.build?.ssr ? false : legacyEnvVarMarker } };
219
219
  },
220
- configResolved(config$1) {
221
- if (overriddenBuildTarget) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`));
222
- if (overriddenBuildTargetOnlyModern) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'modernTargets' as an option to this plugin with the list of browsers to support instead.`));
223
- if (overriddenDefaultModernTargets) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy 'modernTargets' option overrode the builtin targets of modern chunks. Some versions of browsers between legacy and modern may not be supported.`));
224
- if (config$1.isWorker) config$1.logger.warn(import_picocolors.default.yellow(`plugin-legacy should not be passed to 'worker.plugins'. Pass to 'plugins' instead. Note that generating legacy chunks for workers are not supported by plugin-legacy.`));
220
+ configResolved(config) {
221
+ if (overriddenBuildTarget) config.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'targets' as an option to this plugin with the list of legacy browsers to support instead.`));
222
+ if (overriddenBuildTargetOnlyModern) config.logger.warn(import_picocolors.default.yellow(`plugin-legacy overrode 'build.target'. You should pass 'modernTargets' as an option to this plugin with the list of browsers to support instead.`));
223
+ if (overriddenDefaultModernTargets) config.logger.warn(import_picocolors.default.yellow(`plugin-legacy 'modernTargets' option overrode the builtin targets of modern chunks. Some versions of browsers between legacy and modern may not be supported.`));
224
+ if (config.isWorker) config.logger.warn(import_picocolors.default.yellow(`plugin-legacy should not be passed to 'worker.plugins'. Pass to 'plugins' instead. Note that generating legacy chunks for workers are not supported by plugin-legacy.`));
225
225
  }
226
226
  },
227
227
  {
@@ -232,14 +232,14 @@ function viteLegacyPlugin(options = {}) {
232
232
  const chunkFileNameToPolyfills = outputToChunkFileNameToPolyfills.get(opts);
233
233
  if (chunkFileNameToPolyfills == null) throw new Error("Internal @vitejs/plugin-legacy error: discovered polyfills should exist");
234
234
  if (!isLegacyBundle(bundle)) {
235
- for (const { modern } of chunkFileNameToPolyfills.values()) modern.forEach((p$1) => modernPolyfills.add(p$1));
235
+ for (const { modern } of chunkFileNameToPolyfills.values()) modern.forEach((p) => modernPolyfills.add(p));
236
236
  if (!modernPolyfills.size) return;
237
237
  if (isDebug) console.log(`[@vitejs/plugin-legacy] modern polyfills:`, modernPolyfills);
238
238
  await buildPolyfillChunk(this, config.mode, modernPolyfills, bundle, facadeToModernPolyfillMap, config.build, "es", opts, true, genLegacy);
239
239
  return;
240
240
  }
241
241
  if (!genLegacy) return;
242
- for (const { legacy } of chunkFileNameToPolyfills.values()) legacy.forEach((p$1) => legacyPolyfills.add(p$1));
242
+ for (const { legacy } of chunkFileNameToPolyfills.values()) legacy.forEach((p) => legacyPolyfills.add(p));
243
243
  if (options.polyfills !== false) await detectPolyfills(`Promise.resolve(); Promise.all();`, targets, assumptions, legacyPolyfills);
244
244
  if (legacyPolyfills.size || !options.externalSystemJS) {
245
245
  if (isDebug) console.log(`[@vitejs/plugin-legacy] legacy polyfills:`, legacyPolyfills);
@@ -271,12 +271,12 @@ function viteLegacyPlugin(options = {}) {
271
271
  return fileName;
272
272
  };
273
273
  };
274
- const createLegacyOutput = (options$1 = {}) => {
274
+ const createLegacyOutput = (options = {}) => {
275
275
  return {
276
- ...options$1,
276
+ ...options,
277
277
  format: "esm",
278
- entryFileNames: getLegacyOutputFileName(options$1.entryFileNames),
279
- chunkFileNames: getLegacyOutputFileName(options$1.chunkFileNames),
278
+ entryFileNames: getLegacyOutputFileName(options.entryFileNames),
279
+ chunkFileNames: getLegacyOutputFileName(options.chunkFileNames),
280
280
  minify: false
281
281
  };
282
282
  };
@@ -318,8 +318,8 @@ function viteLegacyPlugin(options = {}) {
318
318
  outputOptionsForLegacyChunks.add(opts);
319
319
  const needPolyfills = options.polyfills !== false && !Array.isArray(options.polyfills);
320
320
  const sourceMaps = !!config.build.sourcemap;
321
- const babel$1 = await loadBabel();
322
- const resultSystem = babel$1.transform(raw, {
321
+ const babel = await loadBabel();
322
+ const resultSystem = babel.transform(raw, {
323
323
  babelrc: false,
324
324
  configFile: false,
325
325
  ast: true,
@@ -353,8 +353,8 @@ function viteLegacyPlugin(options = {}) {
353
353
  }]]
354
354
  };
355
355
  let result;
356
- if (resultSystem) result = babel$1.transformFromAstSync(resultSystem.ast, void 0, babelTransformOptions);
357
- else result = babel$1.transform(raw, babelTransformOptions);
356
+ if (resultSystem) result = babel.transformFromAstSync(resultSystem.ast, void 0, babelTransformOptions);
357
+ else result = babel.transform(raw, babelTransformOptions);
358
358
  if (result) return {
359
359
  code: result.code,
360
360
  map: result.map
@@ -502,9 +502,16 @@ async function buildPolyfillChunk(ctx, mode, imports, bundle, facadeToChunkMap,
502
502
  if (chunk.type === "chunk" && chunk.facadeModuleId) facadeToChunkMap.set(chunk.facadeModuleId, polyfillChunk.fileName);
503
503
  }
504
504
  ctx.emitFile({
505
- type: "asset",
505
+ type: "prebuilt-chunk",
506
+ name: polyfillChunk.name,
506
507
  fileName: polyfillChunk.fileName,
507
- source: polyfillChunk.code
508
+ code: polyfillChunk.code,
509
+ facadeModuleId: polyfillChunk.facadeModuleId ?? void 0,
510
+ isEntry: polyfillChunk.isEntry,
511
+ isDynamicEntry: polyfillChunk.isDynamicEntry,
512
+ exports: [],
513
+ map: polyfillChunk.map ?? void 0,
514
+ sourcemapFileName: polyfillChunk.sourcemapFileName ?? void 0
508
515
  });
509
516
  if (polyfillChunk.sourcemapFileName) {
510
517
  const polyfillChunkMapAsset = _polyfillChunk.output.find((chunk) => chunk.type === "asset" && chunk.fileName === polyfillChunk.sourcemapFileName);
@@ -555,11 +562,11 @@ function isLegacyBundle(bundle) {
555
562
  function recordAndRemovePolyfillBabelPlugin(polyfills) {
556
563
  return ({ types: t }) => ({
557
564
  name: "vite-remove-polyfill-import",
558
- post({ path: path$1 }) {
559
- path$1.get("body").forEach((p$1) => {
560
- if (t.isImportDeclaration(p$1.node)) {
561
- polyfills.add(p$1.node.source.value);
562
- p$1.remove();
565
+ post({ path }) {
566
+ path.get("body").forEach((p) => {
567
+ if (t.isImportDeclaration(p.node)) {
568
+ polyfills.add(p.node.source.value);
569
+ p.remove();
563
570
  }
564
571
  });
565
572
  }
@@ -568,8 +575,8 @@ function recordAndRemovePolyfillBabelPlugin(polyfills) {
568
575
  function replaceLegacyEnvBabelPlugin() {
569
576
  return ({ types: t }) => ({
570
577
  name: "vite-replace-env-legacy",
571
- visitor: { Identifier(path$1) {
572
- if (path$1.node.name === legacyEnvVarMarker) path$1.replaceWith(t.booleanLiteral(true));
578
+ visitor: { Identifier(path) {
579
+ if (path.node.name === legacyEnvVarMarker) path.replaceWith(t.booleanLiteral(true));
573
580
  } }
574
581
  });
575
582
  }
@@ -578,10 +585,10 @@ function wrapIIFEBabelPlugin() {
578
585
  const buildIIFE = template(";(function(){%%body%%})();");
579
586
  return {
580
587
  name: "vite-wrap-iife",
581
- post({ path: path$1 }) {
588
+ post({ path }) {
582
589
  if (!this.isWrapped) {
583
590
  this.isWrapped = true;
584
- path$1.replaceWith(t.program(buildIIFE({ body: path$1.node.body })));
591
+ path.replaceWith(t.program(buildIIFE({ body: path.node.body })));
585
592
  }
586
593
  }
587
594
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-legacy",
3
- "version": "8.0.0-beta.0",
3
+ "version": "8.0.0-beta.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -28,15 +28,15 @@
28
28
  "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
29
29
  "funding": "https://github.com/vitejs/vite?sponsor=1",
30
30
  "dependencies": {
31
- "@babel/core": "^7.28.5",
31
+ "@babel/core": "^7.29.0",
32
32
  "@babel/plugin-transform-dynamic-import": "^7.27.1",
33
- "@babel/plugin-transform-modules-systemjs": "^7.28.5",
34
- "@babel/preset-env": "^7.28.5",
35
- "babel-plugin-polyfill-corejs3": "^0.13.0",
36
- "babel-plugin-polyfill-regenerator": "^0.6.5",
37
- "browserslist": "^4.28.0",
33
+ "@babel/plugin-transform-modules-systemjs": "^7.29.0",
34
+ "@babel/preset-env": "^7.29.0",
35
+ "babel-plugin-polyfill-corejs3": "^0.14.0",
36
+ "babel-plugin-polyfill-regenerator": "^0.6.6",
37
+ "browserslist": "^4.28.1",
38
38
  "browserslist-to-esbuild": "^2.1.1",
39
- "core-js": "^3.47.0",
39
+ "core-js": "^3.48.0",
40
40
  "magic-string": "^0.30.21",
41
41
  "regenerator-runtime": "^0.14.1",
42
42
  "systemjs": "^6.15.1"
@@ -48,8 +48,19 @@
48
48
  "devDependencies": {
49
49
  "acorn": "^8.15.0",
50
50
  "picocolors": "^1.1.1",
51
- "tsdown": "^0.16.8",
52
- "vite": "8.0.0-beta.0"
51
+ "tsdown": "^0.20.1",
52
+ "vite": "8.0.0-beta.12"
53
+ },
54
+ "compatiblePackages": {
55
+ "schemaVersion": 1,
56
+ "rolldown": {
57
+ "type": "incompatible",
58
+ "reason": "Only supports Vite"
59
+ },
60
+ "rollup": {
61
+ "type": "incompatible",
62
+ "reason": "Only supports Vite"
63
+ }
53
64
  },
54
65
  "scripts": {
55
66
  "dev": "tsdown --watch",