diff --git a/.eslintrc.js b/.eslintrc.js index 77b30694c234b6..edf6be5da94729 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,7 @@ module.exports = { 'node/no-missing-import': [ 'error', { - allowModules: ['types', 'estree', 'testUtils'], + allowModules: ['types', 'estree', 'testUtils', 'stylus'], tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] } ], @@ -31,7 +31,7 @@ module.exports = { message: `devDependencies can only be imported using ESM syntax so ` + `that they are included in the rollup bundle. If you are trying to ` + - `lazy load a dep, use (await import('dep')).default instead.` + `lazy load a dependency, use (await import('dependency')).default instead.` }) ) ], diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 5d7a1f5413ca4c..c81c77e4875a95 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -2,7 +2,7 @@ name: "\U0001F680 New feature proposal" about: Propose a new feature to be added to Vite title: '' -labels: 'feat: pending triage' +labels: 'enhancement: pending triage' assignees: '' --- diff --git a/docs/config/index.md b/docs/config/index.md index 86a6b7ca41a81f..2b1d614dc32536 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -417,7 +417,7 @@ export default ({ command, mode }) => { The transform is performed with esbuild and the value should be a valid [esbuild target option](https://esbuild.github.io/api/#target). Custom targets can either be a ES version (e.g. `es2015`), a browser with version (e.g. `chrome58`), or an array of multiple target strings. - Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuid docs](https://esbuild.github.io/content-types/#javascript) for more details. + Note the build will fail if the code contains features that cannot be safely transpiled by esbuild. See [esbuild docs](https://esbuild.github.io/content-types/#javascript) for more details. ### build.polyfillDynamicImport @@ -569,6 +569,15 @@ export default ({ command, mode }) => { By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. +### optimizeDeps.keepNames + +- **Type:** `boolean` +- **Default:** `false` + + The bundler sometimes needs to rename symbols to avoid collisions. + Set this to `true` to keep the `name` property on functions and classes. + See [`keepNames`](https://esbuild.github.io/api/#keep-names). + ## SSR Options :::warning Experimental diff --git a/docs/guide/comparisons.md b/docs/guide/comparisons.md index f68319696a986e..3e944d9b23aba5 100644 --- a/docs/guide/comparisons.md +++ b/docs/guide/comparisons.md @@ -39,7 +39,7 @@ Vite was initially created to serve as the future foundation of [Vue.js](https:/ [WMR](https://github.com/preactjs/wmr) by the Preact team provides a similar feature set, and Vite 2.0's support for Rollup's plugin interface is inspired by it. -WMR is mainly designed for [Preact](https://preactjs.com/) projects, and offers more integrated features such as pre-rendering. In terms of scope, it's closer to a Preact meta framework, with the same emphasis on compact size as Preact itself. If you are using Preact, WMR is likely going to offer a more fine-tuned experience. However, it's unlikely for WMR to prioritize support for other frameworks. +WMR is mainly designed for [Preact](https://preactjs.com/) projects, and offers more integrated features such as pre-rendering. In terms of scope, it's closer to a Preact meta framework, with the same emphasis on compact size as Preact itself. If you are using Preact, WMR is likely going to offer a more fine-tuned experience. ## @web/dev-server diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index 819b2b433ce439..3de339465ae0c0 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,11 @@ +## [2.2.2](https://github.com/vitejs/vite/compare/create-app@2.2.1...create-app@2.2.2) (2021-03-25) + + + +## [2.2.1](https://github.com/vitejs/vite/compare/create-app@2.2.0...create-app@2.2.1) (2021-03-25) + + + # [2.2.0](https://github.com/vitejs/vite/compare/create-app@2.1.0...create-app@2.2.0) (2021-03-16) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 8f3524b5030e03..877fbb4b7dc4a9 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "2.2.0", + "version": "2.2.2", "license": "MIT", "author": "Evan You", "bin": { @@ -21,7 +21,8 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/vitejs/vite.git" + "url": "git+https://github.com/vitejs/vite.git", + "directory": "packages/create-app" }, "bugs": { "url": "https://github.com/vitejs/vite/issues" diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index 26f4bb50dfed7a..ae88cc044970da 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -18,7 +18,7 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.1.0", + "vite": "^2.1.3", "typescript": "^4.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json index 50e3f1ef3897db..94b98007ae8389 100644 --- a/packages/create-app/template-lit-element/package.json +++ b/packages/create-app/template-lit-element/package.json @@ -16,6 +16,6 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 50b2ab0a60e20a..97beb965b95440 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@preact/preset-vite": "^2.0.0", "typescript": "^4.1.3", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index 247311f78d3bd7..275575ed65dc27 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.0.0", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index 31caf280489db5..2ae4fa2e2885b4 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -15,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.3.1", "typescript": "^4.1.2", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 9abf4a6cc05d5d..9c5af4769fc06d 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.3.1", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-svelte-ts/package.json b/packages/create-app/template-svelte-ts/package.json index 42909c008923cd..17ae9bd3a6a934 100644 --- a/packages/create-app/template-svelte-ts/package.json +++ b/packages/create-app/template-svelte-ts/package.json @@ -11,6 +11,6 @@ "svelte": "^3.35.0", "svelte-preprocess": "^4.6.9", "typescript": "^4.2.3", - "vite": "^2.1.2" + "vite": "^2.1.3" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-svelte/package.json b/packages/create-app/template-svelte/package.json index e9c02f90d0bba0..ea8852a6219fb3 100644 --- a/packages/create-app/template-svelte/package.json +++ b/packages/create-app/template-svelte/package.json @@ -9,6 +9,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "next", "svelte": "^3.35.0", - "vite": "^2.1.2" + "vite": "^2.1.3" } -} +} \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index 7b671abfdb1087..0336bcb68802f6 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -7,6 +7,6 @@ "serve": "vite preview" }, "devDependencies": { - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index 3a557f747a395b..e08b516a0e2f69 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -13,7 +13,7 @@ "@vitejs/plugin-vue": "^1.1.5", "@vue/compiler-sfc": "^3.0.5", "typescript": "^4.1.3", - "vite": "^2.1.0", - "vue-tsc": "^0.0.8" + "vite": "^2.1.3", + "vue-tsc": "^0.0.15" } -} \ No newline at end of file +} diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index 3cff059b7294a2..3da544228de86f 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@vitejs/plugin-vue": "^1.1.5", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.1.0" + "vite": "^2.1.3" } } \ No newline at end of file diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index d76e350b2e4c69..2f047851e9af5d 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -9,6 +9,6 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.0.5" + "vue": "^3.0.8" } } diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index cc0047dd736ca4..b640d95f294c49 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -5,7 +5,8 @@ import { getColor, isBuild, listAssets, - readManifest + readManifest, + readFile } from '../../testUtils' const assetMatch = isBuild @@ -180,7 +181,7 @@ test('?raw import', async () => { }) test('?url import', async () => { - const src = `console.log('hi')\n` + const src = readFile('foo.js') expect(await page.textContent('.url')).toMatch( isBuild ? `data:application/javascript;base64,${Buffer.from(src).toString( diff --git a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts index fa97cc1393f28a..32333059ad7381 100644 --- a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts +++ b/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts @@ -1,29 +1,31 @@ -import { untilUpdated } from '../../testUtils' +import { isBuild, untilUpdated } from '../../testUtils' test('should load literal dynamic import', async () => { await page.click('.baz') - await untilUpdated(() => page.textContent('.view'), 'Baz view') + await untilUpdated(() => page.textContent('.view'), 'Baz view', true) }) test('should load full dynamic import from public', async () => { await page.click('.qux') - await untilUpdated(() => page.textContent('.view'), 'Qux view') + await untilUpdated(() => page.textContent('.view'), 'Qux view', true) +}) + +test('should load data URL of `blob:`', async () => { + await page.click('.issue-2658-1') + await untilUpdated(() => page.textContent('.view'), 'blob', true) +}) + +test('should load data URL of `data:`', async () => { + await page.click('.issue-2658-2') + await untilUpdated(() => page.textContent('.view'), 'data', true) }) // since this test has a timeout, it should be put last so that it // does not bleed on the last test('should load dynamic import with vars', async () => { await page.click('.foo') - await untilUpdated(() => page.textContent('.view'), 'Foo view') + await untilUpdated(() => page.textContent('.view'), 'Foo view', true) - // first page click will not load the remote message - // because vite needs to compile the lodash dependency await page.click('.bar') - await untilUpdated(() => page.textContent('.view'), '') - - // wait until reload and click again - setTimeout(async () => { - await page.click('.bar') - await untilUpdated(() => page.textContent('.view'), 'Bar view') - }, 10) + await untilUpdated(() => page.textContent('.view'), 'Bar view', true) }) diff --git a/packages/playground/dynamic-import/index.html b/packages/playground/dynamic-import/index.html index ad5e7ab57c98b7..87bb6ebdaa37e8 100644 --- a/packages/playground/dynamic-import/index.html +++ b/packages/playground/dynamic-import/index.html @@ -2,6 +2,8 @@ + +
diff --git a/packages/playground/dynamic-import/nested/index.js b/packages/playground/dynamic-import/nested/index.js index 383e51f3d5dfdd..cc6522016fc1d8 100644 --- a/packages/playground/dynamic-import/nested/index.js +++ b/packages/playground/dynamic-import/nested/index.js @@ -21,6 +21,26 @@ document.querySelector('.qux').addEventListener('click', async () => { text('.view', msg) }) +// data URLs (`blob:`) +const code1 = 'export const msg = "blob"' +const blob = new Blob([code1], { type: 'text/javascript;charset=UTF-8' }) +// eslint-disable-next-line node/no-unsupported-features/node-builtins +const blobURL = URL.createObjectURL(blob) +document.querySelector('.issue-2658-1').addEventListener('click', async () => { + const { msg } = await import(/*@vite-ignore*/ blobURL) + text('.view', msg) +}) + +// data URLs (`data:`) +const code2 = 'export const msg = "data";' +const dataURL = `data:text/javascript;charset=utf-8,${encodeURIComponent( + code2 +)}` +document.querySelector('.issue-2658-2').addEventListener('click', async () => { + const { msg } = await import(/*@vite-ignore*/ dataURL) + text('.view', msg) +}) + function text(el, text) { document.querySelector(el).textContent = text } diff --git a/packages/playground/dynamic-import/package.json b/packages/playground/dynamic-import/package.json index 1bc86fbf6bf84e..91048d3c3b90a2 100644 --- a/packages/playground/dynamic-import/package.json +++ b/packages/playground/dynamic-import/package.json @@ -7,8 +7,5 @@ "build": "vite build", "debug": "node --inspect-brk ../../vite/bin/vite", "serve": "vite preview" - }, - "dependencies": { - "lodash": "4.17.21" } } diff --git a/packages/playground/dynamic-import/views/bar.js b/packages/playground/dynamic-import/views/bar.js index bf14cd33bceb5e..94401802f2dd50 100644 --- a/packages/playground/dynamic-import/views/bar.js +++ b/packages/playground/dynamic-import/views/bar.js @@ -1,5 +1 @@ -import { n } from '../nested/shared' -import { isBoolean } from 'lodash' -console.log('bar' + isBoolean(n)) - export const msg = 'Bar view' diff --git a/packages/playground/file-delete-restore/App.jsx b/packages/playground/file-delete-restore/App.jsx new file mode 100644 index 00000000000000..de41c853cdc3ed --- /dev/null +++ b/packages/playground/file-delete-restore/App.jsx @@ -0,0 +1,12 @@ +import { useState } from 'react' +import Child from './Child' + +function App() { + return ( +
+ +
+ ) +} + +export default App diff --git a/packages/playground/file-delete-restore/Child.jsx b/packages/playground/file-delete-restore/Child.jsx new file mode 100644 index 00000000000000..fa6e1aefb6d829 --- /dev/null +++ b/packages/playground/file-delete-restore/Child.jsx @@ -0,0 +1,3 @@ +export default function Child() { + return

Child state 1

+} diff --git a/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts b/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts new file mode 100644 index 00000000000000..24f1237efedeec --- /dev/null +++ b/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts @@ -0,0 +1,61 @@ +import { + editFile, + untilUpdated, + removeFile, + addFile, + isBuild +} from '../../testUtils' + +if (!isBuild) { + test('should hmr when file is deleted and restored', async () => { + await untilUpdated(() => page.textContent('p'), 'Child state 1') + + editFile('Child.jsx', (code) => + code.replace('Child state 1', 'Child state 2') + ) + + await untilUpdated(() => page.textContent('p'), 'Child state 2') + + editFile('App.jsx', (code) => + code + .replace(`import Child from './Child'`, '') + .replace(``, '

Child deleted

') + ) + removeFile('Child.jsx') + await untilUpdated(() => page.textContent('p'), 'Child deleted') + + // restore Child.jsx + addFile( + 'Child.jsx', + ` export default function Child() { + return

Child state 1

+ } + ` + ) + + // restore App.jsx + editFile( + 'App.jsx', + (code) => + `import { useState } from 'react' + import Child from './Child' + + function App() { + return ( +
+ +
+ ) + } + + export default App + ` + ) + + await untilUpdated(() => page.textContent('p'), 'Child state 1') + }) +} else { + test('dummy test to make jest happy', async () => { + // Your test suite must contain at least one test. + }) +} diff --git a/packages/playground/file-delete-restore/index.html b/packages/playground/file-delete-restore/index.html new file mode 100644 index 00000000000000..ce1b9213c82763 --- /dev/null +++ b/packages/playground/file-delete-restore/index.html @@ -0,0 +1,8 @@ +
+ diff --git a/packages/playground/file-delete-restore/package.json b/packages/playground/file-delete-restore/package.json new file mode 100644 index 00000000000000..702fde46288712 --- /dev/null +++ b/packages/playground/file-delete-restore/package.json @@ -0,0 +1,18 @@ +{ + "name": "test-file-delete-restore", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" + }, + "dependencies": { + "react": "^17.0.1", + "react-dom": "^17.0.1" + }, + "devDependencies": { + "@vitejs/plugin-react-refresh": "^1.3.1" + } +} diff --git a/packages/playground/file-delete-restore/vite.config.js b/packages/playground/file-delete-restore/vite.config.js new file mode 100644 index 00000000000000..3b2c12f9a6c159 --- /dev/null +++ b/packages/playground/file-delete-restore/vite.config.js @@ -0,0 +1,15 @@ +const reactRefresh = require('@vitejs/plugin-react-refresh') + +/** + * @type {import('vite').UserConfig} + */ +module.exports = { + plugins: [reactRefresh()], + build: { + // to make tests faster + minify: false + }, + esbuild: { + jsxInject: `import React from 'react'` + } +} diff --git a/packages/playground/optimize-deps/package.json b/packages/playground/optimize-deps/package.json index 36f7f564b521b8..db3a24ee39b068 100644 --- a/packages/playground/optimize-deps/package.json +++ b/packages/playground/optimize-deps/package.json @@ -18,7 +18,7 @@ "react": "^17.0.1", "react-dom": "^17.0.1", "resolve-linked": "0.0.0", - "vue": "^3.0.5", + "vue": "^3.0.8", "vuex": "^4.0.0-rc.2" } } diff --git a/packages/playground/resolve/__tests__/resolve.spec.ts b/packages/playground/resolve/__tests__/resolve.spec.ts index bdb90f66b2bb13..0bb7c238e77893 100644 --- a/packages/playground/resolve/__tests__/resolve.spec.ts +++ b/packages/playground/resolve/__tests__/resolve.spec.ts @@ -42,6 +42,14 @@ test('implicit dir/index.js vs explicit file', async () => { expect(await page.textContent('.dir-vs-file')).toMatch('[success]') }) +test('exact extension vs. duplicated (.js.js)', async () => { + expect(await page.textContent('.exact-extension')).toMatch('[success]') +}) + +test('dont add extension to directory name (./dir-with-ext.js/index.js)', async () => { + expect(await page.textContent('.dir-with-ext')).toMatch('[success]') +}) + test('filename with dot', async () => { expect(await page.textContent('.dot')).toMatch('[success]') }) @@ -58,7 +66,7 @@ test('monorepo linked dep', async () => { expect(await page.textContent('.monorepo')).toMatch('[success]') }) -test('plugin resolved virutal file', async () => { +test('plugin resolved virtual file', async () => { expect(await page.textContent('.virtual')).toMatch('[success]') }) diff --git a/packages/playground/resolve/browser-field/multiple.dot.path.js b/packages/playground/resolve/browser-field/multiple.dot.path.js new file mode 100644 index 00000000000000..b4022f73daaf6e --- /dev/null +++ b/packages/playground/resolve/browser-field/multiple.dot.path.js @@ -0,0 +1,2 @@ +const fs = require('fs') +console.log('this should not run in the browser') diff --git a/packages/playground/resolve/browser-field/no-ext-index/index.js b/packages/playground/resolve/browser-field/no-ext-index/index.js new file mode 100644 index 00000000000000..d3f4967324ffb7 --- /dev/null +++ b/packages/playground/resolve/browser-field/no-ext-index/index.js @@ -0,0 +1,2 @@ +import jsdom from 'jsdom' // should be redireted to empty module +export default '' diff --git a/packages/playground/resolve/browser-field/no-ext.js b/packages/playground/resolve/browser-field/no-ext.js new file mode 100644 index 00000000000000..d3f4967324ffb7 --- /dev/null +++ b/packages/playground/resolve/browser-field/no-ext.js @@ -0,0 +1,2 @@ +import jsdom from 'jsdom' // should be redireted to empty module +export default '' diff --git a/packages/playground/resolve/browser-field/package.json b/packages/playground/resolve/browser-field/package.json index 76d68b2ff25d57..6c4901f42b387b 100644 --- a/packages/playground/resolve/browser-field/package.json +++ b/packages/playground/resolve/browser-field/package.json @@ -5,7 +5,12 @@ "main": "out/cjs.node.js", "browser": { "./out/cjs.node.js": "./out/esm.browser.js", + "./no-ext": "./out/esm.browser.js", + "./ext.js": "./out/esm.browser.js", + "./ext-index/index.js": "./out/esm.browser.js", + "./no-ext-index": "./out/esm.browser.js", "./not-browser.js": false, + "./multiple.dot.path.js": false, "jsdom": false } } diff --git a/packages/playground/resolve/browser-field/relative.js b/packages/playground/resolve/browser-field/relative.js new file mode 100644 index 00000000000000..bbf6a2c74a10b5 --- /dev/null +++ b/packages/playground/resolve/browser-field/relative.js @@ -0,0 +1,9 @@ +import ra from './no-ext' +import rb from './no-ext.js' // no substitution +import rc from './ext' +import rd from './ext.js' +import re from './ext-index/index.js' +import rf from './ext-index' +import rg from './no-ext-index/index.js' // no substitution + +export { ra, rb, rc, rd, re, rf, rg } diff --git a/packages/playground/resolve/dir-with-ext.js/empty b/packages/playground/resolve/dir-with-ext.js/empty new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/packages/playground/resolve/dir-with-ext/index.js b/packages/playground/resolve/dir-with-ext/index.js new file mode 100644 index 00000000000000..6b0769de24a395 --- /dev/null +++ b/packages/playground/resolve/dir-with-ext/index.js @@ -0,0 +1 @@ +export const file = '[success] ./dir-with-ext/index.js' diff --git a/packages/playground/resolve/exact-extension/file.js b/packages/playground/resolve/exact-extension/file.js new file mode 100644 index 00000000000000..50179e573507d7 --- /dev/null +++ b/packages/playground/resolve/exact-extension/file.js @@ -0,0 +1 @@ +export const file = '[success] file.js' diff --git a/packages/playground/resolve/exact-extension/file.js.js b/packages/playground/resolve/exact-extension/file.js.js new file mode 100644 index 00000000000000..aa47f61185cc74 --- /dev/null +++ b/packages/playground/resolve/exact-extension/file.js.js @@ -0,0 +1 @@ +export const file = 'file.js.js' diff --git a/packages/playground/resolve/index.html b/packages/playground/resolve/index.html index 733d73f2ba838d..722d66de5340ff 100644 --- a/packages/playground/resolve/index.html +++ b/packages/playground/resolve/index.html @@ -24,6 +24,12 @@

Resolve /index.*

Resolve dir and file of the same name (should prioritize file)

fail

+

Resolve to non-duplicated file extension

+

fail

+ +

Don't add extensions to directory names

+

fail

+

Resolve file name containing dot

fail

@@ -95,13 +101,40 @@

resolve.conditions

import { file } from './dir' text('.dir-vs-file', file) + // // exact extension vs. duplicated (.js.js) + import { file as exactExtMsg } from './exact-extension/file.js' + text('.exact-extension', exactExtMsg) + + // don't add extensions to dir name (./dir-with-ext.js/index.js) + import { file as dirWithExtMsg } from './dir-with-ext' + text('.dir-with-ext', dirWithExtMsg) + // filename with dot import { bar } from './util/bar.util' text('.dot', bar()) // browser field - import value from 'resolve-browser-field' - text('.browser', value) + import main from 'resolve-browser-field' + + import a from 'resolve-browser-field/no-ext' + import b from 'resolve-browser-field/no-ext.js' // no substitution + import c from 'resolve-browser-field/ext' + import d from 'resolve-browser-field/ext.js' + import e from 'resolve-browser-field/ext-index/index.js' + import f from 'resolve-browser-field/ext-index' + import g from 'resolve-browser-field/no-ext-index/index.js' // no substitution + + import { ra, rb, rc, rd, re, rf, rg } from 'resolve-browser-field/relative' + + const success = [main, a, c, d, e, f, ra, rc, rd, re, rf] + const noSuccess = [b, g, rb, rg] + + if ( + [...success, ...noSuccess].filter((text) => text.includes('[success]')) + .length === success.length + ) { + text('.browser', main) + } import { msg as customExtMsg } from './custom-ext' text('.custom-ext', customExtMsg) @@ -114,6 +147,7 @@

resolve.conditions

// should be ok to import a file marked with browser: false import 'resolve-browser-field/not-browser' + import 'resolve-browser-field/multiple.dot.path' // css entry import css from 'normalize.css' diff --git a/packages/playground/ssr-vue/package.json b/packages/playground/ssr-vue/package.json index e6849bb6290bfb..6bf759471d3a93 100644 --- a/packages/playground/ssr-vue/package.json +++ b/packages/playground/ssr-vue/package.json @@ -12,13 +12,13 @@ "debug": "node --inspect-brk server" }, "dependencies": { - "vue": "^3.0.6", + "vue": "^3.0.8", "vue-router": "^4.0.3" }, "devDependencies": { "@vitejs/plugin-vue": "^1.0.0", "@vitejs/plugin-vue-jsx": "^1.1.2", - "@vue/compiler-sfc": "^3.0.6", + "@vue/compiler-sfc": "^3.0.8", "@vue/server-renderer": "^3.0.6", "compression": "^1.7.4", "cross-env": "^7.0.3", diff --git a/packages/playground/testUtils.ts b/packages/playground/testUtils.ts index 027506c75f735f..3da60754c891d0 100644 --- a/packages/playground/testUtils.ts +++ b/packages/playground/testUtils.ts @@ -59,6 +59,10 @@ export async function getBg(el: string | ElementHandle) { return el.evaluate((el) => getComputedStyle(el as Element).backgroundImage) } +export function readFile(filename: string) { + return fs.readFileSync(path.resolve(testDir, filename), 'utf-8') +} + export function editFile(filename: string, replacer: (str: string) => string) { if (isBuild) return filename = path.resolve(testDir, filename) @@ -100,9 +104,10 @@ export function readManifest(base = '') { */ export async function untilUpdated( poll: () => string | Promise, - expected: string + expected: string, + runInBuild = false ) { - if (isBuild) return + if (isBuild && !runInBuild) return const maxTries = process.env.CI ? 100 : 50 for (let tries = 0; tries < maxTries; tries++) { const actual = (await poll()) || '' diff --git a/packages/playground/vue/Main.vue b/packages/playground/vue/Main.vue index 465c289bc56317..8ed3ba4de5f301 100644 --- a/packages/playground/vue/Main.vue +++ b/packages/playground/vue/Main.vue @@ -11,6 +11,10 @@ + +
this should be red
+
+ diff --git a/packages/playground/vue/Slotted.vue b/packages/playground/vue/Slotted.vue new file mode 100644 index 00000000000000..5d38a63762e05b --- /dev/null +++ b/packages/playground/vue/Slotted.vue @@ -0,0 +1,12 @@ +> + + \ No newline at end of file diff --git a/packages/playground/vue/__tests__/vue.spec.ts b/packages/playground/vue/__tests__/vue.spec.ts index c331d61fa52e8f..bc5d4e3a5ca9f3 100644 --- a/packages/playground/vue/__tests__/vue.spec.ts +++ b/packages/playground/vue/__tests__/vue.spec.ts @@ -18,6 +18,14 @@ test('should remove comments in prod', async () => { expect(await page.innerHTML('.comments')).toBe(isBuild ? `` : ``) }) +test(':slotted', async () => { + expect(await getColor('.slotted')).toBe('red') +}) + +test('scan deps from