vite 3.0.0-alpha.2 → 3.0.0-alpha.5
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/node/chunks/{dep-c15b7842.js → dep-0232e200.js} +36297 -35993
- package/dist/node/chunks/{dep-df464a73.js → dep-13a14c32.js} +100 -47
- package/dist/node/chunks/{dep-24157481.js → dep-17430d09.js} +0 -0
- package/dist/node/chunks/{dep-c6d28e94.js → dep-21067347.js} +1 -1
- package/dist/node/chunks/{dep-205b15fe.js → dep-cd161504.js} +2 -2
- package/dist/node/cli.js +14 -16
- package/dist/node/config.d.ts +7 -4
- package/dist/node/constants.js +1 -1
- package/dist/node/env.d.ts +3 -0
- package/dist/node/index.d.ts +40 -13
- package/dist/node/index.js +2 -2
- package/dist/node/optimizer/index.d.ts +33 -6
- package/dist/node/optimizer/optimizer.d.ts +4 -0
- package/dist/node/plugin.d.ts +1 -0
- package/dist/node/plugins/optimizedDeps.d.ts +4 -1
- package/dist/node/plugins/preAlias.d.ts +2 -1
- package/dist/node/plugins/resolve.d.ts +5 -3
- package/dist/node/publicUtils.d.ts +1 -0
- package/dist/node/server/index.d.ts +0 -9
- package/dist/node/utils.d.ts +1 -2
- package/dist/node-cjs/publicUtils.cjs +288 -40
- package/package.json +9 -8
- package/dist/node/optimizer/registerMissing.d.ts +0 -3
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import type { BuildOptions as EsbuildBuildOptions } from 'esbuild';
|
|
2
2
|
import { parse } from 'es-module-lexer';
|
|
3
3
|
import type { ResolvedConfig } from '../config';
|
|
4
|
+
export { initDepsOptimizer, getDepsOptimizer } from './optimizer';
|
|
4
5
|
export declare const debuggerViteDeps: (...args: any[]) => any;
|
|
5
6
|
export declare type ExportsData = ReturnType<typeof parse> & {
|
|
6
7
|
hasReExports?: true;
|
|
8
|
+
jsxLoader?: true;
|
|
7
9
|
};
|
|
8
|
-
export interface
|
|
10
|
+
export interface DepsOptimizer {
|
|
9
11
|
metadata: DepOptimizationMetadata;
|
|
10
12
|
scanProcessing?: Promise<void>;
|
|
11
13
|
registerMissingImport: (id: string, resolved: string) => OptimizedDepInfo;
|
|
14
|
+
run: () => void;
|
|
15
|
+
isOptimizedDepFile: (id: string) => boolean;
|
|
16
|
+
isOptimizedDepUrl: (url: string) => boolean;
|
|
17
|
+
getOptimizedDepId: (depInfo: OptimizedDepInfo) => string;
|
|
18
|
+
options: DepOptimizationOptions;
|
|
12
19
|
}
|
|
13
20
|
export interface DepOptimizationOptions {
|
|
14
21
|
/**
|
|
@@ -32,6 +39,12 @@ export interface DepOptimizationOptions {
|
|
|
32
39
|
* cannot be globs).
|
|
33
40
|
*/
|
|
34
41
|
exclude?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Force ESM interop when importing for these dependencies. Some legacy
|
|
44
|
+
* packages advertise themselves as ESM but use `require` internally
|
|
45
|
+
* @experimental
|
|
46
|
+
*/
|
|
47
|
+
needsInterop?: string[];
|
|
35
48
|
/**
|
|
36
49
|
* Options to pass to esbuild during the dep scanning and optimization
|
|
37
50
|
*
|
|
@@ -55,11 +68,13 @@ export interface DepOptimizationOptions {
|
|
|
55
68
|
*/
|
|
56
69
|
extensions?: string[];
|
|
57
70
|
/**
|
|
58
|
-
* Disables dependencies optimizations
|
|
71
|
+
* Disables dependencies optimizations, true disables the optimizer during
|
|
72
|
+
* build and dev. Pass 'build' or 'dev' to only disable the optimizer in
|
|
73
|
+
* one of the modes. Deps optimization is enabled by default in both
|
|
59
74
|
* @default false
|
|
60
75
|
* @experimental
|
|
61
76
|
*/
|
|
62
|
-
disabled?: boolean;
|
|
77
|
+
disabled?: boolean | 'build' | 'dev';
|
|
63
78
|
}
|
|
64
79
|
export interface DepOptimizationResult {
|
|
65
80
|
metadata: DepOptimizationMetadata;
|
|
@@ -87,6 +102,11 @@ export interface OptimizedDepInfo {
|
|
|
87
102
|
* but the bundles may not yet be saved to disk
|
|
88
103
|
*/
|
|
89
104
|
processing?: Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* ExportData cache, discovered deps will parse the src entry to get exports
|
|
107
|
+
* data used both to define if interop is needed and when pre-bundling
|
|
108
|
+
*/
|
|
109
|
+
exportsData?: Promise<ExportsData>;
|
|
90
110
|
}
|
|
91
111
|
export interface DepOptimizationMetadata {
|
|
92
112
|
/**
|
|
@@ -121,7 +141,7 @@ export interface DepOptimizationMetadata {
|
|
|
121
141
|
* Used by Vite CLI when running `vite optimize`
|
|
122
142
|
*/
|
|
123
143
|
export declare function optimizeDeps(config: ResolvedConfig, force?: boolean | undefined, asCommand?: boolean): Promise<DepOptimizationMetadata>;
|
|
124
|
-
export declare function
|
|
144
|
+
export declare function initDepsOptimizerMetadata(config: ResolvedConfig, timestamp?: string): DepOptimizationMetadata;
|
|
125
145
|
export declare function addOptimizedDepInfo(metadata: DepOptimizationMetadata, type: 'optimized' | 'discovered' | 'chunks', depInfo: OptimizedDepInfo): OptimizedDepInfo;
|
|
126
146
|
/**
|
|
127
147
|
* Creates the initial dep optimization metadata, loading it from the deps cache
|
|
@@ -133,12 +153,18 @@ export declare function loadCachedDepOptimizationMetadata(config: ResolvedConfig
|
|
|
133
153
|
* find deps to pre-bundle and include user hard-coded dependencies
|
|
134
154
|
*/
|
|
135
155
|
export declare function discoverProjectDependencies(config: ResolvedConfig, timestamp?: string): Promise<Record<string, OptimizedDepInfo>>;
|
|
156
|
+
/**
|
|
157
|
+
* Create the initial discovered deps list. At build time we only
|
|
158
|
+
* have the manually included deps. During dev, a scan phase is
|
|
159
|
+
* performed and knownDeps is the list of discovered deps
|
|
160
|
+
*/
|
|
161
|
+
export declare function initialProjectDependencies(config: ResolvedConfig, timestamp?: string, knownDeps?: Record<string, string>): Promise<Record<string, OptimizedDepInfo>>;
|
|
136
162
|
export declare function depsLogString(qualifiedIds: string[]): string;
|
|
137
163
|
/**
|
|
138
164
|
* Internally, Vite uses this function to prepare a optimizeDeps run. When Vite starts, we can get
|
|
139
165
|
* the metadata and start the server without waiting for the optimizeDeps processing to be completed
|
|
140
166
|
*/
|
|
141
|
-
export declare function runOptimizeDeps(
|
|
167
|
+
export declare function runOptimizeDeps(resolvedConfig: ResolvedConfig, depsInfo: Record<string, OptimizedDepInfo>): Promise<DepOptimizationResult>;
|
|
142
168
|
export declare function findKnownImports(config: ResolvedConfig): Promise<string[]>;
|
|
143
169
|
export declare function newDepOptimizationProcessing(): DepOptimizationProcessing;
|
|
144
170
|
export declare function depsFromOptimizedDepInfo(depsInfo: Record<string, OptimizedDepInfo>): {
|
|
@@ -148,7 +174,8 @@ export declare function getOptimizedDepPath(id: string, config: ResolvedConfig):
|
|
|
148
174
|
export declare function getDepsCacheDir(config: ResolvedConfig): string;
|
|
149
175
|
export declare function isOptimizedDepFile(id: string, config: ResolvedConfig): boolean;
|
|
150
176
|
export declare function createIsOptimizedDepUrl(config: ResolvedConfig): (url: string) => boolean;
|
|
177
|
+
export declare function extractExportsData(filePath: string, config: ResolvedConfig): Promise<ExportsData>;
|
|
151
178
|
export declare function getDepHash(config: ResolvedConfig): string;
|
|
152
179
|
export declare function optimizedDepInfoFromId(metadata: DepOptimizationMetadata, id: string): OptimizedDepInfo | undefined;
|
|
153
180
|
export declare function optimizedDepInfoFromFile(metadata: DepOptimizationMetadata, file: string): OptimizedDepInfo | undefined;
|
|
154
|
-
export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string): Promise<boolean | undefined>;
|
|
181
|
+
export declare function optimizedDepNeedsInterop(metadata: DepOptimizationMetadata, file: string, config: ResolvedConfig): Promise<boolean | undefined>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ResolvedConfig, ViteDevServer } from '..';
|
|
2
|
+
import type { DepsOptimizer } from '.';
|
|
3
|
+
export declare function getDepsOptimizer(config: ResolvedConfig): DepsOptimizer | undefined;
|
|
4
|
+
export declare function initDepsOptimizer(config: ResolvedConfig, server?: ViteDevServer): Promise<DepsOptimizer>;
|
package/dist/node/plugin.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CustomPluginOptions, LoadResult, PluginContext, ResolveIdResult, Plugin as RollupPlugin, TransformPluginContext, TransformResult } from 'rollup';
|
|
2
|
+
export type { PluginContext } from 'rollup';
|
|
2
3
|
import type { UserConfig } from './config';
|
|
3
4
|
import type { ServerHook } from './server';
|
|
4
5
|
import type { IndexHtmlTransform } from './plugins/html';
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '..';
|
|
1
2
|
import type { Plugin } from '../plugin';
|
|
2
3
|
export declare const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = "ERR_OPTIMIZE_DEPS_PROCESSING_ERROR";
|
|
3
4
|
export declare const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP";
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function registerWorkersSource(config: ResolvedConfig, id: string): void;
|
|
6
|
+
export declare function optimizedDepsPlugin(config: ResolvedConfig): Plugin;
|
|
7
|
+
export declare function optimizedDepsBuildPlugin(config: ResolvedConfig): Plugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '..';
|
|
1
2
|
import type { Plugin } from '../plugin';
|
|
2
3
|
/**
|
|
3
4
|
* A plugin to avoid an aliased AND optimized dep from being aliased in src
|
|
4
5
|
*/
|
|
5
|
-
export declare function preAliasPlugin(): Plugin;
|
|
6
|
+
export declare function preAliasPlugin(config: ResolvedConfig): Plugin;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PartialResolvedId } from 'rollup';
|
|
2
2
|
import type { Plugin } from '../plugin';
|
|
3
|
-
import type {
|
|
3
|
+
import type { DepsOptimizer } from '../optimizer';
|
|
4
|
+
import type { SSROptions } from '..';
|
|
4
5
|
import type { PackageCache, PackageData } from '../packages';
|
|
5
6
|
export declare const browserExternalId = "__vite-browser-external";
|
|
6
7
|
export interface ResolveOptions {
|
|
@@ -31,9 +32,10 @@ export interface InternalResolveOptions extends ResolveOptions {
|
|
|
31
32
|
isFromTsImporter?: boolean;
|
|
32
33
|
tryEsmOnly?: boolean;
|
|
33
34
|
scan?: boolean;
|
|
35
|
+
getDepsOptimizer?: () => DepsOptimizer | undefined;
|
|
34
36
|
}
|
|
35
37
|
export declare function resolvePlugin(baseOptions: InternalResolveOptions): Plugin;
|
|
36
38
|
export declare const idToPkgMap: Map<string, PackageData>;
|
|
37
|
-
export declare function tryNodeResolve(id: string, importer: string | null | undefined, options: InternalResolveOptions, targetWeb: boolean,
|
|
38
|
-
export declare function tryOptimizedResolve(
|
|
39
|
+
export declare function tryNodeResolve(id: string, importer: string | null | undefined, options: InternalResolveOptions, targetWeb: boolean, depsOptimizer?: DepsOptimizer, ssr?: boolean): PartialResolvedId | undefined;
|
|
40
|
+
export declare function tryOptimizedResolve(depsOptimizer: DepsOptimizer, id: string, importer?: string): Promise<string | undefined>;
|
|
39
41
|
export declare function resolvePackageEntry(id: string, { dir, data, setResolvedCache, getResolvedCache }: PackageData, targetWeb: boolean, options: InternalResolveOptions): string | undefined;
|
|
@@ -5,7 +5,6 @@ import type { Connect } from 'types/connect';
|
|
|
5
5
|
import type { SourceMap } from 'rollup';
|
|
6
6
|
import type { CommonServerOptions } from '../http';
|
|
7
7
|
import type { InlineConfig, ResolvedConfig } from '../config';
|
|
8
|
-
import type { OptimizedDeps } from '../optimizer';
|
|
9
8
|
import type { Logger } from '../logger';
|
|
10
9
|
import type { PluginContainer } from './pluginContainer';
|
|
11
10
|
import type { WebSocketServer } from './ws';
|
|
@@ -14,10 +13,6 @@ import type { HmrOptions } from './hmr';
|
|
|
14
13
|
import type { TransformOptions, TransformResult } from './transformRequest';
|
|
15
14
|
export { searchForWorkspaceRoot } from './searchRoot';
|
|
16
15
|
export interface ServerOptions extends CommonServerOptions {
|
|
17
|
-
/**
|
|
18
|
-
* Force dep pre-optimization regardless of whether deps have changed.
|
|
19
|
-
*/
|
|
20
|
-
force?: boolean;
|
|
21
16
|
/**
|
|
22
17
|
* Configure HMR-specific options (port, host, path & protocol)
|
|
23
18
|
*/
|
|
@@ -164,10 +159,6 @@ export interface ViteDevServer {
|
|
|
164
159
|
* @param forceOptimize - force the optimizer to re-bundle, same as --force cli flag
|
|
165
160
|
*/
|
|
166
161
|
restart(forceOptimize?: boolean): Promise<void>;
|
|
167
|
-
/**
|
|
168
|
-
* @internal
|
|
169
|
-
*/
|
|
170
|
-
_optimizedDeps: OptimizedDeps | null;
|
|
171
162
|
/**
|
|
172
163
|
* @internal
|
|
173
164
|
*/
|
package/dist/node/utils.d.ts
CHANGED
|
@@ -102,8 +102,7 @@ export declare function isFileReadable(filename: string): boolean;
|
|
|
102
102
|
*/
|
|
103
103
|
export declare function emptyDir(dir: string, skip?: string[]): void;
|
|
104
104
|
export declare function copyDir(srcDir: string, destDir: string): void;
|
|
105
|
-
export declare
|
|
106
|
-
export declare const removeDir: typeof removeDirSync;
|
|
105
|
+
export declare const removeDir: (dir: string) => void;
|
|
107
106
|
export declare const renameDir: ((arg1: string, arg2: string) => Promise<void>) | typeof fs.renameSync;
|
|
108
107
|
export declare function ensureWatchedFile(watcher: FSWatcher, file: string | null, root: string): void;
|
|
109
108
|
interface ImageCandidate {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var fs = require('fs');
|
|
6
|
-
var os = require('os');
|
|
7
|
-
var path = require('path');
|
|
5
|
+
var fs$1 = require('fs');
|
|
6
|
+
var os$1 = require('os');
|
|
7
|
+
var path$1 = require('path');
|
|
8
8
|
var require$$1 = require('util');
|
|
9
9
|
var module$1 = require('module');
|
|
10
10
|
var require$$0 = require('tty');
|
|
@@ -14,9 +14,9 @@ var readline = require('readline');
|
|
|
14
14
|
|
|
15
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
16
16
|
|
|
17
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
18
|
-
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
19
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
17
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1);
|
|
18
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os$1);
|
|
19
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
|
|
20
20
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
21
21
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
22
22
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
@@ -136,17 +136,6 @@ for (let i = 0; i < chars.length; i++) {
|
|
|
136
136
|
charToInt[c] = i;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
Object.freeze({
|
|
140
|
-
source: null,
|
|
141
|
-
line: null,
|
|
142
|
-
column: null,
|
|
143
|
-
name: null,
|
|
144
|
-
});
|
|
145
|
-
Object.freeze({
|
|
146
|
-
line: null,
|
|
147
|
-
column: null,
|
|
148
|
-
});
|
|
149
|
-
|
|
150
139
|
var picocolors = {exports: {}};
|
|
151
140
|
|
|
152
141
|
let tty = require$$0__default;
|
|
@@ -243,7 +232,7 @@ var ms = function(val, options) {
|
|
|
243
232
|
options = options || {};
|
|
244
233
|
var type = typeof val;
|
|
245
234
|
if (type === 'string' && val.length > 0) {
|
|
246
|
-
return parse(val);
|
|
235
|
+
return parse$1(val);
|
|
247
236
|
} else if (type === 'number' && isFinite(val)) {
|
|
248
237
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
249
238
|
}
|
|
@@ -261,7 +250,7 @@ var ms = function(val, options) {
|
|
|
261
250
|
* @api private
|
|
262
251
|
*/
|
|
263
252
|
|
|
264
|
-
function parse(str) {
|
|
253
|
+
function parse$1(str) {
|
|
265
254
|
str = String(str);
|
|
266
255
|
if (str.length > 100) {
|
|
267
256
|
return;
|
|
@@ -1204,9 +1193,9 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
|
|
|
1204
1193
|
|
|
1205
1194
|
var debug = src.exports;
|
|
1206
1195
|
|
|
1207
|
-
const VITE_PACKAGE_DIR = path.resolve(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');
|
|
1208
|
-
const CLIENT_ENTRY = path.resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
|
|
1209
|
-
path.resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
|
|
1196
|
+
const VITE_PACKAGE_DIR = path$1.resolve(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node-cjs/publicUtils.cjs', document.baseURI).href))), '../../..');
|
|
1197
|
+
const CLIENT_ENTRY = path$1.resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
|
|
1198
|
+
path$1.resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
|
|
1210
1199
|
path__default.dirname(CLIENT_ENTRY);
|
|
1211
1200
|
|
|
1212
1201
|
function slash(p) {
|
|
@@ -1253,6 +1242,19 @@ function normalizePath(id) {
|
|
|
1253
1242
|
function isObject(value) {
|
|
1254
1243
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
1255
1244
|
}
|
|
1245
|
+
function lookupFile(dir, formats, options) {
|
|
1246
|
+
for (const format of formats) {
|
|
1247
|
+
const fullPath = path__default.join(dir, format);
|
|
1248
|
+
if (fs__default.existsSync(fullPath) && fs__default.statSync(fullPath).isFile()) {
|
|
1249
|
+
return options?.pathOnly ? fullPath : fs__default.readFileSync(fullPath, 'utf-8');
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const parentDir = path__default.dirname(dir);
|
|
1253
|
+
if (parentDir !== dir &&
|
|
1254
|
+
(!options?.rootDir || parentDir.startsWith(options?.rootDir))) {
|
|
1255
|
+
return lookupFile(parentDir, formats, options);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1256
1258
|
/**
|
|
1257
1259
|
* Use instead of fs.existsSync(filename)
|
|
1258
1260
|
* #2051 if we don't have read permission on a directory, existsSync() still
|
|
@@ -1268,15 +1270,11 @@ function isFileReadable(filename) {
|
|
|
1268
1270
|
return false;
|
|
1269
1271
|
}
|
|
1270
1272
|
}
|
|
1271
|
-
function removeDirSync(dir) {
|
|
1272
|
-
if (fs__default.existsSync(dir)) {
|
|
1273
|
-
const rmSync = fs__default.rmSync ?? fs__default.rmdirSync; // TODO: Remove after support for Node 12 is dropped
|
|
1274
|
-
rmSync(dir, { recursive: true });
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1273
|
isWindows
|
|
1278
1274
|
? require$$1.promisify(gracefulRemoveDir)
|
|
1279
|
-
: removeDirSync
|
|
1275
|
+
: function removeDirSync(dir) {
|
|
1276
|
+
fs__default.rmSync(dir, { recursive: true, force: true });
|
|
1277
|
+
};
|
|
1280
1278
|
isWindows ? require$$1.promisify(gracefulRename) : fs__default.renameSync;
|
|
1281
1279
|
function arraify(target) {
|
|
1282
1280
|
return Array.isArray(target) ? target : [target];
|
|
@@ -1329,17 +1327,16 @@ function gracefulRename(from, to, cb) {
|
|
|
1329
1327
|
}
|
|
1330
1328
|
const GRACEFUL_REMOVE_DIR_TIMEOUT = 5000;
|
|
1331
1329
|
function gracefulRemoveDir(dir, cb) {
|
|
1332
|
-
const rmdir = fs__default.rm ?? fs__default.rmdir; // TODO: Remove after support for Node 12 is dropped
|
|
1333
1330
|
const start = Date.now();
|
|
1334
1331
|
let backoff = 0;
|
|
1335
|
-
|
|
1332
|
+
fs__default.rm(dir, { recursive: true }, function CB(er) {
|
|
1336
1333
|
if (er) {
|
|
1337
1334
|
if ((er.code === 'ENOTEMPTY' ||
|
|
1338
1335
|
er.code === 'EACCES' ||
|
|
1339
1336
|
er.code === 'EPERM') &&
|
|
1340
1337
|
Date.now() - start < GRACEFUL_REMOVE_DIR_TIMEOUT) {
|
|
1341
1338
|
setTimeout(function () {
|
|
1342
|
-
|
|
1339
|
+
fs__default.rm(dir, { recursive: true }, CB);
|
|
1343
1340
|
}, backoff);
|
|
1344
1341
|
if (backoff < 100)
|
|
1345
1342
|
backoff += 10;
|
|
@@ -1737,19 +1734,19 @@ const ROOT_FILES = [
|
|
|
1737
1734
|
// npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
|
|
1738
1735
|
// yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
|
|
1739
1736
|
function hasWorkspacePackageJSON(root) {
|
|
1740
|
-
const path
|
|
1741
|
-
if (!isFileReadable(path
|
|
1737
|
+
const path = path$1.join(root, 'package.json');
|
|
1738
|
+
if (!isFileReadable(path)) {
|
|
1742
1739
|
return false;
|
|
1743
1740
|
}
|
|
1744
|
-
const content = JSON.parse(fs__default.readFileSync(path
|
|
1741
|
+
const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
|
|
1745
1742
|
return !!content.workspaces;
|
|
1746
1743
|
}
|
|
1747
1744
|
function hasRootFile(root) {
|
|
1748
|
-
return ROOT_FILES.some((file) => fs__default.existsSync(path.join(root, file)));
|
|
1745
|
+
return ROOT_FILES.some((file) => fs__default.existsSync(path$1.join(root, file)));
|
|
1749
1746
|
}
|
|
1750
1747
|
function hasPackageJSON(root) {
|
|
1751
|
-
const path
|
|
1752
|
-
return fs__default.existsSync(path
|
|
1748
|
+
const path = path$1.join(root, 'package.json');
|
|
1749
|
+
return fs__default.existsSync(path);
|
|
1753
1750
|
}
|
|
1754
1751
|
/**
|
|
1755
1752
|
* Search up for the nearest `package.json`
|
|
@@ -1757,7 +1754,7 @@ function hasPackageJSON(root) {
|
|
|
1757
1754
|
function searchForPackageRoot(current, root = current) {
|
|
1758
1755
|
if (hasPackageJSON(current))
|
|
1759
1756
|
return current;
|
|
1760
|
-
const dir = path.dirname(current);
|
|
1757
|
+
const dir = path$1.dirname(current);
|
|
1761
1758
|
// reach the fs root
|
|
1762
1759
|
if (!dir || dir === current)
|
|
1763
1760
|
return root;
|
|
@@ -1771,17 +1768,268 @@ function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
|
|
|
1771
1768
|
return current;
|
|
1772
1769
|
if (hasWorkspacePackageJSON(current))
|
|
1773
1770
|
return current;
|
|
1774
|
-
const dir = path.dirname(current);
|
|
1771
|
+
const dir = path$1.dirname(current);
|
|
1775
1772
|
// reach the fs root
|
|
1776
1773
|
if (!dir || dir === current)
|
|
1777
1774
|
return root;
|
|
1778
1775
|
return searchForWorkspaceRoot(dir, root);
|
|
1779
1776
|
}
|
|
1780
1777
|
|
|
1778
|
+
var main$1 = {exports: {}};
|
|
1779
|
+
|
|
1780
|
+
const fs = fs__default;
|
|
1781
|
+
const path = path__default;
|
|
1782
|
+
const os = os__default;
|
|
1783
|
+
|
|
1784
|
+
function log (message) {
|
|
1785
|
+
console.log(`[dotenv][DEBUG] ${message}`);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
const NEWLINE = '\n';
|
|
1789
|
+
const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*("[^"]*"|'[^']*'|.*?)(\s+#.*)?$/;
|
|
1790
|
+
const RE_NEWLINES = /\\n/g;
|
|
1791
|
+
const NEWLINES_MATCH = /\r\n|\n|\r/;
|
|
1792
|
+
|
|
1793
|
+
// Parses src into an Object
|
|
1794
|
+
function parse (src, options) {
|
|
1795
|
+
const debug = Boolean(options && options.debug);
|
|
1796
|
+
const multiline = Boolean(options && options.multiline);
|
|
1797
|
+
const obj = {};
|
|
1798
|
+
|
|
1799
|
+
// convert Buffers before splitting into lines and processing
|
|
1800
|
+
const lines = src.toString().split(NEWLINES_MATCH);
|
|
1801
|
+
|
|
1802
|
+
for (let idx = 0; idx < lines.length; idx++) {
|
|
1803
|
+
let line = lines[idx];
|
|
1804
|
+
|
|
1805
|
+
// matching "KEY' and 'VAL' in 'KEY=VAL'
|
|
1806
|
+
const keyValueArr = line.match(RE_INI_KEY_VAL);
|
|
1807
|
+
// matched?
|
|
1808
|
+
if (keyValueArr != null) {
|
|
1809
|
+
const key = keyValueArr[1];
|
|
1810
|
+
// default undefined or missing values to empty string
|
|
1811
|
+
let val = (keyValueArr[2] || '');
|
|
1812
|
+
let end = val.length - 1;
|
|
1813
|
+
const isDoubleQuoted = val[0] === '"' && val[end] === '"';
|
|
1814
|
+
const isSingleQuoted = val[0] === "'" && val[end] === "'";
|
|
1815
|
+
|
|
1816
|
+
const isMultilineDoubleQuoted = val[0] === '"' && val[end] !== '"';
|
|
1817
|
+
const isMultilineSingleQuoted = val[0] === "'" && val[end] !== "'";
|
|
1818
|
+
|
|
1819
|
+
// if parsing line breaks and the value starts with a quote
|
|
1820
|
+
if (multiline && (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
|
|
1821
|
+
const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
|
|
1822
|
+
|
|
1823
|
+
val = val.substring(1);
|
|
1824
|
+
|
|
1825
|
+
while (idx++ < lines.length - 1) {
|
|
1826
|
+
line = lines[idx];
|
|
1827
|
+
end = line.length - 1;
|
|
1828
|
+
if (line[end] === quoteChar) {
|
|
1829
|
+
val += NEWLINE + line.substring(0, end);
|
|
1830
|
+
break
|
|
1831
|
+
}
|
|
1832
|
+
val += NEWLINE + line;
|
|
1833
|
+
}
|
|
1834
|
+
// if single or double quoted, remove quotes
|
|
1835
|
+
} else if (isSingleQuoted || isDoubleQuoted) {
|
|
1836
|
+
val = val.substring(1, end);
|
|
1837
|
+
|
|
1838
|
+
// if double quoted, expand newlines
|
|
1839
|
+
if (isDoubleQuoted) {
|
|
1840
|
+
val = val.replace(RE_NEWLINES, NEWLINE);
|
|
1841
|
+
}
|
|
1842
|
+
} else {
|
|
1843
|
+
// remove surrounding whitespace
|
|
1844
|
+
val = val.trim();
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
obj[key] = val;
|
|
1848
|
+
} else if (debug) {
|
|
1849
|
+
const trimmedLine = line.trim();
|
|
1850
|
+
|
|
1851
|
+
// ignore empty and commented lines
|
|
1852
|
+
if (trimmedLine.length && trimmedLine[0] !== '#') {
|
|
1853
|
+
log(`Failed to match key and value when parsing line ${idx + 1}: ${line}`);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
return obj
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
function resolveHome (envPath) {
|
|
1862
|
+
return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
// Populates process.env from .env file
|
|
1866
|
+
function config (options) {
|
|
1867
|
+
let dotenvPath = path.resolve(process.cwd(), '.env');
|
|
1868
|
+
let encoding = 'utf8';
|
|
1869
|
+
const debug = Boolean(options && options.debug);
|
|
1870
|
+
const override = Boolean(options && options.override);
|
|
1871
|
+
const multiline = Boolean(options && options.multiline);
|
|
1872
|
+
|
|
1873
|
+
if (options) {
|
|
1874
|
+
if (options.path != null) {
|
|
1875
|
+
dotenvPath = resolveHome(options.path);
|
|
1876
|
+
}
|
|
1877
|
+
if (options.encoding != null) {
|
|
1878
|
+
encoding = options.encoding;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
try {
|
|
1883
|
+
// specifying an encoding returns a string instead of a buffer
|
|
1884
|
+
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }), { debug, multiline });
|
|
1885
|
+
|
|
1886
|
+
Object.keys(parsed).forEach(function (key) {
|
|
1887
|
+
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
|
1888
|
+
process.env[key] = parsed[key];
|
|
1889
|
+
} else {
|
|
1890
|
+
if (override === true) {
|
|
1891
|
+
process.env[key] = parsed[key];
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
if (debug) {
|
|
1895
|
+
if (override === true) {
|
|
1896
|
+
log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
|
1897
|
+
} else {
|
|
1898
|
+
log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1903
|
+
|
|
1904
|
+
return { parsed }
|
|
1905
|
+
} catch (e) {
|
|
1906
|
+
if (debug) {
|
|
1907
|
+
log(`Failed to load ${dotenvPath} ${e.message}`);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
return { error: e }
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
const DotenvModule = {
|
|
1915
|
+
config,
|
|
1916
|
+
parse
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
main$1.exports.config = DotenvModule.config;
|
|
1920
|
+
main$1.exports.parse = DotenvModule.parse;
|
|
1921
|
+
main$1.exports = DotenvModule;
|
|
1922
|
+
|
|
1923
|
+
var dotenv = main$1.exports;
|
|
1924
|
+
|
|
1925
|
+
var dotenvExpand = function (config) {
|
|
1926
|
+
// if ignoring process.env, use a blank object
|
|
1927
|
+
var environment = config.ignoreProcessEnv ? {} : process.env;
|
|
1928
|
+
|
|
1929
|
+
var interpolate = function (envValue) {
|
|
1930
|
+
var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || [];
|
|
1931
|
+
|
|
1932
|
+
return matches.reduce(function (newEnv, match) {
|
|
1933
|
+
var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match);
|
|
1934
|
+
var prefix = parts[1];
|
|
1935
|
+
|
|
1936
|
+
var value, replacePart;
|
|
1937
|
+
|
|
1938
|
+
if (prefix === '\\') {
|
|
1939
|
+
replacePart = parts[0];
|
|
1940
|
+
value = replacePart.replace('\\$', '$');
|
|
1941
|
+
} else {
|
|
1942
|
+
var key = parts[2];
|
|
1943
|
+
replacePart = parts[0].substring(prefix.length);
|
|
1944
|
+
// process.env value 'wins' over .env file's value
|
|
1945
|
+
value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '');
|
|
1946
|
+
|
|
1947
|
+
// Resolve recursive interpolations
|
|
1948
|
+
value = interpolate(value);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
return newEnv.replace(replacePart, value)
|
|
1952
|
+
}, envValue)
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
for (var configKey in config.parsed) {
|
|
1956
|
+
var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey];
|
|
1957
|
+
|
|
1958
|
+
config.parsed[configKey] = interpolate(value);
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
for (var processKey in config.parsed) {
|
|
1962
|
+
environment[processKey] = config.parsed[processKey];
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
return config
|
|
1966
|
+
};
|
|
1967
|
+
|
|
1968
|
+
var main = dotenvExpand;
|
|
1969
|
+
|
|
1970
|
+
function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
1971
|
+
if (mode === 'local') {
|
|
1972
|
+
throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
|
|
1973
|
+
`the .local postfix for .env files.`);
|
|
1974
|
+
}
|
|
1975
|
+
prefixes = arraify(prefixes);
|
|
1976
|
+
const env = {};
|
|
1977
|
+
const envFiles = [
|
|
1978
|
+
/** mode local file */ `.env.${mode}.local`,
|
|
1979
|
+
/** mode file */ `.env.${mode}`,
|
|
1980
|
+
/** local file */ `.env.local`,
|
|
1981
|
+
/** default file */ `.env`
|
|
1982
|
+
];
|
|
1983
|
+
// check if there are actual env variables starting with VITE_*
|
|
1984
|
+
// these are typically provided inline and should be prioritized
|
|
1985
|
+
for (const key in process.env) {
|
|
1986
|
+
if (prefixes.some((prefix) => key.startsWith(prefix)) &&
|
|
1987
|
+
env[key] === undefined) {
|
|
1988
|
+
env[key] = process.env[key];
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
for (const file of envFiles) {
|
|
1992
|
+
const path = lookupFile(envDir, [file], { pathOnly: true, rootDir: envDir });
|
|
1993
|
+
if (path) {
|
|
1994
|
+
const parsed = dotenv.parse(fs__default.readFileSync(path), {
|
|
1995
|
+
debug: process.env.DEBUG?.includes('vite:dotenv') || undefined
|
|
1996
|
+
});
|
|
1997
|
+
// let environment variables use each other
|
|
1998
|
+
main({
|
|
1999
|
+
parsed,
|
|
2000
|
+
// prevent process.env mutation
|
|
2001
|
+
ignoreProcessEnv: true
|
|
2002
|
+
});
|
|
2003
|
+
// only keys that start with prefix are exposed to client
|
|
2004
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
2005
|
+
if (prefixes.some((prefix) => key.startsWith(prefix)) &&
|
|
2006
|
+
env[key] === undefined) {
|
|
2007
|
+
env[key] = value;
|
|
2008
|
+
}
|
|
2009
|
+
else if (key === 'NODE_ENV' &&
|
|
2010
|
+
process.env.VITE_USER_NODE_ENV === undefined) {
|
|
2011
|
+
// NODE_ENV override in .env file
|
|
2012
|
+
process.env.VITE_USER_NODE_ENV = value;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
return env;
|
|
2018
|
+
}
|
|
2019
|
+
function resolveEnvPrefix({ envPrefix = 'VITE_' }) {
|
|
2020
|
+
envPrefix = arraify(envPrefix);
|
|
2021
|
+
if (envPrefix.some((prefix) => prefix === '')) {
|
|
2022
|
+
throw new Error(`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`);
|
|
2023
|
+
}
|
|
2024
|
+
return envPrefix;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
1781
2027
|
exports.createLogger = createLogger;
|
|
2028
|
+
exports.loadEnv = loadEnv;
|
|
1782
2029
|
exports.mergeAlias = mergeAlias;
|
|
1783
2030
|
exports.mergeConfig = mergeConfig;
|
|
1784
2031
|
exports.normalizePath = normalizePath;
|
|
2032
|
+
exports.resolveEnvPrefix = resolveEnvPrefix;
|
|
1785
2033
|
exports.searchForWorkspaceRoot = searchForWorkspaceRoot;
|
|
1786
2034
|
exports.send = send;
|
|
1787
2035
|
exports.splitVendorChunk = splitVendorChunk;
|