vite 4.1.2 → 4.1.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.

Potentially problematic release.


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

@@ -13307,7 +13307,7 @@ var TSConfckParseError = class extends Error {
13307
13307
 
13308
13308
  const debug$f = createDebugger('vite:esbuild');
13309
13309
  const INJECT_HELPERS_IIFE_RE = /^(.*?)((?:const|var)\s+\S+\s*=\s*function\s*\([^)]*\)\s*\{.*?"use strict";)/s;
13310
- const INJECT_HELPERS_UMD_RE = /^(.*?)(\(function\([^)]*\)\s*\{.+amd.+function\([^)]*\)\s*\{.*?"use strict";)/s;
13310
+ const INJECT_HELPERS_UMD_RE = /^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{.*?"use strict";)/s;
13311
13311
  let server;
13312
13312
  async function transformWithEsbuild(code, filename, options, inMap) {
13313
13313
  let loader = options?.loader;
@@ -21367,6 +21367,7 @@ function resolvePlugin(resolveOptions) {
21367
21367
  }
21368
21368
  const ensureVersionQuery = (resolved) => {
21369
21369
  if (!options.isBuild &&
21370
+ !options.scan &&
21370
21371
  depsOptimizer &&
21371
21372
  !(resolved === normalizedClientEntry$1 ||
21372
21373
  resolved === normalizedEnvEntry$1)) {
@@ -35417,6 +35418,7 @@ async function traverseHtml(html, filePath, visitor) {
35417
35418
  // lazy load compiler
35418
35419
  const { parse } = await import('./dep-98d07f71.js');
35419
35420
  const ast = parse(html, {
35421
+ scriptingEnabled: false,
35420
35422
  sourceCodeLocationInfo: true,
35421
35423
  onParseError: (e) => {
35422
35424
  handleParseError(e, html, filePath);
@@ -35827,20 +35829,20 @@ function buildHtmlPlugin(config) {
35827
35829
  assetTags = imports.map((chunk) => toScriptTag(chunk, toOutputAssetFilePath, isAsync));
35828
35830
  }
35829
35831
  else {
35832
+ assetTags = [toScriptTag(chunk, toOutputAssetFilePath, isAsync)];
35830
35833
  const { modulePreload } = config.build;
35831
- const resolveDependencies = typeof modulePreload === 'object' &&
35832
- modulePreload.resolveDependencies;
35833
- const importsFileNames = imports.map((chunk) => chunk.fileName);
35834
- const resolvedDeps = resolveDependencies
35835
- ? resolveDependencies(chunk.fileName, importsFileNames, {
35836
- hostId: relativeUrlPath,
35837
- hostType: 'html',
35838
- })
35839
- : importsFileNames;
35840
- assetTags = [
35841
- toScriptTag(chunk, toOutputAssetFilePath, isAsync),
35842
- ...resolvedDeps.map((i) => toPreloadTag(i, toOutputAssetFilePath)),
35843
- ];
35834
+ if (modulePreload !== false) {
35835
+ const resolveDependencies = typeof modulePreload === 'object' &&
35836
+ modulePreload.resolveDependencies;
35837
+ const importsFileNames = imports.map((chunk) => chunk.fileName);
35838
+ const resolvedDeps = resolveDependencies
35839
+ ? resolveDependencies(chunk.fileName, importsFileNames, {
35840
+ hostId: relativeUrlPath,
35841
+ hostType: 'html',
35842
+ })
35843
+ : importsFileNames;
35844
+ assetTags.push(...resolvedDeps.map((i) => toPreloadTag(i, toOutputAssetFilePath)));
35845
+ }
35844
35846
  }
35845
35847
  assetTags.push(...getCssTagsForChunk(chunk, toOutputAssetFilePath));
35846
35848
  result = injectToHead(result, assetTags);
@@ -36372,13 +36374,18 @@ function cssPostPlugin(config) {
36372
36374
  let isPureCssChunk = true;
36373
36375
  const ids = Object.keys(chunk.modules);
36374
36376
  for (const id of ids) {
36375
- if (!isCSSRequest(id) ||
36376
- cssModuleRE.test(id) ||
36377
- commonjsProxyRE.test(id)) {
36378
- isPureCssChunk = false;
36379
- }
36380
36377
  if (styles.has(id)) {
36381
36378
  chunkCSS += styles.get(id);
36379
+ // a css module contains JS, so it makes this not a pure css chunk
36380
+ if (cssModuleRE.test(id)) {
36381
+ isPureCssChunk = false;
36382
+ }
36383
+ }
36384
+ else {
36385
+ // if the module does not have a style, then it's not a pure css chunk.
36386
+ // this is true because in the `transform` hook above, only modules
36387
+ // that are css gets added to the `styles` map.
36388
+ isPureCssChunk = false;
36382
36389
  }
36383
36390
  }
36384
36391
  if (!chunkCSS) {
@@ -39455,7 +39462,12 @@ async function loadAndTransform(id, url, server, options, timestamp) {
39455
39462
  `going through the plugin transforms, and therefore should not be ` +
39456
39463
  `imported from source code. It can only be referenced via HTML tags.`
39457
39464
  : `Does the file exist?`;
39458
- const err = new Error(`Failed to load url ${url} (resolved id: ${id}). ${msg}`);
39465
+ const importerMod = server.moduleGraph.idToModuleMap
39466
+ .get(id)
39467
+ ?.importers.values()
39468
+ .next().value;
39469
+ const importer = importerMod?.file || importerMod?.url;
39470
+ const err = new Error(`Failed to load url ${url} (resolved id: ${id})${importer ? ` in ${importer}` : ''}. ${msg}`);
39459
39471
  err.code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL;
39460
39472
  throw err;
39461
39473
  }
@@ -40386,15 +40398,23 @@ function definePlugin(config) {
40386
40398
  __vite_process_env_NODE_ENV: JSON.stringify(nodeEnv),
40387
40399
  });
40388
40400
  }
40389
- const env = { ...config.env };
40390
40401
  const userDefine = {};
40402
+ const userDefineEnv = {};
40391
40403
  for (const key in config.define) {
40392
40404
  const val = config.define[key];
40393
40405
  userDefine[key] = typeof val === 'string' ? val : JSON.stringify(val);
40394
40406
  // make sure `import.meta.env` object has user define properties
40395
- const match = key.match(metaEnvRe);
40396
- if (match) {
40397
- env[match[1]] = val;
40407
+ if (isBuild) {
40408
+ const match = key.match(metaEnvRe);
40409
+ if (match) {
40410
+ userDefineEnv[match[1]] =
40411
+ // test if value is raw identifier to wrap with __vite__ so when
40412
+ // stringified for `import.meta.env`, we can remove the quotes and
40413
+ // retain being an identifier
40414
+ typeof val === 'string' && /^[\p{L}_$]/u.test(val.trim())
40415
+ ? `__vite__${val}__vite__`
40416
+ : val;
40417
+ }
40398
40418
  }
40399
40419
  }
40400
40420
  // during dev, import.meta properties are handled by importAnalysis plugin.
@@ -40402,7 +40422,10 @@ function definePlugin(config) {
40402
40422
  const importMetaKeys = {};
40403
40423
  const importMetaFallbackKeys = {};
40404
40424
  if (isBuild) {
40405
- env.SSR = !!config.build.ssr;
40425
+ const env = {
40426
+ ...config.env,
40427
+ SSR: !!config.build.ssr,
40428
+ };
40406
40429
  // set here to allow override with config.define
40407
40430
  importMetaKeys['import.meta.hot'] = `undefined`;
40408
40431
  for (const key in env) {
@@ -40410,7 +40433,7 @@ function definePlugin(config) {
40410
40433
  }
40411
40434
  Object.assign(importMetaFallbackKeys, {
40412
40435
  'import.meta.env.': `({}).`,
40413
- 'import.meta.env': JSON.stringify(env),
40436
+ 'import.meta.env': JSON.stringify({ ...env, ...userDefineEnv }).replace(/"__vite__(.+?)__vite__"/g, (_, val) => val),
40414
40437
  });
40415
40438
  }
40416
40439
  function generatePattern(ssr) {
@@ -58106,6 +58129,12 @@ function createWebSocketServer(server, config, httpsOptions) {
58106
58129
  const client = getSocketClient(socket);
58107
58130
  listeners.forEach((listener) => listener(parsed.data, client));
58108
58131
  });
58132
+ socket.on('error', (err) => {
58133
+ config.logger.error(`${picocolorsExports.red(`ws error:`)}\n${err.stack}`, {
58134
+ timestamp: true,
58135
+ error: err,
58136
+ });
58137
+ });
58109
58138
  socket.send(JSON.stringify({ type: 'connected' }));
58110
58139
  if (bufferedError) {
58111
58140
  socket.send(JSON.stringify(bufferedError));
@@ -61671,6 +61700,16 @@ function resolvePreviewOptions(preview, server) {
61671
61700
  */
61672
61701
  async function preview(inlineConfig = {}) {
61673
61702
  const config = await resolveConfig(inlineConfig, 'serve', 'production', 'production');
61703
+ const distDir = path$o.resolve(config.root, config.build.outDir);
61704
+ if (!fs$l.existsSync(distDir) &&
61705
+ // error if no plugins implement `configurePreviewServer`
61706
+ config.plugins.every((plugin) => !plugin.configurePreviewServer) &&
61707
+ // error if called in CLI only. programmatic usage could access `httpServer`
61708
+ // and affect file serving
61709
+ process.argv[1]?.endsWith(path$o.normalize('bin/vite.js')) &&
61710
+ process.argv[2] === 'preview') {
61711
+ throw new Error(`The directory "${config.build.outDir}" does not exist. Did you build your project?`);
61712
+ }
61674
61713
  const app = connect();
61675
61714
  const httpServer = await resolveHttpServer(config.preview, app, await resolveHttpsConfig(config.preview?.https));
61676
61715
  setClientErrorHandler(httpServer, config.logger);
@@ -61692,7 +61731,6 @@ async function preview(inlineConfig = {}) {
61692
61731
  app.use(compression());
61693
61732
  const previewBase = config.base === './' || config.base === '' ? '/' : config.base;
61694
61733
  // static assets
61695
- const distDir = path$o.resolve(config.root, config.build.outDir);
61696
61734
  const headers = config.preview.headers;
61697
61735
  const assetServer = sirv(distDir, {
61698
61736
  etag: true,
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-9912c491.js';
5
+ import { A as picocolorsExports, B as bindShortcuts, w as createLogger, h as resolveConfig } from './chunks/dep-ca21228b.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-9912c491.js').then(function (n) { return n.E; });
732
+ const { createServer } = await import('./chunks/dep-ca21228b.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-9912c491.js').then(function (n) { return n.D; });
810
+ const { build } = await import('./chunks/dep-ca21228b.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-9912c491.js').then(function (n) { return n.C; });
838
+ const { optimizeDeps } = await import('./chunks/dep-ca21228b.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-9912c491.js').then(function (n) { return n.F; });
863
+ const { preview } = await import('./chunks/dep-ca21228b.js').then(function (n) { return n.F; });
864
864
  try {
865
865
  const server = await preview({
866
866
  root,
@@ -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-9912c491.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-ca21228b.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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",