vite 3.0.0-alpha.2 → 3.0.0-alpha.3

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,5 +1,5 @@
1
1
  import require$$0 from 'postcss';
2
- import { v as commonjsGlobal } from './dep-c15b7842.js';
2
+ import { v as commonjsGlobal } from './dep-6f5ac69c.js';
3
3
  import path$2 from 'path';
4
4
  import require$$1 from 'crypto';
5
5
  import fs__default from 'fs';
@@ -1,4 +1,4 @@
1
- import { w as getAugmentedNamespace, x as getDefaultExportFromCjs } from './dep-c15b7842.js';
1
+ import { w as getAugmentedNamespace, x as getDefaultExportFromCjs } from './dep-6f5ac69c.js';
2
2
 
3
3
  import { fileURLToPath as __cjs_fileURLToPath } from 'url';
4
4
  import { dirname as __cjs_dirname } from 'path';
package/dist/node/cli.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { performance } from 'perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { u as colors, k as createLogger, e as resolveConfig } from './chunks/dep-c15b7842.js';
3
+ import { u as colors, i as createLogger, e as resolveConfig } from './chunks/dep-6f5ac69c.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'fs';
6
6
  import 'path';
7
7
  import 'url';
8
8
  import 'module';
9
9
  import 'tty';
10
- import 'os';
11
10
  import 'esbuild';
12
11
  import 'assert';
13
12
  import 'resolve';
@@ -15,6 +14,7 @@ import 'util';
15
14
  import 'net';
16
15
  import 'http';
17
16
  import 'stream';
17
+ import 'os';
18
18
  import 'child_process';
19
19
  import 'crypto';
20
20
  import 'buffer';
