vite 6.0.0-alpha.4 → 6.0.0-alpha.6

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.
@@ -15158,6 +15158,34 @@ function terserPlugin(config) {
15158
15158
  };
15159
15159
  }
15160
15160
 
15161
+ async function resolveBoundedPlugins(environment) {
15162
+ const resolvedPlugins = [];
15163
+ for (const plugin of environment.config.plugins) {
15164
+ if (plugin.create) {
15165
+ const boundedPlugin = await plugin.create(environment);
15166
+ if (boundedPlugin) {
15167
+ const flatPlugins = await asyncFlattenBoundedPlugin(environment, boundedPlugin);
15168
+ resolvedPlugins.push(...flatPlugins);
15169
+ }
15170
+ }
15171
+ else {
15172
+ resolvedPlugins.push(plugin);
15173
+ }
15174
+ }
15175
+ return resolvedPlugins;
15176
+ }
15177
+ async function asyncFlattenBoundedPlugin(environment, plugins) {
15178
+ if (!Array.isArray(plugins)) {
15179
+ plugins = [plugins];
15180
+ }
15181
+ do {
15182
+ plugins = (await Promise.all(plugins.map((p) => (p && p.split ? p.split(environment) : p))))
15183
+ .flat(Infinity)
15184
+ .filter(Boolean);
15185
+ } while (plugins.some((v) => v?.then || v?.split));
15186
+ return plugins;
15187
+ }
15188
+
15161
15189
  const mimes = {
15162
15190
  "3g2": "video/3gpp2",
15163
15191
  "3gp": "video/3gpp",
@@ -36429,34 +36457,6 @@ function esbuildCjsExternalPlugin(externals, platform) {
36429
36457
  };
36430
36458
  }
36431
36459
 
36432
- async function resolveBoundedPlugins(environment) {
36433
- const resolvedPlugins = [];
36434
- for (const plugin of environment.config.plugins) {
36435
- if (plugin.create) {
36436
- const boundedPlugin = await plugin.create(environment);
36437
- if (boundedPlugin) {
36438
- const flatPlugins = await asyncFlattenBoundedPlugin(environment, boundedPlugin);
36439
- resolvedPlugins.push(...flatPlugins);
36440
- }
36441
- }
36442
- else {
36443
- resolvedPlugins.push(plugin);
36444
- }
36445
- }
36446
- return resolvedPlugins;
36447
- }
36448
- async function asyncFlattenBoundedPlugin(environment, plugins) {
36449
- if (!Array.isArray(plugins)) {
36450
- plugins = [plugins];
36451
- }
36452
- do {
36453
- plugins = (await Promise.all(plugins.map((p) => (p && p.split ? p.split(environment) : p))))
36454
- .flat(Infinity)
36455
- .filter(Boolean);
36456
- } while (plugins.some((v) => v?.then || v?.split));
36457
- return plugins;
36458
- }
36459
-
36460
36460
  // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
36461
36461
  // License: MIT.
36462
36462
  var HashbangComment, Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
@@ -68015,8 +68015,8 @@ async function build(inlineConfig = {}) {
68015
68015
  return builder.build(environment);
68016
68016
  }
68017
68017
  }
