vite 3.2.0-beta.1 → 3.2.0-beta.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.
@@ -1,5 +1,5 @@
1
1
  import require$$0$1 from 'postcss';
2
- import { z as commonjsGlobal } from './dep-34b5a6bf.js';
2
+ import { z as commonjsGlobal } from './dep-0856a44a.js';
3
3
  import require$$0 from 'path';
4
4
  import require$$5 from 'crypto';
5
5
  import require$$0__default from 'fs';
@@ -1,11 +1,11 @@
1
1
  import fs$l, { promises as promises$2 } from 'node:fs';
2
- import path$n, { posix as posix$2, isAbsolute as isAbsolute$3, resolve as resolve$6, join as join$2, relative as relative$2, dirname as dirname$2, basename as basename$2, extname as extname$1 } from 'node:path';
2
+ import path$n, { posix as posix$2, isAbsolute as isAbsolute$2, resolve as resolve$6, join as join$2, relative as relative$2, dirname as dirname$2, basename as basename$2, extname as extname$1 } from 'node:path';
3
3
  import { URL as URL$3, pathToFileURL, URLSearchParams, parse as parse$k } from 'node:url';
4
4
  import { performance } from 'node:perf_hooks';
5
5
  import { createRequire as createRequire$1, builtinModules } from 'node:module';
6
6
  import require$$0$3 from 'tty';
7
7
  import { transform as transform$2, build as build$3, formatMessages } from 'esbuild';
8
- import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$2, normalize } from 'path';
8
+ import require$$0$4, { sep, resolve as resolve$4, posix as posix$1, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, win32 as win32$1, isAbsolute as isAbsolute$1, normalize } from 'path';
9
9
  import * as require$$0$2 from 'fs';
10
10
  import require$$0__default, { existsSync, readFileSync, statSync as statSync$1, promises as promises$1, readdirSync } from 'fs';
11
11
  import require$$0$5 from 'events';
