vite 6.0.0-beta.2 → 6.0.0-beta.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.
@@ -15,7 +15,7 @@ import * as url from 'node:url';
15
15
  import { URL } from 'node:url';
16
16
  import * as stream from 'node:stream';
17
17
  import { Duplex, DuplexOptions } from 'node:stream';
18
- import { FetchFunctionOptions, FetchResult, ModuleRunner, ModuleRunnerOptions, ModuleRunnerHMRConnection, ModuleRunnerHmr, ModuleEvaluator } from 'vite/module-runner';
18
+ import { FetchFunctionOptions, FetchResult, ModuleRunnerOptions, ModuleRunnerHMRConnection, ModuleRunnerHmr, ModuleEvaluator, ModuleRunner } from 'vite/module-runner';
19
19
  export { FetchFunction, FetchResult } from 'vite/module-runner';
20
20
  import { BuildOptions as esbuild_BuildOptions, TransformOptions as esbuild_TransformOptions, TransformResult as esbuild_TransformResult } from 'esbuild';
21
21
  export { TransformOptions as EsbuildTransformOptions, version as esbuildVersion } from 'esbuild';
@@ -921,8 +921,8 @@ type DepOptimizationOptions = DepOptimizationConfig & {
921
921
  * will crawl those entry points instead.
922
922
  *
923
923
  * If neither of these fit your needs, you can specify custom entries using
924
- * this option - the value should be a fast-glob pattern or array of patterns
925
- * (https://github.com/mrmlnc/fast-glob#basic-syntax) that are relative from
924
+ * this option - the value should be a tinyglobby pattern or array of patterns
925
+ * (https://github.com/SuperchupuDev/tinyglobby) that are relative from
926
926
  * vite project root. This will overwrite default entries inference.
927
927
  */
928
928
  entries?: string | string[];
@@ -1278,7 +1278,20 @@ declare class DevEnvironment extends BaseEnvironment {
1278
1278
  constructor(name: string, config: ResolvedConfig, context: DevEnvironmentContext);
1279
1279
  init(options?: {
1280
1280
  watcher?: FSWatcher;
1281
+ /**
1282
+ * the previous instance used for the environment with the same name
1283
+ *
1284
+ * when using, the consumer should check if it's an instance generated from the same class or factory function
1285
+ */
1286
+ previousInstance?: DevEnvironment;
1281
1287
  }): Promise<void>;
1288
+ /**
1289
+ * When the dev server is restarted, the methods are called in the following order:
1290
+ * - new instance `init`
1291
+ * - previous instance `close`
1292
+ * - new instance `listen`
1293
+ */
1294
+ listen(server: ViteDevServer): Promise<void>;
1282
1295
  fetchModule(id: string, importer?: string, options?: FetchFunctionOptions): Promise<FetchResult>;
1283
1296
  reloadModule(module: EnvironmentModuleNode): Promise<void>;
1284
1297
  transformRequest(url: string): Promise<TransformResult | null>;
@@ -1771,15 +1784,80 @@ interface TerserOptions extends Terser.MinifyOptions {
1771
1784
  maxWorkers?: number;
1772
1785
  }
1773
1786
 
1787
+ interface FsUtils {
1788
+ existsSync: (path: string) => boolean;
1789
+ isDirectory: (path: string) => boolean;
1790
+ tryResolveRealFile: (path: string, preserveSymlinks?: boolean) => string | undefined;
1791
+ tryResolveRealFileWithExtensions: (path: string, extensions: string[], preserveSymlinks?: boolean) => string | undefined;
1792
+ tryResolveRealFileOrType: (path: string, preserveSymlinks?: boolean) => {
1793
+ path?: string;
1794
+ type: 'directory' | 'file';
1795
+ } | undefined;
1796
+ initWatcher?: (watcher: FSWatcher) => void;
1797
+ }
1798
+
1799
+ interface EnvironmentResolveOptions {
1800
+ /**
1801
+ * @default ['browser', 'module', 'jsnext:main', 'jsnext']
1802
+ */
1803
+ mainFields?: string[];
1804
+ conditions?: string[];
1805
+ externalConditions?: string[];
1806
+ /**
1807
+ * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
1808
+ */
1809
+ extensions?: string[];
1810
+ dedupe?: string[];
1811
+ /**
1812
+ * external/noExternal logic, this only works for certain environments
1813
+ * Previously this was ssr.external/ssr.noExternal
1814
+ * TODO: better abstraction that works for the client environment too?
1815
+ */
1816
+ noExternal?: string | RegExp | (string | RegExp)[] | true;
1817
+ external?: string[] | true;
1818
+ }
1819
+ interface ResolveOptions extends EnvironmentResolveOptions {
1820
+ /**
1821
+ * @default false
1822
+ */
1823
+ preserveSymlinks?: boolean;
1824
+ }
1825
+ interface ResolvePluginOptions {
1826
+ root: string;
1827
+ isBuild: boolean;
1828
+ isProduction: boolean;
1829
+ packageCache?: PackageCache;
1830
+ fsUtils?: FsUtils;
1831
+ /**
1832
+ * src code mode also attempts the following:
1833
+ * - resolving /xxx as URLs
1834
+ * - resolving bare imports from optimized deps
1835
+ */
1836
+ asSrc?: boolean;
1837
+ tryIndex?: boolean;
1838
+ tryPrefix?: string;
1839
+ preferRelative?: boolean;
1840
+ isRequire?: boolean;
1841
+ webCompatible?: boolean;
1842
+ isFromTsImporter?: boolean;
1843
+ scan?: boolean;
1844
+ ssrOptimizeCheck?: boolean;
1845
+ /**
1846
+ * @deprecated environment.config are used instead
1847
+ */
1848
+ ssrConfig?: SSROptions;
1849
+ }
1850
+ interface InternalResolveOptions extends Required<ResolveOptions>, ResolvePluginOptions {
1851
+ }
1852
+ type InternalResolveOptionsWithOverrideConditions = InternalResolveOptions & {};
1853
+
1774
1854
  /** Cache for package.json resolution and package.json contents */
1775
1855
  type PackageCache = Map<string, PackageData>;
1776
1856
  interface PackageData {
1777
1857
  dir: string;
1778
1858
  hasSideEffects: (id: string) => boolean | 'no-treeshake' | null;
1779
- webResolvedImports: Record<string, string | undefined>;
1780
- nodeResolvedImports: Record<string, string | undefined>;
1781
- setResolvedCache: (key: string, entry: string, targetWeb: boolean) => void;
1782
- getResolvedCache: (key: string, targetWeb: boolean) => string | undefined;
1859
+ setResolvedCache: (key: string, entry: string, options: InternalResolveOptionsWithOverrideConditions) => void;
1860
+ getResolvedCache: (key: string, options: InternalResolveOptionsWithOverrideConditions) => string | undefined;
1783
1861
  data: {
1784
1862
  [field: string]: any;
1785
1863
  name: string;
@@ -2069,14 +2147,14 @@ interface ViteBuilder {
2069
2147
  interface BuilderOptions {
2070
2148
  sharedConfigBuild?: boolean;
2071
2149
  sharedPlugins?: boolean;
2072
- entireApp?: boolean;
2073
2150
  buildApp?: (builder: ViteBuilder) => Promise<void>;
2074
2151
  }
2075
2152
  type ResolvedBuilderOptions = Required<BuilderOptions>;
2076
2153
  /**
2077
2154
  * Creates a ViteBuilder to orchestrate building multiple environments.
2155
+ * @experimental
2078
2156
  */
2079
- declare function createBuilder(inlineConfig?: InlineConfig): Promise<ViteBuilder>;
2157
+ declare function createBuilder(inlineConfig?: InlineConfig, useLegacyBuilder?: null | boolean): Promise<ViteBuilder>;
2080
2158
 
2081
2159
  type Environment = DevEnvironment | BuildEnvironment | UnknownEnvironment;
2082
2160
 
@@ -2996,73 +3074,6 @@ type ESBuildTransformResult = Omit<esbuild_TransformResult, 'map'> & {
2996
3074
  };
2997
3075
  declare function transformWithEsbuild(code: string, filename: string, options?: esbuild_TransformOptions, inMap?: object): Promise<ESBuildTransformResult>;
2998
3076
 
2999
- interface FsUtils {
3000
- existsSync: (path: string) => boolean;
3001
- isDirectory: (path: string) => boolean;
3002
- tryResolveRealFile: (path: string, preserveSymlinks?: boolean) => string | undefined;
3003
- tryResolveRealFileWithExtensions: (path: string, extensions: string[], preserveSymlinks?: boolean) => string | undefined;
3004
- tryResolveRealFileOrType: (path: string, preserveSymlinks?: boolean) => {
3005
- path?: string;
3006
- type: 'directory' | 'file';
3007
- } | undefined;
3008
- initWatcher?: (watcher: FSWatcher) => void;
3009
- }
3010
-
3011
- interface EnvironmentResolveOptions {
3012
- /**
3013
- * @default ['browser', 'module', 'jsnext:main', 'jsnext']
3014
- */
3015
- mainFields?: string[];
3016
- conditions?: string[];
3017
- externalConditions?: string[];
3018
- /**
3019
- * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
3020
- */
3021
- extensions?: string[];
3022
- dedupe?: string[];
3023
- /**
3024
- * external/noExternal logic, this only works for certain environments
3025
- * Previously this was ssr.external/ssr.noExternal
3026
- * TODO: better abstraction that works for the client environment too?
3027
- */
3028
- noExternal?: string | RegExp | (string | RegExp)[] | true;
3029
- external?: string[] | true;
3030
- }
3031
- interface ResolveOptions extends EnvironmentResolveOptions {
3032
- /**
3033
- * @default false
3034
- */
3035
- preserveSymlinks?: boolean;
3036
- }
3037
- interface ResolvePluginOptions {
3038
- root: string;
3039
- isBuild: boolean;
3040
- isProduction: boolean;
3041
- packageCache?: PackageCache;
3042
- fsUtils?: FsUtils;
3043
- /**
3044
- * src code mode also attempts the following:
3045
- * - resolving /xxx as URLs
3046
- * - resolving bare imports from optimized deps
3047
- */
3048
- asSrc?: boolean;
3049
- tryIndex?: boolean;
3050
- tryPrefix?: string;
3051
- preferRelative?: boolean;
3052
- isRequire?: boolean;
3053
- webCompatible?: boolean;
3054
- isFromTsImporter?: boolean;
3055
- tryEsmOnly?: boolean;
3056
- scan?: boolean;
3057
- ssrOptimizeCheck?: boolean;
3058
- /**
3059
- * @deprecated environment.config are used instead
3060
- */
3061
- ssrConfig?: SSROptions;
3062
- }
3063
- interface InternalResolveOptions extends Required<ResolveOptions>, ResolvePluginOptions {
3064
- }
3065
-
3066
3077
  // This file is autogenerated by build-prefixes.js. DO NOT EDIT!
3067
3078
 
3068
3079
  interface Targets {
@@ -3544,6 +3555,8 @@ type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFnObject |
3544
3555
  declare function defineConfig(config: UserConfig): UserConfig;
3545
3556
  declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
3546
3557
  declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
3558
+ declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
3559
+ declare function defineConfig(config: UserConfigFn): UserConfigFn;
3547
3560
  declare function defineConfig(config: UserConfigExport): UserConfigExport;
3548
3561
  interface CreateDevEnvironmentContext {
3549
3562
  ws: WebSocketServer;
@@ -3708,6 +3721,7 @@ interface UserConfig extends DefaultEnvironmentOptions {
3708
3721
  assetsInclude?: string | RegExp | (string | RegExp)[];
3709
3722
  /**
3710
3723
  * Builder specific options
3724
+ * @experimental
3711
3725
  */
3712
3726
  builder?: BuilderOptions;
3713
3727
  /**
@@ -3896,7 +3910,8 @@ type ResolvedConfig = Readonly<Omit<UserConfig, 'plugins' | 'css' | 'assetsInclu
3896
3910
  esbuild: ESBuildOptions | false;
3897
3911
  server: ResolvedServerOptions;
3898
3912
  dev: ResolvedDevEnvironmentOptions;
3899
- builder: ResolvedBuilderOptions;
3913
+ /** @experimental */
3914
+ builder: ResolvedBuilderOptions | undefined;
3900
3915
  build: ResolvedBuildOptions;
3901
3916
  preview: ResolvedPreviewOptions;
3902
3917
  ssr: ResolvedSSROptions;
@@ -3933,17 +3948,42 @@ declare function createIdResolver(config: ResolvedConfig, options?: Partial<Inte
3933
3948
 
3934
3949
  declare function buildErrorMessage(err: RollupError, args?: string[], includeStack?: boolean): string;
3935
3950
 
3951
+ /**
3952
+ * @experimental
3953
+ */
3954
+ interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, 'root' | 'fetchModule' | 'hmr' | 'transport'> {
3955
+ /**
3956
+ * Disable HMR or configure HMR logger.
3957
+ */
3958
+ hmr?: false | {
3959
+ connection?: ModuleRunnerHMRConnection;
3960
+ logger?: ModuleRunnerHmr['logger'];
3961
+ };
3962
+ /**
3963
+ * Provide a custom module evaluator. This controls how the code is executed.
3964
+ */
3965
+ evaluator?: ModuleEvaluator;
3966
+ }
3967
+ /**
3968
+ * Create an instance of the Vite SSR runtime that support HMR.
3969
+ * @experimental
3970
+ */
3971
+ declare function createServerModuleRunner(environment: DevEnvironment, options?: ServerModuleRunnerOptions): ModuleRunner;
3972
+
3936
3973
  declare function createRunnableDevEnvironment(name: string, config: ResolvedConfig, context?: RunnableDevEnvironmentContext): DevEnvironment;
3937
3974
  interface RunnableDevEnvironmentContext extends Omit<DevEnvironmentContext, 'hot'> {
3938
- runner?: (environment: RunnableDevEnvironment) => ModuleRunner;
3975
+ runner?: (environment: RunnableDevEnvironment, options?: ServerModuleRunnerOptions) => ModuleRunner;
3976
+ runnerOptions?: ServerModuleRunnerOptions;
3939
3977
  hot?: false | HotChannel;
3940
3978
  }
3941
3979
  declare function isRunnableDevEnvironment(environment: Environment): environment is RunnableDevEnvironment;
3942
3980
  declare class RunnableDevEnvironment extends DevEnvironment {
3943
3981
  private _runner;
3944
3982
  private _runnerFactory;
3983
+ private _runnerOptions;
3945
3984
  constructor(name: string, config: ResolvedConfig, context: RunnableDevEnvironmentContext);
3946
3985
  get runner(): ModuleRunner;
3986
+ close(): Promise<void>;
3947
3987
  }
3948
3988
 
3949
3989
  interface FetchModuleOptions {
@@ -3957,28 +3997,6 @@ interface FetchModuleOptions {
3957
3997
  */
3958
3998
  declare function fetchModule(environment: DevEnvironment, url: string, importer?: string, options?: FetchModuleOptions): Promise<FetchResult>;
3959
3999
 
3960
- /**
3961
- * @experimental
3962
- */
3963
- interface ServerModuleRunnerOptions extends Omit<ModuleRunnerOptions, 'root' | 'fetchModule' | 'hmr' | 'transport'> {
3964
- /**
3965
- * Disable HMR or configure HMR logger.
3966
- */
3967
- hmr?: false | {
3968
- connection?: ModuleRunnerHMRConnection;
3969
- logger?: ModuleRunnerHmr['logger'];
3970
- };
3971
- /**
3972
- * Provide a custom module evaluator. This controls how the code is executed.
3973
- */
3974
- evaluator?: ModuleEvaluator;
3975
- }
3976
- /**
3977
- * Create an instance of the Vite SSR runtime that support HMR.
3978
- * @experimental
3979
- */
3980
- declare function createServerModuleRunner(environment: DevEnvironment, options?: ServerModuleRunnerOptions): ModuleRunner;
3981
-
3982
4000
  /**
3983
4001
  * The connector class to establish HMR communication between the server and the Vite runtime.
3984
4002
  * @experimental
@@ -1,6 +1,6 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-BHXIdTzn.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, j as buildErrorMessage, e as createBuilder, z as createFilter, f as createIdResolver, E as createLogger, k as createRunnableDevEnvironment, c as createServer, u as createServerHotChannel, q as createServerModuleRunner, d as defineConfig, n as fetchModule, g as formatPostcssSourceMap, H as isFileLoadingAllowed, G as isFileServingAllowed, m as isRunnableDevEnvironment, l as loadConfigFromFile, I as loadEnv, y as mergeAlias, x as mergeConfig, v as moduleRunnerTransform, w as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, J as resolveEnvPrefix, A as rollupVersion, F as searchForWorkspaceRoot, C as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-BHXIdTzn.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-Cpgpmu8-.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, j as buildErrorMessage, e as createBuilder, z as createFilter, f as createIdResolver, E as createLogger, k as createRunnableDevEnvironment, c as createServer, u as createServerHotChannel, q as createServerModuleRunner, d as defineConfig, n as fetchModule, g as formatPostcssSourceMap, H as isFileLoadingAllowed, G as isFileServingAllowed, m as isRunnableDevEnvironment, l as loadConfigFromFile, I as loadEnv, y as mergeAlias, x as mergeConfig, v as moduleRunnerTransform, w as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, J as resolveEnvPrefix, A as rollupVersion, F as searchForWorkspaceRoot, C as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-Cpgpmu8-.js';
4
4
  export { VERSION as version } from './constants.js';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
@@ -10,15 +10,12 @@ import 'node:url';
10
10
  import 'node:util';
11
11
  import 'node:perf_hooks';
12
12
  import 'node:module';
13
- import 'tty';
14
13
  import 'path';
15
14
  import 'fs';
16
- import 'node:events';
17
- import 'node:stream';
18
- import 'node:string_decoder';
19
15
  import 'node:child_process';
20
16
  import 'node:http';
21
17
  import 'node:https';
18
+ import 'tty';
22
19
  import 'util';
23
20
  import 'net';
24
21
  import 'events';
@@ -32,12 +29,14 @@ import 'node:crypto';
32
29
  import 'node:dns';
33
30
  import 'vite/module-runner';
34
31
  import 'node:readline';
32
+ import 'node:process';
33
+ import 'node:buffer';
34
+ import 'node:events';
35
35
  import 'crypto';
36
36
  import 'module';
37
37
  import 'node:assert';
38
38
  import 'node:v8';
39
39
  import 'node:worker_threads';
40
- import 'node:buffer';
41
40
  import 'zlib';
42
41
  import 'buffer';
43
42
  import 'https';
@@ -118,7 +118,7 @@ declare class ModuleRunner {
118
118
  private readonly resetSourceMapSupport?;
119
119
  private readonly root;
120
120
  private readonly concurrentModuleNodePromises;
121
- private destroyed;
121
+ private closed;
122
122
  constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
123
123
  /**
124
124
  * URL to execute. Accepts file path, server path or id relative to the root.
@@ -132,11 +132,11 @@ declare class ModuleRunner {
132
132
  * Clears all caches, removes all HMR listeners, and resets source map support.
133
133
  * This method doesn't stop the HMR connection.
134
134
  */
135
- destroy(): Promise<void>;
135
+ close(): Promise<void>;
136
136
  /**
137
- * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
137
+ * Returns `true` if the runtime has been closed by calling `close()` method.
138
138
  */
139
- isDestroyed(): boolean;
139
+ isClosed(): boolean;
140
140
  private processImport;
141
141
  private isCircularModule;
142
142
  private isCircularImport;
@@ -448,7 +448,7 @@ class HMRClient {
448
448
  }
449
449
  // After an HMR update, some modules are no longer imported on the page
450
450
  // but they may have left behind side effects that need to be cleaned up
451
- // (.e.g style injections)
451
+ // (e.g. style injections)
452
452
  async prunePaths(paths) {
453
453
  await Promise.all(
454
454
  paths.map((path) => {
@@ -536,7 +536,7 @@ function createHMRHandler(runner) {
536
536
  }
537
537
  async function handleHotPayload(runner, payload) {
538
538
  const hmrClient = runner.hmrClient;
539
- if (!(!hmrClient || runner.isDestroyed()))
539
+ if (!(!hmrClient || runner.isClosed()))
540
540
  switch (payload.type) {
541
541
  case "connected":
542
542
  hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
@@ -864,7 +864,7 @@ class ModuleRunner {
864
864
  resetSourceMapSupport;
865
865
  root;
866
866
  concurrentModuleNodePromises = /* @__PURE__ */ new Map();
867
- destroyed = !1;
867
+ closed = !1;
868
868
  /**
869
869
  * URL to execute. Accepts file path, server path or id relative to the root.
870
870
  */
@@ -882,14 +882,14 @@ class ModuleRunner {
882
882
  * Clears all caches, removes all HMR listeners, and resets source map support.
883
883
  * This method doesn't stop the HMR connection.
884
884
  */
885
- async destroy() {
886
- this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.destroyed = !0;
885
+ async close() {
886
+ this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.closed = !0;
887
887
  }
888
888
  /**
889
- * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
889
+ * Returns `true` if the runtime has been closed by calling `close()` method.
890
890
  */
891
- isDestroyed() {
892
- return this.destroyed;
891
+ isClosed() {
892
+ return this.closed;
893
893
  }
894
894
  processImport(exports, fetchResult, metadata) {
895
895
  if (!("externalize" in fetchResult))
@@ -954,8 +954,8 @@ ${getStack()}`
954
954
  return cached;
955
955
  }
956
956
  async getModuleInformation(url, importer, cachedModule) {
957
- if (this.destroyed)
958
- throw new Error("Vite module runner has been destroyed.");
957
+ if (this.closed)
958
+ throw new Error("Vite module runner has been closed.");
959
959
  this.debug?.("[module runner] fetching", url);
960
960
  const isCached = !!(typeof cachedModule == "object" && cachedModule.meta), fetchedModule = (
961
961
  // fast return for established externalized pattern
@@ -1020,7 +1020,7 @@ ${getStack()}`
1020
1020
  enumerable: !0,
1021
1021
  get: () => {
1022
1022
  if (!this.hmrClient)
1023
- throw new Error("[module runner] HMR client was destroyed.");
1023
+ throw new Error("[module runner] HMR client was closed.");
1024
1024
  return this.debug?.("[module runner] creating hmr context for", mod.url), hotContext ||= new HMRContext(this.hmrClient, mod.url), hotContext;
1025
1025
  },
1026
1026
  set: (value) => {