vite 6.0.0-alpha.1 → 6.0.0-alpha.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.
@@ -1,4 +1,4 @@
1
- import { G as getDefaultExportFromCjs } from './dep-gq9_cnPm.js';
1
+ import { G as getDefaultExportFromCjs } from './dep-E4cF1RpV.js';
2
2
  import require$$0 from 'path';
3
3
  import require$$0__default from 'fs';
4
4
  import { l as lib } from './dep-IQS-Za7F.js';
@@ -1,4 +1,4 @@
1
- import { H as commonjsGlobal, G as getDefaultExportFromCjs } from './dep-gq9_cnPm.js';
1
+ import { H as commonjsGlobal, G as getDefaultExportFromCjs } from './dep-E4cF1RpV.js';
2
2
  import require$$0__default from 'fs';
3
3
  import require$$0 from 'postcss';
4
4
  import require$$0$1 from 'path';
@@ -59587,8 +59587,13 @@ function definePlugin(config) {
59587
59587
  userDefineEnv[key.slice(16)] = config.define[key];
59588
59588
  }
59589
59589
  }
59590
- function generatePattern(ssr) {
59591
- const replaceProcessEnv = !ssr || config.ssr?.target === 'webworker';
59590
+ function generatePattern(environment) {
59591
+ // This is equivalent to the old `!ssr || config.ssr?.target === 'webworker'`
59592
+ // TODO: We shouldn't keep options.nodeCompatible and options.webCompatible
59593
+ // This is a place where using `!options.nodeCompatible` fails and it is confusing why
59594
+ // Do we need a per-environment replaceProcessEnv option?
59595
+ // Is it useful to have define be configured per-environment?
59596
+ const replaceProcessEnv = environment.options.webCompatible;
59592
59597
  const define = {
59593
59598
  ...(replaceProcessEnv ? processEnv : {}),
59594
59599
  ...importMetaKeys,
@@ -59596,6 +59601,10 @@ function definePlugin(config) {
59596
59601
  ...importMetaFallbackKeys,
59597
59602
  };
59598
59603
  // Additional define fixes based on `ssr` value
59604
+ // Backward compatibility. Any non client environment will get import.meta.env.SSR = true
59605
+ // TODO: Check if we should only do this for the SSR environment and how to abstract
59606
+ // maybe we need import.meta.env.environmentName ?
59607
+ const ssr = environment.name !== 'client';
59599
59608
  if ('import.meta.env.SSR' in define) {
59600
59609
  define['import.meta.env.SSR'] = ssr + '';
59601
59610
  }
@@ -59619,13 +59628,23 @@ function definePlugin(config) {
59619
59628
  : null;
59620
59629
  return [define, pattern];
59621
59630
  }
59622
- const defaultPattern = generatePattern(false);
59623
- const ssrPattern = generatePattern(true);
59631
+ const patternsCache = new WeakMap();
59632
+ function getPattern(environment) {
59633
+ let pattern = patternsCache.get(environment);
59634
+ if (!pattern) {
59635
+ pattern = generatePattern(environment);
59636
+ patternsCache.set(environment, pattern);
59637
+ }
59638
+ return pattern;
59639
+ }
59624
59640
  return {
59625
59641
  name: 'vite:define',
59626
- async transform(code, id, options) {
59627
- const ssr = options?.ssr === true;
59628
- if (!ssr && !isBuild) {
59642
+ async transform(code, id) {
59643
+ const { environment } = this;
59644
+ if (!environment) {
59645
+ return;
59646
+ }
59647
+ if (environment.name === 'client' && !isBuild) {
59629
59648
  // for dev we inject actual global defines in the vite client to
59630
59649
  // avoid the transform cost. see the `clientInjection` and
59631
59650
  // `importAnalysis` plugin.
@@ -59639,7 +59658,7 @@ function definePlugin(config) {
59639
59658
  config.assetsInclude(id)) {
59640
59659
  return;
59641
59660
  }
59642
- const [define, pattern] = ssr ? ssrPattern : defaultPattern;
59661
+ const [define, pattern] = getPattern(environment);
59643
59662
  if (!pattern)
59644
59663
  return;
59645
59664
  // Check if our code needs any replacements before running esbuild
@@ -60144,7 +60163,7 @@ function preAliasPlugin(config) {
60144
60163
  },
60145
60164
  };
60146
60165
  }
60147
- // TODO: ?
60166
+ // TODO: environment?
60148
60167
  function optimizeAliasReplacementForSSR(id, optimizeDeps) {
60149
60168
  if (optimizeDeps.include?.includes(id)) {
60150
60169
  return true;
@@ -61124,9 +61143,12 @@ function workerImportMetaUrlPlugin(config) {
61124
61143
  return true;
61125
61144
  }
61126
61145
  },
61127
- async transform(code, id, options) {
61146
+ async transform(code, id) {
61128
61147
  const { environment } = this;
61129
- if (environment && !options?.ssr && isIncludeWorkerImportMetaUrl(code)) {
61148
+ // TODO: environment, same as with assetImportMetaUrlPlugin
61149
+ if (environment &&
61150
+ environment.name === 'client' &&
61151
+ isIncludeWorkerImportMetaUrl(code)) {
61130
61152
  let s;
61131
61153
  const cleanString = stripLiteral(code);
61132
61154
  const workerImportMetaUrlRE = /\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
@@ -61212,7 +61234,8 @@ function assetImportMetaUrlPlugin(config) {
61212
61234
  async transform(code, id, options) {
61213
61235
  const { environment } = this;
61214
61236
  if (environment &&
61215
- !options?.ssr &&
61237
+ // TODO: Should this be done only for the client or for any webCompatible environment?
61238
+ environment.name === 'client' &&
61216
61239
  id !== preloadHelperId &&
61217
61240
  id !== CLIENT_ENTRY &&
61218
61241
  code.includes('new URL') &&
@@ -64139,8 +64162,7 @@ async function prepareEsbuildOptimizerRun(environment, depsInfo, processingCache
64139
64162
  const define = {
64140
64163
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || config.mode),
64141
64164
  };
64142
- const ssr = environment.name !== 'client'; // TODO:depsOptimizer
64143
- const platform = ssr && config.ssr?.target !== 'webworker' ? 'node' : 'browser';
64165
+ const platform = environment.options.webCompatible ? 'browser' : 'node';
64144
64166
  const external = [...(optimizeDeps?.exclude ?? [])];
64145
64167
  const plugins = [...pluginsFromConfig];
64146
64168
  if (external.length) {
@@ -65728,7 +65750,7 @@ function cssPostPlugin(config) {
65728
65750
  if (isDirectCSSRequest(id)) {
65729
65751
  return null;
65730
65752
  }
65731
- // server only
65753
+ // server only, TODO: environment
65732
65754
  if (options?.ssr) {
65733
65755
  return modulesCode || `export default ${JSON.stringify(css)}`;
65734
65756
  }
@@ -66405,8 +66427,8 @@ function createCachedImport(imp) {
66405
66427
  return cached;
66406
66428
  };
66407
66429
  }
66408
- const importPostcssImport = createCachedImport(() => import('./dep-DPzWXNBe.js').then(function (n) { return n.i; }));
66409
- const importPostcssModules = createCachedImport(() => import('./dep-BD8Vf02W.js').then(function (n) { return n.i; }));
66430
+ const importPostcssImport = createCachedImport(() => import('./dep-DK04Q0H9.js').then(function (n) { return n.i; }));
66431
+ const importPostcssModules = createCachedImport(() => import('./dep-DKZVy3_n.js').then(function (n) { return n.i; }));
66410
66432
  const importPostcss = createCachedImport(() => import('postcss'));
66411
66433
  const preprocessorWorkerControllerCache = new WeakMap();
66412
66434
  let alwaysFakeWorkerWorkerControllerCache;
@@ -68209,17 +68231,8 @@ async function buildEnvironment(config, environment, libOptions = false) {
68209
68231
  config.logger.warnOnce(colors$1.yellow(`Vite does not support "rollupOptions.output.sourcemap". ` +
68210
68232
  `Please use "build.sourcemap" instead.`));
68211
68233
  }
68212
- /**
68213
- * TODO:
68214
- * if (ssr.target === 'webworker') {
68215
- * build.rollupOptions.entryFileNames = '[name].js'
68216
- * build.rollupOptions.inlineDynamicImports = (typeof input === 'string' || Object.keys(input).length === 1))
68217
- * }
68218
- */
68219
- const ssrNodeBuild = ssr && config.ssr.target === 'node';
68220
- const ssrWorkerBuild = ssr && config.ssr.target === 'webworker';
68221
68234
  const format = output.format || 'es';
68222
- const jsExt = ssrNodeBuild || libOptions
68235
+ const jsExt = !environment.options.webCompatible || libOptions
68223
68236
  ? resolveOutputJsExtension(format, findNearestPackageData(config.root, config.packageCache)?.data
68224
68237
  .type)
68225
68238
  : 'js';
@@ -68248,7 +68261,11 @@ async function buildEnvironment(config, environment, libOptions = false) {
68248
68261
  : path$o.posix.join(options.assetsDir, `[name]-[hash].[ext]`),
68249
68262
  inlineDynamicImports: output.format === 'umd' ||
68250
68263
  output.format === 'iife' ||
68251
- (ssrWorkerBuild &&
68264
+ // TODO: We need an abstraction for non-client environments?
68265
+ // We should remove the explicit 'client' hcek here.
68266
+ // Or maybe `inlineDynamicImports` should be an environment option?
68267
+ (environment.name !== 'client' &&
68268
+ environment.options.webCompatible &&
68252
68269
  (typeof input === 'string' || Object.keys(input).length === 1)),
68253
68270
  ...output,
68254
68271
  };
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { E as colors, x as createLogger, r as resolveConfig, F as Environment } from './chunks/dep-gq9_cnPm.js';
5
+ import { E as colors, x as createLogger, r as resolveConfig, F as Environment } from './chunks/dep-E4cF1RpV.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:fs/promises';
8
8
  import 'node:url';
@@ -766,7 +766,7 @@ cli
766
766
  filterDuplicateOptions(options);
767
767
  // output structure is preserved even after bundling so require()
768
768
  // is ok here
769
- const { createServer } = await import('./chunks/dep-gq9_cnPm.js').then(function (n) { return n.I; });
769
+ const { createServer } = await import('./chunks/dep-E4cF1RpV.js').then(function (n) { return n.I; });
770
770
  try {
771
771
  const server = await createServer({
772
772
  root,
@@ -847,7 +847,7 @@ cli
847
847
  .option('--all', `[boolean] build all environments`)
848
848
  .action(async (root, options) => {
849
849
  filterDuplicateOptions(options);
850
- const { build, createViteBuilder } = await import('./chunks/dep-gq9_cnPm.js').then(function (n) { return n.K; });
850
+ const { build, createViteBuilder } = await import('./chunks/dep-E4cF1RpV.js').then(function (n) { return n.K; });
851
851
  const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
852
852
  const config = {
853
853
  root,
@@ -891,7 +891,7 @@ cli
891
891
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
892
892
  .action(async (root, options) => {
893
893
  filterDuplicateOptions(options);
894
- const { optimizeDeps } = await import('./chunks/dep-gq9_cnPm.js').then(function (n) { return n.J; });
894
+ const { optimizeDeps } = await import('./chunks/dep-E4cF1RpV.js').then(function (n) { return n.J; });
895
895
  try {
896
896
  const config = await resolveConfig({
897
897
  root,
@@ -918,7 +918,7 @@ cli
918
918
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
919
919
  .action(async (root, options) => {
920
920
  filterDuplicateOptions(options);
921
- const { preview } = await import('./chunks/dep-gq9_cnPm.js').then(function (n) { return n.L; });
921
+ const { preview } = await import('./chunks/dep-E4cF1RpV.js').then(function (n) { return n.L; });
922
922
  try {
923
923
  const server = await preview({
924
924
  root,
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-gq9_cnPm.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, b as build, h as buildErrorMessage, u as createFilter, x as createLogger, j as createNodeDevEnvironment, c as createServer, e as createViteBuilder, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, g as preprocessCSS, p as preview, r as resolveConfig, C as resolveEnvPrefix, v as rollupVersion, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-gq9_cnPm.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-E4cF1RpV.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, b as build, h as buildErrorMessage, u as createFilter, x as createLogger, j as createNodeDevEnvironment, c as createServer, e as createViteBuilder, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, g as preprocessCSS, p as preview, r as resolveConfig, C as resolveEnvPrefix, v as rollupVersion, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-E4cF1RpV.js';
4
4
  import { existsSync, readFileSync } from 'node:fs';
5
5
  import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
6
6
  export { VERSION as version } from './constants.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.0.0-alpha.1",
3
+ "version": "6.0.0-alpha.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",