Alias
// aliased to an absolute URL in CJS, should be optimized import { isFunction } from '@vue/shared' + // also check name clash for aliased deps + export { isFunction } from '@vue/shared' console.log(isFunction(() => {})) diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index ead0c3a70d8e10..cd01caa7cf1a90 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -10,7 +10,7 @@ }, "devDependencies": { "sass": "^1.53.0", - "tailwindcss": "^3.1.4", + "tailwindcss": "^3.1.6", "fast-glob": "^3.2.11" } } diff --git a/playground/build-old/__tests__/build-old.spec.ts b/playground/build-old/__tests__/build-old.spec.ts new file mode 100644 index 00000000000000..085d1bbe75b986 --- /dev/null +++ b/playground/build-old/__tests__/build-old.spec.ts @@ -0,0 +1,11 @@ +import { describe, test } from 'vitest' +import { page } from '~utils' + +describe('syntax preserve', () => { + test('import.meta.url', async () => { + expect(await page.textContent('.import-meta-url')).toBe('string') + }) + test('dynamic import', async () => { + expect(await page.textContent('.dynamic-import')).toBe('success') + }) +}) diff --git a/playground/build-old/dynamic.js b/playground/build-old/dynamic.js new file mode 100644 index 00000000000000..739bb26e01b765 --- /dev/null +++ b/playground/build-old/dynamic.js @@ -0,0 +1 @@ +export default 'success' diff --git a/playground/build-old/index.html b/playground/build-old/index.html new file mode 100644 index 00000000000000..118332ac0a42fc --- /dev/null +++ b/playground/build-old/index.html @@ -0,0 +1,19 @@ +Build Old
+ +import meta url
+ + +dynamic import
+ + + diff --git a/playground/build-old/package.json b/playground/build-old/package.json new file mode 100644 index 00000000000000..bb7f1b9b861538 --- /dev/null +++ b/playground/build-old/package.json @@ -0,0 +1,11 @@ +{ + "name": "test-build-old", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", + "preview": "vite preview" + } +} diff --git a/playground/build-old/vite.config.js b/playground/build-old/vite.config.js new file mode 100644 index 00000000000000..aa85af55972eb1 --- /dev/null +++ b/playground/build-old/vite.config.js @@ -0,0 +1,8 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + build: { + // old browsers only + target: ['chrome60'] + } +}) diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts index 5b7114c07f46cd..31425a19fc2c98 100644 --- a/playground/css/__tests__/css.spec.ts +++ b/playground/css/__tests__/css.spec.ts @@ -349,8 +349,7 @@ test('PostCSS dir-dependency', async () => { } }) -// skip because #8278 is reverted -test.skip('import dependency includes css import', async () => { +test('import dependency includes css import', async () => { expect(await getColor('.css-js-dep')).toBe('green') expect(await getColor('.css-js-dep-module')).toBe('green') }) @@ -437,9 +436,16 @@ test('PostCSS source.input.from includes query', async () => { ) }) -// skip because #8278 is reverted -test.skip('aliased css has content', async () => { +test('aliased css has content', async () => { expect(await getColor('.aliased')).toBe('blue') - expect(await page.textContent('.aliased-content')).toMatch('.aliased') + // skipped: currently not supported see #8936 + // expect(await page.textContent('.aliased-content')).toMatch('.aliased') expect(await getColor('.aliased-module')).toBe('blue') }) + +test.runIf(isBuild)('warning can be suppressed by esbuild.logOverride', () => { + serverLogs.forEach((log) => { + // no warning from esbuild css minifier + expect(log).not.toMatch('unsupported-css-property') + }) +}) diff --git a/playground/css/main.js b/playground/css/main.js index c9384b6a79013c..45e7730b868eb1 100644 --- a/playground/css/main.js +++ b/playground/css/main.js @@ -104,3 +104,5 @@ import aliasModule from '#alias-module' document .querySelector('.aliased-module') .classList.add(aliasModule.aliasedModule) + +import './unsupported.css' diff --git a/playground/css/unsupported.css b/playground/css/unsupported.css new file mode 100644 index 00000000000000..c17818a3ab33d7 --- /dev/null +++ b/playground/css/unsupported.css @@ -0,0 +1,3 @@ +.unsupported { + overflow-x: hidden; +} diff --git a/playground/css/vite.config.js b/playground/css/vite.config.js index c501213b47cded..704eb134e25880 100644 --- a/playground/css/vite.config.js +++ b/playground/css/vite.config.js @@ -7,6 +7,11 @@ module.exports = { build: { cssTarget: 'chrome61' }, + esbuild: { + logOverride: { + 'unsupported-css-property': 'silent' + } + }, resolve: { alias: { '@': __dirname, diff --git a/playground/fs-serve/__tests__/fs-serve.spec.ts b/playground/fs-serve/__tests__/fs-serve.spec.ts index 2111cac80cc4e7..142b4ac9ca3131 100644 --- a/playground/fs-serve/__tests__/fs-serve.spec.ts +++ b/playground/fs-serve/__tests__/fs-serve.spec.ts @@ -21,6 +21,11 @@ describe.runIf(isServe)('main', () => { expect(await page.textContent('.safe-fetch-status')).toBe('200') }) + test('safe fetch with query', async () => { + expect(await page.textContent('.safe-fetch-query')).toMatch('KEY=safe') + expect(await page.textContent('.safe-fetch-query-status')).toBe('200') + }) + test('safe fetch with special characters', async () => { expect( await page.textContent('.safe-fetch-subdir-special-characters') @@ -42,11 +47,21 @@ describe.runIf(isServe)('main', () => { expect(await page.textContent('.unsafe-fetch-8498-status')).toBe('403') }) + test('unsafe fetch with special characters 2 (#8498)', async () => { + expect(await page.textContent('.unsafe-fetch-8498-2')).toMatch('') + expect(await page.textContent('.unsafe-fetch-8498-2-status')).toBe('404') + }) + test('safe fs fetch', async () => { expect(await page.textContent('.safe-fs-fetch')).toBe(stringified) expect(await page.textContent('.safe-fs-fetch-status')).toBe('200') }) + test('safe fs fetch', async () => { + expect(await page.textContent('.safe-fs-fetch-query')).toBe(stringified) + expect(await page.textContent('.safe-fs-fetch-query-status')).toBe('200') + }) + test('safe fs fetch with special characters', async () => { expect(await page.textContent('.safe-fs-fetch-special-characters')).toBe( stringified @@ -64,6 +79,11 @@ describe.runIf(isServe)('main', () => { expect(await page.textContent('.unsafe-fs-fetch-8498-status')).toBe('403') }) + test('unsafe fs fetch with special characters 2 (#8498)', async () => { + expect(await page.textContent('.unsafe-fs-fetch-8498-2')).toBe('') + expect(await page.textContent('.unsafe-fs-fetch-8498-2-status')).toBe('404') + }) + test('nested entry', async () => { expect(await page.textContent('.nested-entry')).toBe('foobar') }) diff --git a/playground/fs-serve/root/src/index.html b/playground/fs-serve/root/src/index.html index 6939e0f4b09ed9..95b31e73d72ea6 100644 --- a/playground/fs-serve/root/src/index.html +++ b/playground/fs-serve/root/src/index.html @@ -7,6 +7,8 @@Normal Import
Safe Fetch
+ +Safe Fetch Subdirectory
@@ -19,10 +21,14 @@Unsafe Fetch
+ +Safe /@fs/ Fetch
+ + @@ -31,6 +37,8 @@Unsafe /@fs/ Fetch
+ +Nested Entry
@@ -54,6 +62,17 @@Denied
.then((data) => { text('.safe-fetch', JSON.stringify(data)) }) + + // inside allowed dir with query, safe fetch + fetch('/src/safe.txt?query') + .then((r) => { + text('.safe-fetch-query-status', r.status) + return r.text() + }) + .then((data) => { + text('.safe-fetch-query', JSON.stringify(data)) + }) + // inside allowed dir, safe fetch fetch('/src/subdir/safe.txt') .then((r) => { @@ -100,6 +119,19 @@Denied
console.error(e) }) + // outside of allowed dir with special characters 2 #8498 + fetch('/src/%252e%252e%252funsafe%252etxt') + .then((r) => { + text('.unsafe-fetch-8498-2-status', r.status) + return r.text() + }) + .then((data) => { + text('.unsafe-fetch-8498-2', data) + }) + .catch((e) => { + console.error(e) + }) + // imported before, should be treated as safe fetch('/@fs/' + ROOT + '/safe.json') .then((r) => { @@ -110,6 +142,16 @@Denied
text('.safe-fs-fetch', JSON.stringify(data)) }) + // imported before with query, should be treated as safe + fetch('/@fs/' + ROOT + '/safe.json?query') + .then((r) => { + text('.safe-fs-fetch-query-status', r.status) + return r.json() + }) + .then((data) => { + text('.safe-fs-fetch-query', JSON.stringify(data)) + }) + // not imported before, outside of root, treated as unsafe fetch('/@fs/' + ROOT + '/unsafe.json') .then((r) => { @@ -133,6 +175,18 @@Denied
text('.unsafe-fs-fetch-8498', JSON.stringify(data)) }) + // outside root with special characters 2 #8498 + fetch( + '/@fs/' + ROOT + '/root/src/%252e%252e%252f%252e%252e%252funsafe%252ejson' + ) + .then((r) => { + text('.unsafe-fs-fetch-8498-2-status', r.status) + return r.json() + }) + .then((data) => { + text('.unsafe-fs-fetch-8498-2', JSON.stringify(data)) + }) + // not imported before, inside root with special characters, treated as safe fetch( '/@fs/' + diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index 7b9b0aa622381e..27c8dd716d0358 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -92,6 +92,12 @@ test('import glob raw', async () => { ) }) +test('import property access', async () => { + expect(await page.textContent('.property-access')).toBe( + JSON.stringify(rawResult['/dir/baz.json'], null, 2) + ) +}) + test('import relative glob raw', async () => { expect(await page.textContent('.relative-glob-raw')).toBe( JSON.stringify(relativeRawResult, null, 2) diff --git a/playground/glob-import/index.html b/playground/glob-import/index.html index ca00c065e7402d..a0ac2d866699ae 100644 --- a/playground/glob-import/index.html +++ b/playground/glob-import/index.html @@ -1,8 +1,17 @@ +Glob import
+Normal
+Eager
+node_modules
+Raw
+Property access
+ +Relative raw
+Side effect
@@ -63,6 +72,18 @@ ) + + diff --git a/playground/import-assertion/package.json b/playground/import-assertion/package.json new file mode 100644 index 00000000000000..68128c59993ffb --- /dev/null +++ b/playground/import-assertion/package.json @@ -0,0 +1,14 @@ +{ + "name": "test-import-assertion", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../packages/vite/bin/vite", + "preview": "vite preview" + }, + "dependencies": { + "@vitejs/import-assertion-dep": "file:./import-assertion-dep" + } +} diff --git a/playground/import-assertion/vite.config.js b/playground/import-assertion/vite.config.js new file mode 100644 index 00000000000000..13a5b43e3c7946 --- /dev/null +++ b/playground/import-assertion/vite.config.js @@ -0,0 +1,12 @@ +import { defineConfig } from 'vite' + +export default defineConfig({ + build: { + commonjsOptions: { + include: [] + } + }, + optimizeDeps: { + disabled: false + } +}) diff --git a/playground/legacy/package.json b/playground/legacy/package.json index 4d6549302951df..678d47745696b4 100644 --- a/playground/legacy/package.json +++ b/playground/legacy/package.json @@ -13,6 +13,6 @@ "devDependencies": { "@vitejs/plugin-legacy": "workspace:*", "express": "^4.18.1", - "terser": "^5.14.1" + "terser": "^5.14.2" } } diff --git a/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts index b0af6debca526e..a62b4525e057be 100644 --- a/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -105,14 +105,11 @@ test('vue + vuex', async () => { // When we use the Rollup CommonJS plugin instead of esbuild prebundling, // the esbuild plugins won't apply to dependencies -test.skipIf(isBuild && process.env.VITE_TEST_LEGACY_CJS_PLUGIN)( - 'esbuild-plugin', - async () => { - expect(await page.textContent('.esbuild-plugin')).toMatch( - `Hello from an esbuild plugin` - ) - } -) +test('esbuild-plugin', async () => { + expect(await page.textContent('.esbuild-plugin')).toMatch( + `Hello from an esbuild plugin` + ) +}) test('import from hidden dir', async () => { expect(await page.textContent('.hidden-dir')).toBe('hello!') diff --git a/playground/optimize-deps/cjs.js b/playground/optimize-deps/cjs.js index 53da284e0dc8d2..9a4651d6ad4008 100644 --- a/playground/optimize-deps/cjs.js +++ b/playground/optimize-deps/cjs.js @@ -6,6 +6,11 @@ import ReactDOM from 'react-dom/client' import { Socket } from 'phoenix' import clip from 'clipboard' +// Test exporting a name that was already imported +export { useState } from 'react' +export { useState as anotherNameForUseState } from 'react' +export { default as React } from 'react' + if (typeof clip === 'function') { text('.cjs-clipboard', 'ok') } diff --git a/playground/optimize-deps/package.json b/playground/optimize-deps/package.json index 7fbb2b6577d69f..19184eb8af8c77 100644 --- a/playground/optimize-deps/package.json +++ b/playground/optimize-deps/package.json @@ -26,7 +26,7 @@ "added-in-entries": "file:./added-in-entries", "lodash-es": "^4.17.21", "nested-exclude": "file:./nested-exclude", - "phoenix": "^1.6.10", + "phoenix": "^1.6.11", "react": "^18.2.0", "react-dom": "^18.2.0", "resolve-linked": "workspace:0.0.0", diff --git a/playground/optimize-deps/vite.config.js b/playground/optimize-deps/vite.config.js index 0b857173fe1e83..091f994e2c6aec 100644 --- a/playground/optimize-deps/vite.config.js +++ b/playground/optimize-deps/vite.config.js @@ -14,8 +14,8 @@ module.exports = { 'node:url': 'url' } }, - optimizeDeps: { + disabled: false, include: [ 'dep-linked-include', 'nested-exclude > nested-include', @@ -44,7 +44,11 @@ module.exports = { build: { // to make tests faster - minify: false + minify: false, + // Avoid @rollup/plugin-commonjs + commonjsOptions: { + include: [] + } }, plugins: [ diff --git a/playground/preload/package.json b/playground/preload/package.json index c72b346dece591..a42f414575cd22 100644 --- a/playground/preload/package.json +++ b/playground/preload/package.json @@ -10,11 +10,11 @@ }, "dependencies": { "vue": "^3.2.37", - "vue-router": "^4.0.16" + "vue-router": "^4.1.2" }, "devDependencies": { "@vitejs/plugin-vue": "workspace:*", - "terser": "^5.14.1", + "terser": "^5.14.2", "dep-a": "file:./dep-a", "dep-including-a": "file:./dep-including-a" } diff --git a/playground/react-emotion/package.json b/playground/react-emotion/package.json index 7ef711da793e2c..c9b77a7374df8d 100644 --- a/playground/react-emotion/package.json +++ b/playground/react-emotion/package.json @@ -15,7 +15,7 @@ "react-switch": "^7.0.0" }, "devDependencies": { - "@babel/plugin-proposal-pipeline-operator": "^7.18.6", + "@babel/plugin-proposal-pipeline-operator": "^7.18.9", "@emotion/babel-plugin": "^11.9.2", "@vitejs/plugin-react": "workspace:*" }, diff --git a/playground/react-sourcemap/App.jsx b/playground/react-sourcemap/App.jsx new file mode 100644 index 00000000000000..ec47ca46ad212e --- /dev/null +++ b/playground/react-sourcemap/App.jsx @@ -0,0 +1,8 @@ +console.log('App.jsx 1') // for sourcemap +function App() { + returnfail
++ A ts module can import another ESM module using its corresponding mjs file + name +
+fail
+ ++ A ts module can import another CommonJS module using its corresponding cjs + file name +
+fail
+Resolve file name containing dot
fail
+Resolve drive-relative path (Windows only)
+fail
+ +Resolve absolute path
+fail
+Browser Field
fail
@@ -70,6 +88,9 @@