@@ -682,7 +682,7 @@ cli
682
682
  .action(async (root, options) => {
683
683
  // output structure is preserved even after bundling so require()
684
684
  // is ok here
685
- const { createServer } = await import('./chunks/dep-c15b7842.js').then(function (n) { return n.A; });
685
+ const { createServer } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.A; });
686
686
  try {
687
687
  const server = await createServer({
688
688
  root,
@@ -698,17 +698,13 @@ cli
698
698
  }
699
699
  await server.listen();
700
700
  const info = server.config.logger.info;
701
- info(colors.cyan(`\n vite v${VERSION}`) +
702
- colors.green(` dev server running at:\n`), {
703
- clear: !server.config.logger.hasWarned
704
- });
705
- server.printUrls();
706
701
  // @ts-ignore
707
- if (global.__vite_start_time) {
708
- // @ts-ignore
709
- const startupDuration = performance.now() - global.__vite_start_time;
710
- info(`\n ${colors.cyan(`ready in ${Math.ceil(startupDuration)}ms.`)}\n`);
711
- }
702
+ const viteStartTime = global.__vite_start_time ?? false;
703
+ const startupDurationString = viteStartTime
704
+ ? colors.dim(`ready in ${colors.white(colors.bold(Math.ceil(performance.now() - viteStartTime)))} ms`)
705
+ : '';
706
+ info(`\n ${colors.green(`${colors.bold('VITE')} v${VERSION}`)} ${startupDurationString}\n`, { clear: !server.config.logger.hasWarned });
707
+ server.printUrls();
712
708
  }
713
709
  catch (e) {
714
710
  createLogger(options.logLevel).error(colors.red(`error when starting dev server:\n${e.stack}`), { error: e });
@@ -731,7 +727,7 @@ cli
731
727
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
732
728
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
733
729
  .action(async (root, options) => {
734
- const { build } = await import('./chunks/dep-c15b7842.js').then(function (n) { return n.z; });
730
+ const { build } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.z; });
735
731
  const buildOptions = cleanOptions(options);
736
732
  try {
737
733
  await build({
@@ -754,7 +750,7 @@ cli
754
750
  .command('optimize [root]', 'pre-bundle dependencies')
755
751
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
756
752
  .action(async (root, options) => {
757
- const { optimizeDeps } = await import('./chunks/dep-c15b7842.js').then(function (n) { return n.y; });
753
+ const { optimizeDeps } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.y; });
758
754
  try {
759
755
  const config = await resolveConfig({
760
756
  root,
@@ -777,7 +773,7 @@ cli
777
773
  .option('--https', `[boolean] use TLS + HTTP/2`)
778
774
  .option('--open [path]', `[boolean | string] open browser on startup`)
779
775
  .action(async (root, options) => {
780
- const { preview } = await import('./chunks/dep-c15b7842.js').then(function (n) { return n.B; });
776
+ const { preview } = await import('./chunks/dep-6f5ac69c.js').then(function (n) { return n.B; });
781
777
  try {
782
778
  const server = await preview({
783
779
  root,
@@ -1,7 +1,7 @@
1
1
  import type { Alias, AliasOptions } from 'types/alias';
2
2
  import type { RollupOptions } from 'rollup';
3
3
  import type { Plugin } from './plugin';
4
- import type { BuildOptions } from './build';
4
+ import type { BuildOptions, ResolvedBuildOptions } from './build';
5
5
  import type { ResolvedServerOptions, ServerOptions } from './server';
6
6
  import type { PreviewOptions, ResolvedPreviewOptions } from './preview';
7
7
  import type { CSSOptions } from './plugins/css';
@@ -11,7 +11,6 @@ import type { LogLevel, Logger } from './logger';
11
11
  import type { DepOptimizationOptions } from './optimizer';
12
12
  import type { JsonOptions } from './plugins/json';
13
13
  import type { PackageCache } from './packages';
14
- import type { ResolvedBuildOptions } from '.';
15
14
  export interface ConfigEnv {
16
15
  command: 'build' | 'serve';
17
16
  mode: string;
@@ -239,5 +238,3 @@ export declare function loadConfigFromFile(configEnv: ConfigEnv, configFile?: st
239
238
  config: UserConfig;
240
239
  dependencies: string[];
241
240
  } | null>;
242
- export declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
243
- export declare function resolveEnvPrefix({ envPrefix }: UserConfig): string[];
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'path';
2
2
  import { fileURLToPath } from 'url';
3
3
 
4
- var version = "3.0.0-alpha.2";
4
+ var version = "3.0.0-alpha.3";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -0,0 +1,3 @@
1
+ import type { UserConfig } from './config';
2
+ export declare function loadEnv(mode: string, envDir: string, prefixes?: string | string[]): Record<string, string>;
3
+ export declare function resolveEnvPrefix({ envPrefix }: UserConfig): string[];
@@ -1,11 +1,10 @@
1
- export { b as build, k as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, g as loadEnv, i as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, h as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, q as searchForWorkspaceRoot, j as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-c15b7842.js';
1
+ export { b as build, i as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, l as loadConfigFromFile, k as loadEnv, g as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, e as resolveConfig, q as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, j as searchForWorkspaceRoot, h as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-6f5ac69c.js';
2
2
  import 'fs';
3
3
  import 'path';
4
4
  import 'url';
5
5
  import 'perf_hooks';
6
6
  import 'module';
7
7
  import 'tty';
8
- import 'os';
9
8
  import 'esbuild';
10
9
  import 'events';
11
10
  import 'assert';
@@ -14,6 +13,7 @@ import 'util';
14
13
  import 'net';
15
14
  import 'http';
16
15
  import 'stream';
16
+ import 'os';
17
17
  import 'child_process';
18
18
  import 'crypto';
19
19
  import './constants.js';
@@ -8,3 +8,4 @@ export { normalizePath, mergeConfig, mergeAlias } from './utils';
8
8
  export { send } from './server/send';
9
9
  export { createLogger } from './logger';
10
10
  export { searchForWorkspaceRoot } from './server/searchRoot';
11
+ export { loadEnv, resolveEnvPrefix } from './env';
@@ -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 function removeDirSync(dir: string): void;
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);
@@ -243,7 +243,7 @@ var ms = function(val, options) {
243
243
  options = options || {};
244
244
  var type = typeof val;
245
245
  if (type === 'string' && val.length > 0) {
246
- return parse(val);
246
+ return parse$1(val);
247
247
  } else if (type === 'number' && isFinite(val)) {
248
248
  return options.long ? fmtLong(val) : fmtShort(val);
249
249
  }
@@ -261,7 +261,7 @@ var ms = function(val, options) {
261
261
  * @api private
262
262
  */
263
263
 
264
- function parse(str) {
264
+ function parse$1(str) {
265
265
  str = String(str);
266
266
  if (str.length > 100) {
267
267
  return;
@@ -1204,9 +1204,9 @@ if (typeof process === 'undefined' || process.type === 'renderer' || process.bro
1204
1204
 
1205
1205
  var debug = src.exports;
1206
1206
 
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');
1207
+ 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))), '../../..');
1208
+ const CLIENT_ENTRY = path$1.resolve(VITE_PACKAGE_DIR, 'dist/client/client.mjs');
1209
+ path$1.resolve(VITE_PACKAGE_DIR, 'dist/client/env.mjs');
1210
1210
  path__default.dirname(CLIENT_ENTRY);
1211
1211
 
1212
1212
  function slash(p) {
@@ -1253,6 +1253,19 @@ function normalizePath(id) {
1253
1253
  function isObject(value) {
1254
1254
  return Object.prototype.toString.call(value) === '[object Object]';
1255
1255
  }
1256
+ function lookupFile(dir, formats, options) {
1257
+ for (const format of formats) {
1258
+ const fullPath = path__default.join(dir, format);
1259
+ if (fs__default.existsSync(fullPath) && fs__default.statSync(fullPath).isFile()) {
1260
+ return options?.pathOnly ? fullPath : fs__default.readFileSync(fullPath, 'utf-8');
1261
+ }
1262
+ }
1263
+ const parentDir = path__default.dirname(dir);
1264
+ if (parentDir !== dir &&
1265
+ (!options?.rootDir || parentDir.startsWith(options?.rootDir))) {
1266
+ return lookupFile(parentDir, formats, options);
1267
+ }
1268
+ }
1256
1269
  /**
1257
1270
  * Use instead of fs.existsSync(filename)
1258
1271
  * #2051 if we don't have read permission on a directory, existsSync() still
@@ -1268,15 +1281,11 @@ function isFileReadable(filename) {
1268
1281
  return false;
1269
1282
  }
1270
1283
  }
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
1284
  isWindows
1278
1285
  ? require$$1.promisify(gracefulRemoveDir)
1279
- : removeDirSync;
1286
+ : function removeDirSync(dir) {
1287
+ fs__default.rmSync(dir, { recursive: true, force: true });
1288
+ };
1280
1289
  isWindows ? require$$1.promisify(gracefulRename) : fs__default.renameSync;
1281
1290
  function arraify(target) {
1282
1291
  return Array.isArray(target) ? target : [target];
@@ -1329,17 +1338,16 @@ function gracefulRename(from, to, cb) {
1329
1338
  }
1330
1339
  const GRACEFUL_REMOVE_DIR_TIMEOUT = 5000;
1331
1340
  function gracefulRemoveDir(dir, cb) {
1332
- const rmdir = fs__default.rm ?? fs__default.rmdir; // TODO: Remove after support for Node 12 is dropped
1333
1341
  const start = Date.now();
1334
1342
  let backoff = 0;
1335
- rmdir(dir, { recursive: true }, function CB(er) {
1343
+ fs__default.rm(dir, { recursive: true }, function CB(er) {
1336
1344
  if (er) {
1337
1345
  if ((er.code === 'ENOTEMPTY' ||
1338
1346
  er.code === 'EACCES' ||
1339
1347
  er.code === 'EPERM') &&
1340
1348
  Date.now() - start < GRACEFUL_REMOVE_DIR_TIMEOUT) {
1341
1349
  setTimeout(function () {
1342
- rmdir(dir, { recursive: true }, CB);
1350
+ fs__default.rm(dir, { recursive: true }, CB);
1343
1351
  }, backoff);
1344
1352
  if (backoff < 100)
1345
1353
  backoff += 10;
@@ -1737,19 +1745,19 @@ const ROOT_FILES = [
1737
1745
  // npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
1738
1746
  // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
1739
1747
  function hasWorkspacePackageJSON(root) {
1740
- const path$1 = path.join(root, 'package.json');
1741
- if (!isFileReadable(path$1)) {
1748
+ const path = path$1.join(root, 'package.json');
1749
+ if (!isFileReadable(path)) {
1742
1750
  return false;
1743
1751
  }
1744
- const content = JSON.parse(fs__default.readFileSync(path$1, 'utf-8')) || {};
1752
+ const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
1745
1753
  return !!content.workspaces;
1746
1754
  }
1747
1755
  function hasRootFile(root) {
1748
- return ROOT_FILES.some((file) => fs__default.existsSync(path.join(root, file)));
1756
+ return ROOT_FILES.some((file) => fs__default.existsSync(path$1.join(root, file)));
1749
1757
  }
1750
1758
  function hasPackageJSON(root) {
1751
- const path$1 = path.join(root, 'package.json');
1752
- return fs__default.existsSync(path$1);
1759
+ const path = path$1.join(root, 'package.json');
1760
+ return fs__default.existsSync(path);
1753
1761
  }
1754
1762
  /**
1755
1763
  * Search up for the nearest `package.json`
@@ -1757,7 +1765,7 @@ function hasPackageJSON(root) {
1757
1765
  function searchForPackageRoot(current, root = current) {
1758
1766
  if (hasPackageJSON(current))
1759
1767
  return current;
1760
- const dir = path.dirname(current);
1768
+ const dir = path$1.dirname(current);
1761
1769
  // reach the fs root
1762
1770
  if (!dir || dir === current)
1763
1771
  return root;
@@ -1771,17 +1779,268 @@ function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
1771
1779
  return current;
1772
1780
  if (hasWorkspacePackageJSON(current))
1773
1781
  return current;
1774
- const dir = path.dirname(current);
1782
+ const dir = path$1.dirname(current);
1775
1783
  // reach the fs root
1776
1784
  if (!dir || dir === current)
1777
1785
  return root;
1778
1786
  return searchForWorkspaceRoot(dir, root);
1779
1787
  }
1780
1788
 
1789
+ var main$1 = {exports: {}};
1790
+
1791
+ const fs = fs__default;
1792
+ const path = path__default;
1793
+ const os = os__default;
1794
+
1795
+ function log (message) {
1796
+ console.log(`[dotenv][DEBUG] ${message}`);
1797
+ }
1798
+
1799
+ const NEWLINE = '\n';
1800
+ const RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*("[^"]*"|'[^']*'|.*?)(\s+#.*)?$/;
1801
+ const RE_NEWLINES = /\\n/g;
1802
+ const NEWLINES_MATCH = /\r\n|\n|\r/;
1803
+
1804
+ // Parses src into an Object
1805
+ function parse (src, options) {
1806
+ const debug = Boolean(options && options.debug);
1807
+ const multiline = Boolean(options && options.multiline);
1808
+ const obj = {};
1809
+
1810
+ // convert Buffers before splitting into lines and processing
1811
+ const lines = src.toString().split(NEWLINES_MATCH);
1812
+
1813
+ for (let idx = 0; idx < lines.length; idx++) {
1814
+ let line = lines[idx];
1815
+
1816
+ // matching "KEY' and 'VAL' in 'KEY=VAL'
1817
+ const keyValueArr = line.match(RE_INI_KEY_VAL);
1818
+ // matched?
1819
+ if (keyValueArr != null) {
1820
+ const key = keyValueArr[1];
1821
+ // default undefined or missing values to empty string
1822
+ let val = (keyValueArr[2] || '');
1823
+ let end = val.length - 1;
1824
+ const isDoubleQuoted = val[0] === '"' && val[end] === '"';
1825
+ const isSingleQuoted = val[0] === "'" && val[end] === "'";
1826
+
1827
+ const isMultilineDoubleQuoted = val[0] === '"' && val[end] !== '"';
1828
+ const isMultilineSingleQuoted = val[0] === "'" && val[end] !== "'";
1829
+
1830
+ // if parsing line breaks and the value starts with a quote
1831
+ if (multiline && (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
1832
+ const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
1833
+
1834
+ val = val.substring(1);
1835
+
1836
+ while (idx++ < lines.length - 1) {
1837
+ line = lines[idx];
1838
+ end = line.length - 1;
1839
+ if (line[end] === quoteChar) {
1840
+ val += NEWLINE + line.substring(0, end);
1841
+ break
1842
+ }
1843
+ val += NEWLINE + line;
1844
+ }
1845
+ // if single or double quoted, remove quotes
1846
+ } else if (isSingleQuoted || isDoubleQuoted) {
1847
+ val = val.substring(1, end);
1848
+
1849
+ // if double quoted, expand newlines
1850
+ if (isDoubleQuoted) {
1851
+ val = val.replace(RE_NEWLINES, NEWLINE);
1852
+ }
1853
+ } else {
1854
+ // remove surrounding whitespace
1855
+ val = val.trim();
1856
+ }
1857
+
1858
+ obj[key] = val;
1859
+ } else if (debug) {
1860
+ const trimmedLine = line.trim();
1861
+
1862
+ // ignore empty and commented lines
1863
+ if (trimmedLine.length && trimmedLine[0] !== '#') {
1864
+ log(`Failed to match key and value when parsing line ${idx + 1}: ${line}`);
1865
+ }
1866
+ }
1867
+ }
1868
+
1869
+ return obj
1870
+ }
1871
+
1872
+ function resolveHome (envPath) {
1873
+ return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
1874
+ }
1875
+
1876
+ // Populates process.env from .env file
1877
+ function config (options) {
1878
+ let dotenvPath = path.resolve(process.cwd(), '.env');
1879
+ let encoding = 'utf8';
1880
+ const debug = Boolean(options && options.debug);
1881
+ const override = Boolean(options && options.override);
1882
+ const multiline = Boolean(options && options.multiline);
1883
+
1884
+ if (options) {
1885
+ if (options.path != null) {
1886
+ dotenvPath = resolveHome(options.path);
1887
+ }
1888
+ if (options.encoding != null) {
1889
+ encoding = options.encoding;
1890
+ }
1891
+ }
1892
+
1893
+ try {
1894
+ // specifying an encoding returns a string instead of a buffer
1895
+ const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }), { debug, multiline });
1896
+
1897
+ Object.keys(parsed).forEach(function (key) {
1898
+ if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
1899
+ process.env[key] = parsed[key];
1900
+ } else {
1901
+ if (override === true) {
1902
+ process.env[key] = parsed[key];
1903
+ }
1904
+
1905
+ if (debug) {
1906
+ if (override === true) {
1907
+ log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
1908
+ } else {
1909
+ log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
1910
+ }
1911
+ }
1912
+ }
1913
+ });
1914
+
1915
+ return { parsed }
1916
+ } catch (e) {
1917
+ if (debug) {
1918
+ log(`Failed to load ${dotenvPath} ${e.message}`);
1919
+ }
1920
+
1921
+ return { error: e }
1922
+ }
1923
+ }
1924
+
1925
+ const DotenvModule = {
1926
+ config,
1927
+ parse
1928
+ };
1929
+
1930
+ main$1.exports.config = DotenvModule.config;
1931
+ main$1.exports.parse = DotenvModule.parse;
1932
+ main$1.exports = DotenvModule;
1933
+
1934
+ var dotenv = main$1.exports;
1935
+
1936
+ var dotenvExpand = function (config) {
1937
+ // if ignoring process.env, use a blank object
1938
+ var environment = config.ignoreProcessEnv ? {} : process.env;
1939
+
1940
+ var interpolate = function (envValue) {
1941
+ var matches = envValue.match(/(.?\${?(?:[a-zA-Z0-9_]+)?}?)/g) || [];
1942
+
1943
+ return matches.reduce(function (newEnv, match) {
1944
+ var parts = /(.?)\${?([a-zA-Z0-9_]+)?}?/g.exec(match);
1945
+ var prefix = parts[1];
1946
+
1947
+ var value, replacePart;
1948
+
1949
+ if (prefix === '\\') {
1950
+ replacePart = parts[0];
1951
+ value = replacePart.replace('\\$', '$');
1952
+ } else {
1953
+ var key = parts[2];
1954
+ replacePart = parts[0].substring(prefix.length);
1955
+ // process.env value 'wins' over .env file's value
1956
+ value = environment.hasOwnProperty(key) ? environment[key] : (config.parsed[key] || '');
1957
+
1958
+ // Resolve recursive interpolations
1959
+ value = interpolate(value);
1960
+ }
1961
+
1962
+ return newEnv.replace(replacePart, value)
1963
+ }, envValue)
1964
+ };
1965
+
1966
+ for (var configKey in config.parsed) {
1967
+ var value = environment.hasOwnProperty(configKey) ? environment[configKey] : config.parsed[configKey];
1968
+
1969
+ config.parsed[configKey] = interpolate(value);
1970
+ }
1971
+
1972
+ for (var processKey in config.parsed) {
1973
+ environment[processKey] = config.parsed[processKey];
1974
+ }
1975
+
1976
+ return config
1977
+ };
1978
+
1979
+ var main = dotenvExpand;
1980
+
1981
+ function loadEnv(mode, envDir, prefixes = 'VITE_') {
1982
+ if (mode === 'local') {
1983
+ throw new Error(`"local" cannot be used as a mode name because it conflicts with ` +
1984
+ `the .local postfix for .env files.`);
1985
+ }
1986
+ prefixes = arraify(prefixes);
1987
+ const env = {};
1988
+ const envFiles = [
1989
+ /** mode local file */ `.env.${mode}.local`,
1990
+ /** mode file */ `.env.${mode}`,
1991
+ /** local file */ `.env.local`,
1992
+ /** default file */ `.env`
1993
+ ];
1994
+ // check if there are actual env variables starting with VITE_*
1995
+ // these are typically provided inline and should be prioritized
1996
+ for (const key in process.env) {
1997
+ if (prefixes.some((prefix) => key.startsWith(prefix)) &&
1998
+ env[key] === undefined) {
1999
+ env[key] = process.env[key];
2000
+ }
2001
+ }
2002
+ for (const file of envFiles) {
2003
+ const path = lookupFile(envDir, [file], { pathOnly: true, rootDir: envDir });
2004
+ if (path) {
2005
+ const parsed = dotenv.parse(fs__default.readFileSync(path), {
2006
+ debug: process.env.DEBUG?.includes('vite:dotenv') || undefined
2007
+ });
2008
+ // let environment variables use each other
2009
+ main({
2010
+ parsed,
2011
+ // prevent process.env mutation
2012
+ ignoreProcessEnv: true
2013
+ });
2014
+ // only keys that start with prefix are exposed to client
2015
+ for (const [key, value] of Object.entries(parsed)) {
2016
+ if (prefixes.some((prefix) => key.startsWith(prefix)) &&
2017
+ env[key] === undefined) {
2018
+ env[key] = value;
2019
+ }
2020
+ else if (key === 'NODE_ENV' &&
2021
+ process.env.VITE_USER_NODE_ENV === undefined) {
2022
+ // NODE_ENV override in .env file
2023
+ process.env.VITE_USER_NODE_ENV = value;
2024
+ }
2025
+ }
2026
+ }
2027
+ }
2028
+ return env;
2029
+ }
2030
+ function resolveEnvPrefix({ envPrefix = 'VITE_' }) {
2031
+ envPrefix = arraify(envPrefix);
2032
+ if (envPrefix.some((prefix) => prefix === '')) {
2033
+ throw new Error(`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`);
2034
+ }
2035
+ return envPrefix;
2036
+ }
2037
+
1781
2038
  exports.createLogger = createLogger;
2039
+ exports.loadEnv = loadEnv;
1782
2040
  exports.mergeAlias = mergeAlias;
1783
2041
  exports.mergeConfig = mergeConfig;
1784
2042
  exports.normalizePath = normalizePath;
2043
+ exports.resolveEnvPrefix = resolveEnvPrefix;
1785
2044
  exports.searchForWorkspaceRoot = searchForWorkspaceRoot;
1786
2045
  exports.send = send;
1787
2046
  exports.splitVendorChunk = splitVendorChunk;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",