68018
- function resolveConfigToBuild(inlineConfig = {}, patchConfig) {
68019
- return resolveConfig(inlineConfig, 'build', 'production', 'production', false, patchConfig);
68018
+ function resolveConfigToBuild(inlineConfig = {}, patchConfig, patchPlugins) {
68019
+ return resolveConfig(inlineConfig, 'build', 'production', 'production', false, patchConfig, patchPlugins);
68020
68020
  }
68021
68021
  /**
68022
68022
  * Build an App environment, or a App library (if librayOptions is provided)
@@ -68056,9 +68056,8 @@ async function buildEnvironment(config, environment, libOptions = false) {
68056
68056
  }
68057
68057
  const outDir = resolve(options.outDir);
68058
68058
  // inject environment and ssr arg to plugin load/transform hooks
68059
- const plugins = (environment || ssr
68060
- ? config.plugins.map((p) => injectEnvironmentToHooks(p, environment))
68061
- : config.plugins);
68059
+ // TODO: rework lib mode
68060
+ const plugins = (libOptions ? config : environment).plugins.map((p) => injectEnvironmentToHooks(p, environment));
68062
68061
  const rollupOptions = {
68063
68062
  preserveEntrySignatures: ssr
68064
68063
  ? 'allow-extension'
@@ -68410,9 +68409,7 @@ function wrapEnvironmentLoad(hook, environment) {
68410
68409
  return;
68411
68410
  const fn = getHookHandler(hook);
68412
68411
  const handler = function (id, ...args) {
68413
- return fn.call(injectEnvironmentInContext(this, environment), id,
68414
- // @ts-expect-error: Receiving options param to be future-proof if Rollup adds it
68415
- injectSsrFlag(args[0], environment));
68412
+ return fn.call(injectEnvironmentInContext(this, environment), id, injectSsrFlag(args[0], environment));
68416
68413
  };
68417
68414
  if ('handler' in hook) {
68418
68415
  return {
@@ -68429,9 +68426,7 @@ function wrapEnvironmentTransform(hook, environment) {
68429
68426
  return;
68430
68427
  const fn = getHookHandler(hook);
68431
68428
  const handler = function (code, importer, ...args) {
68432
- return fn.call(injectEnvironmentInContext(this, environment), code, importer,
68433
- // @ts-expect-error: Receiving options param to be future-proof if Rollup adds it
68434
- injectSsrFlag(args[0], environment));
68429
+ return fn.call(injectEnvironmentInContext(this, environment), code, importer, injectSsrFlag(args[0], environment));
68435
68430
  };
68436
68431
  if ('handler' in hook) {
68437
68432
  return {
@@ -68580,6 +68575,13 @@ class BuildEnvironment extends Environment {
68580
68575
  }
68581
68576
  super(name, config, options);
68582
68577
  }
68578
+ async init() {
68579
+ if (this._inited) {
68580
+ return;
68581
+ }
68582
+ this._inited = true;
68583
+ this._plugins = await resolveBoundedPlugins(this);
68584
+ }
68583
68585
  }
68584
68586
  async function defaultBuildApp(builder) {
68585
68587
  for (const environment of Object.values(builder.environments)) {
@@ -68622,8 +68624,14 @@ async function createBuilder(inlineConfig = {}) {
68622
68624
  let environmentConfig = config;
68623
68625
  if (!config.builder.sharedConfigBuild) {
68624
68626
  const patchConfig = (resolved) => {
68627
+ resolved.build = {
68628
+ ...resolved.environments[name].build,
68629
+ lib: false,
68630
+ };
68631
+ };
68632
+ const patchPlugins = (resolvedPlugins) => {
68625
68633
  // Force opt-in shared plugins
68626
- const environmentPlugins = [...resolved.plugins];
68634
+ const environmentPlugins = [...resolvedPlugins];
68627
68635
  let validMixedPlugins = true;
68628
68636
  for (let i = 0; i < environmentPlugins.length; i++) {
68629
68637
  const environmentPlugin = environmentPlugins[i];
@@ -68638,16 +68646,15 @@ async function createBuilder(inlineConfig = {}) {
68638
68646
  }
68639
68647
  }
68640
68648
  if (validMixedPlugins) {
68641
- resolved.plugins = environmentPlugins;
68649
+ for (let i = 0; i < environmentPlugins.length; i++) {
68650
+ resolvedPlugins[i] = environmentPlugins[i];
68651
+ }
68642
68652
  }
68643
- resolved.build = {
68644
- ...resolved.environments[name].build,
68645
- lib: false,
68646
- };
68647
68653
  };
68648
- environmentConfig = await resolveConfigToBuild(inlineConfig, patchConfig);
68654
+ environmentConfig = await resolveConfigToBuild(inlineConfig, patchConfig, patchPlugins);
68649
68655
  }
68650
68656
  const environment = await createEnvironment(name, environmentConfig);
68657
+ await environment.init();
68651
68658
  environments[name] = environment;
68652
68659
  }
68653
68660
  return builder;
@@ -69061,7 +69068,7 @@ function resolveOptimizeDepsConfig(optimizeDeps, preserveSymlinks) {
69061
69068
  disabled: optimizeDeps.disabled,
69062
69069
  };
69063
69070
  }
69064
- async function resolveConfig(inlineConfig, command, defaultMode = 'development', defaultNodeEnv = 'development', isPreview = false, patchConfig = undefined) {
69071
+ async function resolveConfig(inlineConfig, command, defaultMode = 'development', defaultNodeEnv = 'development', isPreview = false, patchConfig = undefined, patchPlugins = undefined) {
69065
69072
  let config = inlineConfig;
69066
69073
  let configFileDependencies = [];
69067
69074
  let mode = inlineConfig.mode || defaultMode;
@@ -69428,9 +69435,16 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development',
69428
69435
  ...config,
69429
69436
  ...resolved,
69430
69437
  };
69431
- resolved.plugins = await resolvePlugins(resolved, prePlugins, normalPlugins, postPlugins);
69432
- // Backward compatibility hook used in builder
69438
+ // Backward compatibility hook, modify the resolved config before it is used
69439
+ // to create inernal plugins. For example, `config.build.ssr`. Once we rework
69440
+ // internal plugins to use environment.options, we can remove the dual
69441
+ // patchConfig/patchPlugins and have a single patchConfig before configResolved
69442
+ // gets called
69433
69443
  patchConfig?.(resolved);
69444
+ const resolvedPlugins = await resolvePlugins(resolved, prePlugins, normalPlugins, postPlugins);
69445
+ // Backward compatibility hook used in builder
69446
+ patchPlugins?.(resolvedPlugins);
69447
+ resolved.plugins = resolvedPlugins;
69434
69448
  Object.assign(resolved, createPluginHookUtils(resolved.plugins));
69435
69449
  // call configResolved hooks
69436
69450
  await Promise.all(resolved
package/dist/node/cli.js CHANGED
@@ -731,7 +731,7 @@ cli
731
731
  filterDuplicateOptions(options);
732
732
  // output structure is preserved even after bundling so require()
733
733
  // is ok here
734
- const { createServer } = await import('./chunks/dep-8UjKy9Ch.js').then(function (n) { return n.C; });
734
+ const { createServer } = await import('./chunks/dep-CM9bEhFZ.js').then(function (n) { return n.C; });
735
735
  try {
736
736
  const server = await createServer({
737
737
  root,
@@ -812,7 +812,7 @@ cli
812
812
  .option('--app', `[boolean] same as builder.entireApp`)
813
813
  .action(async (root, options) => {
814
814
  filterDuplicateOptions(options);
815
- const { createBuilder, buildEnvironment } = await import('./chunks/dep-8UjKy9Ch.js').then(function (n) { return n.E; });
815
+ const { createBuilder, buildEnvironment } = await import('./chunks/dep-CM9bEhFZ.js').then(function (n) { return n.E; });
816
816
  const buildOptions = cleanGlobalCLIOptions(cleanBuilderCLIOptions(options));
817
817
  const config = {
818
818
  root,
@@ -888,7 +888,7 @@ cli
888
888
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
889
889
  .action(async (root, options) => {
890
890
  filterDuplicateOptions(options);
891
- const { preview } = await import('./chunks/dep-8UjKy9Ch.js').then(function (n) { return n.F; });
891
+ const { preview } = await import('./chunks/dep-CM9bEhFZ.js').then(function (n) { return n.F; });
892
892
  try {
893
893
  const server = await preview({
894
894
  root,
@@ -2932,6 +2932,7 @@ declare class BuildEnvironment extends Environment {
2932
2932
  constructor(name: string, config: ResolvedConfig, setup?: {
2933
2933
  options?: EnvironmentOptions;
2934
2934
  });
2935
+ init(): Promise<void>;
2935
2936
  }
2936
2937
  interface ViteBuilder {
2937
2938
  environments: Record<string, BuildEnvironment>;
@@ -3871,7 +3872,7 @@ interface PluginHookUtils {
3871
3872
  getSortedPluginHooks: <K extends keyof Plugin>(hookName: K) => NonNullable<HookHandler<Plugin[K]>>[];
3872
3873
  }
3873
3874
  type ResolveFn = (id: string, importer?: string, aliasOnly?: boolean, ssr?: boolean) => Promise<string | undefined>;
3874
- declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean, patchConfig?: ((config: ResolvedConfig) => void) | undefined): Promise<ResolvedConfig>;
3875
+ declare function resolveConfig(inlineConfig: InlineConfig, command: 'build' | 'serve', defaultMode?: string, defaultNodeEnv?: string, isPreview?: boolean, patchConfig?: ((config: ResolvedConfig) => void) | undefined, patchPlugins?: ((plugins: Plugin[]) => void) | undefined): Promise<ResolvedConfig>;
3875
3876
  declare function sortUserPlugins(plugins: (Plugin | Plugin[])[] | undefined): [Plugin[], Plugin[], Plugin[]];
3876
3877
  declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: string, configRoot?: string, logLevel?: LogLevel, customLogger?: Logger): Promise<{
3877
3878
  path: string;
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-8UjKy9Ch.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, e as createBuilder, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, o as mergeConfig, n as normalizePath, g as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-8UjKy9Ch.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-CM9bEhFZ.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, e as createBuilder, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, o as mergeConfig, n as normalizePath, g as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-CM9bEhFZ.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  export { c as createLogger } from './chunks/dep-C7zR1Rh8.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "6.0.0-alpha.4",
3
+ "version": "6.0.0-alpha.6",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",