@@ -4331,7 +4331,7 @@ function ownProp (obj, field) {
4331
4331
  var fs$i = require$$0__default;
4332
4332
  var path$i = require$$0$4;
4333
4333
  var minimatch = minimatch_1;
4334
- var isAbsolute$1 = pathIsAbsolute.exports;
4334
+ var isAbsolute = pathIsAbsolute.exports;
4335
4335
  var Minimatch = minimatch.Minimatch;
4336
4336
 
4337
4337
  function alphasort (a, b) {
@@ -4419,7 +4419,7 @@ function setopts (self, pattern, options) {
4419
4419
 
4420
4420
  // TODO: is an absolute `cwd` supposed to be resolved against `root`?
4421
4421
  // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
4422
- self.cwdAbs = isAbsolute$1(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
4422
+ self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
4423
4423
  if (process.platform === "win32")
4424
4424
  self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
4425
4425
  self.nomount = !!options.nomount;
@@ -4518,7 +4518,7 @@ function makeAbs (self, f) {
4518
4518
  var abs = f;
4519
4519
  if (f.charAt(0) === '/') {
4520
4520
  abs = path$i.join(self.root, f);
4521
- } else if (isAbsolute$1(f) || f === '') {
4521
+ } else if (isAbsolute(f) || f === '') {
4522
4522
  abs = f;
4523
4523
  } else if (self.changedCwd) {
4524
4524
  abs = path$i.resolve(self.cwd, f);
@@ -11526,7 +11526,7 @@ const normalizePath$4 = function normalizePath(filename) {
11526
11526
  };
11527
11527
 
11528
11528
  function getMatcherString(id, resolutionBase) {
11529
- if (resolutionBase === false || isAbsolute$2(id) || id.startsWith('*')) {
11529
+ if (resolutionBase === false || isAbsolute$1(id) || id.startsWith('*')) {
11530
11530
  return normalizePath$4(id);
11531
11531
  }
11532
11532
  // resolve('') is valid and will default to process.cwd()
@@ -34968,12 +34968,24 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
34968
34968
  if (nestedRoot) {
34969
34969
  basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
34970
34970
  }
34971
+ // nearest package.json
34972
+ let nearestPkg;
34973
+ // nearest package.json that may have the `exports` field
34971
34974
  let pkg;
34972
- const pkgId = possiblePkgIds.reverse().find((pkgId) => {
34973
- pkg = resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
34974
- return pkg;
34975
+ let pkgId = possiblePkgIds.reverse().find((pkgId) => {
34976
+ nearestPkg = resolvePackageData(pkgId, basedir, preserveSymlinks, packageCache);
34977
+ return nearestPkg;
34975
34978
  });
34976
- if (!pkg) {
34979
+ const rootPkgId = possiblePkgIds[0];
34980
+ const rootPkg = resolvePackageData(rootPkgId, basedir, preserveSymlinks, packageCache);
34981
+ if (rootPkg?.data?.exports) {
34982
+ pkg = rootPkg;
34983
+ pkgId = rootPkgId;
34984
+ }
34985
+ else {
34986
+ pkg = nearestPkg;
34987
+ }
34988
+ if (!pkg || !nearestPkg) {
34977
34989
  // if import can't be found, check if it's an optional peer dep.
34978
34990
  // if so, we can resolve to a special id that errors only when imported.
34979
34991
  if (basedir !== root && // root has no peer dep
@@ -35060,7 +35072,7 @@ function tryNodeResolve(id, importer, options, targetWeb, depsOptimizer, ssr, ex
35060
35072
  });
35061
35073
  }
35062
35074
  const ext = path$n.extname(resolved);
35063
- const isCJS = ext === '.cjs' || (ext === '.js' && pkg.data.type !== 'module');
35075
+ const isCJS = ext === '.cjs' || (ext === '.js' && nearestPkg.data.type !== 'module');
35064
35076
  if (!options.ssrOptimizeCheck &&
35065
35077
  (!resolved.includes('node_modules') || // linked
35066
35078
  !depsOptimizer || // resolving before listening to the server
@@ -35541,8 +35553,7 @@ function esbuildDepPlugin(qualified, exportsData, external, config, ssr) {
35541
35553
  const flatId = flattenId(id);
35542
35554
  if (flatId in qualified) {
35543
35555
  return {
35544
- path: flatId,
35545
- namespace: 'dep'
35556
+ path: qualified[flatId]
35546
35557
  };
35547
35558
  }
35548
35559
  }
@@ -35571,43 +35582,6 @@ function esbuildDepPlugin(qualified, exportsData, external, config, ssr) {
35571
35582
  return resolveResult(id, resolved);
35572
35583
  }
35573
35584
  });
35574
- // For entry files, we'll read it ourselves and construct a proxy module
35575
- // to retain the entry's raw id instead of file path so that esbuild
35576
- // outputs desired output file structure.
35577
- // It is necessary to do the re-exporting to separate the virtual proxy
35578
- // module from the actual module since the actual module may get
35579
- // referenced via relative imports - if we don't separate the proxy and
35580
- // the actual module, esbuild will create duplicated copies of the same
35581
- // module!
35582
- const root = path$n.resolve(config.root);
35583
- build.onLoad({ filter: /.*/, namespace: 'dep' }, ({ path: id }) => {
35584
- const entryFile = qualified[id];
35585
- let relativePath = normalizePath$3(path$n.relative(root, entryFile));
35586
- if (!relativePath.startsWith('./') &&
35587
- !relativePath.startsWith('../') &&
35588
- relativePath !== '.') {
35589
- relativePath = `./${relativePath}`;
35590
- }
35591
- let contents = '';
35592
- const { hasImports, exports, hasReExports } = exportsData[id];
35593
- if (!hasImports && !exports.length) {
35594
- // cjs
35595
- contents += `export default require("${relativePath}");`;
35596
- }
35597
- else {
35598
- if (exports.includes('default')) {
35599
- contents += `import d from "${relativePath}";export default d;`;
35600
- }
35601
- if (hasReExports || exports.length > 1 || exports[0] !== 'default') {
35602
- contents += `\nexport * from "${relativePath}"`;
35603
- }
35604
- }
35605
- return {
35606
- loader: 'js',
35607
- contents,
35608
- resolveDir: root
35609
- };
35610
- });
35611
35585
  build.onLoad({ filter: /.*/, namespace: 'browser-external' }, ({ path }) => {
35612
35586
  if (config.isProduction) {
35613
35587
  return {
@@ -36497,7 +36471,7 @@ async function toAbsoluteGlob(glob, root, importer, resolveId) {
36497
36471
  if (glob.startsWith('**'))
36498
36472
  return pre + glob;
36499
36473
  const resolved = normalizePath$3((await resolveId(glob, importer)) || glob);
36500
- if (isAbsolute$3(resolved)) {
36474
+ if (isAbsolute$2(resolved)) {
36501
36475
  return pre + globSafeResolvedPath(resolved, glob);
36502
36476
  }
36503
36477
  throw new Error(`Invalid glob: "${glob}" (resolved: "${resolved}"). It must start with '/' or './'`);
@@ -44972,7 +44946,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
44972
44946
  logger: config.logger
44973
44947
  }));
44974
44948
  if (isModule) {
44975
- postcssPlugins.unshift((await import('./dep-46ac452b.js').then(function (n) { return n.i; })).default({
44949
+ postcssPlugins.unshift((await import('./dep-0726141c.js').then(function (n) { return n.i; })).default({
44976
44950
  ...modulesOptions,
44977
44951
  getJSON(cssFileName, _modules, outputFileName) {
44978
44952
  modules = _modules;
@@ -53825,7 +53799,7 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
53825
53799
  preserveSymlinks,
53826
53800
  isBuild: true,
53827
53801
  isProduction,
53828
- isRequire: true,
53802
+ isRequire: false,
53829
53803
  root
53830
53804
  };
53831
53805
  // Since dynamic imports can happen in parallel, we need to
@@ -53896,6 +53870,11 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
53896
53870
  }
53897
53871
  return Object.freeze(ssrModule);
53898
53872
  }
53873
+ // `nodeImport` may run in parallel on multiple `ssrLoadModule` calls.
53874
+ // We keep track of the current importing count so that the first import
53875
+ // would `hookNodeResolve`, and the last import would `unhookNodeResolve`.
53876
+ let importingCount = 0;
53877
+ let unhookNodeResolve;
53899
53878
  // In node@12+ we can use dynamic import to load CJS and ESM
53900
53879
  async function nodeImport(id, importer, resolveOptions) {
53901
53880
  // Node's module resolution is hi-jacked so Vite can ensure the
@@ -53909,30 +53888,32 @@ async function nodeImport(id, importer, resolveOptions) {
53909
53888
  }
53910
53889
  return resolved.id;
53911
53890
  };
53912
- // When an ESM module imports an ESM dependency, this hook is *not* used.
53913
- const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
53914
- // Use the Vite resolver only for bare imports while skipping
53915
- // any absolute paths, built-in modules and binary modules.
53916
- if (!bareImportRE.test(id) ||
53917
- path$n.isAbsolute(id) ||
53918
- isBuiltin(id) ||
53919
- id.endsWith('.node')) {
53920
- return nodeResolve(id, parent, isMain, options);
53921
- }
53922
- if (parent) {
53923
- let resolved = viteResolve(id, parent.id);
53924
- if (resolved) {
53925
- // hookNodeResolve must use platform-specific path.normalize
53926
- // to be compatible with dynamicImport (#6080)
53927
- resolved = path$n.normalize(resolved);
53891
+ if (importingCount === 0) {
53892
+ // When an ESM module imports an ESM dependency, this hook is *not* used.
53893
+ unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
53894
+ // Use the Vite resolver only for bare imports while skipping
53895
+ // any absolute paths, built-in modules and binary modules.
53896
+ if (!bareImportRE.test(id) ||
53897
+ path$n.isAbsolute(id) ||
53898
+ isBuiltin(id) ||
53899
+ id.endsWith('.node')) {
53900
+ return nodeResolve(id, parent, isMain, options);
53901
+ }
53902
+ if (parent) {
53903
+ let resolved = viteResolve(id, parent.id);
53904
+ if (resolved) {
53905
+ // hookNodeResolve must use platform-specific path.normalize
53906
+ // to be compatible with dynamicImport (#6080)
53907
+ resolved = path$n.normalize(resolved);
53908
+ }
53909
+ return resolved;
53928
53910
  }
53929
- return resolved;
53930
- }
53931
- // Importing a CJS module from an ESM module. In this case, the import
53932
- // specifier is already an absolute path, so this is a no-op.
53933
- // Options like `resolve.dedupe` and `mode` are not respected.
53934
- return id;
53935
- });
53911
+ // Importing a CJS module from an ESM module. In this case, the import
53912
+ // specifier is already an absolute path, so this is a no-op.
53913
+ // Options like `resolve.dedupe` and `mode` are not respected.
53914
+ return id;
53915
+ });
53916
+ }
53936
53917
  let url;
53937
53918
  if (id.startsWith('node:') || isBuiltin(id)) {
53938
53919
  url = id;
@@ -53950,11 +53931,15 @@ async function nodeImport(id, importer, resolveOptions) {
53950
53931
  }
53951
53932
  }
53952
53933
  try {
53934
+ importingCount++;
53953
53935
  const mod = await dynamicImport(url);
53954
53936
  return proxyESM(mod);
53955
53937
  }
53956
53938
  finally {
53957
- unhookNodeResolve();
53939
+ importingCount--;
53940
+ if (importingCount === 0) {
53941
+ unhookNodeResolve?.();
53942
+ }
53958
53943
  }
53959
53944
  }
53960
53945
  // rollup-style default import interop for cjs
@@ -62582,6 +62567,11 @@ async function createServer(inlineConfig = {}) {
62582
62567
  ssrRewriteStacktrace(stack) {
62583
62568
  return ssrRewriteStacktrace(stack, moduleGraph);
62584
62569
  },
62570
+ async reloadModule(module) {
62571
+ if (serverConfig.hmr !== false && module.file) {
62572
+ updateModules(module.file, [module], Date.now(), server);
62573
+ }
62574
+ },
62585
62575
  async listen(port, isRestart) {
62586
62576
  await startServer(server, port, isRestart);
62587
62577
  if (httpServer) {
@@ -63922,7 +63912,11 @@ async function bundleConfigFile(fileName, isESM) {
63922
63912
  };
63923
63913
  build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
63924
63914
  // externalize bare imports
63925
- if (id[0] !== '.' && !isAbsolute(id)) {
63915
+ if (id[0] !== '.' && !path$n.isAbsolute(id) && !isBuiltin(id)) {
63916
+ // partial deno support as `npm:` does not work in `tryNodeResolve`
63917
+ if (id.startsWith('npm:')) {
63918
+ return { external: true };
63919
+ }
63926
63920
  let idFsPath = tryNodeResolve(id, importer, options, false)?.id;
63927
63921
  if (idFsPath && (isESM || kind === 'dynamic-import')) {
63928
63922
  idFsPath = pathToFileURL(idFsPath).href;
@@ -64025,8 +64019,5 @@ function isDepsOptimizerEnabled(config, ssr) {
64025
64019
  (command === 'build' && disabled === 'build') ||
64026
64020
  (command === 'serve' && disabled === 'dev'));
64027
64021
  }
64028
- function isAbsolute(id) {
64029
- return path$n.isAbsolute(id) || path$n.posix.isAbsolute(id);
64030
- }
64031
64022
 
64032
64023
  export { index$1 as A, build$1 as B, index as C, preview$1 as D, resolvePackageData as a, build as b, createServer as c, defineConfig as d, resolveConfig as e, formatPostcssSourceMap as f, resolveBaseUrl as g, getDepOptimizationConfig as h, isDepsOptimizerEnabled as i, mergeAlias as j, createFilter as k, loadConfigFromFile as l, mergeConfig as m, normalizePath$3 as n, optimizeDeps as o, preview as p, send as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, createLogger as u, searchForWorkspaceRoot as v, loadEnv as w, resolveEnvPrefix as x, picocolors as y, commonjsGlobal as z };
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { EventEmitter } from 'events';
3
- import { y as picocolors, u as createLogger, e as resolveConfig } from './chunks/dep-34b5a6bf.js';
3
+ import { y as picocolors, u as createLogger, e as resolveConfig } from './chunks/dep-0856a44a.js';
4
4
  import { VERSION } from './constants.js';
5
5
  import 'node:fs';
6
6
  import 'node:path';
@@ -695,7 +695,7 @@ cli
695
695
  .action(async (root, options) => {
696
696
  // output structure is preserved even after bundling so require()
697
697
  // is ok here
698
- const { createServer } = await import('./chunks/dep-34b5a6bf.js').then(function (n) { return n.C; });
698
+ const { createServer } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.C; });
699
699
  try {
700
700
  const server = await createServer({
701
701
  root,
@@ -742,7 +742,7 @@ cli
742
742
  .option('--emptyOutDir', `[boolean] force empty outDir when it's outside of root`)
743
743
  .option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
744
744
  .action(async (root, options) => {
745
- const { build } = await import('./chunks/dep-34b5a6bf.js').then(function (n) { return n.B; });
745
+ const { build } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.B; });
746
746
  const buildOptions = cleanOptions(options);
747
747
  try {
748
748
  await build({
@@ -766,7 +766,7 @@ cli
766
766
  .command('optimize [root]', 'pre-bundle dependencies')
767
767
  .option('--force', `[boolean] force the optimizer to ignore the cache and re-bundle`)
768
768
  .action(async (root, options) => {
769
- const { optimizeDeps } = await import('./chunks/dep-34b5a6bf.js').then(function (n) { return n.A; });
769
+ const { optimizeDeps } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.A; });
770
770
  try {
771
771
  const config = await resolveConfig({
772
772
  root,
@@ -789,7 +789,7 @@ cli
789
789
  .option('--https', `[boolean] use TLS + HTTP/2`)
790
790
  .option('--open [path]', `[boolean | string] open browser on startup`)
791
791
  .action(async (root, options) => {
792
- const { preview } = await import('./chunks/dep-34b5a6bf.js').then(function (n) { return n.D; });
792
+ const { preview } = await import('./chunks/dep-0856a44a.js').then(function (n) { return n.D; });
793
793
  try {
794
794
  const server = await preview({
795
795
  root,
@@ -1,7 +1,7 @@
1
1
  import path, { resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
 
4
- var version = "3.2.0-beta.1";
4
+ var version = "3.2.0-beta.2";
5
5
 
6
6
  const VERSION = version;
7
7
  const DEFAULT_MAIN_FIELDS = [
@@ -2521,6 +2521,11 @@ export declare interface ViteDevServer {
2521
2521
  * Mutates the given SSR error by rewriting the stacktrace
2522
2522
  */
2523
2523
  ssrFixStacktrace(e: Error): void;
2524
+ /**
2525
+ * Triggers HMR for a module in the module graph. You can use the `server.moduleGraph`
2526
+ * API to retrieve the module to be reloaded. If `hmr` is false, this is a no-op.
2527
+ */
2528
+ reloadModule(module: ModuleNode): Promise<void>;
2524
2529
  /**
2525
2530
  * Start the server.
2526
2531
  */
@@ -1,4 +1,4 @@
1
- export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-34b5a6bf.js';
1
+ export { b as build, k as createFilter, u as createLogger, c as createServer, d as defineConfig, f as formatPostcssSourceMap, h as getDepOptimizationConfig, i as isDepsOptimizerEnabled, l as loadConfigFromFile, w as loadEnv, j as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, p as preview, g as resolveBaseUrl, e as resolveConfig, x as resolveEnvPrefix, a as resolvePackageData, r as resolvePackageEntry, v as searchForWorkspaceRoot, q as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-0856a44a.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';
@@ -31,7 +31,7 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
31
31
  var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
32
32
  var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
33
33
 
34
- var version = "3.2.0-beta.1";
34
+ var version = "3.2.0-beta.2";
35
35
 
36
36
  const VERSION = version;
37
37
  const VITE_PACKAGE_DIR = path$3.resolve(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "3.2.0-beta.1",
3
+ "version": "3.2.0-beta.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",