vite 2.6.10 → 2.6.14

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.

@@ -3883,6 +3883,8 @@ function unwrapId$1(id) {
3883
3883
  const flattenId = (id) => id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.]/g, '_');
3884
3884
  const normalizeId$1 = (id) => id.replace(/(\s*>\s*)/g, ' > ');
3885
3885
  function isBuiltin(id) {
3886
+ const deepMatch = id.match(deepImportRE);
3887
+ id = deepMatch ? deepMatch[1] || deepMatch[2] : id;
3886
3888
  return builtinModules_1.includes(id);
3887
3889
  }
3888
3890
  const bareImportRE = /^[\w@](?!.*:\/\/)/;
@@ -4141,6 +4143,21 @@ function writeFile(filename, content) {
4141
4143
  }
4142
4144
  fs__default.writeFileSync(filename, content);
4143
4145
  }
4146
+ /**
4147
+ * Use instead of fs.existsSync(filename)
4148
+ * #2051 if we don't have read permission on a directory, existsSync() still
4149
+ * works and will result in massively slow subsequent checks (which are
4150
+ * unnecessary in the first place)
4151
+ */
4152
+ function isFileReadable(filename) {
4153
+ try {
4154
+ fs__default.accessSync(filename, fs__default.constants.R_OK);
4155
+ return true;
4156
+ }
4157
+ catch {
4158
+ return false;
4159
+ }
4160
+ }
4144
4161
  /**
4145
4162
  * Delete every file and subdirectory. **The given directory must exist.**
4146
4163
  * Pass an optional `skip` array to preserve files in the root directory.
@@ -19873,7 +19890,7 @@ function cssPlugin(config) {
19873
19890
  const thisModule = moduleGraph.getModuleById(id);
19874
19891
  if (thisModule) {
19875
19892
  // CSS modules cannot self-accept since it exports values
19876
- const isSelfAccepting = !modules;
19893
+ const isSelfAccepting = !modules && !inlineRE.test(id);
19877
19894
  if (deps) {
19878
19895
  // record deps in the module graph so edits to @import css can trigger
19879
19896
  // main import to hot update
@@ -19958,13 +19975,10 @@ function cssPostPlugin(config) {
19958
19975
  if (!inlined) {
19959
19976
  styles.set(id, css);
19960
19977
  }
19961
- else {
19962
- css = await minifyCSS(css, config);
19963
- }
19964
19978
  return {
19965
19979
  code: modulesCode ||
19966
19980
  (usedRE.test(id)
19967
- ? `export default ${JSON.stringify(css)}`
19981
+ ? `export default ${JSON.stringify(inlined ? await minifyCSS(css, config) : css)}`
19968
19982
  : `export default ''`),
19969
19983
  map: { mappings: '' },
19970
19984
  // avoid the css module from being tree-shaken so that we can retrieve
@@ -20243,7 +20257,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
20243
20257
  replacer: urlReplacer
20244
20258
  }));
20245
20259
  if (isModule) {
20246
- postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-8e7741a0.js'); }).then(function (n) { return n.index; })).default({
20260
+ postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-c98c5b6d.js'); }).then(function (n) { return n.index; })).default({
20247
20261
  ...modulesOptions,
20248
20262
  getJSON(cssFileName, _modules, outputFileName) {
20249
20263
  modules = _modules;
@@ -21208,7 +21222,7 @@ const assetAttrsConfig = {
21208
21222
  const isAsyncScriptMap = new WeakMap();
21209
21223
  async function traverseHtml(html, filePath, visitor) {
21210
21224
  // lazy load compiler
21211
- const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-9b6b378f.js'); }).then(function (n) { return n.compilerDom_cjs; });
21225
+ const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-66b16601.js'); }).then(function (n) { return n.compilerDom_cjs; });
21212
21226
  // @vue/compiler-core doesn't like lowercase doctypes
21213
21227
  html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
21214
21228
  try {
@@ -29964,16 +29978,10 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
29964
29978
  }
29965
29979
  }
29966
29980
  function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSymlinks, tryPrefix, skipPackageJson) {
29967
- let isReadable = false;
29968
- try {
29969
- // #2051 if we don't have read permission on a directory, existsSync() still
29970
- // works and will result in massively slow subsequent checks (which are
29971
- // unnecessary in the first place)
29972
- fs__default.accessSync(file, fs__default.constants.R_OK);
29973
- isReadable = true;
29974
- }
29975
- catch (e) { }
29976
- if (isReadable) {
29981
+ // #2051 if we don't have read permission on a directory, existsSync() still
29982
+ // works and will result in massively slow subsequent checks (which are
29983
+ // unnecessary in the first place)
29984
+ if (isFileReadable(file)) {
29977
29985
  if (!fs__default.statSync(file).isDirectory()) {
29978
29986
  return getRealPath(file, preserveSymlinks) + postfix;
29979
29987
  }
@@ -42060,36 +42068,11 @@ function errorMiddleware(server, allowNext = false) {
42060
42068
  next();
42061
42069
  }
42062
42070
  else {
42063
- if (err instanceof AccessRestrictedError) {
42064
- res.statusCode = 403;
42065
- res.write(renderErrorHTML(err.message));
42066
- res.end();
42067
- }
42068
42071
  res.statusCode = 500;
42069
42072
  res.end();
42070
42073
  }
42071
42074
  };
42072
42075
  }
42073
- class AccessRestrictedError extends Error {
42074
- constructor(msg) {
42075
- super(msg);
42076
- }
42077
- }
42078
- function renderErrorHTML(msg) {
42079
- // to have syntax highlighting and autocompletion in IDE
42080
- const html = String.raw;
42081
- return html `
42082
- <body>
42083
- <h1>403 Restricted</h1>
42084
- <p>${msg.replace(/\n/g, '<br/>')}</p>
42085
- <style>
42086
- body {
42087
- padding: 1em 2em;
42088
- }
42089
- </style>
42090
- </body>
42091
- `;
42092
- }
42093
42076
 
42094
42077
  /**
42095
42078
  * This file is refactored into TypeScript based on
@@ -42877,7 +42860,7 @@ function loadFallbackPlugin() {
42877
42860
  name: 'vite:load-fallback',
42878
42861
  async load(id) {
42879
42862
  try {
42880
- return fs$r.promises.readFile(cleanUrl(id), 'utf-8');
42863
+ return await fs$r.promises.readFile(cleanUrl(id), 'utf-8');
42881
42864
  }
42882
42865
  catch (e) {
42883
42866
  return fs$r.promises.readFile(id, 'utf-8');
@@ -43041,6 +43024,7 @@ async function doBuild(inlineConfig = {}) {
43041
43024
  const rollup = require('rollup');
43042
43025
  const rollupOptions = {
43043
43026
  input,
43027
+ context: 'globalThis',
43044
43028
  preserveEntrySignatures: ssr
43045
43029
  ? 'allow-extension'
43046
43030
  : libOptions
@@ -49054,7 +49038,7 @@ function readFileIfExists(value) {
49054
49038
  * https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
49055
49039
  */
