vite 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -35230,12 +35230,13 @@ function stripLiteralAcorn(code) {
35230
35230
  return result;
35231
35231
  }
35232
35232
 
35233
- const multilineCommentsRE = /\/\*.*?\*\//gms;
35233
+ const multilineCommentsRE = /\/\*([^*\/])*?\*\//gms;
35234
35234
  const singlelineCommentsRE = /(?:^|\n|\r)\s*\/\/.*(?:\r|\n|$)/gm;
35235
35235
  const templateLiteralRE = /\$\{(\s*(?:(?!\$\{).|\n|\r)*?\s*)\}/g;
35236
35236
  const quotesRE = [
35237
35237
  /(["'`])((?:\\\1|(?!\1)|.|\r)*?)\1/gm,
35238
35238
  /([`])((?:\\\1|(?!\1)|.|\n|\r)*?)\1/gm
35239
+ // multi-line strings (i.e. template literals only)
35239
35240
  ];
35240
35241
  function stripLiteralRegex(code) {
35241
35242
  code = code.replace(multilineCommentsRE, (s) => " ".repeat(s.length)).replace(singlelineCommentsRE, (s) => " ".repeat(s.length));
@@ -35308,15 +35309,15 @@ function polyfill() {
35308
35309
  }
35309
35310
  }
35310
35311
  }).observe(document, { childList: true, subtree: true });
35311
- function getFetchOpts(script) {
35312
+ function getFetchOpts(link) {
35312
35313
  const fetchOpts = {};
35313
- if (script.integrity)
35314
- fetchOpts.integrity = script.integrity;
35315
- if (script.referrerpolicy)
35316
- fetchOpts.referrerPolicy = script.referrerpolicy;
35317
- if (script.crossorigin === 'use-credentials')
35314
+ if (link.integrity)
35315
+ fetchOpts.integrity = link.integrity;
35316
+ if (link.referrerPolicy)
35317
+ fetchOpts.referrerPolicy = link.referrerPolicy;
35318
+ if (link.crossOrigin === 'use-credentials')
35318
35319
  fetchOpts.credentials = 'include';
35319
- else if (script.crossorigin === 'anonymous')
35320
+ else if (link.crossOrigin === 'anonymous')
35320
35321
  fetchOpts.credentials = 'omit';
35321
35322
  else
35322
35323
  fetchOpts.credentials = 'same-origin';
@@ -39767,13 +39768,14 @@ function importAnalysisPlugin(config) {
39767
39768
  const prop = source.slice(end, end + 4);
39768
39769
  if (prop === '.hot') {
39769
39770
  hasHMR = true;
39770
- if (source.slice(end + 4, end + 11) === '.accept') {
39771
+ const endHot = end + 4 + (source[end + 4] === '?' ? 1 : 0);
39772
+ if (source.slice(endHot, endHot + 7) === '.accept') {
39771
39773
  // further analyze accepted modules
39772
- if (source.slice(end + 4, end + 18) === '.acceptExports') {
39773
- lexAcceptedHmrExports(source, source.indexOf('(', end + 18) + 1, acceptedExports);
39774
+ if (source.slice(endHot, endHot + 14) === '.acceptExports') {
39775
+ lexAcceptedHmrExports(source, source.indexOf('(', endHot + 14) + 1, acceptedExports);
39774
39776
  isPartiallySelfAccepting = true;
39775
39777
  }
39776
- else if (lexAcceptedHmrDeps(source, source.indexOf('(', end + 11) + 1, acceptedUrls)) {
39778
+ else if (lexAcceptedHmrDeps(source, source.indexOf('(', endHot + 7) + 1, acceptedUrls)) {
39777
39779
  isSelfAccepting = true;
39778
39780
  }
39779
39781
  }
@@ -40362,6 +40364,7 @@ function getAliasPatterns(entries) {
40362
40364
  }
40363
40365
 
40364
40366
  const nonJsRe = /\.json(?:$|\?)/;
40367
+ const metaEnvRe = /import\.meta\.env\.(.+)/;
40365
40368
  const isNonJsRequest = (request) => nonJsRe.test(request);
40366
40369
  function definePlugin(config) {
40367
40370
  const isBuild = config.command === 'build';
@@ -40383,20 +40386,23 @@ function definePlugin(config) {
40383
40386
  __vite_process_env_NODE_ENV: JSON.stringify(nodeEnv),
40384
40387
  });
40385
40388
  }
40389
+ const env = { ...config.env };
40386
40390
  const userDefine = {};
40387
40391
  for (const key in config.define) {
40388
40392
  const val = config.define[key];
40389
40393
  userDefine[key] = typeof val === 'string' ? val : JSON.stringify(val);
40394
+ // make sure `import.meta.env` object has user define properties
40395
+ const match = key.match(metaEnvRe);
40396
+ if (match) {
40397
+ env[match[1]] = val;
40398
+ }
40390
40399
  }
40391
40400
  // during dev, import.meta properties are handled by importAnalysis plugin.
40392
40401
  // ignore replace import.meta.env in lib build
40393
40402
  const importMetaKeys = {};
40394
40403
  const importMetaFallbackKeys = {};
40395
40404
  if (isBuild) {
40396
- const env = {
40397
- ...config.env,
40398
- SSR: !!config.build.ssr,
40399
- };
40405
+ env.SSR = !!config.build.ssr;
40400
40406
  // set here to allow override with config.define
40401
40407
  importMetaKeys['import.meta.hot'] = `undefined`;
40402
40408
  for (const key in env) {
@@ -40404,7 +40410,7 @@ function definePlugin(config) {
40404
40410
  }
40405
40411
  Object.assign(importMetaFallbackKeys, {
40406
40412
  'import.meta.env.': `({}).`,
40407
- 'import.meta.env': JSON.stringify(config.env),
40413
+ 'import.meta.env': JSON.stringify(env),
40408
40414
  });
40409
40415
  }
40410
40416
  function generatePattern(ssr) {
@@ -41399,12 +41405,8 @@ async function createPluginContainer(config, moduleGraph, watcher) {
41399
41405
  err.id = ctx._activeId;
41400
41406
  if (ctx._activeCode) {
41401
41407
  err.pluginCode = ctx._activeCode;
41402
- const pos = position != null
41403
- ? position
41404
- : err.pos != null
41405
- ? err.pos
41406
- : // some rollup plugins, e.g. json, sets position instead of pos
41407
- err.position;
41408
+ // some rollup plugins, e.g. json, sets err.position instead of err.pos
41409
+ const pos = position ?? err.pos ?? err.position;
41408
41410
  if (pos != null) {
41409
41411
  let errLocation;
41410
41412
  try {
@@ -42496,7 +42498,7 @@ async function createDepsOptimizer(config, server) {
42496
42498
  id,
42497
42499
  file: getOptimizedDepPath(id, config, ssr),
42498
42500
  src: resolved,
42499
- // Assing a browserHash to this missing dependency that is unique to
42501
+ // Adding a browserHash to this missing dependency that is unique to
42500
42502
  // the current state of known + missing deps. If its optimizeDeps run
42501
42503
  // doesn't alter the bundled files of previous known dependencies,
42502
42504
  // we don't need a full reload and this browserHash will be kept
@@ -43491,7 +43493,7 @@ function buildImportAnalysisPlugin(config) {
43491
43493
  // The importerUrl is passed as third parameter to __vitePreload in this case
43492
43494
  `function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
43493
43495
  : // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
43494
- // is appendended inside __vitePreload too.
43496
+ // is appended inside __vitePreload too.
43495
43497
  `function(dep) { return ${JSON.stringify(config.base)}+dep }`;
43496
43498
  const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`;
43497
43499
  return {
@@ -44259,6 +44261,10 @@ function _interpolate (envValue, environment, config) {
44259
44261
  replacePart = parts[0];
44260
44262
  value = replacePart.replace('\\$', '$');
44261
44263
  } else {
44264
+ // PATCH: compatible with env variables ended with unescaped $
44265
+ if(!parts[2]) {
44266
+ return newEnv
44267
+ }
44262
44268
  const keyParts = parts[2].split(':-');
44263
44269
  const key = keyParts[0];
44264
44270
  replacePart = parts[0].substring(prefix.length);
@@ -44335,18 +44341,9 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
44335
44341
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
44336
44342
  process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
44337
44343
  }
44338
- try {
44339
- // let environment variables use each other
44340
- expand_1({ parsed });
44341
- }
44342
- catch (e) {
44343
- // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream
44344
- // check for message "TypeError: Cannot read properties of undefined (reading 'split')"
44345
- if (e.message.includes('split')) {
44346
- throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?');
44347
- }
44348
- throw e;
44349
- }
44344
+ // let environment variables use each other
44345
+ // `expand` patched in patches/dotenv-expand@9.0.0.patch
44346
+ expand_1({ parsed });
44350
44347
  // only keys that start with prefix are exposed to client
44351
44348
  for (const [key, value] of Object.entries(parsed)) {
44352
44349
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
@@ -51811,7 +51808,7 @@ async function ssrTransformScript(code, inMap, url, originalCode) {
51811
51808
  if (!err.loc || !err.loc.line)
51812
51809
  throw err;
51813
51810
  const line = err.loc.line;
51814
- throw new Error(`Parse failure: ${err.message}\nContents of line ${line}: ${code.split('\n')[line - 1]}`);
51811
+ throw new Error(`Parse failure: ${err.message}\nAt file: ${url}\nContents of line ${line}: ${code.split('\n')[line - 1]}`);
51815
51812
  }
51816
51813
  let uid = 0;
51817
51814
  const deps = new Set();
@@ -52244,13 +52241,13 @@ function ssrRewriteStacktrace(stack, moduleGraph) {
52244
52241
  if (!pos.source || pos.line == null || pos.column == null) {
52245
52242
  return input;
52246
52243
  }
52247
- const trimedVarName = varName.trim();
52244
+ const trimmedVarName = varName.trim();
52248
52245
  const source = `${pos.source}:${pos.line}:${pos.column}`;
52249
- if (!trimedVarName || trimedVarName === 'eval') {
52246
+ if (!trimmedVarName || trimmedVarName === 'eval') {
52250
52247
  return ` at ${source}`;
52251
52248
  }
52252
52249
  else {
52253
- return ` at ${trimedVarName} (${source})`;
52250
+ return ` at ${trimmedVarName} (${source})`;
52254
52251
  }
52255
52252
  });
52256
52253
  })
package/dist/node/cli.js CHANGED
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'node:fs';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { EventEmitter } from 'events';
5
- import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-3007b26d.js';
5
+ import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-9912c491.js';
6
6
  import { VERSION } from './constants.js';
7
7
  import 'node:url';
8
8
  import 'node:module';
@@ -729,7 +729,7 @@ cli
729
729
  filterDuplicateOptions(options);
730
730
  // output structure is preserved even after bundling so require()
731
731
  // is ok here
732
- const { createServer } = await import('./chunks/dep-3007b26d.js').then(function (n) { return n.E; });
732
+ const { createServer } = await import('./chunks/dep-9912c491.js').then(function (n) { return n.E; });
733
733
  try {
734
734
  const server = await createServer({
735
735
  root,
@@ -807,7 +807,7 @@ cli
807
807
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
808
808
  .action(async (root, options) => {
809
809
  filterDuplicateOptions(options);
810
- const { build } = await import('./chunks/dep-3007b26d.js').then(function (n) { return n.D; });
810
+ const { build } = await import('./chunks/dep-9912c491.js').then(function (n) { return n.D; });
811
811
  const buildOptions = cleanOptions(options);
812
812
  try {
813
813
  await build({
@@ -835,7 +835,7 @@ cli
835
835
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
836
836
  .action(async (root, options) => {
837
837
  filterDuplicateOptions(options);
838
- const { optimizeDeps } = await import('./chunks/dep-3007b26d.js').then(function (n) { return n.C; });
838
+ const { optimizeDeps } = await import('./chunks/dep-9912c491.js').then(function (n) { return n.C; });
839
839
  try {
840
840
  const config = await resolveConfig({
841
841
  root,
@@ -860,7 +860,7 @@ cli
860
860
  .option('--outDir <dir>', `[string] output directory (default: dist)`)
861
861
  .action(async (root, options) => {
862
862
  filterDuplicateOptions(options);
863
- const { preview } = await import('./chunks/dep-3007b26d.js').then(function (n) { return n.F; });
863
+ const { preview } = await import('./chunks/dep-9912c491.js').then(function (n) { return n.F; });
864
864
  try {
865
865
  const server = await preview({
866
866
  root,
@@ -143,6 +143,7 @@ export declare interface BuildOptions {
143
143
  *
144
144
  * For custom targets, see https://esbuild.github.io/api/#target and
145
145
  * https://esbuild.github.io/content-types/#javascript for more details.
146
+ * @default 'modules'
146
147
  */
147
148
  target?: 'modules' | EsbuildTransformOptions['target'] | false;
148
149
  /**
@@ -190,6 +191,7 @@ export declare interface BuildOptions {
190
191
  * a niche browser that comes with most modern JavaScript features
191
192
  * but has poor CSS support, e.g. Android WeChat WebView, which
192
193
  * doesn't support the #RGBA syntax.
194
+ * @default target
193
195
  */
194
196
  cssTarget?: EsbuildTransformOptions['target'] | false;
195
197
  /**
@@ -264,16 +266,19 @@ export declare interface BuildOptions {
264
266
  * Build in library mode. The value should be the global name of the lib in
265
267
  * UMD mode. This will produce esm + cjs + umd bundle formats with default
266
268
  * configurations that are suitable for distributing libraries.
269
+ * @default false
267
270
  */
268
271
  lib?: LibraryOptions | false;
269
272
  /**
270
273
  * Produce SSR oriented build. Note this requires specifying SSR entry via
271
274
  * `rollupOptions.input`.
275
+ * @default false
272
276
  */
273
277
  ssr?: boolean | string;
274
278
  /**
275
279
  * Generate SSR manifest for determining style links and asset preload
276
280
  * directives in production.
281
+ * @default false
277
282
  */
278
283
  ssrManifest?: boolean | string;
279
284
  /**
@@ -285,6 +290,7 @@ export declare interface BuildOptions {
285
290
  /**
286
291
  * Set to false to disable reporting compressed chunk sizes.
287
292
  * Can slightly improve build speed.
293
+ * @default true
288
294
  */
289
295
  reportCompressedSize?: boolean;
290
296
  /**
@@ -295,6 +301,7 @@ export declare interface BuildOptions {
295
301
  /**
296
302
  * Rollup watch options
297
303
  * https://rollupjs.org/configuration-options/#watch
304
+ * @default null
298
305
  */
299
306
  watch?: WatcherOptions | null;
300
307
  }
@@ -1723,6 +1730,9 @@ export declare type ResolveModulePreloadDependenciesFn = (filename: string, deps
1723
1730
  }) => string[];
1724
1731
 
1725
1732
  export declare interface ResolveOptions {
1733
+ /**
1734
+ * @default ['module', 'jsnext:main', 'jsnext']
1735
+ */
1726
1736
  mainFields?: string[];
1727
1737
  /**
1728
1738
  * @deprecated In future, `mainFields` should be used instead.
@@ -1730,8 +1740,14 @@ export declare interface ResolveOptions {
1730
1740
  */
1731
1741
  browserField?: boolean;
1732
1742
  conditions?: string[];
1743
+ /**
1744
+ * @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
1745
+ */
1733
1746
  extensions?: string[];
1734
1747
  dedupe?: string[];
1748
+ /**
1749
+ * @default false
1750
+ */
1735
1751
  preserveSymlinks?: boolean;
1736
1752
  }
1737
1753
 
@@ -2031,6 +2047,7 @@ export declare interface ServerOptions extends CommonServerOptions {
2031
2047
  watch?: WatchOptions;
2032
2048
  /**
2033
2049
  * Create Vite dev server to be used as a middleware in an existing server
2050
+ * @default false
2034
2051
  */
2035
2052
  middlewareMode?: boolean | 'html' | 'ssr';
2036
2053
  /**
@@ -2086,7 +2103,7 @@ export declare interface SSROptions {
2086
2103
  /**
2087
2104
  * Define the target for the ssr build. The browser field in package.json
2088
2105
  * is ignored for node but used if webworker is the target
2089
- * Default: 'node'
2106
+ * @default 'node'
2090
2107
  */
2091
2108
  target?: SSRTarget;
2092
2109
  /**
@@ -2095,6 +2112,7 @@ export declare interface SSROptions {
2095
2112
  * left marked as experimental to give users more time to update to ESM. CJS builds requires
2096
2113
  * complex externalization heuristics that aren't present in the ESM format.
2097
2114
  * @experimental
2115
+ * @default 'esm'
2098
2116
  */
2099
2117
  format?: SSRFormat;
2100
2118
  /**
@@ -1,4 +1,4 @@
1
- export { b as build, e as buildErrorMessage, u as createFilter, w as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, j as getDepOptimizationConfig, k as isDepsOptimizerEnabled, l as loadConfigFromFile, y as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, i as resolveBaseUrl, h as resolveConfig, z as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, x as searchForWorkspaceRoot, v as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-3007b26d.js';
1
+ export { b as build, e as buildErrorMessage, u as createFilter, w as createLogger, c as createServer, g as defineConfig, f as formatPostcssSourceMap, j as getDepOptimizationConfig, k as isDepsOptimizerEnabled, l as loadConfigFromFile, y as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, a as preprocessCSS, p as preview, i as resolveBaseUrl, h as resolveConfig, z as resolveEnvPrefix, d as resolvePackageData, r as resolvePackageEntry, x as searchForWorkspaceRoot, v as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-9912c491.js';
2
2
  export { VERSION as version } from './constants.js';
3
3
  export { version as esbuildVersion } from 'esbuild';
4
4
  export { VERSION as rollupVersion } from 'rollup';
@@ -4195,6 +4195,10 @@ function _interpolate (envValue, environment, config) {
4195
4195
  replacePart = parts[0];
4196
4196
  value = replacePart.replace('\\$', '$');
4197
4197
  } else {
4198
+ // PATCH: compatible with env variables ended with unescaped $
4199
+ if(!parts[2]) {
4200
+ return newEnv
4201
+ }
4198
4202
  const keyParts = parts[2].split(':-');
4199
4203
  const key = keyParts[0];
4200
4204
  replacePart = parts[0].substring(prefix.length);
@@ -4271,18 +4275,9 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
4271
4275
  if (parsed.BROWSER_ARGS && process.env.BROWSER_ARGS === undefined) {
4272
4276
  process.env.BROWSER_ARGS = parsed.BROWSER_ARGS;
4273
4277
  }
4274
- try {
4275
- // let environment variables use each other
4276
- expand_1({ parsed });
4277
- }
4278
- catch (e) {
4279
- // custom error handling until https://github.com/motdotla/dotenv-expand/issues/65 is fixed upstream
4280
- // check for message "TypeError: Cannot read properties of undefined (reading 'split')"
4281
- if (e.message.includes('split')) {
4282
- throw new Error('dotenv-expand failed to expand env vars. Maybe you need to escape `$`?');
4283
- }
4284
- throw e;
4285
- }
4278
+ // let environment variables use each other
4279
+ // `expand` patched in patches/dotenv-expand@9.0.0.patch
4280
+ expand_1({ parsed });
4286
4281
  // only keys that start with prefix are exposed to client
4287
4282
  for (const [key, value] of Object.entries(parsed)) {
4288
4283
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -125,7 +125,7 @@
125
125
  "source-map-js": "^1.0.2",
126
126
  "source-map-support": "^0.5.21",
127
127
  "strip-ansi": "^7.0.1",
128
- "strip-literal": "^0.4.2",
128
+ "strip-literal": "^1.0.1",
129
129
  "tsconfck": "^2.0.2",
130
130
  "tslib": "^2.5.0",
131
131
  "types": "link:./types",