vite 2.7.0-beta.9 → 2.7.0

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.

@@ -5981,7 +5981,7 @@ function assetFileNamesToFileName(assetFileNames, file, contentHash, content) {
5981
5981
  // placeholders for `assetFileNames`
5982
5982
  // `hash` is slightly different from the rollup's one
5983
5983
  const extname = path__default.extname(basename);
5984
- const ext = extname.substr(1);
5984
+ const ext = extname.substring(1);
5985
5985
  const name = basename.slice(0, -extname.length);
5986
5986
  const hash = contentHash;
5987
5987
  if (typeof assetFileNames === 'function') {
@@ -20396,7 +20396,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20396
20396
  replacer: urlReplacer
20397
20397
  }));
20398
20398
  if (isModule) {
20399
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-f90ad7ac.js'); }).then(function (n) { return n.index; })).default({
20399
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-4619561c.js'); }).then(function (n) { return n.index; })).default({
20400
20400
  ...modulesOptions,
20401
20401
  getJSON(cssFileName, _modules, outputFileName) {
20402
20402
  modules = _modules;
@@ -21374,7 +21374,7 @@ const assetAttrsConfig = {
21374
21374
  const isAsyncScriptMap = new WeakMap();
21375
21375
  async function traverseHtml(html, filePath, visitor) {
21376
21376
  // lazy load compiler
21377
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-ff5fc8ed.js'); }).then(function (n) { return n.compilerDom_cjs; });
21377
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-1ce37657.js'); }).then(function (n) { return n.compilerDom_cjs; });
21378
21378
  // @vue/compiler-core doesn't like lowercase doctypes
21379
21379
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21380
21380
  try {
@@ -30126,8 +30126,8 @@ function resolvePlugin(baseOptions) {
30126
30126
  // this is passed by @rollup/plugin-commonjs
30127
30127
  const isRequire = (_c = (_b = (_a = resolveOpts === null || resolveOpts === void 0 ? void 0 : resolveOpts.custom) === null || _a === void 0 ? void 0 : _a['node-resolve']) === null || _b === void 0 ? void 0 : _b.isRequire) !== null && _c !== void 0 ? _c : false;
30128
30128
  const options = {
30129
- ...baseOptions,
30130
30129
  isRequire,
30130
+ ...baseOptions,
30131
30131
  isFromTsImporter: isTsRequest(importer !== null && importer !== void 0 ? importer : '')
30132
30132
  };
30133
30133
  let res;
@@ -30712,7 +30712,7 @@ function resolveSSRExternal(config, knownImports) {
30712
30712
  ssrExternals.add(id);
30713
30713
  seen.add(id);
30714
30714
  });
30715
- collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen);
30715
+ collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen, config.logger);
30716
30716
  const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
30717
30717
  for (const dep of importedDeps) {
30718
30718
  // Assume external if not yet seen
@@ -30732,16 +30732,16 @@ function resolveSSRExternal(config, knownImports) {
30732
30732
  return externals;
30733
30733
  }
30734
30734
  // do we need to do this ahead of time or could we do it lazily?
30735
- function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30735
+ function collectExternals(root, preserveSymlinks, ssrExternals, seen, logger) {
30736
30736
  var _a;
30737
- const pkgContent = lookupFile(root, ['package.json']);
30738
- if (!pkgContent) {
30737
+ const rootPkgContent = lookupFile(root, ['package.json']);
30738
+ if (!rootPkgContent) {
30739
30739
  return;
30740
30740
  }
30741
- const pkg = JSON.parse(pkgContent);
30741
+ const rootPkg = JSON.parse(rootPkgContent);
30742
30742
  const deps = {
30743
- ...pkg.devDependencies,
30744
- ...pkg.dependencies
30743
+ ...rootPkg.devDependencies,
30744
+ ...rootPkg.dependencies
30745
30745
  };
30746
30746
  const resolveOptions = {
30747
30747
  root,
@@ -30797,6 +30797,12 @@ function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30797
30797
  // or are there others like SystemJS / AMD that we'd need to handle?
30798
30798
  // for now, we'll just leave this as is
30799
30799
  else if (/\.m?js$/.test(esmEntry)) {
30800
+ const pkgPath = resolveFrom$3(`${id}/package.json`, root);
30801
+ const pkgContent = fs__default.readFileSync(pkgPath, 'utf-8');
30802
+ if (!pkgContent) {
30803
+ continue;
30804
+ }
30805
+ const pkg = JSON.parse(pkgContent);
30800
30806
  if (pkg.type === 'module' || esmEntry.endsWith('.mjs')) {
30801
30807
  ssrExternals.add(id);
30802
30808
  continue;
@@ -30805,11 +30811,13 @@ function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
30805
30811
  const content = fs__default.readFileSync(esmEntry, 'utf-8');
30806
30812
  if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
30807
30813
  ssrExternals.add(id);
30814
+ continue;
30808
30815
  }
30816
+ logger.warn(`${id} is incorrectly packaged. Please contact the package author to fix.`);
30809
30817
  }
30810
30818
  }
30811
30819
  for (const depRoot of depsToTrace) {
30812
- collectExternals(depRoot, preserveSymlinks, ssrExternals, seen);
30820
+ collectExternals(depRoot, preserveSymlinks, ssrExternals, seen, logger);
30813
30821
  }
30814
30822
  }
30815
30823
  function shouldExternalizeForSSR(id, externals) {
@@ -43018,11 +43026,15 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
43018
43026
  const contextMatch = openTag.match(contextRE);
43019
43027
  const context = contextMatch &&
43020
43028
  (contextMatch[1] || contextMatch[2] || contextMatch[3]);
43021
- if ((path.endsWith('.vue') && setupRE.test(raw)) ||
43029
+ if ((path.endsWith('.vue') && setupRE.test(openTag)) ||
43022
43030
  (path.endsWith('.svelte') && context !== 'module')) {
43031
+ // append imports in TS to prevent esbuild from removing them
43032
+ // since they may be used in the template
43033
+ const localContent = content +
43034
+ (loader.startsWith('ts') ? extractImportPaths(content) : '');
43023
43035
  localScripts[path] = {
43024
43036
  loader,
43025
- contents: content
43037
+ contents: localContent
43026
43038
  };
43027
43039
  js += `import '${virtualModulePrefix}${path}';\n`;
43028
43040
  }
@@ -43031,26 +43043,10 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
43031
43043
  }
43032
43044
  }
43033
43045
  }
43034
- // empty singleline & multiline comments to avoid matching comments
43035
- const code = js
43036
- .replace(multilineCommentsRE, '/* */')
43037
- .replace(singlelineCommentsRE, '');
43038
- if (loader.startsWith('ts') &&
43039
- (path.endsWith('.svelte') ||
43040
- (path.endsWith('.vue') && setupRE.test(raw)))) {
43041
- // when using TS + (Vue + <script setup>) or Svelte, imports may seem
43042
- // unused to esbuild and dropped in the build output, which prevents
43043
- // esbuild from crawling further.
43044
- // the solution is to add `import 'x'` for every source to force
43045
- // esbuild to keep crawling due to potential side effects.
43046
- let m;
43047
- while ((m = importsRE.exec(code)) != null) {
43048
- // This is necessary to avoid infinite loops with zero-width matches
43049
- if (m.index === importsRE.lastIndex) {
43050
- importsRE.lastIndex++;
43051
- }
43052
- js += `\nimport ${m[1]}`;
43053
- }
43046
+ // `<script>` in Svelte has imports that can be used in the template
43047
+ // so we handle them here too
43048
+ if (loader.startsWith('ts') && path.endsWith('.svelte')) {
43049
+ js += extractImportPaths(js);
43054
43050
  }
43055
43051
  // This will trigger incorrectly if `export default` is contained
43056
43052
  // anywhere in a string. Svelte and Astro files can't have
@@ -43192,6 +43188,29 @@ async function transformGlob(source, importer, root, loader) {
43192
43188
  }
43193
43189
  return s.toString();
43194
43190
  }
43191
+ /**
43192
+ * when using TS + (Vue + `<script setup>`) or Svelte, imports may seem
43193
+ * unused to esbuild and dropped in the build output, which prevents
43194
+ * esbuild from crawling further.
43195
+ * the solution is to add `import 'x'` for every source to force
43196
+ * esbuild to keep crawling due to potential side effects.
43197
+ */
43198
+ function extractImportPaths(code) {
43199
+ // empty singleline & multiline comments to avoid matching comments
43200
+ code = code
43201
+ .replace(multilineCommentsRE, '/* */')
43202
+ .replace(singlelineCommentsRE, '');
43203
+ let js = '';
43204
+ let m;
43205
+ while ((m = importsRE.exec(code)) != null) {
43206
+ // This is necessary to avoid infinite loops with zero-width matches
43207
+ if (m.index === importsRE.lastIndex) {
43208
+ importsRE.lastIndex++;
43209
+ }
43210
+ js += `\nimport ${m[1]}`;
43211
+ }
43212
+ return js;
43213
+ }
43195
43214
  function shouldExternalizeDep(resolvedId, rawId) {
43196
43215
  // not a valid file path
43197
43216
  if (!path__default.isAbsolute(resolvedId)) {
@@ -43500,6 +43519,12 @@ async function doBuild(inlineConfig = {}) {
43500
43519
  };
43501
43520
  try {
43502
43521
  const buildOutputOptions = (output = {}) => {
43522
+ // @ts-ignore
43523
+ if (output.output) {
43524
+ config.logger.warn(`You've set "rollupOptions.output.output" in your config. ` +
43525
+ `This is deprecated and will override all Vite.js default output options. ` +
43526
+ `Please use "rollupOptions.output" instead.`);
43527
+ }
43503
43528
  return {
43504
43529
  dir: outDir,
43505
43530
  format: ssr ? 'cjs' : 'es',
@@ -49508,7 +49533,7 @@ function readFileIfExists(value) {
49508
49533
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49509
49534
  */
49510
49535
  async function createCertificate() {
49511
- const { generate } = await Promise.resolve().then(function () { return require('./dep-a2051654.js'); }).then(function (n) { return n.index; });
49536
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-4dd87a09.js'); }).then(function (n) { return n.index; });
49512
49537
  const pems = generate(null, {
49513
49538
  algorithm: 'sha256',
49514
49539
  days: 30,
@@ -57677,7 +57702,13 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
57677
57702
  // add HTML Proxy to Map
57678
57703
  addToHTMLProxyCache(config, url, scriptModuleIndex, contents);
57679
57704
  // inline js module. convert to src="proxy"
57680
- s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${config.base + url.slice(1)}?html-proxy&index=${scriptModuleIndex}.js"></script>`);
57705
+ const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${scriptModuleIndex}.js`;
57706
+ // invalidate the module so the newly cached contents will be served
57707
+ const module = server === null || server === void 0 ? void 0 : server.moduleGraph.getModuleById(modulePath);
57708
+ if (module) {
57709
+ server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateModule(module);
57710
+ }
57711
+ s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
57681
57712
  }
57682
57713
  }
57683
57714
  // elements with [href/src] attrs
@@ -63712,7 +63743,7 @@ ssr) {
63712
63743
  data.browserHash = require$$1$1.createHash('sha256')
63713
63744
  .update(data.hash + JSON.stringify(deps))
63714
63745
  .digest('hex')
63715
- .substr(0, 8);
63746
+ .substring(0, 8);
63716
63747
  const missingIds = Object.keys(missing);
63717
63748
  if (missingIds.length) {
63718
63749
  throw new Error(`The following dependencies are imported but could not be resolved:\n\n ${missingIds
@@ -63900,7 +63931,7 @@ function getDepHash(root, config) {
63900
63931
  }
63901
63932
  return value;
63902
63933
  });
63903
- return require$$1$1.createHash('sha256').update(content).digest('hex').substr(0, 8);
63934
+ return require$$1$1.createHash('sha256').update(content).digest('hex').substring(0, 8);
63904
63935
  }
63905
63936
 
63906
63937
  var index$1 = {
@@ -67125,9 +67156,10 @@ function rebindErrorStacktrace(e, stacktrace) {
67125
67156
  * in development.
67126
67157
  */
67127
67158
  function ssrRequireHookPlugin(config) {
67128
- var _a;
67159
+ var _a, _b;
67129
67160
  if (config.command !== 'build' ||
67130
67161
  !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length) ||
67162
+ ((_b = config.ssr) === null || _b === void 0 ? void 0 : _b.noExternal) === true ||
67131
67163
  isBuildOutputEsm(config)) {
67132
67164
  return null;
67133
67165
  }
@@ -67350,19 +67382,24 @@ async function nodeImport(id, importer, resolveOptions) {
67350
67382
  }
67351
67383
  try {
67352
67384
  const mod = await dynamicImport(url);
67353
- return proxyESM(id, mod);
67385
+ return proxyESM(mod);
67354
67386
  }
67355
67387
  finally {
67356
67388
  unhookNodeResolve();
67357
67389
  }
67358
67390
  }
67359
67391
  // rollup-style default import interop for cjs
67360
- function proxyESM(id, mod) {
67361
- const defaultExport = mod.__esModule
67362
- ? mod.default
67363
- : mod.default
67364
- ? mod.default
67365
- : mod;
67392
+ function proxyESM(mod) {
67393
+ // This is the only sensible option when the exports object is a primitve
67394
+ if (isPrimitive(mod))
67395
+ return { default: mod };
67396
+ let defaultExport = 'default' in mod ? mod.default : mod;
67397
+ if (!isPrimitive(defaultExport) && '__esModule' in defaultExport) {
67398
+ mod = defaultExport;
67399
+ if ('default' in defaultExport) {
67400
+ defaultExport = defaultExport.default;
67401
+ }
67402
+ }
67366
67403
  return new Proxy(mod, {
67367
67404
  get(mod, prop) {
67368
67405
  var _a;
@@ -67372,6 +67409,9 @@ function proxyESM(id, mod) {
67372
67409
  }
67373
67410
  });
67374
67411
  }
67412
+ function isPrimitive(value) {
67413
+ return !value || (typeof value !== 'object' && typeof value !== 'function');
67414
+ }
67375
67415
 
67376
67416
  /**
67377
67417
  * The amount to wait for requests to register newly found dependencies before triggering
@@ -67540,6 +67580,7 @@ async function createServer(inlineConfig = {}) {
67540
67580
  pluginContainer: container,
67541
67581
  ws,
67542
67582
  moduleGraph,
67583
+ ssrTransform,
67543
67584
  transformWithEsbuild,
67544
67585
  transformRequest(url, options) {
67545
67586
  return transformRequest(url, server, options);
@@ -82416,4 +82457,4 @@ exports.send = send$1;
82416
82457
  exports.sortUserPlugins = sortUserPlugins;
82417
82458
  exports.source = source;
82418
82459
  exports.transformWithEsbuild = transformWithEsbuild;
82419
- //# sourceMappingURL=dep-9aea22f6.js.map
82460
+ //# sourceMappingURL=dep-7e125991.js.map