49056
49040
  async function createCertificate() {
49057
- const { generate } = await Promise.resolve().then(function () { return require('./dep-b502d052.js'); }).then(function (n) { return n.index; });
49041
+ const { generate } = await Promise.resolve().then(function () { return require('./dep-7113cb3d.js'); }).then(function (n) { return n.index; });
49058
49042
  const pems = generate(null, {
49059
49043
  algorithm: 'sha256',
49060
49044
  days: 30,
@@ -56147,6 +56131,14 @@ function walk(root, { onIdentifier, onImportMeta, onDynamicImport }) {
56147
56131
  }
56148
56132
  }
56149
56133
  else if (isFunction(node)) {
56134
+ // If it is a function declaration, it could be shadowing an import
56135
+ // Add its name to the scope so it won't get replaced
56136
+ if (node.type === 'FunctionDeclaration') {
56137
+ const parentFunction = findParentFunction(parentStack);
56138
+ if (parentFunction) {
56139
+ setScope(parentFunction, node.id.name);
56140
+ }
56141
+ }
56150
56142
  // walk function expressions and add its arguments to known identifiers
56151
56143
  // so that we don't prefix them
56152
56144
  node.params.forEach((p) => walk$1(p.type === 'AssignmentPattern' ? p.left : p, {
@@ -56281,6 +56273,10 @@ const isDebug$3 = !!process.env.DEBUG;
56281
56273
  const debug$4 = createDebugger('vite:sourcemap', {
56282
56274
  onlyWhenFocused: true
56283
56275
  });
56276
+ // Virtual modules should be prefixed with a null byte to avoid a
56277
+ // false positive "missing source" warning. We also check for certain
56278
+ // prefixes used for special handling in esbuildDepPlugin.
56279
+ const virtualSourceRE = /^(\0|dep:|browser-external:)/;
56284
56280
  async function injectSourcesContent(map, file, logger) {
56285
56281
  let sourceRoot;
56286
56282
  try {
@@ -56290,7 +56286,7 @@ async function injectSourcesContent(map, file, logger) {
56290
56286
  catch { }
56291
56287
  const missingSources = [];
56292
56288
  map.sourcesContent = await Promise.all(map.sources.map((sourcePath) => {
56293
- if (sourcePath) {
56289
+ if (sourcePath && !virtualSourceRE.test(sourcePath)) {
56294
56290
  sourcePath = decodeURI(sourcePath);
56295
56291
  if (sourceRoot) {
56296
56292
  sourcePath = path__default.resolve(sourceRoot, sourcePath);
@@ -56568,22 +56564,24 @@ function servePublicMiddleware(dir) {
56568
56564
  serve(req, res, next);
56569
56565
  };
56570
56566
  }
56571
- function serveStaticMiddleware(dir, config) {
56567
+ function serveStaticMiddleware(dir, server) {
56572
56568
  const serve = sirv(dir, sirvOptions);
56573
56569
  // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
56574
56570
  return function viteServeStaticMiddleware(req, res, next) {
56575
- // only serve the file if it's not an html request
56571
+ // only serve the file if it's not an html request or ends with `/`
56576
56572
  // so that html requests can fallthrough to our html middleware for
56577
56573
  // special processing
56578
56574
  // also skip internal requests `/@fs/ /@vite-client` etc...
56579
- if (path__default.extname(cleanUrl(req.url)) === '.html' ||
56575
+ const cleanedUrl = cleanUrl(req.url);
56576
+ if (cleanedUrl.endsWith('/') ||
56577
+ path__default.extname(cleanedUrl) === '.html' ||
56580
56578
  isInternalRequest(req.url)) {
56581
56579
  return next();
56582
56580
  }
56583
56581
  const url = decodeURI(req.url);
56584
56582
  // apply aliases to static requests as well
56585
56583
  let redirected;
56586
- for (const { find, replacement } of config.resolve.alias) {
56584
+ for (const { find, replacement } of server.config.resolve.alias) {
56587
56585
  const matches = typeof find === 'string' ? url.startsWith(find) : find.test(url);
56588
56586
  if (matches) {
56589
56587
  redirected = url.replace(find, replacement);
@@ -56595,6 +56593,16 @@ function serveStaticMiddleware(dir, config) {
56595
56593
  if (redirected.startsWith(dir)) {
56596
56594
  redirected = redirected.slice(dir.length);
56597
56595
  }
56596
+ }
56597
+ const resolvedUrl = redirected || url;
56598
+ let fileUrl = path__default.resolve(dir, resolvedUrl.replace(/^\//, ''));
56599
+ if (resolvedUrl.endsWith('/') && !fileUrl.endsWith('/')) {
56600
+ fileUrl = fileUrl + '/';
56601
+ }
56602
+ if (!ensureServingAccess(fileUrl, server, res, next)) {
56603
+ return;
56604
+ }
56605
+ if (redirected) {
56598
56606
  req.url = redirected;
56599
56607
  }
56600
56608
  serve(req, res, next);
@@ -56611,7 +56619,9 @@ function serveRawFsMiddleware(server) {
56611
56619
  // searching based from fs root.
56612
56620
  if (url.startsWith(FS_PREFIX)) {
56613
56621
  // restrict files outside of `fs.allow`
56614
- ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server);
56622
+ if (!ensureServingAccess(slash$3(path__default.resolve(fsPathFromId(url))), server, res, next)) {
56623
+ return;
56624
+ }
56615
56625
  url = url.slice(FS_PREFIX.length);
56616
56626
  if (isWindows$4)
56617
56627
  url = url.replace(/^[A-Z]:/i, '');
@@ -56627,29 +56637,60 @@ function isFileServingAllowed(url, server) {
56627
56637
  // explicitly disabled
56628
56638
  if (server.config.server.fs.strict === false)
56629
56639
  return true;
56630
- const file = ensureLeadingSlash(normalizePath$4(cleanUrl(url)));
56640
+ const cleanedUrl = cleanUrl(url);
56641
+ const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
56631
56642
  if (server.moduleGraph.safeModulesPath.has(file))
56632
56643
  return true;
56633
56644
  if (server.config.server.fs.allow.some((i) => file.startsWith(i + '/')))
56634
56645
  return true;
56635
56646
  if (!server.config.server.fs.strict) {
56636
- server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56637
- server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56638
- `be restricted by default in the future version of Vite. ` +
56639
- `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56647
+ if (isFileReadable(cleanedUrl)) {
56648
+ server.config.logger.warnOnce(`Unrestricted file system access to "${url}"`);
56649
+ server.config.logger.warnOnce(`For security concerns, accessing files outside of serving allow list will ` +
56650
+ `be restricted by default in the future version of Vite. ` +
56651
+ `Refer to https://vitejs.dev/config/#server-fs-allow for more details.`);
56652
+ }
56640
56653
  return true;
56641
56654
  }
56642
56655
  return false;
56643
56656
  }
56644
- function ensureServingAccess(url, server) {
56645
- if (!isFileServingAllowed(url, server)) {
56646
- const allow = server.config.server.fs.allow;
56647
- throw new AccessRestrictedError(`The request url "${url}" is outside of Vite serving allow list:
56648
-
56649
- ${allow.map((i) => `- ${i}`).join('\n')}
56657
+ function ensureServingAccess(url, server, res, next) {
56658
+ if (isFileServingAllowed(url, server)) {
56659
+ return true;
56660
+ }
56661
+ if (isFileReadable(cleanUrl(url))) {
56662
+ const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
56663
+ const hintMessage = `
56664
+ ${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
56650
56665
 
56651
- Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`);
56666
+ Refer to docs https://vitejs.dev/config/#server-fs-allow for configurations and more details.`;
56667
+ server.config.logger.error(urlMessage);
56668
+ server.config.logger.warnOnce(hintMessage + '\n');
56669
+ res.statusCode = 403;
56670
+ res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
56671
+ res.end();
56672
+ }
56673
+ else {
56674
+ // if the file doesn't exist, we shouldn't restrict this path as it can
56675
+ // be an API call. Middlewares would issue a 404 if the file isn't handled
56676
+ next();
56652
56677
  }
56678
+ return false;
56679
+ }
56680
+ function renderRestrictedErrorHTML(msg) {
56681
+ // to have syntax highlighting and autocompletion in IDE
56682
+ const html = String.raw;
56683
+ return html `
56684
+ <body>
56685
+ <h1>403 Restricted</h1>
56686
+ <p>${msg.replace(/\n/g, '<br/>')}</p>
56687
+ <style>
56688
+ body {
56689
+ padding: 1em 2em;
56690
+ }
56691
+ </style>
56692
+ </body>
56693
+ `;
56653
56694
  }
56654
56695
 
56655
56696
  const debugLoad = createDebugger('vite:load');
@@ -57250,7 +57291,6 @@ async function handleHMRUpdate(file, server) {
57250
57291
  const filteredModules = await plugin.handleHotUpdate(hmrContext);
57251
57292
  if (filteredModules) {
57252
57293
  hmrContext.modules = filteredModules;
57253
- break;
57254
57294
  }
57255
57295
  }
57256
57296
  }
@@ -66618,10 +66658,7 @@ const ROOT_FILES = [
66618
66658
  // yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
66619
66659
  function hasWorkspacePackageJSON(root) {
66620
66660
  const path = path$t.join(root, 'package.json');
66621
- try {
66622
- fs__default.accessSync(path, fs__default.constants.R_OK);
66623
- }
66624
- catch {
66661
+ if (!isFileReadable(path)) {
66625
66662
  return false;
66626
66663
  }
66627
66664
  const content = JSON.parse(fs__default.readFileSync(path, 'utf-8')) || {};
@@ -66839,7 +66876,7 @@ async function createServer(inlineConfig = {}) {
66839
66876
  middlewares.use(transformMiddleware(server));
66840
66877
  // serve static files
66841
66878
  middlewares.use(serveRawFsMiddleware(server));
66842
- middlewares.use(serveStaticMiddleware(root, config));
66879
+ middlewares.use(serveStaticMiddleware(root, server));
66843
66880
  // spa fallback
66844
66881
  if (!middlewareMode || middlewareMode === 'html') {
66845
66882
  middlewares.use(spaFallbackMiddleware(root));
@@ -92052,4 +92089,4 @@ exports.send = send$1;
92052
92089
  exports.sortUserPlugins = sortUserPlugins;
92053
92090
  exports.source = source;
92054
92091
  exports.transformWithEsbuild = transformWithEsbuild;
92055
- //# sourceMappingURL=dep-be032392.js.map
92092
+ //# sourceMappingURL=dep-e0fe87f8.js.map