diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3128e91c9df364..948041496208bb 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -181,6 +181,21 @@ module.exports = defineConfig({ '@typescript-eslint/no-empty-function': 'off', }, }, + { + files: ['playground/**'], + excludedFiles: [ + 'playground/ssr-resolve/**', + 'playground/**/*{commonjs,cjs}*/**', + 'playground/**/*{commonjs,cjs}*', + 'playground/**/*dep*/**', + 'playground/resolve/browser-module-field2/index.web.js', + 'playground/resolve/browser-field/**', + 'playground/tailwind/**', // blocked by https://github.com/postcss/postcss-load-config/issues/239 + ], + rules: { + 'import/no-commonjs': 'error', + }, + }, { files: [ 'playground/tsconfig-json/**', diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73c08de2f54f28..04b2c3f1f3fca0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@7ecfc6730dff8072d1cc5215a24cc9478f55264d # v35.8.0 + uses: tj-actions/changed-files@cf4fe8759a45edd76ed6215da3529d2dbd2a3c68 # v36.0.9 with: files: | docs/** diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d167d77f6442a8..8a37bb1f6685ae 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -12,6 +12,9 @@ jobs: # prevents this action from running on forks if: github.repository == 'vitejs/vite' runs-on: ubuntu-latest + permissions: + contents: read + id-token: write environment: Release steps: - name: Checkout diff --git a/.npmrc b/.npmrc index 4d97f291fd1e49..f1b91089bd4116 100644 --- a/.npmrc +++ b/.npmrc @@ -1,10 +1,6 @@ -hoist-pattern[]=*eslint* -hoist-pattern[]=*babel* -hoist-pattern[]=@emotion/* -hoist-pattern[]=postcss -hoist-pattern[]=pug -hoist-pattern[]=source-map-support -hoist-pattern[]=ts-node +hoist-pattern[]=ts-node # package/vite: postcss-load-config +hoist-pattern[]=postcss # package/vite +hoist-pattern[]=pug # playground/tailwind: @vue/compiler-sfc strict-peer-dependencies=false shell-emulator=true auto-install-peers=false diff --git a/docs/.vitepress/theme/composables/sponsor.ts b/docs/.vitepress/theme/composables/sponsor.ts index 3251509acc589d..096927d4521ef3 100644 --- a/docs/.vitepress/theme/composables/sponsor.ts +++ b/docs/.vitepress/theme/composables/sponsor.ts @@ -21,8 +21,27 @@ const data = ref() const dataHost = 'https://sponsors.vuejs.org' const dataUrl = `${dataHost}/vite.json` -// no sponsors yet :( -const viteSponsors: Pick = { +const viteSponsors: Pick = { + special: [ + // sponsors patak-dev + { + name: 'StackBlitz', + url: 'https://stackblitz.com', + img: '/stackblitz.svg', + }, + // sponsors antfu + { + name: 'NuxtLabs', + url: 'https://nuxtlabs.com', + img: '/nuxtlabs.svg', + }, + // sponsors bluwy + { + name: 'Astro', + url: 'https://astro.build', + img: '/astro.svg', + }, + ], gold: [], } @@ -46,7 +65,12 @@ export function useSponsor() { function mapSponsors(sponsors: Sponsors) { return [ { - tier: 'Platinum Sponsor', + tier: 'Special Sponsors', + size: 'big', + items: viteSponsors['special'], + }, + { + tier: 'Platinum Sponsors', size: 'big', items: mapImgPath(sponsors['platinum']), }, @@ -58,9 +82,20 @@ function mapSponsors(sponsors: Sponsors) { ] } +const viteSponsorNames = new Set( + Object.values(viteSponsors).flatMap((sponsors) => + sponsors.map((s) => s.name), + ), +) + +/** + * Map Vue/Vite sponsors data to objects and filter out Vite-specific sponsors + */ function mapImgPath(sponsors: Sponsor[]) { - return sponsors.map((sponsor) => ({ - ...sponsor, - img: `${dataHost}/images/${sponsor.img}`, - })) + return sponsors + .filter((sponsor) => !viteSponsorNames.has(sponsor.name)) + .map((sponsor) => ({ + ...sponsor, + img: `${dataHost}/images/${sponsor.img}`, + })) } diff --git a/docs/.vitepress/theme/styles/vars.css b/docs/.vitepress/theme/styles/vars.css index 8af0ae2653a204..58e5e79ff0f703 100644 --- a/docs/.vitepress/theme/styles/vars.css +++ b/docs/.vitepress/theme/styles/vars.css @@ -114,3 +114,7 @@ .dark .vp-doc .custom-block a { transition: color 0.25s; } + +.vp-sponsor.aside .vp-sponsor-grid.mini .vp-sponsor-grid-image { + max-width: 124px; +} diff --git a/docs/config/build-options.md b/docs/config/build-options.md index ff4dbbd50e3bbf..22306a7eabcc3b 100644 --- a/docs/config/build-options.md +++ b/docs/config/build-options.md @@ -98,7 +98,7 @@ If you specify `build.lib`, `build.assetsInlineLimit` will be ignored and assets - **Type:** `boolean` - **Default:** `true` -Enable/disable CSS code splitting. When enabled, CSS imported in async chunks will be inlined into the async chunk itself and inserted when the chunk is loaded. +Enable/disable CSS code splitting. When enabled, CSS imported in async JS chunks will be preserved as chunks and fetched together when the chunk is fetched. If disabled, all CSS in the entire project will be extracted into a single CSS file. diff --git a/docs/config/dep-optimization-options.md b/docs/config/dep-optimization-options.md index 6c7f372a02109c..d6b994b32cd809 100644 --- a/docs/config/dep-optimization-options.md +++ b/docs/config/dep-optimization-options.md @@ -35,6 +35,16 @@ export default defineConfig({ By default, linked packages not inside `node_modules` are not pre-bundled. Use this option to force a linked package to be pre-bundled. +**Experimental:** If you're using a library with many deep imports, you can also specify a trailing glob pattern to pre-bundle all deep imports at once. This will avoid constantly pre-bundling whenever a new deep import is used. For example: + +```js +export default defineConfig({ + optimizeDeps: { + include: ['my-lib/components/**/*.vue'], + }, +}) +``` + ## optimizeDeps.esbuildOptions - **Type:** [`EsbuildBuildOptions`](https://esbuild.github.io/api/#simple-options) @@ -65,3 +75,10 @@ Optimizing dependencies in build mode is **experimental**. If enabled, it remove If you want to try this build strategy, you can use `optimizeDeps.disabled: false`. `@rollup/plugin-commonjs` can be removed by passing `build.commonjsOptions: { include: [] }`. ::: + +## optimizeDeps.needsInterop + +- **Experimental** +- **Type:** `string[]` + +Forces ESM interop when importing these dependencies. Vite is able to properly detect when a dependency needs interop, so this option isn't generally needed. However, different combinations of dependencies could cause some of them to be prebundled differently. Adding these packages to `needsInterop` can speed up cold start by avoiding full-page reloads. You'll receive a warning if this is the case for one of your dependencies, suggesting to add the package name to this array in your config. diff --git a/docs/config/server-options.md b/docs/config/server-options.md index ab0f1b261ddb7c..8ee1a40b7f79b0 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -34,6 +34,13 @@ The second case is when wildcard hosts (e.g. `0.0.0.0`) are used. This is becaus ::: +::: tip Accessing the server on WSL2 from your LAN + +When running Vite on WSL2, it is not sufficient to set `host: true` to access the server from your LAN. +See [the WSL document](https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan) for more details. + +::: + ## server.port - **Type:** `number` @@ -259,6 +266,8 @@ Restrict serving files outside of workspace root. Restrict files that could be served via `/@fs/`. When `server.fs.strict` is set to `true`, accessing files outside this directory list that aren't imported from an allowed file will result in a 403. +Both directories and files can be provided. + Vite will search for the root of the potential workspace and use it as default. A valid workspace met the following conditions, otherwise will fall back to the [project root](/guide/#index-html-and-project-root). - contains `workspaces` field in `package.json` @@ -291,7 +300,8 @@ export default defineConfig({ // search up for workspace root searchForWorkspaceRoot(process.cwd()), // your custom rules - '/path/to/custom/allow', + '/path/to/custom/allow_directory', + '/path/to/custom/allow_file.demo', ], }, }, diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md index 41086c8d3404df..cb1540950ec23c 100644 --- a/docs/guide/api-javascript.md +++ b/docs/guide/api-javascript.md @@ -266,6 +266,10 @@ function mergeConfig( Deeply merge two Vite configs. `isRoot` represents the level within the Vite config which is being merged. For example, set `false` if you're merging two `build` options. +::: tip NOTE +`mergeConfig` accepts only config in object form. If you have a config in callback form, you should call it before passing into `mergeConfig`. +::: + ## `searchForWorkspaceRoot` **Type Signature:** diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index d5f92bad9ad879..6024a6d97df9bb 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -159,7 +159,9 @@ The following hooks are called on each incoming module request: - [`load`](https://rollupjs.org/plugin-development/#load) - [`transform`](https://rollupjs.org/plugin-development/#transform) -They also have an extended `options` parameter with additional Vite-specific properties. You can read more in the [SSR documentation](/guide/ssr#ssr-specific-plugin-logic). +These hooks also have an extended `options` parameter with additional Vite-specific properties. You can read more in the [SSR documentation](/guide/ssr#ssr-specific-plugin-logic). + +Some `resolveId` calls' `importer` value may be an absolute path for a generic `index.html` at root as it's not always possible to derive the actual importer due to Vite's unbundled dev server pattern. For imports handled within Vite's resolve pipeline, the importer can be tracked during the import analysis phase, providing the correct `importer` value. The following hooks are called when the server is closed: @@ -343,6 +345,8 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo - An array of tag descriptor objects (`{ tag, attrs, children }`) to inject to the existing HTML. Each tag can also specify where it should be injected to (default is prepending to ``) - An object containing both as `{ html, tags }` + By default `order` is `undefined`, with this hook applied after the html has been transformed. In order to inject a script that should go through the Vite plugins pipeline, `order: 'pre'` will apply the hook before processing the HTML. `order: 'post'` applies the hook after all hooks with `order` undefined are applied. + **Basic Example:** ```js diff --git a/docs/guide/build.md b/docs/guide/build.md index 370b1264e68475..f817afaa6614bc 100644 --- a/docs/guide/build.md +++ b/docs/guide/build.md @@ -60,6 +60,10 @@ export default defineConfig({ This strategy is also provided as a `splitVendorChunk({ cache: SplitVendorChunkCache })` factory, in case composition with custom logic is needed. `cache.reset()` needs to be called at `buildStart` for build watch mode to work correctly in this case. +::: warning +You should use `build.rollupOptions.output.manualChunks` function form when using this plugin. If the object form is used, the plugin won't have any effect. +::: + ## Rebuild on files changes You can enable rollup watcher with `vite build --watch`. Or, you can directly adjust the underlying [`WatcherOptions`](https://rollupjs.org/configuration-options/#watch) via `build.watch`: @@ -114,6 +118,8 @@ export default defineConfig({ If you specify a different root, remember that `__dirname` will still be the folder of your vite.config.js file when resolving the input paths. Therefore, you will need to add your `root` entry to the arguments for `resolve`. +Note that for HTML files, Vite ignores the name given to the entry in the `rollupOptions.input` object and instead respects the resolved id of the file when generating the HTML asset in the dist folder. This ensures a consistent structure with the way the dev server works. + ## Library Mode When you are developing a browser-oriented library, you are likely spending most of the time on a test/demo page that imports your actual library. With Vite, you can use your `index.html` for that purpose to get the smooth development experience. diff --git a/docs/guide/cli.md b/docs/guide/cli.md index 91a894970947a0..050610701c4d70 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -98,7 +98,7 @@ vite optimize [root] ### `vite preview` -Locally preview production build. +Locally preview the production build. Do not use this as a production server as it's not designed for it. #### Usage diff --git a/docs/guide/features.md b/docs/guide/features.md index 6b2fab9611a83f..c9e658076b677d 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -138,8 +138,8 @@ Vite provides first-class Vue support: - Vue 3 SFC support via [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue) - Vue 3 JSX support via [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx) -- Vue 2.7 support via [@vitejs/plugin-vue2](https://github.com/vitejs/vite-plugin-vue2) -- Vue <2.7 support via [vite-plugin-vue2](https://github.com/underfin/vite-plugin-vue2) +- Vue 2.7 SFC support via [@vitejs/plugin-vue2](https://github.com/vitejs/vite-plugin-vue2) +- Vue 2.7 JSX support via [@vitejs/plugin-vue2-jsx](https://github.com/vitejs/vite-plugin-vue2-jsx) ## JSX @@ -541,7 +541,7 @@ import MyWorker from './worker?worker' const worker = new MyWorker() ``` -The worker script can also use `import` statements instead of `importScripts()` - note during dev this relies on browser native support and currently only works in Chrome, but for the production build it is compiled away. +The worker script can also use ESM `import` statements instead of `importScripts()`. **Note**: During dev this relies on [browser native support](https://caniuse.com/?search=module%20worker) (currently not supported in Firefox), but for the production build it is compiled away. By default, the worker script will be emitted as a separate chunk in the production build. If you wish to inline the worker as base64 strings, add the `inline` query: diff --git a/docs/guide/index.md b/docs/guide/index.md index 3ae2c5a0d27e3b..118c53a2f38515 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -110,6 +110,7 @@ Vite also supports [multi-page apps](./build#multi-page-app) with multiple `.htm #### Specifying Alternative Root Running `vite` starts the dev server using the current working directory as root. You can specify an alternative root with `vite serve some/sub/dir`. +Note that Vite will also resolve [its config file (i.e. `vite.config.js`)](/config/#configuring-vite) inside the project root, so you'll need to move it if the root is changed. ## Command Line Interface diff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.md index c9eeab879c5c5a..4108902477bbfa 100644 --- a/docs/guide/troubleshooting.md +++ b/docs/guide/troubleshooting.md @@ -15,6 +15,23 @@ You will need to either: - Switch to another package manager (e.g. `pnpm`, `yarn`) - Remove `&` from the path to your project +## Config + +### This package is ESM only + +When importing a ESM only package by `require`, the following error happens. + +> Failed to resolve "foo". This package is ESM only but it was tried to load by `require`. + +> "foo" resolved to an ESM file. ESM file cannot be loaded by `require`. + +ESM files cannot be loaded by [`require`](). + +We recommend converting your config to ESM by either: + +- adding `"type": "module"` to the nearest `package.json` +- renaming `vite.config.js`/`vite.config.ts` to `vite.config.mjs`/`vite.config.mts` + ## Dev Server ### Requests are stalled forever @@ -154,3 +171,14 @@ If these code are used inside dependencies, you could use [`patch-package`](http ### Browser extensions Some browser extensions (like ad-blockers) may prevent the Vite client from sending requests to the Vite dev server. You may see a white screen without logged errors in this case. Try disabling extensions if you have this issue. + +### Cross drive links on Windows + +If there's a cross drive links in your project on Windows, Vite may not work. + +An example of cross drive links are: + +- a virtual drive linked to a folder by `subst` command +- a symlink/junction to a different drive by `mklink` command (e.g. Yarn global cache) + +Related issue: [#10802](https://github.com/vitejs/vite/issues/10802) diff --git a/docs/plugins/index.md b/docs/plugins/index.md index dd7cfce8733419..c16a1a3224a50f 100644 --- a/docs/plugins/index.md +++ b/docs/plugins/index.md @@ -18,7 +18,11 @@ Check out [Using Plugins](../guide/using-plugins) for information on how to use ### [@vitejs/plugin-vue2](https://github.com/vitejs/vite-plugin-vue2) -- Provides Vue 2 Single File Components support. +- Provides Vue 2.7 Single File Components support. + +### [@vitejs/plugin-vue2-jsx](https://github.com/vitejs/vite-plugin-vue2-jsx) + +- Provides Vue 2.7 JSX support (via [dedicated Babel transform](https://github.com/vuejs/jsx-vue2/)). ### [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react) diff --git a/docs/public/astro.svg b/docs/public/astro.svg new file mode 100644 index 00000000000000..079378b2d9851e --- /dev/null +++ b/docs/public/astro.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/nuxtlabs.svg b/docs/public/nuxtlabs.svg new file mode 100644 index 00000000000000..d2935645c9c520 --- /dev/null +++ b/docs/public/nuxtlabs.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/public/stackblitz.svg b/docs/public/stackblitz.svg new file mode 100644 index 00000000000000..a16fcd92ef988b --- /dev/null +++ b/docs/public/stackblitz.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docs/releases.md b/docs/releases.md index d9c2eddbc8f668..31599406414403 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -53,9 +53,3 @@ We periodically deprecate features that have been superseded by better alternati ## Experimental Features​ Some features are marked as experimental when released in a stable version of Vite. Experimental features allows us to gather real-world experience to influence their final design. The goal is to let users provide feedback by testing them in production. Experimental features themselves are considered unstable, and should only be used in a controlled manner. These features may change between Minors, so users must pin their Vite version when they rely on them. - -## RFCs​ - -Many changes, including features, bug fixes, and documentation improvements are discussed, implemented and reviewed via GitHub discussions, issues, and pull requests workflow. For substantial changes that would affect several downstream projects, we offer a Request For Comments (RFC) process to help gather consensus among the Vite core team, the Ecosystem, and the community. - -Continue reading about the RFC process in the [vitejs/rfcs](https://github.com/vitejs/rfcs) repo on GitHub. diff --git a/package.json b/package.json index 2dd7730e80f000..dc01b6adbcc5d9 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,10 @@ "node": "^14.18.0 || >=16.0.0" }, "homepage": "https://vitejs.dev/", + "repository": { + "type": "git", + "url": "git+https://github.com/vitejs/vite.git" + }, "keywords": [ "frontend", "hmr", @@ -41,6 +45,7 @@ "@microsoft/api-extractor": "^7.34.4", "@rollup/plugin-typescript": "^11.1.0", "@types/babel__core": "^7.20.0", + "@types/babel__preset-env": "^7.9.2", "@types/babel__standalone": "^7.1.4", "@types/convert-source-map": "^2.0.0", "@types/cross-spawn": "^6.0.2", @@ -59,7 +64,7 @@ "@types/ws": "^8.5.4", "@typescript-eslint/eslint-plugin": "^5.59.0", "@typescript-eslint/parser": "^5.59.0", - "@vitejs/release-scripts": "^1.1.0", + "@vitejs/release-scripts": "^1.2.0", "conventional-changelog-cli": "^2.2.2", "eslint": "^8.38.0", "eslint-define-config": "^1.18.0", @@ -83,7 +88,7 @@ "typescript": "^5.0.2", "unbuild": "^1.2.1", "vite": "workspace:*", - "vitepress": "^1.0.0-alpha.73", + "vitepress": "1.0.0-beta.1", "vitest": "^0.30.1", "vue": "^3.2.47" }, diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md index 0b0e445752db88..d50842b51478f7 100644 --- a/packages/create-vite/CHANGELOG.md +++ b/packages/create-vite/CHANGELOG.md @@ -1,3 +1,11 @@ +## 4.3.2 (2023-05-29) + +* fix: upgrade svelte-check preventing unmet peer deps errors (#13103) ([c63ba3f](https://github.com/vitejs/vite/commit/c63ba3f)), closes [#13103](https://github.com/vitejs/vite/issues/13103) +* fix(create-vite): use `"target": "ES2020"` in React template (#13147) ([23096b1](https://github.com/vitejs/vite/commit/23096b1)), closes [#13147](https://github.com/vitejs/vite/issues/13147) +* chore(deps): update all non-major dependencies (#12805) ([5731ac9](https://github.com/vitejs/vite/commit/5731ac9)), closes [#12805](https://github.com/vitejs/vite/issues/12805) + + + ## 4.3.1 (2023-04-25) * chore(create-vite): bump vue-tsc (#12952) ([30fd101](https://github.com/vitejs/vite/commit/30fd101)), closes [#12952](https://github.com/vitejs/vite/issues/12952) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 23cd7a7e57480f..591d731da7dc7f 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -1,6 +1,6 @@ { "name": "create-vite", - "version": "4.3.1", + "version": "4.3.2", "type": "module", "license": "MIT", "author": "Evan You", diff --git a/packages/create-vite/src/index.ts b/packages/create-vite/src/index.ts index dfc9473e23ff55..47d9dab68cf9ca 100755 --- a/packages/create-vite/src/index.ts +++ b/packages/create-vite/src/index.ts @@ -324,17 +324,27 @@ async function init() { if (customCommand) { const fullCustomCommand = customCommand - .replace(/^npm create/, `${pkgManager} create`) + .replace(/^npm create /, () => { + // `bun create` uses it's own set of templates, + // the closest alternative is using `bun x` directly on the package + if (pkgManager === 'bun') { + return 'bun x create-' + } + return `${pkgManager} create ` + }) // Only Yarn 1.x doesn't support `@version` in the `create` command .replace('@latest', () => (isYarn1 ? '' : '@latest')) .replace(/^npm exec/, () => { - // Prefer `pnpm dlx` or `yarn dlx` + // Prefer `pnpm dlx`, `yarn dlx`, or `bun x` if (pkgManager === 'pnpm') { return 'pnpm dlx' } if (pkgManager === 'yarn' && !isYarn1) { return 'yarn dlx' } + if (pkgManager === 'bun') { + return 'bun x' + } // Use `npm exec` in all other cases, // including Yarn 1.x and other custom npm clients. return 'npm exec' diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json index 943bbcb13d482a..cd344421463331 100644 --- a/packages/create-vite/template-lit-ts/package.json +++ b/packages/create-vite/template-lit-ts/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json index be2ce45aa302a2..0d889824581633 100644 --- a/packages/create-vite/template-lit/package.json +++ b/packages/create-vite/template-lit/package.json @@ -12,6 +12,6 @@ "lit": "^2.7.2" }, "devDependencies": { - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json index 7a7eef5bacdee6..83ac2f2dab9dbe 100644 --- a/packages/create-vite/template-preact-ts/package.json +++ b/packages/create-vite/template-preact-ts/package.json @@ -14,6 +14,6 @@ "devDependencies": { "@preact/preset-vite": "^2.5.0", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json index 6a116ff5e2ccd9..b1ee76ee5c7eb9 100644 --- a/packages/create-vite/template-preact/package.json +++ b/packages/create-vite/template-preact/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.5.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index 63bd22951713e5..b40dedc9d50f66 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -23,6 +23,6 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-react-ts/tsconfig.json b/packages/create-vite/template-react-ts/tsconfig.json index c81ef9f382291a..a7fc6fbf23de2a 100644 --- a/packages/create-vite/template-react-ts/tsconfig.json +++ b/packages/create-vite/template-react-ts/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { - "target": "ESNext", - "lib": ["DOM", "DOM.Iterable", "ESNext"], + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index 181f6b2d5befa4..902650e99682a2 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -21,6 +21,6 @@ "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.3.4", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json index 5669fca81962d0..5dc5b424573708 100644 --- a/packages/create-vite/template-svelte-ts/package.json +++ b/packages/create-vite/template-svelte-ts/package.json @@ -13,9 +13,9 @@ "@sveltejs/vite-plugin-svelte": "^2.0.4", "@tsconfig/svelte": "^4.0.1", "svelte": "^3.58.0", - "svelte-check": "^2.10.3", + "svelte-check": "^3.3.1", "tslib": "^2.5.0", "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-svelte/package.json b/packages/create-vite/template-svelte/package.json index 947d254ffea078..47679aad225444 100644 --- a/packages/create-vite/template-svelte/package.json +++ b/packages/create-vite/template-svelte/package.json @@ -11,6 +11,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^2.0.4", "svelte": "^3.58.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json index 7c063e00a3c35a..eaff1bfcee21b3 100644 --- a/packages/create-vite/template-vanilla-ts/package.json +++ b/packages/create-vite/template-vanilla-ts/package.json @@ -10,6 +10,6 @@ }, "devDependencies": { "typescript": "^5.0.2", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json index a7b823bc7e67c5..e8d3427fee3890 100644 --- a/packages/create-vite/template-vanilla/package.json +++ b/packages/create-vite/template-vanilla/package.json @@ -9,6 +9,6 @@ "preview": "vite preview" }, "devDependencies": { - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/create-vite/template-vue-ts/package.json b/packages/create-vite/template-vue-ts/package.json index 6dfe1065a2b269..d8d8fc3338ada7 100644 --- a/packages/create-vite/template-vue-ts/package.json +++ b/packages/create-vite/template-vue-ts/package.json @@ -14,7 +14,7 @@ "devDependencies": { "@vitejs/plugin-vue": "^4.1.0", "typescript": "^5.0.2", - "vite": "^4.3.2", + "vite": "^4.3.9", "vue-tsc": "^1.4.2" } } diff --git a/packages/create-vite/template-vue/package.json b/packages/create-vite/template-vue/package.json index 4edfd38a30aebc..86630df8abe203 100644 --- a/packages/create-vite/template-vue/package.json +++ b/packages/create-vite/template-vue/package.json @@ -13,6 +13,6 @@ }, "devDependencies": { "@vitejs/plugin-vue": "^4.1.0", - "vite": "^4.3.2" + "vite": "^4.3.9" } } diff --git a/packages/plugin-legacy/CHANGELOG.md b/packages/plugin-legacy/CHANGELOG.md index 2597f3e33ec033..d579c56c351fb1 100644 --- a/packages/plugin-legacy/CHANGELOG.md +++ b/packages/plugin-legacy/CHANGELOG.md @@ -1,3 +1,10 @@ +## 4.0.4 (2023-05-24) + +* fix(legacy): import `@babel/preset-env` (#12961) ([d53c650](https://github.com/vitejs/vite/commit/d53c650)), closes [#12961](https://github.com/vitejs/vite/issues/12961) +* chore(deps): update all non-major dependencies (#12805) ([5731ac9](https://github.com/vitejs/vite/commit/5731ac9)), closes [#12805](https://github.com/vitejs/vite/issues/12805) + + + ## 4.0.3 (2023-04-25) * feat(plugin-legacy): support file protocol (#8524) ([7a87ff4](https://github.com/vitejs/vite/commit/7a87ff4)), closes [#8524](https://github.com/vitejs/vite/issues/8524) diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md index 5381633aa9a91f..04abcec6a3a4e5 100644 --- a/packages/plugin-legacy/README.md +++ b/packages/plugin-legacy/README.md @@ -159,7 +159,7 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https - `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=` - `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=` -- `sha256-p7PoC97FO+Lu90RNjGWxhbm13yALSR4xzV8vaDhaQBo=` +- `sha256-4y/gEB2/KIwZFTfNqwXJq4olzvmQ0S214m9jwKgNXoc=` - `sha256-+5XkZFazzJo8n0iOP4ti/cLCMUudTf//Mzkb7xNPXIc=` /gs const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i @@ -378,12 +377,11 @@ function esbuildScanPlugin( // Avoid matching the content of the comment raw = raw.replace(commentRE, '') const isHtml = path.endsWith('.html') - const regex = isHtml ? scriptModuleRE : scriptRE - regex.lastIndex = 0 + scriptRE.lastIndex = 0 let js = '' let scriptId = 0 let match: RegExpExecArray | null - while ((match = regex.exec(raw))) { + while ((match = scriptRE.exec(raw))) { const [, openTag, content] = match const typeMatch = openTag.match(typeRE) const type = @@ -391,6 +389,10 @@ function esbuildScanPlugin( const langMatch = openTag.match(langRE) const lang = langMatch && (langMatch[1] || langMatch[2] || langMatch[3]) + // skip non type module script + if (isHtml && type !== 'module') { + continue + } // skip type="application/ld+json" and other non-JS types if ( type && diff --git a/packages/vite/src/node/packages.ts b/packages/vite/src/node/packages.ts index c82367a48cca64..106631baff6a4d 100644 --- a/packages/vite/src/node/packages.ts +++ b/packages/vite/src/node/packages.ts @@ -58,20 +58,18 @@ export function resolvePackageData( const cacheKey = getRpdCacheKey(pkgName, basedir, preserveSymlinks) if (packageCache?.has(cacheKey)) return packageCache.get(cacheKey)! - let pkg: string | null try { - pkg = pnp.resolveToUnqualified(pkgName, basedir, { + const pkg = pnp.resolveToUnqualified(pkgName, basedir, { considerBuiltins: false, }) + if (!pkg) return null + + const pkgData = loadPackageData(path.join(pkg, 'package.json')) + packageCache?.set(cacheKey, pkgData) + return pkgData } catch { return null } - if (!pkg) return null - - const pkgData = loadPackageData(path.join(pkg, 'package.json')) - packageCache?.set(cacheKey, pkgData) - - return pkgData } const originalBasedir = basedir diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 174b3e5826646c..651bd7b3b8b9c0 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -1,6 +1,7 @@ import path from 'node:path' import { parse as parseUrl } from 'node:url' -import fs, { promises as fsp } from 'node:fs' +import fs from 'node:fs' +import fsp from 'node:fs/promises' import { Buffer } from 'node:buffer' import * as mrmime from 'mrmime' import type { diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index 6872de5249e014..369e8a5e12026f 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -5,6 +5,7 @@ import type { Plugin } from '../plugin' import type { ResolvedConfig } from '../config' import type { ResolveFn } from '../' import { + injectQuery, isParentDirectory, normalizePath, slash, @@ -13,6 +14,8 @@ import { import { CLIENT_ENTRY } from '../constants' import { fileToUrl } from './asset' import { preloadHelperId } from './importAnalysisBuild' +import type { InternalResolveOptions } from './resolve' +import { tryFsResolve } from './resolve' /** * Convert `new URL('./foo.png', import.meta.url)` to its resolved built URL @@ -28,6 +31,16 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { const normalizedPublicDir = normalizePath(config.publicDir) let assetResolver: ResolveFn + const fsResolveOptions: InternalResolveOptions = { + ...config.resolve, + root: config.root, + isProduction: config.isProduction, + isBuild: config.command === 'build', + packageCache: config.packageCache, + ssrConfig: config.ssr, + asSrc: true, + } + return { name: 'vite:asset-import-meta-url', async transform(code, id, options) { @@ -55,7 +68,15 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { // potential dynamic template string if (rawUrl[0] === '`' && rawUrl.includes('${')) { - const ast = this.parse(rawUrl) + const queryDelimiterIndex = getQueryDelimiterIndex(rawUrl) + const hasQueryDelimiter = queryDelimiterIndex !== -1 + const pureUrl = hasQueryDelimiter + ? rawUrl.slice(0, queryDelimiterIndex) + '`' + : rawUrl + const queryString = hasQueryDelimiter + ? rawUrl.slice(queryDelimiterIndex, -1) + : '' + const ast = this.parse(pureUrl) const templateLiteral = (ast as any).body[0].expression if (templateLiteral.expressions.length) { const pattern = buildGlobPattern(templateLiteral) @@ -65,6 +86,12 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { continue } + const globOptions = { + eager: true, + import: 'default', + // A hack to allow 'as' & 'query' exist at the same time + query: injectQuery(queryString, 'url'), + } // Note: native import.meta.url is not supported in the baseline // target so we use the global location here. It can be // window.location or self.location in case it is used in a Web Worker. @@ -74,7 +101,9 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { index + exp.length, `new URL((import.meta.glob(${JSON.stringify( pattern, - )}, { eager: true, import: 'default', as: 'url' }))[${rawUrl}], self.location)`, + )}, ${JSON.stringify( + globOptions, + )}))[${pureUrl}], self.location)`, ) continue } @@ -84,6 +113,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { let file: string | undefined if (url[0] === '.') { file = slash(path.resolve(path.dirname(id), url)) + file = tryFsResolve(file, fsResolveOptions) ?? file } else { assetResolver ??= config.createResolver({ extensions: [], @@ -153,3 +183,17 @@ function buildGlobPattern(ast: any) { } return pattern } + +function getQueryDelimiterIndex(rawUrl: string): number { + let bracketsStack = 0 + for (let i = 0; i < rawUrl.length; i++) { + if (rawUrl[i] === '{') { + bracketsStack++ + } else if (rawUrl[i] === '}') { + bracketsStack-- + } else if (rawUrl[i] === '?' && bracketsStack === 0) { + return i + } + } + return -1 +} diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 7366c1b093799d..7228c2fae781e2 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -404,7 +404,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } if (isDirectCSSRequest(id)) { - return await getContentWithSourcemap(css) + return null } // server only if (options?.ssr) { @@ -517,7 +517,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { ? getCssAssetDirname(cssAssetName) : undefined - const toRelative = (filename: string, importer: string) => { + const toRelative = (filename: string) => { // relative base + extracted CSS const relativePath = path.posix.relative(cssAssetDirname!, filename) return relativePath[0] === '.' ? relativePath : './' + relativePath @@ -636,10 +636,10 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { `${style}.textContent = ${cssString};` + `document.head.appendChild(${style});` const wrapIdx = code.indexOf('System.register') - const insertMark = "'use strict';" - const insertIdx = code.indexOf(insertMark, wrapIdx) + const executeFnStart = + code.indexOf('{', code.indexOf('execute:', wrapIdx)) + 1 const s = new MagicString(code) - s.appendLeft(insertIdx + insertMark.length, injectCode) + s.appendRight(executeFnStart, injectCode) if (config.build.sourcemap) { // resolve public URL from CSS paths, we need to use absolute paths return { @@ -954,6 +954,12 @@ async function compileCSS( return id }, + async load(id) { + const code = fs.readFileSync(id, 'utf-8') + const result = await compileCSS(id, code, config) + result.deps?.forEach((dep) => deps.add(dep)) + return result.code + }, nameLayer(index) { return `vite--anon-layer-${getHash(id)}-${index}` }, @@ -1003,6 +1009,7 @@ async function compileCSS( return { code, map: preprocessorMap, + deps, } } @@ -1411,8 +1418,7 @@ async function minifyCSS(css: string, config: ResolvedConfig) { const { code, warnings } = await transform(css, { loader: 'css', target: config.build.cssTarget || undefined, - charset: 'utf8', - ...resolveEsbuildMinifyOptions(config.esbuild || {}), + ...resolveMinifyCssEsbuildOptions(config.esbuild || {}), }) if (warnings.length) { const msgs = await formatMessages(warnings, { kind: 'warning' }) @@ -1432,10 +1438,11 @@ async function minifyCSS(css: string, config: ResolvedConfig) { } } -function resolveEsbuildMinifyOptions( +function resolveMinifyCssEsbuildOptions( options: ESBuildOptions, ): TransformOptions { const base: TransformOptions = { + charset: options.charset ?? 'utf8', logLevel: options.logLevel, logLimit: options.logLimit, logOverride: options.logOverride, @@ -1600,6 +1607,7 @@ function cleanScssBugUrl(url: string) { if ( // check bug via `window` and `location` global typeof window !== 'undefined' && + typeof location !== 'undefined' && typeof location?.href === 'string' ) { const prefix = location.href.replace(/\/$/, '') diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 119f0192cabb43..219c9dd2a9138f 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -254,9 +254,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // since we are already in the transform phase of the importer, it must // have been loaded so its entry is guaranteed in the module graph. const importerModule = moduleGraph.getModuleById(importer)! - if (!importerModule && depsOptimizer?.isOptimizedDepFile(importer)) { - // Ids of optimized deps could be invalidated and removed from the graph - // Return without transforming, this request is no longer valid, a full reload + if (!importerModule) { + // When the server is restarted, the module graph is cleared, so we + // return without transforming. This request is no longer valid, a full reload // is going to request this id again. Throwing an outdated error so we // properly finish the request with a 504 sent to the browser. throwOutdatedRequest(importer) @@ -741,8 +741,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // normalize and rewrite accepted urls const normalizedAcceptedUrls = new Set() for (const { url, start, end } of acceptedUrls) { + const isRelative = url[0] === '.' const [normalized] = await moduleGraph.resolveUrl( - toAbsoluteUrl(url), + isRelative ? toAbsoluteUrl(url) : url, ssr, ) normalizedAcceptedUrls.add(normalized) diff --git a/packages/vite/src/node/plugins/importMetaGlob.ts b/packages/vite/src/node/plugins/importMetaGlob.ts index 10fe5f9120bbd5..4b6aa267261a6e 100644 --- a/packages/vite/src/node/plugins/importMetaGlob.ts +++ b/packages/vite/src/node/plugins/importMetaGlob.ts @@ -13,7 +13,7 @@ import type { TemplateLiteral, } from 'estree' import { parseExpressionAt } from 'acorn' -import type { RollupError } from 'rollup' +import type { CustomPluginOptions, RollupError } from 'rollup' import { findNodeAt } from 'acorn-walk' import MagicString from 'magic-string' import fg from 'fast-glob' @@ -75,7 +75,8 @@ export function importGlobPlugin(config: ResolvedConfig): Plugin { code, id, config.root, - (im) => this.resolve(im, id).then((i) => i?.id || im), + (im, _, options) => + this.resolve(im, id, options).then((i) => i?.id || im), config.isProduction, config.experimental.importGlobRestoreExtension, ) @@ -354,7 +355,7 @@ export async function transformGlobImport( ): Promise { id = slash(id) root = slash(root) - const isVirtual = isVirtualModule(id) + const isVirtual = !isAbsolute(id) const dir = isVirtual ? undefined : dirname(id) const matches = await parseImportGlob( code, @@ -546,6 +547,12 @@ export async function transformGlobImport( type IdResolver = ( id: string, importer?: string, + options?: { + assertions?: Record + custom?: CustomPluginOptions + isEntry?: boolean + skipSelf?: boolean + }, ) => Promise | string | undefined function globSafePath(path: string) { @@ -594,7 +601,16 @@ export async function toAbsoluteGlob( if (glob.startsWith('../')) return pre + posix.join(dir, glob) if (glob.startsWith('**')) return pre + glob - const resolved = normalizePath((await resolveId(glob, importer)) || glob) + const isSubImportsPattern = glob.startsWith('#') && glob.includes('*') + + const resolved = normalizePath( + (await resolveId(glob, importer, { + custom: { 'vite:import-glob': { isSubImportsPattern } }, + })) || glob, + ) + if (isSubImportsPattern) { + return join(root, resolved) + } if (isAbsolute(resolved)) { return pre + globSafeResolvedPath(resolved, glob) } @@ -629,8 +645,3 @@ export function getCommonBase(globsResolved: string[]): null | string { return commonAncestor } - -export function isVirtualModule(id: string): boolean { - // https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention - return id.startsWith('virtual:') || id[0] === '\0' || !id.includes('/') -} diff --git a/packages/vite/src/node/plugins/loadFallback.ts b/packages/vite/src/node/plugins/loadFallback.ts index fc32e781e58c4d..b806f8b93ac201 100644 --- a/packages/vite/src/node/plugins/loadFallback.ts +++ b/packages/vite/src/node/plugins/loadFallback.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'node:fs' +import fsp from 'node:fs/promises' import type { Plugin } from '..' import { cleanUrl } from '../utils' @@ -11,9 +11,9 @@ export function loadFallbackPlugin(): Plugin { async load(id) { try { // if we don't add `await` here, we couldn't catch the error in readFile - return await fs.readFile(cleanUrl(id), 'utf-8') + return await fsp.readFile(cleanUrl(id), 'utf-8') } catch (e) { - return fs.readFile(id, 'utf-8') + return fsp.readFile(id, 'utf-8') } }, } diff --git a/packages/vite/src/node/plugins/modulePreloadPolyfill.ts b/packages/vite/src/node/plugins/modulePreloadPolyfill.ts index 0f1ef11cf26f5e..ede79c8b882f77 100644 --- a/packages/vite/src/node/plugins/modulePreloadPolyfill.ts +++ b/packages/vite/src/node/plugins/modulePreloadPolyfill.ts @@ -25,7 +25,7 @@ export function modulePreloadPolyfillPlugin(config: ResolvedConfig): Plugin { if (!polyfillString) { polyfillString = `${isModernFlag}&&(${polyfill.toString()}());` } - return polyfillString + return { code: polyfillString, moduleSideEffects: true } } }, } diff --git a/packages/vite/src/node/plugins/optimizedDeps.ts b/packages/vite/src/node/plugins/optimizedDeps.ts index f832e5da395c6c..7bb1e040517320 100644 --- a/packages/vite/src/node/plugins/optimizedDeps.ts +++ b/packages/vite/src/node/plugins/optimizedDeps.ts @@ -106,12 +106,12 @@ export function optimizedDepsBuildPlugin(config: ResolvedConfig): Plugin { ...options, skipSelf: true, }) - if (resolved) { + if (resolved && !resolved.external) { depsOptimizer.delayDepsOptimizerUntil(resolved.id, async () => { await this.load(resolved) }) - return resolved } + return resolved } }, diff --git a/packages/vite/src/node/plugins/reporter.ts b/packages/vite/src/node/plugins/reporter.ts index 147090ac3faf9d..f36081041ca1c5 100644 --- a/packages/vite/src/node/plugins/reporter.ts +++ b/packages/vite/src/node/plugins/reporter.ts @@ -98,8 +98,7 @@ export function buildReporterPlugin(config: ResolvedConfig): Plugin { buildEnd() { if (shouldLogInfo) { if (tty) { - process.stdout.clearLine(0) - process.stdout.cursorTo(0) + clearLine() } config.logger.info( `${colors.green(`✓`)} ${transformedCount} modules transformed.`, diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index c5a0876a0963a4..f89abbe267422d 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -185,6 +185,10 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin { ) if (resolvedImports) { id = resolvedImports + + if (resolveOpts.custom?.['vite:import-glob']?.isSubImportsPattern) { + return id + } } if (importer) { @@ -498,7 +502,7 @@ function splitFileAndPostfix(path: string) { return { file, postfix: path.slice(file.length) } } -function tryFsResolve( +export function tryFsResolve( fsPath: string, options: InternalResolveOptions, tryIndex = true, @@ -1101,8 +1105,6 @@ function resolveExportsOrImports( return options.isProduction case 'development': return !options.isProduction - case 'module': - return !options.isRequire } return true }) diff --git a/packages/vite/src/node/plugins/splitVendorChunk.ts b/packages/vite/src/node/plugins/splitVendorChunk.ts index efe0a18a2c9440..b8c5d2ca855b61 100644 --- a/packages/vite/src/node/plugins/splitVendorChunk.ts +++ b/packages/vite/src/node/plugins/splitVendorChunk.ts @@ -116,6 +116,10 @@ export function splitVendorChunkPlugin(): Plugin { } // else, leave the object form of manualChunks untouched, as // we can't safely replicate rollup handling. + // eslint-disable-next-line no-console + console.warn( + "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.manualChunks`. Consider using the function form instead.", + ) } else { output.manualChunks = viteManualChunks } diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index 2bda9ab737e273..5e186af64f8648 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -17,6 +17,8 @@ import type { ResolveFn } from '..' import type { WorkerType } from './worker' import { WORKER_FILE_ID, workerFileToUrl } from './worker' import { fileToUrl } from './asset' +import type { InternalResolveOptions } from './resolve' +import { tryFsResolve } from './resolve' const ignoreFlagRE = /\/\*\s*@vite-ignore\s*\*\// @@ -99,6 +101,16 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin { const isBuild = config.command === 'build' let workerResolver: ResolveFn + const fsResolveOptions: InternalResolveOptions = { + ...config.resolve, + root: config.root, + isProduction: config.isProduction, + isBuild: config.command === 'build', + packageCache: config.packageCache, + ssrConfig: config.ssr, + asSrc: true, + } + return { name: 'vite:worker-import-meta-url', @@ -143,6 +155,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin { let file: string | undefined if (url[0] === '.') { file = path.resolve(path.dirname(id), url) + file = tryFsResolve(file, fsResolveOptions) ?? file } else { workerResolver ??= config.createResolver({ extensions: [], diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index 13e870df0a84f2..17f10e5e8676ab 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -366,7 +366,7 @@ export async function _createServer( const watcher = chokidar.watch( // config file dependencies and env file might be outside of root - [root, ...config.configFileDependencies, path.join(config.envDir, '.env*')], + [root, ...config.configFileDependencies, config.envDir], resolvedWatchOptions, ) as FSWatcher @@ -404,7 +404,9 @@ export async function _createServer( if (isDepsOptimizerEnabled(config, true)) { await initDevSsrDepsOptimizer(config, server) } - await updateCjsSsrExternals(server) + if (config.legacy?.buildSsrCjsExternalHeuristics) { + await updateCjsSsrExternals(server) + } return ssrLoadModule( url, server, @@ -608,6 +610,16 @@ export async function _createServer( // open in editor support middlewares.use('/__open-in-editor', launchEditorMiddleware()) + // ping request handler + // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` + middlewares.use(function viteHMRPingMiddleware(req, res, next) { + if (req.headers['accept'] === 'text/x-vite-ping') { + res.writeHead(204).end() + } else { + next() + } + }) + // serve static files under /public // this applies before the transform middleware so that these files are served // as-is without transforms. @@ -675,6 +687,8 @@ export async function _createServer( const listen = httpServer.listen.bind(httpServer) httpServer.listen = (async (port: number, ...args: any[]) => { try { + // ensure ws server started + ws.listen() await initServer() } catch (e) { httpServer.emit('error', e) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 4ab0038333c2e6..a063bc91bdbaf9 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -28,6 +28,7 @@ import { ensureWatchedFile, fsPathFromId, injectQuery, + isJSRequest, joinUrlSegments, normalizePath, processSrcSetSync, @@ -35,7 +36,9 @@ import { unwrapId, wrapId, } from '../../utils' +import { isCSSRequest } from '../../plugins/css' import { checkPublicFile } from '../../plugins/asset' +import { getCodeWithSourcemap, injectSourcesContent } from '../sourcemap' interface AssetNode { start: number @@ -81,6 +84,12 @@ function getHtmlFilename(url: string, server: ViteDevServer) { } } +function shouldPreTransform(url: string, config: ResolvedConfig) { + return ( + !checkPublicFile(url, config) && (isJSRequest(url) || isCSSRequest(url)) + ) +} + const processNodeUrl = ( attr: Token.Attribute, sourceCodeLocation: Token.Location, @@ -103,7 +112,7 @@ const processNodeUrl = ( // prefix with base (dev only, base is never relative) const fullUrl = path.posix.join(devBase, url) overwriteAttrValue(s, sourceCodeLocation, fullUrl) - if (server && !checkPublicFile(url, config)) { + if (server && shouldPreTransform(url, config)) { preTransformRequest(server, fullUrl, devBase) } } else if ( @@ -115,7 +124,7 @@ const processNodeUrl = ( // prefix with base (dev only, base is never relative) const replacer = (url: string) => { const fullUrl = path.posix.join(devBase, url) - if (server && !checkPublicFile(url, config)) { + if (server && shouldPreTransform(url, config)) { preTransformRequest(server, fullUrl, devBase) } return fullUrl @@ -268,7 +277,22 @@ const devHtmlHook: IndexHtmlTransformHook = async ( ensureWatchedFile(watcher, mod.file, config.root) const result = await server!.pluginContainer.transform(code, mod.id!) - s.overwrite(start, end, result?.code || '') + let content = '' + if (result) { + if (result.map) { + if (result.map.mappings && !result.map.sourcesContent) { + await injectSourcesContent( + result.map, + proxyModulePath, + config.logger, + ) + } + content = getCodeWithSourcemap('css', result.code, result.map) + } else { + content = result.code + } + } + s.overwrite(start, end, content) }), ) diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index f07b93e0746223..66f99f94f0609d 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -79,6 +79,19 @@ export function proxyMiddleware( res.end() } }) + + proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => { + socket.on('error', (err) => { + config.logger.error( + `${colors.red(`ws proxy socket error:`)}\n${err.stack}`, + { + timestamp: true, + error: err, + }, + ) + }) + }) + // clone before saving because http-proxy mutates the options proxies[context] = [proxy, { ...opts }] }) diff --git a/packages/vite/src/node/server/middlewares/static.ts b/packages/vite/src/node/server/middlewares/static.ts index 28ea57e87dca94..b0c7c83d619f4a 100644 --- a/packages/vite/src/node/server/middlewares/static.ts +++ b/packages/vite/src/node/server/middlewares/static.ts @@ -14,6 +14,7 @@ import { isImportRequest, isInternalRequest, isParentDirectory, + isSameFileUri, isWindows, removeLeadingSlash, shouldServeFile, @@ -100,7 +101,7 @@ export function serveStaticMiddleware( return next() } - const url = new URL(req.url!, 'http://example.com') + const url = new URL(req.url!.replace(/^\/+/, '/'), 'http://example.com') const pathname = decodeURI(url.pathname) // apply aliases to static requests as well @@ -153,7 +154,7 @@ export function serveRawFsMiddleware( // Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...` return function viteServeRawFsMiddleware(req, res, next) { - const url = new URL(req.url!, 'http://example.com') + const url = new URL(req.url!.replace(/^\/+/, '/'), 'http://example.com') // In some cases (e.g. linked monorepos) files outside of root will // reference assets that are also out of served root. In such cases // the paths are rewritten to `/@fs/` prefixed paths and must be served by @@ -199,7 +200,11 @@ export function isFileServingAllowed( if (server.moduleGraph.safeModulesPath.has(file)) return true - if (server.config.server.fs.allow.some((dir) => isParentDirectory(dir, file))) + if ( + server.config.server.fs.allow.some( + (uri) => isSameFileUri(uri, file) || isParentDirectory(uri, file), + ) + ) return true return false diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index 38c057bbbf8c29..a0e46cf4a2fb06 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -76,6 +76,7 @@ import { numberToPos, prettifyUrl, timeFrom, + unwrapId, } from '../utils' import { FS_PREFIX } from '../constants' import type { ResolvedConfig } from '../config' @@ -116,7 +117,7 @@ export interface PluginContainer { inMap?: SourceDescription['map'] ssr?: boolean }, - ): Promise + ): Promise<{ code: string; map: SourceMap | null }> load( id: string, options?: { @@ -313,7 +314,7 @@ export async function createPluginContainer( } & Partial>, ): Promise { // We may not have added this to our module graph yet, so ensure it exists - await moduleGraph?.ensureEntryFromUrl(options.id) + await moduleGraph?.ensureEntryFromUrl(unwrapId(options.id), this.ssr) // Not all options passed to this function make sense in the context of loading individual files, // but we can at least update the module info properties we support updateModuleInfo(options.id, options) diff --git a/packages/vite/src/node/server/sourcemap.ts b/packages/vite/src/node/server/sourcemap.ts index a1494fa01de223..a2e8c55542fc8e 100644 --- a/packages/vite/src/node/server/sourcemap.ts +++ b/packages/vite/src/node/server/sourcemap.ts @@ -1,5 +1,5 @@ import path from 'node:path' -import { promises as fs } from 'node:fs' +import fsp from 'node:fs/promises' import type { ExistingRawSourceMap, SourceMap } from 'rollup' import type { Logger } from '../logger' import { createDebugger } from '../utils' @@ -27,7 +27,7 @@ export async function injectSourcesContent( let sourceRoot: string | undefined try { // The source root is undefined for virtual modules and permission errors. - sourceRoot = await fs.realpath( + sourceRoot = await fsp.realpath( path.resolve(path.dirname(file), map.sourceRoot || ''), ) } catch {} @@ -40,7 +40,7 @@ export async function injectSourcesContent( if (sourceRoot) { sourcePath = path.resolve(sourceRoot, sourcePath) } - return fs.readFile(sourcePath, 'utf-8').catch(() => { + return fsp.readFile(sourcePath, 'utf-8').catch(() => { missingSources.push(sourcePath) return null }) diff --git a/packages/vite/src/node/server/transformRequest.ts b/packages/vite/src/node/server/transformRequest.ts index b08a01e5d01b9e..4d05ca102a531d 100644 --- a/packages/vite/src/node/server/transformRequest.ts +++ b/packages/vite/src/node/server/transformRequest.ts @@ -1,4 +1,4 @@ -import { promises as fs } from 'node:fs' +import fsp from 'node:fs/promises' import path from 'node:path' import { performance } from 'node:perf_hooks' import getEtag from 'etag' @@ -188,7 +188,7 @@ async function loadAndTransform( // like /service-worker.js or /api/users if (options.ssr || isFileServingAllowed(file, server)) { try { - code = await fs.readFile(file, 'utf-8') + code = await fsp.readFile(file, 'utf-8') debugLoad?.(`${timeFrom(loadStart)} [fs] ${prettyUrl}`) } catch (e) { if (e.code !== 'ENOENT') { @@ -324,7 +324,7 @@ async function loadAndTransform( function createConvertSourceMapReadMap(originalFileName: string) { return (filename: string) => { - return fs.readFile( + return fsp.readFile( path.resolve(path.dirname(originalFileName), filename), 'utf-8', ) diff --git a/packages/vite/src/node/ssr/index.ts b/packages/vite/src/node/ssr/index.ts index be2d436749dc80..caf85dab072aa1 100644 --- a/packages/vite/src/node/ssr/index.ts +++ b/packages/vite/src/node/ssr/index.ts @@ -47,16 +47,8 @@ export function resolveSSROptions( ): ResolvedSSROptions { ssr ??= {} const optimizeDeps = ssr.optimizeDeps ?? {} - let format: SSRFormat = 'esm' - let target: SSRTarget = 'node' - if (buildSsrCjsExternalHeuristics) { - if (ssr) { - format = 'cjs' - } else { - target = 'node' - format = 'cjs' - } - } + const format: SSRFormat = buildSsrCjsExternalHeuristics ? 'cjs' : 'esm' + const target: SSRTarget = 'node' return { format, target, diff --git a/packages/vite/src/node/ssr/ssrExternal.ts b/packages/vite/src/node/ssr/ssrExternal.ts index 7fd01d5a878642..145e8e8f4925c2 100644 --- a/packages/vite/src/node/ssr/ssrExternal.ts +++ b/packages/vite/src/node/ssr/ssrExternal.ts @@ -7,6 +7,7 @@ import { bareImportRE, createDebugger, createFilter, + getNpmPackageName, isBuiltin, isDefined, isInNodeModules, @@ -341,13 +342,3 @@ export function cjsShouldExternalizeForSSR( }) return should } - -function getNpmPackageName(importPath: string): string | null { - const parts = importPath.split('/') - if (parts[0][0] === '@') { - if (!parts[1]) return null - return `${parts[0]}/${parts[1]}` - } else { - return parts[0] - } -} diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index 2f9e71f55569bd..3e498809f32829 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -189,7 +189,7 @@ async function instantiateModule( function ssrExportAll(sourceModule: any) { for (const key in sourceModule) { - if (key !== 'default') { + if (key !== 'default' && key !== '__esModule') { Object.defineProperty(ssrModule, key, { enumerable: true, configurable: true, @@ -222,7 +222,7 @@ async function instantiateModule( ssrExportAllKey, '"use strict";' + result.code + - `\n//# sourceURL=${mod.url}${sourceMapSuffix}`, + `\n//# sourceURL=${mod.id}${sourceMapSuffix}`, ) await initModule( context.global, diff --git a/packages/vite/src/node/ssr/ssrStacktrace.ts b/packages/vite/src/node/ssr/ssrStacktrace.ts index fe66b8803530b7..a98af4dd94bb74 100644 --- a/packages/vite/src/node/ssr/ssrStacktrace.ts +++ b/packages/vite/src/node/ssr/ssrStacktrace.ts @@ -1,30 +1,39 @@ +import path from 'node:path' import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping' import type { ModuleGraph } from '../server/moduleGraph' let offset: number -try { - new Function('throw new Error(1)')() -} catch (e) { - // in Node 12, stack traces account for the function wrapper. - // in Node 13 and later, the function wrapper adds two lines, - // which must be subtracted to generate a valid mapping - const match = /:(\d+):\d+\)$/.exec(e.stack.split('\n')[1]) - offset = match ? +match[1] - 1 : 0 + +function calculateOffsetOnce() { + if (offset !== undefined) { + return + } + + try { + new Function('throw new Error(1)')() + } catch (e) { + // in Node 12, stack traces account for the function wrapper. + // in Node 13 and later, the function wrapper adds two lines, + // which must be subtracted to generate a valid mapping + const match = /:(\d+):\d+\)$/.exec(e.stack.split('\n')[1]) + offset = match ? +match[1] - 1 : 0 + } } export function ssrRewriteStacktrace( stack: string, moduleGraph: ModuleGraph, ): string { + calculateOffsetOnce() return stack .split('\n') .map((line) => { return line.replace( /^ {4}at (?:(\S.*?)\s\()?(.+?):(\d+)(?::(\d+))?\)?/, - (input, varName, url, line, column) => { - if (!url) return input + (input, varName, id, line, column) => { + if (!id) return input - const mod = moduleGraph.urlToModuleMap.get(url) + const mod = moduleGraph.idToModuleMap.get(id) const rawSourceMap = mod?.ssrTransformResult?.map if (!rawSourceMap) { @@ -35,7 +44,8 @@ export function ssrRewriteStacktrace( const pos = originalPositionFor(traced, { line: Number(line) - offset, - column: Number(column), + // stacktrace's column is 1-indexed, but sourcemap's one is 0-indexed + column: Number(column) - 1, }) if (!pos.source || pos.line == null || pos.column == null) { @@ -43,7 +53,9 @@ export function ssrRewriteStacktrace( } const trimmedVarName = varName.trim() - const source = `${pos.source}:${pos.line}:${pos.column}` + const sourceFile = path.resolve(path.dirname(id), pos.source) + // stacktrace's column is 1-indexed, but sourcemap's one is 0-indexed + const source = `${sourceFile}:${pos.line}:${pos.column + 1}` if (!trimmedVarName || trimmedVarName === 'eval') { return ` at ${source}` } else { diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index 8a62094dcb0789..5496019504e50d 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -1,3 +1,4 @@ +import path from 'node:path' import MagicString from 'magic-string' import type { SourceMap } from 'rollup' import type { @@ -285,7 +286,7 @@ async function ssrTransformScript( false, ) as SourceMap } else { - map.sources = [url] + map.sources = [path.basename(url)] // needs to use originalCode instead of code // because code might be already transformed even if map is null map.sourcesContent = [originalCode] diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index d962bccc8eee6e..c1dbc05c204e46 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -137,7 +137,7 @@ export function isOptimizable( ) } -export const bareImportRE = /^[\w@](?!.*:\/\/)/ +export const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/ export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\// // TODO: use import() @@ -169,7 +169,7 @@ export function createDebugger( if (enabled) { return (...args: [string, ...any[]]) => { - if (!filter || args.some((a) => a?.includes(filter))) { + if (!filter || args.some((a) => a?.includes?.(filter))) { log(...args) } } @@ -240,6 +240,22 @@ export function isParentDirectory(dir: string, file: string): boolean { ) } +/** + * Check if 2 file name are identical + * + * Warning: parameters are not validated, only works with normalized absolute paths + * + * @param file1 - normalized absolute path + * @param file2 - normalized absolute path + * @returns true if both files url are identical + */ +export function isSameFileUri(file1: string, file2: string): boolean { + return ( + file1 === file2 || + (isCaseInsensitiveFS && file1.toLowerCase() === file2.toLowerCase()) + ) +} + export const queryRE = /\?.*$/s const postfixRE = /[?#].*$/s @@ -881,13 +897,18 @@ export async function resolveServerUrls( const base = config.rawBase === './' || config.rawBase === '' ? '/' : config.rawBase - if (hostname.host && loopbackHosts.has(hostname.host)) { + if (hostname.host !== undefined && !wildcardHosts.has(hostname.host)) { let hostnameName = hostname.name // ipv6 host if (hostnameName.includes(':')) { hostnameName = `[${hostnameName}]` } - local.push(`${protocol}://${hostnameName}:${port}${base}`) + const address = `${protocol}://${hostnameName}:${port}${base}` + if (loopbackHosts.has(hostname.host)) { + local.push(address) + } else { + network.push(address) + } } else { Object.values(os.networkInterfaces()) .flatMap((nInterface) => nInterface ?? []) @@ -1037,11 +1058,18 @@ function mergeConfigRecursively( return merged } -export function mergeConfig( - defaults: Record, - overrides: Record, +export function mergeConfig< + D extends Record, + O extends Record, +>( + defaults: D extends Function ? never : D, + overrides: O extends Function ? never : O, isRoot = true, ): Record { + if (typeof defaults === 'function' || typeof overrides === 'function') { + throw new Error(`Cannot merge config in form of callback`) + } + return mergeConfigRecursively(defaults, overrides, isRoot ? '' : '.') } @@ -1210,6 +1238,16 @@ export function evalValue(rawValue: string): T { return fn() } +export function getNpmPackageName(importPath: string): string | null { + const parts = importPath.split('/') + if (parts[0][0] === '@') { + if (!parts[1]) return null + return `${parts[0]}/${parts[1]}` + } else { + return parts[0] + } +} + const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g export function escapeRegex(str: string): string { return str.replace(escapeRegexRE, '\\$&') diff --git a/packages/vite/src/types/shims.d.ts b/packages/vite/src/types/shims.d.ts index 4e31945d0449ae..de2875bd239cfd 100644 --- a/packages/vite/src/types/shims.d.ts +++ b/packages/vite/src/types/shims.d.ts @@ -31,6 +31,7 @@ declare module 'postcss-import' { basedir: string, importOptions: any, ) => string | string[] | Promise + load: (id: string) => Promise nameLayer: (index: number, rootFilename: string) => string }) => Plugin export = plugin diff --git a/playground/alias/package.json b/playground/alias/package.json index 60c9a67218b86a..78995fa19e045c 100644 --- a/playground/alias/package.json +++ b/playground/alias/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-alias", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/alias/vite.config.js b/playground/alias/vite.config.js index c2b2e7e2e923e0..1312b295b985dd 100644 --- a/playground/alias/vite.config.js +++ b/playground/alias/vite.config.js @@ -1,6 +1,9 @@ import path from 'node:path' +import module from 'node:module' import { defineConfig } from 'vite' +const require = module.createRequire(import.meta.url) + export default defineConfig({ resolve: { alias: [ diff --git a/playground/assets-sanitize/.env b/playground/assets-sanitize/.env new file mode 100644 index 00000000000000..d0e0cfd28cbe57 --- /dev/null +++ b/playground/assets-sanitize/.env @@ -0,0 +1 @@ +KEY=unsafe diff --git a/playground/assets-sanitize/__tests__/assets-sanitize.spec.ts b/playground/assets-sanitize/__tests__/assets-sanitize.spec.ts index 9fd8b1e988b089..f4a25aa1ef6264 100644 --- a/playground/assets-sanitize/__tests__/assets-sanitize.spec.ts +++ b/playground/assets-sanitize/__tests__/assets-sanitize.spec.ts @@ -25,3 +25,8 @@ if (!isBuild) { expect(Object.keys(manifest).length).toBe(3) // 2 svg, 1 index.js }) } + +test.runIf(!isBuild)('denied .env', async () => { + expect(await page.textContent('.unsafe-dotenv')).toBe('403') + expect(await page.textContent('.unsafe-dotenv-double-slash')).toBe('403') +}) diff --git a/playground/assets-sanitize/index.html b/playground/assets-sanitize/index.html index e4b4913ca7142c..0e634695c584fb 100644 --- a/playground/assets-sanitize/index.html +++ b/playground/assets-sanitize/index.html @@ -6,6 +6,35 @@ margin-bottom: 1rem; } -

test elements below should show circles and their url

+

test elements below should show circles and their url

+ +

Denied .env

+
+
+ + diff --git a/playground/assets-sanitize/package.json b/playground/assets-sanitize/package.json index 5deedbfaf97f38..1a110936d06db9 100644 --- a/playground/assets-sanitize/package.json +++ b/playground/assets-sanitize/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-assets-sanitize", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index 3aa3a9ab3189dd..ddc2d28d270999 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -312,6 +312,15 @@ test('new URL("/...", import.meta.url)', async () => { ) }) +test('new URL(..., import.meta.url) without extension', async () => { + expect(await page.textContent('.import-meta-url-without-extension')).toMatch( + isBuild ? 'data:application/javascript' : 'nested/test.js', + ) + expect( + await page.textContent('.import-meta-url-content-without-extension'), + ).toContain('export default class') +}) + test('new URL(`${dynamic}`, import.meta.url)', async () => { expect(await page.textContent('.dynamic-import-meta-url-1')).toMatch( isBuild ? 'data:image/png;base64' : '/foo/nested/icon.png', @@ -324,6 +333,28 @@ test('new URL(`${dynamic}`, import.meta.url)', async () => { ) }) +test('new URL(`./${dynamic}?abc`, import.meta.url)', async () => { + expect(await page.textContent('.dynamic-import-meta-url-1-query')).toMatch( + isBuild ? 'data:image/png;base64' : '/foo/nested/icon.png?abc', + ) + expect(await page.textContent('.dynamic-import-meta-url-2-query')).toMatch( + isBuild + ? /\/foo\/assets\/asset-\w{8}\.png\?abc/ + : '/foo/nested/asset.png?abc', + ) +}) + +test('new URL(`./${1 === 0 ? static : dynamic}?abc`, import.meta.url)', async () => { + expect(await page.textContent('.dynamic-import-meta-url-1-ternary')).toMatch( + isBuild ? 'data:image/png;base64' : '/foo/nested/icon.png?abc', + ) + expect(await page.textContent('.dynamic-import-meta-url-2-ternary')).toMatch( + isBuild + ? /\/foo\/assets\/asset-\w{8}\.png\?abc/ + : '/foo/nested/asset.png?abc', + ) +}) + test('new URL(`non-existent`, import.meta.url)', async () => { expect(await page.textContent('.non-existent-import-meta-url')).toMatch( new URL('non-existent', page.url()).pathname, @@ -377,12 +408,13 @@ test('inline style test', async () => { if (!isBuild) { test('@import in html style tag hmr', async () => { await untilUpdated(() => getColor('.import-css'), 'rgb(0, 136, 255)') + const loadPromise = page.waitForEvent('load') editFile( './css/import.css', (code) => code.replace('#0088ff', '#00ff88'), true, ) - await page.waitForNavigation() + await loadPromise await untilUpdated(() => getColor('.import-css'), 'rgb(0, 255, 136)') }) } diff --git a/playground/assets/index.html b/playground/assets/index.html index 57caa90f4f552d..5b30b733c2f9c9 100644 --- a/playground/assets/index.html +++ b/playground/assets/index.html @@ -190,6 +190,14 @@

new URL('/...', import.meta.url)

+

new URL('...', import.meta.url (without extension))

+

+ +

+

+ +

+

new URL('...', import.meta.url,) (with comma)

@@ -221,6 +229,26 @@

new URL(`./${dynamic}`, import.meta.url,) (with comma)

+

new URL(`./${dynamic}?abc`, import.meta.url)

+

+ + +

+

+ + +

+ +

new URL(`./${1 === 0 ? static : dynamic}?abc`, import.meta.url)

+

+ + +

+

+ + +

+

new URL(`non-existent`, import.meta.url)

@@ -383,6 +411,13 @@

assets in noscript

text('.import-meta-url-base-path', metaUrlBasePath) document.querySelector('.import-meta-url-base-path-img').src = metaUrlBasePath + const metaUrlWithoutExtension = new URL('./nested/test', import.meta.url) + text('.import-meta-url-without-extension', metaUrlWithoutExtension) + ;(async () => { + const res = await fetch(metaUrlWithoutExtension) + text('.import-meta-url-content-without-extension', await res.text()) + })() + // prettier-ignore const metaUrlWithComma = new URL('./nested/asset.png', import.meta.url,) text('.import-meta-url-comma', metaUrlWithComma) @@ -432,6 +467,28 @@

assets in noscript

testDynamicImportMetaUrlWithComma('icon', 1) testDynamicImportMetaUrlWithComma('asset', 2) + function testDynamicImportMetaUrlWithQuery(name, i) { + // prettier-ignore + const metaUrl = new URL(`./nested/${name}.png?abc`, import.meta.url,) + text(`.dynamic-import-meta-url-${i}-query`, metaUrl) + document.querySelector(`.dynamic-import-meta-url-img-${i}-query`).src = + metaUrl + } + + testDynamicImportMetaUrlWithQuery('icon', 1) + testDynamicImportMetaUrlWithQuery('asset', 2) + + function testDynamicImportMetaUrlWithTernaryOperator(name, i) { + // prettier-ignore + const metaUrl = new URL(`./nested/${1 === 0 ? 'failed' : name}.png?abc`, import.meta.url,) + text(`.dynamic-import-meta-url-${i}-ternary`, metaUrl) + document.querySelector(`.dynamic-import-meta-url-img-${i}-ternary`).src = + metaUrl + } + + testDynamicImportMetaUrlWithTernaryOperator('icon', 1) + testDynamicImportMetaUrlWithTernaryOperator('asset', 2) + { const name = 'test' const js = new URL(`./nested/${name}.js`, import.meta.url).href diff --git a/playground/assets/package.json b/playground/assets/package.json index 47e127261142e7..eeec51861fe068 100644 --- a/playground/assets/package.json +++ b/playground/assets/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-assets", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "debug": "node --inspect-brk ../../packages/vite/bin/vite", "dev": "vite", diff --git a/playground/backend-integration/package.json b/playground/backend-integration/package.json index d2d7ac79804c41..12b1aa1de18298 100644 --- a/playground/backend-integration/package.json +++ b/playground/backend-integration/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-backend-integration", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/backend-integration/postcss.config.js b/playground/backend-integration/postcss.config.js index f2f538422a839e..431c1ca465d257 100644 --- a/playground/backend-integration/postcss.config.js +++ b/playground/backend-integration/postcss.config.js @@ -1,5 +1,10 @@ -// postcss.config.js -module.exports = { +import { fileURLToPath } from 'node:url' +import { dirname } from 'node:path' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +export default { plugins: { tailwindcss: { config: __dirname + '/tailwind.config.js' }, }, diff --git a/playground/backend-integration/tailwind.config.js b/playground/backend-integration/tailwind.config.js index a91db5247f6553..bf91cec6521e40 100644 --- a/playground/backend-integration/tailwind.config.js +++ b/playground/backend-integration/tailwind.config.js @@ -1,4 +1,6 @@ -module.exports = { +/** @type {import('tailwindcss').Config} */ + +export default { content: [__dirname + '/frontend/**/*.{css,html,ts,js}'], theme: { extend: {}, diff --git a/playground/build-old/package.json b/playground/build-old/package.json index 9766699a41d435..695d5e6f28fbc7 100644 --- a/playground/build-old/package.json +++ b/playground/build-old/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-build-old", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/cli/package.json b/playground/cli/package.json index 39b7efc3b24304..09b97d52574733 100644 --- a/playground/cli/package.json +++ b/playground/cli/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-cli", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/config/__tests__/load.spec.ts b/playground/config/__tests__/load.spec.ts index 6236fff91b9272..a95cf592130f0b 100644 --- a/playground/config/__tests__/load.spec.ts +++ b/playground/config/__tests__/load.spec.ts @@ -20,7 +20,7 @@ it('loadConfigFromFile', async () => { 4, ], ], - "moduleCondition": "require condition", + "moduleCondition": "import condition", } `) }) diff --git a/playground/config/packages/entry/package.json b/playground/config/packages/entry/package.json index 287aa6c698618b..bb0e07d0af7389 100644 --- a/playground/config/packages/entry/package.json +++ b/playground/config/packages/entry/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-entry", + "type": "module", "dependencies": { "@vite/test-config-plugin-module-condition": "link:../plugin-module-condition" } diff --git a/playground/config/packages/plugin-module-condition/package.json b/playground/config/packages/plugin-module-condition/package.json index 38df99751d9e3e..623a54914737cf 100644 --- a/playground/config/packages/plugin-module-condition/package.json +++ b/playground/config/packages/plugin-module-condition/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-plugin-module-condition", + "type": "module", "exports": { ".": { "types": "./index.d.ts", diff --git a/playground/config/packages/siblings/foo.ts b/playground/config/packages/siblings/foo.ts index 78a8912131faed..efc3b112053c58 100644 --- a/playground/config/packages/siblings/foo.ts +++ b/playground/config/packages/siblings/foo.ts @@ -1,3 +1,3 @@ -import { partition } from 'lodash' +import lodash from 'lodash' -export const array = partition([1, 2, 3, 4], (n) => n % 2) +export const array = lodash.partition([1, 2, 3, 4], (n) => n % 2) diff --git a/playground/config/packages/siblings/package.json b/playground/config/packages/siblings/package.json index 1d7775558a79ac..b4bcc544931887 100644 --- a/playground/config/packages/siblings/package.json +++ b/playground/config/packages/siblings/package.json @@ -1,5 +1,6 @@ { "name": "@vite/test-config-sibling", + "type": "module", "devDependencies": { "@types/lodash": "^4.14.194", "lodash": "^4.17.21" diff --git a/playground/css-codesplit-cjs/package.json b/playground/css-codesplit-cjs/package.json index 97f1473d267e46..e305007adfcb98 100644 --- a/playground/css-codesplit-cjs/package.json +++ b/playground/css-codesplit-cjs/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-codesplit-cjs", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css-codesplit/package.json b/playground/css-codesplit/package.json index ac3149030dceaf..f7edd868783ebf 100644 --- a/playground/css-codesplit/package.json +++ b/playground/css-codesplit/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-codesplit", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css-dynamic-import/package.json b/playground/css-dynamic-import/package.json index 60b8fa380e2243..2b5339f8c72760 100644 --- a/playground/css-dynamic-import/package.json +++ b/playground/css-dynamic-import/package.json @@ -1,5 +1,6 @@ { "name": "@vitejs/test-css-dynamic-import", "private": true, + "type": "module", "version": "0.0.0" } diff --git a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts index 696864b12ffd64..94ce57bd54b235 100644 --- a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts +++ b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts @@ -37,22 +37,7 @@ describe.runIf(isServe)('serve', () => { }, ) const css = await res.text() - const map = extractSourcemap(css) - expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` - { - "mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACT,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;", - "sources": [ - "/root/linked.css", - ], - "sourcesContent": [ - ".linked { - color: red; - } - ", - ], - "version": 3, - } - `) + expect(css).not.toContain('sourceMappingURL') }) test('linked css with import', async () => { diff --git a/playground/css-sourcemap/package.json b/playground/css-sourcemap/package.json index 0bb168faa6360f..d1ff56dafa781f 100644 --- a/playground/css-sourcemap/package.json +++ b/playground/css-sourcemap/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css-sourcemap", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts index e0ef92c74c149b..5c85f24fe8820b 100644 --- a/playground/css/__tests__/css.spec.ts +++ b/playground/css/__tests__/css.spec.ts @@ -534,3 +534,7 @@ test('async css order with css modules', async () => { expect(await getColor('.modules-pink')).toMatchInlineSnapshot('"pink"') }, true) }) + +test('@import scss', async () => { + expect(await getColor('.at-import-scss')).toBe('red') +}) diff --git a/playground/css/imported.scss b/playground/css/imported.scss new file mode 100644 index 00000000000000..eee442a32c9eb5 --- /dev/null +++ b/playground/css/imported.scss @@ -0,0 +1,5 @@ +$color: red; + +.at-import-scss { + color: $color; +} diff --git a/playground/css/index.html b/playground/css/index.html index 748181b87f064e..2016c1b3c72ca8 100644 --- a/playground/css/index.html +++ b/playground/css/index.html @@ -192,5 +192,8 @@

CSS


   

import '#alias-module': this should be blue

- + +
@import scss: this should be red
diff --git a/playground/css/package.json b/playground/css/package.json index 43e4f87e12db72..d95ef47367e343 100644 --- a/playground/css/package.json +++ b/playground/css/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-css", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/blue-app/package.json b/playground/css/postcss-caching/blue-app/package.json index 82ba64fadd44b4..528263c4e60923 100644 --- a/playground/css/postcss-caching/blue-app/package.json +++ b/playground/css/postcss-caching/blue-app/package.json @@ -2,6 +2,7 @@ "name": "blue-app", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/blue-app/postcss.config.js b/playground/css/postcss-caching/blue-app/postcss.config.js index 50764f3ff8f21a..679b801013ef1a 100644 --- a/playground/css/postcss-caching/blue-app/postcss.config.js +++ b/playground/css/postcss-caching/blue-app/postcss.config.js @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [replacePinkWithBlue], } diff --git a/playground/css/postcss-caching/css.spec.ts b/playground/css/postcss-caching/css.spec.ts index 5f2893f0873e44..842d2726590d31 100644 --- a/playground/css/postcss-caching/css.spec.ts +++ b/playground/css/postcss-caching/css.spec.ts @@ -33,7 +33,7 @@ test.runIf(isServe)('postcss config', async () => { blueApp = await startServer(blueAppDir) - await page.goto(`http://localhost:${port}`) + await page.goto(`http://localhost:${port}`, { waitUntil: 'load' }) const blueA = await page.$('.postcss-a') expect(await getColor(blueA)).toBe('blue') const blueB = await page.$('.postcss-b') @@ -44,9 +44,9 @@ test.runIf(isServe)('postcss config', async () => { await blueApp.close() blueApp = null - const navigationPromise = page.waitForNavigation() // wait for server restart auto reload + const loadPromise = page.waitForEvent('load') // wait for server restart auto reload greenApp = await startServer(greenAppDir) - await navigationPromise + await loadPromise const greenA = await page.$('.postcss-a') expect(await getColor(greenA)).toBe('black') diff --git a/playground/css/postcss-caching/green-app/package.json b/playground/css/postcss-caching/green-app/package.json index 72bd0f45b8865f..110ea74558435d 100644 --- a/playground/css/postcss-caching/green-app/package.json +++ b/playground/css/postcss-caching/green-app/package.json @@ -2,6 +2,7 @@ "name": "green-app", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/css/postcss-caching/green-app/postcss.config.js b/playground/css/postcss-caching/green-app/postcss.config.js index 7d9d8818540e09..c0a74e3676976d 100644 --- a/playground/css/postcss-caching/green-app/postcss.config.js +++ b/playground/css/postcss-caching/green-app/postcss.config.js @@ -1,4 +1,4 @@ -module.exports = { +export default { plugins: [replacePinkWithGreen], } diff --git a/playground/css/postcss.config.js b/playground/css/postcss.config.js index 955878ac216f53..4d2c144b9fa66c 100644 --- a/playground/css/postcss.config.js +++ b/playground/css/postcss.config.js @@ -1,11 +1,12 @@ -module.exports = { - plugins: [require('postcss-nested'), testDirDep, testSourceInput], -} +import fs from 'node:fs' +import path from 'node:path' +import glob from 'fast-glob' +import { normalizePath } from 'vite' +import postcssNested from 'postcss-nested' -const fs = require('node:fs') -const path = require('node:path') -const glob = require('fast-glob') -const { normalizePath } = require('vite') +export default { + plugins: [postcssNested, testDirDep, testSourceInput], +} /** * A plugin for testing the `dir-dependency` message handling. diff --git a/playground/data-uri/package.json b/playground/data-uri/package.json index c19befed0bca09..4e8b2d699f2ac8 100644 --- a/playground/data-uri/package.json +++ b/playground/data-uri/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-data-uri", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/define/package.json b/playground/define/package.json index 9a144c76a4dfb0..a65b36c1c3df67 100644 --- a/playground/define/package.json +++ b/playground/define/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-define", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/dynamic-import/package.json b/playground/dynamic-import/package.json index 55137ef5fb9375..d3ab6846463268 100644 --- a/playground/dynamic-import/package.json +++ b/playground/dynamic-import/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-dynamic-import", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/dynamic-import/vite.config.js b/playground/dynamic-import/vite.config.js index 15aa703d74530a..dc8ecbd8bbdfe5 100644 --- a/playground/dynamic-import/vite.config.js +++ b/playground/dynamic-import/vite.config.js @@ -1,8 +1,8 @@ import fs from 'node:fs' import path from 'node:path' -import vite from 'vite' +import { defineConfig } from 'vite' -export default vite.defineConfig({ +export default defineConfig({ plugins: [ { name: 'copy', diff --git a/playground/env-nested/package.json b/playground/env-nested/package.json index 545eefb2f690d5..060888e998c98d 100644 --- a/playground/env-nested/package.json +++ b/playground/env-nested/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-env-nested", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/env/package.json b/playground/env/package.json index 969f4061114a9d..a50e47e1c17313 100644 --- a/playground/env/package.json +++ b/playground/env/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-env", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "VITE_INLINE=inline-serve vite", "build": "VITE_INLINE=inline-build vite build", diff --git a/playground/extensions/package.json b/playground/extensions/package.json index 30dde24815a6ce..b11cc4a213e352 100644 --- a/playground/extensions/package.json +++ b/playground/extensions/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-extensions", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/external/package.json b/playground/external/package.json index c27e446e8fbdee..6f5141bb15ae9f 100644 --- a/playground/external/package.json +++ b/playground/external/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-external", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/fs-serve/package.json b/playground/fs-serve/package.json index 15fdfe3294cd83..ceb4552d1c244f 100644 --- a/playground/fs-serve/package.json +++ b/playground/fs-serve/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-fs-serve", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite root", "build": "vite build root", diff --git a/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts index 34b77127cdb1e0..cf1b6c199e73aa 100644 --- a/playground/glob-import/__tests__/glob-import.spec.ts +++ b/playground/glob-import/__tests__/glob-import.spec.ts @@ -240,3 +240,7 @@ test('escapes special chars in globs without mangling user supplied glob suffix' .sort() expect(expectedNames).toEqual(foundAliasNames) }) + +test('sub imports', async () => { + expect(await page.textContent('.sub-imports')).toMatch('bar foo') +}) diff --git a/playground/glob-import/imports-path/bar.js b/playground/glob-import/imports-path/bar.js new file mode 100644 index 00000000000000..4548a26ba14dc8 --- /dev/null +++ b/playground/glob-import/imports-path/bar.js @@ -0,0 +1 @@ +export default 'bar' diff --git a/playground/glob-import/imports-path/foo.js b/playground/glob-import/imports-path/foo.js new file mode 100644 index 00000000000000..7e942cf45c8a37 --- /dev/null +++ b/playground/glob-import/imports-path/foo.js @@ -0,0 +1 @@ +export default 'foo' diff --git a/playground/glob-import/index.html b/playground/glob-import/index.html index a899d244326f68..b726965ff62067 100644 --- a/playground/glob-import/index.html +++ b/playground/glob-import/index.html @@ -21,6 +21,8 @@

Escape relative glob


 

Escape alias glob


+

Sub imports

+

 
 
 
 
+
+
 
diff --git a/playground/glob-import/package.json b/playground/glob-import/package.json
index f3ac7ae9313db5..7d9104ab431c28 100644
--- a/playground/glob-import/package.json
+++ b/playground/glob-import/package.json
@@ -2,6 +2,10 @@
   "name": "@vitejs/test-import-context",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
+  "imports": {
+    "#imports/*": "./imports-path/*"
+  },
   "scripts": {
     "dev": "vite",
     "build": "vite build",
diff --git a/playground/hmr/__tests__/hmr.spec.ts b/playground/hmr/__tests__/hmr.spec.ts
index a7fbbad80ae90e..163931724470a0 100644
--- a/playground/hmr/__tests__/hmr.spec.ts
+++ b/playground/hmr/__tests__/hmr.spec.ts
@@ -9,6 +9,7 @@ import {
   removeFile,
   untilBrowserLogAfter,
   untilUpdated,
+  viteServer,
   viteTestUrl,
 } from '~utils'
 
@@ -229,7 +230,7 @@ if (!isBuild) {
   })
 
   test('not loaded dynamic import', async () => {
-    await page.goto(viteTestUrl + '/counter/index.html')
+    await page.goto(viteTestUrl + '/counter/index.html', { waitUntil: 'load' })
 
     let btn = await page.$('button')
     expect(await btn.textContent()).toBe('Counter 0')
@@ -237,8 +238,9 @@ if (!isBuild) {
     expect(await btn.textContent()).toBe('Counter 1')
 
     // Modifying `index.ts` triggers a page reload, as expected
+    const indexTsLoadPromise = page.waitForEvent('load')
     editFile('counter/index.ts', (code) => code)
-    await page.waitForNavigation()
+    await indexTsLoadPromise
     btn = await page.$('button')
     expect(await btn.textContent()).toBe('Counter 0')
 
@@ -251,13 +253,12 @@ if (!isBuild) {
     // (Note that, a dynamic import that is never loaded and that does not
     // define `accept.module.hot.accept` may wrongfully trigger a full page
     // reload, see discussion at #7561.)
+    const depTsLoadPromise = page.waitForEvent('load', { timeout: 1000 })
     editFile('counter/dep.ts', (code) => code)
-    try {
-      await page.waitForNavigation({ timeout: 1000 })
-    } catch (err) {
-      const errMsg = 'page.waitForNavigation: Timeout 1000ms exceeded.'
-      expect(err.message.slice(0, errMsg.length)).toBe(errMsg)
-    }
+    await expect(depTsLoadPromise).rejects.toThrow(
+      /page\.waitForEvent: Timeout \d+ms exceeded while waiting for event "load"/,
+    )
+
     btn = await page.$('button')
     expect(await btn.textContent()).toBe('Counter 1')
   })
@@ -653,10 +654,12 @@ if (!isBuild) {
   test('css in html hmr', async () => {
     await page.goto(viteTestUrl)
     expect(await getBg('.import-image')).toMatch('icon')
-    await page.goto(viteTestUrl + '/foo/')
+    await page.goto(viteTestUrl + '/foo/', { waitUntil: 'load' })
     expect(await getBg('.import-image')).toMatch('icon')
+
+    const loadPromise = page.waitForEvent('load')
     editFile('index.html', (code) => code.replace('url("./icon.png")', ''))
-    await page.waitForNavigation()
+    await loadPromise
     expect(await getBg('.import-image')).toMatch('')
   })
 
@@ -664,14 +667,24 @@ if (!isBuild) {
     await page.goto(viteTestUrl + '/counter/index.html')
     let btn = await page.$('button')
     expect(await btn.textContent()).toBe('Counter 0')
+
+    const loadPromise = page.waitForEvent('load')
     editFile('counter/index.html', (code) =>
       code.replace('Counter', 'Compteur'),
     )
-    await page.waitForNavigation()
+    await loadPromise
     btn = await page.$('button')
     expect(await btn.textContent()).toBe('Compteur 0')
   })
 
+  test('virtual module in module graph', async () => {
+    const moduleGraph = viteServer.moduleGraph
+    const virtualId = Array.from(moduleGraph.idToModuleMap.keys()).filter(
+      (id: string) => id.includes('virtual'),
+    )
+    expect(virtualId).toEqual(['\x00virtual:file', '/@id/__x00__virtual:file'])
+  })
+
   test('handle virtual module updates', async () => {
     await page.goto(viteTestUrl)
     const el = await page.$('.virtual')
@@ -699,20 +712,21 @@ if (!isBuild) {
     const file = 'missing-import/a.js'
     const importCode = "import 'missing-modules'"
     const unImportCode = `// ${importCode}`
-    const timeout = 2000
 
-    await page.goto(viteTestUrl + '/missing-import/index.html')
+    await page.goto(viteTestUrl + '/missing-import/index.html', {
+      waitUntil: 'load',
+    })
 
     await untilBrowserLogAfter(async () => {
-      const navigationPromise = page.waitForNavigation({ timeout })
+      const loadPromise = page.waitForEvent('load')
       editFile(file, (code) => code.replace(importCode, unImportCode))
-      await navigationPromise
+      await loadPromise
     }, 'missing test')
 
     await untilBrowserLogAfter(async () => {
-      const navigationPromise = page.waitForNavigation({ timeout })
+      const loadPromise = page.waitForEvent('load')
       editFile(file, (code) => code.replace(unImportCode, importCode))
-      await navigationPromise
+      await loadPromise
     }, /500/)
   })
 
diff --git a/playground/hmr/hmr.ts b/playground/hmr/hmr.ts
index 9748fdd1e8bc11..7a31477d52f556 100644
--- a/playground/hmr/hmr.ts
+++ b/playground/hmr/hmr.ts
@@ -42,6 +42,13 @@ if (import.meta.hot) {
     handleDep('multi deps', foo, nestedFoo)
   })
 
+  import.meta.hot.accept(
+    ['virtual:file', '/@id/__x00__virtual:file'],
+    ([rawVirtualPath, acceptedVirtualPath]) => {
+      text('.virtual', acceptedVirtualPath.virtual)
+    },
+  )
+
   import.meta.hot.dispose(() => {
     console.log(`foo was:`, foo)
   })
diff --git a/playground/hmr/package.json b/playground/hmr/package.json
index 8bb1d44d18bbe0..35e0799c262738 100644
--- a/playground/hmr/package.json
+++ b/playground/hmr/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-hmr",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build",
diff --git a/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json
deleted file mode 100644
index ca98b7ce20a3ca..00000000000000
--- a/playground/hmr/tsconfig.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  "extends": "../tsconfig.json",
-  "include": ["."],
-  "exclude": ["**/dist/**", "**/__tests__/**"],
-  "compilerOptions": {
-    "target": "ES2020",
-    "module": "ESNext",
-    "outDir": "dist",
-    "allowJs": true,
-    "esModuleInterop": true,
-    "moduleResolution": "bundler",
-    "baseUrl": ".",
-    "jsx": "preserve",
-    "types": ["vite/client", "node"]
-  }
-}
diff --git a/playground/html/package.json b/playground/html/package.json
index 9eadef9f1a71a8..6bdb23d06194a4 100644
--- a/playground/html/package.json
+++ b/playground/html/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-html",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build",
diff --git a/playground/import-assertion/package.json b/playground/import-assertion/package.json
index 03248a46ef4dd3..04ecce34c1f5ec 100644
--- a/playground/import-assertion/package.json
+++ b/playground/import-assertion/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-import-assertion",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build",
diff --git a/playground/js-sourcemap/package.json b/playground/js-sourcemap/package.json
index 4b82881a37e473..6381b13c9b09e9 100644
--- a/playground/js-sourcemap/package.json
+++ b/playground/js-sourcemap/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-js-sourcemap",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build",
diff --git a/playground/json/__tests__/json.spec.ts b/playground/json/__tests__/csr/json.spec.ts
similarity index 89%
rename from playground/json/__tests__/json.spec.ts
rename to playground/json/__tests__/csr/json.spec.ts
index 5837a236eee314..cec1fb5f0eb0ba 100644
--- a/playground/json/__tests__/json.spec.ts
+++ b/playground/json/__tests__/csr/json.spec.ts
@@ -1,10 +1,10 @@
 import { readFileSync } from 'node:fs'
 import { expect, test } from 'vitest'
-import testJson from '../test.json'
-import hmrJson from '../hmr.json'
+import deepJson from 'vue/package.json'
+import testJson from '../../test.json'
+import hmrJson from '../../hmr.json'
 import { editFile, isBuild, isServe, page, untilUpdated } from '~utils'
 
-const deepJson = require('vue/package.json')
 const stringified = JSON.stringify(testJson)
 const deepStringified = JSON.stringify(deepJson)
 const hmrStringified = JSON.stringify(hmrJson)
@@ -45,7 +45,7 @@ test('?url', async () => {
 
 test('?raw', async () => {
   expect(await page.textContent('.raw')).toBe(
-    readFileSync(require.resolve('../test.json'), 'utf-8'),
+    readFileSync(require.resolve('../../test.json'), 'utf-8'),
   )
 })
 
diff --git a/playground/json/__tests__/ssr/json.spec.ts b/playground/json/__tests__/ssr/json.spec.ts
new file mode 100644
index 00000000000000..5efbeac7da12d6
--- /dev/null
+++ b/playground/json/__tests__/ssr/json.spec.ts
@@ -0,0 +1,20 @@
+import { beforeEach, test } from 'vitest'
+import { port } from './serve'
+import { page, untilUpdated } from '~utils'
+
+const url = `http://localhost:${port}`
+
+beforeEach(async () => {
+  await page.goto(url)
+})
+
+test('load json module', async () => {
+  await untilUpdated(
+    () => page.textContent('.fetch-json-module pre'),
+    'export default JSON.parse("{\\n  \\"hello\\": \\"hi\\"\\n}\\n")',
+  )
+})
+
+test('fs json', async () => {
+  await untilUpdated(() => page.textContent('.fetch-json-fs pre'), '61')
+})
diff --git a/playground/json/__tests__/ssr/serve.ts b/playground/json/__tests__/ssr/serve.ts
new file mode 100644
index 00000000000000..369d3b3999df28
--- /dev/null
+++ b/playground/json/__tests__/ssr/serve.ts
@@ -0,0 +1,35 @@
+// this is automatically detected by playground/vitestSetup.ts and will replace
+// the default e2e test serve behavior
+
+import path from 'node:path'
+import kill from 'kill-port'
+import { ports, rootDir } from '~utils'
+
+export const port = ports.json
+
+export async function serve(): Promise<{ close(): Promise }> {
+  await kill(port)
+
+  const { createServer } = await import(path.resolve(rootDir, 'server.js'))
+  const { app, vite } = await createServer(rootDir)
+
+  return new Promise((resolve, reject) => {
+    try {
+      const server = app.listen(port, () => {
+        resolve({
+          // for test teardown
+          async close() {
+            await new Promise((resolve) => {
+              server.close(resolve)
+            })
+            if (vite) {
+              await vite.close()
+            }
+          },
+        })
+      })
+    } catch (e) {
+      reject(e)
+    }
+  })
+}
diff --git a/playground/json/package.json b/playground/json/package.json
index 748e23fda44137..1484ada27924e5 100644
--- a/playground/json/package.json
+++ b/playground/json/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-json",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build",
@@ -12,8 +13,8 @@
     "debug:ssr": "node --inspect-brk server"
   },
   "devDependencies": {
-    "express": "^4.18.2",
     "@vitejs/test-json-module": "file:./json-module",
+    "express": "^4.18.2",
     "vue": "^3.2.47"
   }
 }
diff --git a/playground/json/server.js b/playground/json/server.js
index 5a7a989d9c39e3..705fd0efa0aabb 100644
--- a/playground/json/server.js
+++ b/playground/json/server.js
@@ -1,21 +1,22 @@
 // @ts-check
-const fs = require('node:fs')
-const path = require('node:path')
-const express = require('express')
+import fs from 'node:fs'
+import path from 'node:path'
+import { fileURLToPath } from 'node:url'
+import express from 'express'
 
+const __dirname = path.dirname(fileURLToPath(import.meta.url))
 const isTest = process.env.VITEST
 
-async function createServer(
-  root = process.cwd(),
-  isProd = process.env.NODE_ENV === 'production',
-) {
+export async function createServer(root = process.cwd()) {
   const resolve = (p) => path.resolve(__dirname, p)
   const app = express()
 
   /**
    * @type {import('vite').ViteDevServer}
    */
-  const vite = await require('vite').createServer({
+  const vite = await (
+    await import('vite')
+  ).createServer({
     root,
     logLevel: isTest ? 'error' : 'info',
     server: {
@@ -50,13 +51,16 @@ async function createServer(
 
       if (url === '/json-fs') {
         console.time('transform module')
-        const source = fs.readFileSync('./test.json', { encoding: 'utf-8' })
+        const source = fs.readFileSync(path.resolve(__dirname, './test.json'), {
+          encoding: 'utf-8',
+        })
         const json = await vite.ssrTransform(
           `export default ${source}`,
           null,
           './output.json',
         )
         console.timeEnd('transform module')
+        // @ts-expect-error ignore in test
         res.status(200).end(String(json.code.length))
         return
       }
@@ -83,6 +87,3 @@ if (!isTest) {
     }),
   )
 }
-
-// for test use
-exports.createServer = createServer
diff --git a/playground/legacy/__tests__/client-and-ssr/serve.ts b/playground/legacy/__tests__/client-and-ssr/serve.ts
index 3dc22f7adc0f45..46a075549db53a 100644
--- a/playground/legacy/__tests__/client-and-ssr/serve.ts
+++ b/playground/legacy/__tests__/client-and-ssr/serve.ts
@@ -34,7 +34,7 @@ export async function serve(): Promise<{ close(): Promise }> {
 
   app.use('/', async (_req, res) => {
     const { render } = await import(
-      path.resolve(rootDir, './dist/server/entry-server-sequential.mjs')
+      path.resolve(rootDir, './dist/server/entry-server-sequential.js')
     )
     const html = await render()
     res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
diff --git a/playground/legacy/__tests__/ssr/serve.ts b/playground/legacy/__tests__/ssr/serve.ts
index 69ff2ec940b825..2b20dfc8455d69 100644
--- a/playground/legacy/__tests__/ssr/serve.ts
+++ b/playground/legacy/__tests__/ssr/serve.ts
@@ -22,7 +22,7 @@ export async function serve(): Promise<{ close(): Promise }> {
 
   app.use('/', async (_req, res) => {
     const { render } = await import(
-      path.resolve(rootDir, './dist/server/entry-server.mjs')
+      path.resolve(rootDir, './dist/server/entry-server.js')
     )
     const html = await render()
     res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
diff --git a/playground/legacy/package.json b/playground/legacy/package.json
index b47df1430d6cdc..897d9c94ef819d 100644
--- a/playground/legacy/package.json
+++ b/playground/legacy/package.json
@@ -2,6 +2,7 @@
   "name": "@vitejs/test-legacy",
   "private": true,
   "version": "0.0.0",
+  "type": "module",
   "scripts": {
     "dev": "vite",
     "build": "vite build --debug legacy",
diff --git a/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts
index ce309a2285fe98..d4ced107fdea7a 100644
--- a/playground/lib/__tests__/lib.spec.ts
+++ b/playground/lib/__tests__/lib.spec.ts
@@ -15,8 +15,10 @@ describe.runIf(isBuild)('build', () => {
 
   test('umd', async () => {
     expect(await page.textContent('.umd')).toBe('It works')
-    const code = readFile('dist/my-lib-custom-filename.umd.js')
-    const noMinifyCode = readFile('dist/nominify/my-lib-custom-filename.umd.js')
+    const code = readFile('dist/my-lib-custom-filename.umd.cjs')
+    const noMinifyCode = readFile(
+      'dist/nominify/my-lib-custom-filename.umd.cjs',
+    )
     // esbuild helpers are injected inside of the UMD wrapper
     expect(code).toMatch(/^\(function\(/)
     expect(noMinifyCode).toMatch(
@@ -46,7 +48,7 @@ describe.runIf(isBuild)('build', () => {
     expect(code).not.toMatch('__vitePreload')
 
     // Test that library chunks are hashed
-    expect(code).toMatch(/await import\("\.\/message-[a-z\d]{8}.mjs"\)/)
+    expect(code).toMatch(/await import\("\.\/message-[a-z\d]{8}.js"\)/)
   })
 
   test('@import hoist', async () => {
@@ -57,9 +59,9 @@ describe.runIf(isBuild)('build', () => {
   })
 
   test('preserve process.env', () => {
-    const es = readFile('dist/my-lib-custom-filename.mjs')
+    const es = readFile('dist/my-lib-custom-filename.js')
     const iife = readFile('dist/my-lib-custom-filename.iife.js')
-    const umd = readFile('dist/my-lib-custom-filename.umd.js')
+    const umd = readFile('dist/my-lib-custom-filename.umd.cjs')
     expect(es).toMatch('process.env.NODE_ENV')
     expect(iife).toMatch('process.env.NODE_ENV')
     expect(umd).toMatch('process.env.NODE_ENV')
diff --git a/playground/lib/index.dist.html b/playground/lib/index.dist.html
index b719268ded6365..e7fb284811876a 100644
--- a/playground/lib/index.dist.html
+++ b/playground/lib/index.dist.html
@@ -14,7 +14,7 @@
 
 
 
@@ -25,7 +25,7 @@
   message('.dynamic-import-message')
 
 
-
+
 
+
+
+
+
diff --git a/playground/optimize-deps/index.html b/playground/optimize-deps/index.html
index 8c5719075650ce..a07e6a17798154 100644
--- a/playground/optimize-deps/index.html
+++ b/playground/optimize-deps/index.html
@@ -165,6 +165,7 @@ 

Pre bundle css require

) import './index.astro' + import './generics.vue' // All these imports should end up resolved to the same URL (same ?v= injected on them) import { add as addFromDirectAbsolutePath } from '/node_modules/@vitejs/test-dep-non-optimized/index.js' diff --git a/playground/optimize-deps/package.json b/playground/optimize-deps/package.json index eaa950d06ccbbd..c46247676a1313 100644 --- a/playground/optimize-deps/package.json +++ b/playground/optimize-deps/package.json @@ -1,6 +1,7 @@ { "name": "@vitejs/test-optimize-deps", "private": true, + "type": "module", "version": "0.0.0", "scripts": { "dev": "vite", @@ -22,6 +23,8 @@ "@vitejs/test-dep-linked-include": "link:./dep-linked-include", "@vitejs/test-dep-node-env": "file:./dep-node-env", "@vitejs/test-dep-not-js": "file:./dep-not-js", + "@vitejs/test-dep-optimize-exports-with-glob": "file:./dep-optimize-exports-with-glob", + "@vitejs/test-dep-optimize-with-glob": "file:./dep-optimize-with-glob", "@vitejs/test-dep-relative-to-main": "file:./dep-relative-to-main", "@vitejs/test-dep-with-builtin-module-cjs": "file:./dep-with-builtin-module-cjs", "@vitejs/test-dep-with-builtin-module-esm": "file:./dep-with-builtin-module-esm", diff --git a/playground/optimize-deps/vite.config.js b/playground/optimize-deps/vite.config.js index 7eb4c5b10c3101..8947bb66020b7c 100644 --- a/playground/optimize-deps/vite.config.js +++ b/playground/optimize-deps/vite.config.js @@ -1,5 +1,7 @@ import fs from 'node:fs' +import module from 'node:module' import { defineConfig } from 'vite' +const require = module.createRequire(import.meta.url) // Overriding the NODE_ENV set by vitest process.env.NODE_ENV = '' @@ -21,6 +23,8 @@ export default defineConfig({ '@vitejs/test-nested-exclude > @vitejs/test-nested-include', // will throw if optimized (should log warning instead) '@vitejs/test-non-optimizable-include', + '@vitejs/test-dep-optimize-exports-with-glob/**/*', + '@vitejs/test-dep-optimize-with-glob/**/*.js', ], exclude: ['@vitejs/test-nested-exclude', '@vitejs/test-dep-non-optimized'], esbuildOptions: { @@ -121,6 +125,11 @@ export default defineComponent({ `.trim(), } } + + // fallback to empty module for other vue files + if (id.endsWith('.vue')) { + return { code: `export default {}` } + } }, } } diff --git a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts index c4c455eaaf7bbb..29b7d12dba9502 100644 --- a/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts +++ b/playground/optimize-missing-deps/__test__/optimize-missing-deps.spec.ts @@ -1,4 +1,3 @@ -import { platform } from 'node:os' import fetch from 'node-fetch' import { expect, test } from 'vitest' import { port } from './serve' @@ -6,8 +5,7 @@ import { page, untilUpdated } from '~utils' const url = `http://localhost:${port}/` -// TODO: on macOS this test causing the process exists for some reason -test.skipIf(platform() === 'darwin')('optimize', async () => { +test('optimize', async () => { await page.goto(url) // reload page to get optimized missing deps await page.reload() diff --git a/playground/optimize-missing-deps/__test__/serve.ts b/playground/optimize-missing-deps/__test__/serve.ts index ed9ad41a7c90a1..2472e170236d5d 100644 --- a/playground/optimize-missing-deps/__test__/serve.ts +++ b/playground/optimize-missing-deps/__test__/serve.ts @@ -7,7 +7,7 @@ import { hmrPorts, ports, rootDir } from '~utils' export const port = ports['optimize-missing-deps'] export async function serve(): Promise<{ close(): Promise }> { - const { createServer } = require(path.resolve(rootDir, 'server.js')) + const { createServer } = await import(path.resolve(rootDir, 'server.js')) const { app, vite } = await createServer( rootDir, hmrPorts['optimize-missing-deps'], diff --git a/playground/optimize-missing-deps/package.json b/playground/optimize-missing-deps/package.json index e968a34bc7c9de..21281f45bd66f8 100644 --- a/playground/optimize-missing-deps/package.json +++ b/playground/optimize-missing-deps/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-optimize-missing-deps", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "node server" }, diff --git a/playground/optimize-missing-deps/server.js b/playground/optimize-missing-deps/server.js index 1940d76fa7e0cd..411c3342b02d9c 100644 --- a/playground/optimize-missing-deps/server.js +++ b/playground/optimize-missing-deps/server.js @@ -1,11 +1,11 @@ // @ts-check -const fs = require('node:fs') -const path = require('node:path') -const express = require('express') +import fs from 'node:fs' +import path from 'node:path' +import express from 'express' const isTest = process.env.VITEST -async function createServer(root = process.cwd(), hmrPort) { +export async function createServer(root = process.cwd(), hmrPort) { const resolve = (p) => path.resolve(__dirname, p) const app = express() @@ -13,7 +13,9 @@ async function createServer(root = process.cwd(), hmrPort) { /** * @type {import('vite').ViteDevServer} */ - const vite = await require('vite').createServer({ + const vite = await ( + await import('vite') + ).createServer({ root, logLevel: isTest ? 'error' : 'info', server: { @@ -62,6 +64,3 @@ if (!isTest) { }), ) } - -// for test use -exports.createServer = createServer diff --git a/playground/package.json b/playground/package.json index fc131d3f5f50bb..e0c5e6c2879392 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,6 +1,7 @@ { "name": "@vitejs/vite-playground", "private": true, + "type": "module", "version": "1.0.0", "scripts": { "typecheck": "tsc --noEmit" diff --git a/playground/preload/package.json b/playground/preload/package.json index 68d58d996559cf..04c021be9ca04e 100644 --- a/playground/preload/package.json +++ b/playground/preload/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-preload", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/preserve-symlinks/package.json b/playground/preserve-symlinks/package.json index 31f1c672e1b3b3..8a68c00cc82ddf 100644 --- a/playground/preserve-symlinks/package.json +++ b/playground/preserve-symlinks/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-preserve-symlinks", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite --force", "build": "vite build", diff --git a/playground/resolve-config/package.json b/playground/resolve-config/package.json index f413cd269d38d9..5a0d84c6295bd0 100644 --- a/playground/resolve-config/package.json +++ b/playground/resolve-config/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-resolve-config", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "dev": "vite --force", "build": "vite build", diff --git a/playground/resolve-linked/package.json b/playground/resolve-linked/package.json index cd8b9a24b2303a..a95a9ff5562bc0 100644 --- a/playground/resolve-linked/package.json +++ b/playground/resolve-linked/package.json @@ -2,5 +2,6 @@ "name": "@vitejs/test-resolve-linked", "private": true, "version": "0.0.0", + "type": "module", "main": "src/index.js" } diff --git a/playground/resolve/__tests__/resolve.spec.ts b/playground/resolve/__tests__/resolve.spec.ts index fa274846b4d869..90d02a761258e6 100644 --- a/playground/resolve/__tests__/resolve.spec.ts +++ b/playground/resolve/__tests__/resolve.spec.ts @@ -67,6 +67,15 @@ test('Respect exports to take precedence over mainFields', async () => { expect(await page.textContent('.exports-with-module')).toMatch('[success]') }) +test('import and require resolve using module condition', async () => { + expect(await page.textContent('.exports-with-module-condition')).toMatch( + '[success]', + ) + expect( + await page.textContent('.exports-with-module-condition-required'), + ).toMatch('[success]') +}) + test('implicit dir/index.js', async () => { expect(await page.textContent('.index')).toMatch('[success]') }) diff --git a/playground/resolve/config-dep.js b/playground/resolve/config-dep.cjs similarity index 100% rename from playground/resolve/config-dep.js rename to playground/resolve/config-dep.cjs diff --git a/playground/resolve/exports-with-module-condition-required/index.cjs b/playground/resolve/exports-with-module-condition-required/index.cjs new file mode 100644 index 00000000000000..b06508a52c8cc2 --- /dev/null +++ b/playground/resolve/exports-with-module-condition-required/index.cjs @@ -0,0 +1,3 @@ +/* eslint-disable import/no-commonjs */ +const { msg } = require('@vitejs/test-resolve-exports-with-module-condition') +module.exports = { msg } diff --git a/playground/resolve/exports-with-module-condition-required/package.json b/playground/resolve/exports-with-module-condition-required/package.json new file mode 100644 index 00000000000000..8e1b2969fbf7f2 --- /dev/null +++ b/playground/resolve/exports-with-module-condition-required/package.json @@ -0,0 +1,9 @@ +{ + "name": "@vitejs/test-resolve-exports-with-module-condition-required", + "private": true, + "version": "1.0.0", + "main": "index.cjs", + "dependencies": { + "@vitejs/test-resolve-exports-with-module-condition": "link:../exports-with-module-condition" + } +} diff --git a/playground/resolve/exports-with-module-condition/index.esm.js b/playground/resolve/exports-with-module-condition/index.esm.js new file mode 100644 index 00000000000000..f1e0b54ee0c7ac --- /dev/null +++ b/playground/resolve/exports-with-module-condition/index.esm.js @@ -0,0 +1 @@ +export const msg = '[success] exports with module condition (index.esm.js)' diff --git a/playground/resolve/exports-with-module-condition/index.js b/playground/resolve/exports-with-module-condition/index.js new file mode 100644 index 00000000000000..6465a8c55084c3 --- /dev/null +++ b/playground/resolve/exports-with-module-condition/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-commonjs */ +module.exports.msg = '[fail] exports with module condition (index.js)' diff --git a/playground/resolve/exports-with-module-condition/index.mjs b/playground/resolve/exports-with-module-condition/index.mjs new file mode 100644 index 00000000000000..1696a05425e35f --- /dev/null +++ b/playground/resolve/exports-with-module-condition/index.mjs @@ -0,0 +1 @@ +export const msg = '[fail] exports with module condition (index.mjs)' diff --git a/playground/resolve/exports-with-module-condition/package.json b/playground/resolve/exports-with-module-condition/package.json new file mode 100644 index 00000000000000..92a8f2dd2d1f80 --- /dev/null +++ b/playground/resolve/exports-with-module-condition/package.json @@ -0,0 +1,10 @@ +{ + "name": "@vitejs/test-resolve-exports-with-module-condition", + "private": true, + "version": "1.0.0", + "exports": { + "module": "./index.esm.js", + "import": "./index.mjs", + "require": "./index.js" + } +} diff --git a/playground/resolve/index.html b/playground/resolve/index.html index 3aba3224c4822c..64d9306266a68d 100644 --- a/playground/resolve/index.html +++ b/playground/resolve/index.html @@ -36,6 +36,13 @@

Exports with legacy fallback

Exports with module

fail

+

+ Both import and require resolve using module condition (avoids dual package + hazard) +

+

fail

+

fail

+

Resolving top level with imports field

fail

@@ -214,6 +221,14 @@

resolve package that contains # in path

import { msg as exportsWithModule } from '@vitejs/test-resolve-exports-with-module' text('.exports-with-module', exportsWithModule) + import { msg as exportsWithModuleCondition } from '@vitejs/test-resolve-exports-with-module-condition' + import { msg as exportsWithModuleConditionRequired } from '@vitejs/test-resolve-exports-with-module-condition-required' + text('.exports-with-module-condition', exportsWithModuleCondition) + text( + '.exports-with-module-condition-required', + exportsWithModuleConditionRequired, + ) + // imports field import { msg as importsTopLevel } from '#top-level' text('.imports-top-level', importsTopLevel) diff --git a/playground/resolve/package.json b/playground/resolve/package.json index 4a8fc641d6b756..6e3a7d50b86a63 100644 --- a/playground/resolve/package.json +++ b/playground/resolve/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-resolve", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", @@ -33,6 +34,8 @@ "@vitejs/test-resolve-exports-legacy-fallback": "link:./exports-legacy-fallback", "@vitejs/test-resolve-exports-path": "link:./exports-path", "@vitejs/test-resolve-exports-with-module": "link:./exports-with-module", + "@vitejs/test-resolve-exports-with-module-condition": "link:./exports-with-module-condition", + "@vitejs/test-resolve-exports-with-module-condition-required": "link:./exports-with-module-condition-required", "@vitejs/test-resolve-linked": "workspace:*", "@vitejs/test-resolve-imports-pkg": "link:./imports-path/other-pkg", "@vitejs/test-resolve-sharp-dir": "link:./sharp-dir" diff --git a/playground/resolve/vite.config.js b/playground/resolve/vite.config.js index efffc50960a86b..f4d923d1a05ae0 100644 --- a/playground/resolve/vite.config.js +++ b/playground/resolve/vite.config.js @@ -1,6 +1,6 @@ import path from 'node:path' import { defineConfig, normalizePath } from 'vite' -import { a } from './config-dep' +import { a } from './config-dep.cjs' const virtualFile = '@virtual-file' const virtualId = '\0' + virtualFile @@ -102,6 +102,7 @@ export default defineConfig({ ], optimizeDeps: { include: [ + '@vitejs/test-resolve-exports-with-module-condition-required', '@vitejs/test-require-pkg-with-module-field', '@vitejs/test-resolve-sharp-dir', ], diff --git a/playground/ssr-deps/package.json b/playground/ssr-deps/package.json index ce48077dc196d0..9b07ce7cb45d1e 100644 --- a/playground/ssr-deps/package.json +++ b/playground/ssr-deps/package.json @@ -1,8 +1,8 @@ { "name": "@vitejs/test-ssr-deps", "private": true, - "version": "0.0.0", "type": "module", + "version": "0.0.0", "scripts": { "dev": "node server", "serve": "NODE_ENV=production node server", diff --git a/playground/ssr-html/__tests__/ssr-html.spec.ts b/playground/ssr-html/__tests__/ssr-html.spec.ts index 2b9da5cadd01c0..50b6e9540426bc 100644 --- a/playground/ssr-html/__tests__/ssr-html.spec.ts +++ b/playground/ssr-html/__tests__/ssr-html.spec.ts @@ -48,10 +48,13 @@ describe.runIf(isServe)('hmr', () => { await page.goto(url) const el = await page.$('.virtual') expect(await el.textContent()).toBe('[success]') + + const loadPromise = page.waitForEvent('load') editFile('src/importedVirtual.js', (code) => code.replace('[success]', '[wow]'), ) - await page.waitForNavigation() + await loadPromise + await untilUpdated(async () => { const el = await page.$('.virtual') return await el.textContent() @@ -62,23 +65,36 @@ describe.runIf(isServe)('hmr', () => { describe.runIf(isServe)('stacktrace', () => { const execFileAsync = promisify(execFile) - for (const sourcemapsEnabled of [false, true]) { - test(`stacktrace is correct when sourcemaps is${ - sourcemapsEnabled ? '' : ' not' - } enabled in Node.js`, async () => { - const testStacktraceFile = path.resolve( - __dirname, - '../test-stacktrace.js', - ) + for (const ext of ['js', 'ts']) { + for (const sourcemapsEnabled of [false, true]) { + test(`stacktrace of ${ext} is correct when sourcemaps is${ + sourcemapsEnabled ? '' : ' not' + } enabled in Node.js`, async () => { + const testStacktraceFile = path.resolve( + __dirname, + '../test-stacktrace.js', + ) + + const p = await execFileAsync('node', [ + testStacktraceFile, + '' + sourcemapsEnabled, + ext, + ]) + const lines = p.stdout + .split('\n') + .filter((line) => line.includes('Module.error')) - const p = await execFileAsync('node', [ - testStacktraceFile, - '' + sourcemapsEnabled, - ]) - const line = p.stdout - .split('\n') - .find((line) => line.includes('Module.error')) - expect(line.trim()).toMatch(/[\\/]src[\\/]error\.js:2:9/) - }) + const reg = new RegExp( + path + .resolve(__dirname, '../src', `error.${ext}`) + .replace(/\\/g, '\\\\') + ':2:9', + 'i', + ) + + lines.forEach((line) => { + expect(line.trim()).toMatch(reg) + }) + }) + } } }) diff --git a/playground/ssr-html/src/error.ts b/playground/ssr-html/src/error.ts new file mode 100644 index 00000000000000..fe8eeb20af8f8a --- /dev/null +++ b/playground/ssr-html/src/error.ts @@ -0,0 +1,3 @@ +export function error() { + throw new Error('e') +} diff --git a/playground/ssr-html/test-stacktrace.js b/playground/ssr-html/test-stacktrace.js index c3ce5e56736799..327a8b4c423dae 100644 --- a/playground/ssr-html/test-stacktrace.js +++ b/playground/ssr-html/test-stacktrace.js @@ -3,8 +3,10 @@ import { fileURLToPath } from 'node:url' import { createServer } from 'vite' const isSourceMapEnabled = process.argv[2] === 'true' +const ext = process.argv[3] process.setSourceMapsEnabled(isSourceMapEnabled) console.log('# sourcemaps enabled:', isSourceMapEnabled) +console.log('# source file extension:', ext) const version = (() => { const m = process.version.match(/^v(\d+)\.(\d+)\.\d+$/) @@ -31,17 +33,24 @@ const vite = await createServer({ appType: 'custom', }) -const mod = await vite.ssrLoadModule('/src/error.js') -try { - mod.error() -} catch (e) { - // this should not be called - // when sourcemap support for `new Function` is supported and sourcemap is enabled - // because the stacktrace is already rewritten by Node.js - if (!(isSourceMapEnabled && isFunctionSourceMapSupported)) { - vite.ssrFixStacktrace(e) +const dir = path.dirname(fileURLToPath(import.meta.url)) + +const abs1 = await vite.ssrLoadModule(`/src/error.${ext}`) +const abs2 = await vite.ssrLoadModule(path.resolve(dir, `./src/error.${ext}`)) +const relative = await vite.ssrLoadModule(`./src/error.${ext}`) + +for (const mod of [abs1, abs2, relative]) { + try { + mod.error() + } catch (e) { + // this should not be called + // when sourcemap support for `new Function` is supported and sourcemap is enabled + // because the stacktrace is already rewritten by Node.js + if (!(isSourceMapEnabled && isFunctionSourceMapSupported)) { + vite.ssrFixStacktrace(e) + } + console.log(e) } - console.log(e) } await vite.close() diff --git a/playground/ssr-resolve/package.json b/playground/ssr-resolve/package.json index f228e2b0c2c17b..a764b385967ed2 100644 --- a/playground/ssr-resolve/package.json +++ b/playground/ssr-resolve/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-ssr-resolve", "private": true, "version": "0.0.0", + "type": "commonjs", "scripts": { "build": "vite build", "debug": "node --inspect-brk ../../packages/vite/bin/vite build" diff --git a/playground/tailwind-sourcemap/package.json b/playground/tailwind-sourcemap/package.json index 69be4ad200f198..814f251a092146 100644 --- a/playground/tailwind-sourcemap/package.json +++ b/playground/tailwind-sourcemap/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-tailwind-sourcemap", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/tailwind-sourcemap/postcss.config.js b/playground/tailwind-sourcemap/postcss.config.js index 8c777303543114..431c1ca465d257 100644 --- a/playground/tailwind-sourcemap/postcss.config.js +++ b/playground/tailwind-sourcemap/postcss.config.js @@ -1,4 +1,10 @@ -module.exports = { +import { fileURLToPath } from 'node:url' +import { dirname } from 'node:path' + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +export default { plugins: { tailwindcss: { config: __dirname + '/tailwind.config.js' }, }, diff --git a/playground/tailwind-sourcemap/tailwind.config.js b/playground/tailwind-sourcemap/tailwind.config.js index dd95de6c830d45..15a94467c22c09 100644 --- a/playground/tailwind-sourcemap/tailwind.config.js +++ b/playground/tailwind-sourcemap/tailwind.config.js @@ -1,4 +1,6 @@ -module.exports = { +/** @type {import('tailwindcss').Config} */ + +export default { content: ['./index.html'], theme: { extend: {}, diff --git a/playground/tailwind/tailwind.config.js b/playground/tailwind/tailwind.config.js index 5b9644f4f646d5..1b80b08aba2ef1 100644 --- a/playground/tailwind/tailwind.config.js +++ b/playground/tailwind/tailwind.config.js @@ -1,3 +1,5 @@ +/** @type {import('tailwindcss').Config} */ + module.exports = { content: [ // Before editing this section, make sure no paths are matching with `/src/App.vue` diff --git a/playground/test-utils.ts b/playground/test-utils.ts index 6d3489ad66dd03..c7a2cf6c5dab4f 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -5,7 +5,7 @@ import fs from 'node:fs' import path from 'node:path' import colors from 'css-color-names' import type { ConsoleMessage, ElementHandle } from 'playwright-chromium' -import type { Manifest } from 'vite' +import type { DepOptimizationMetadata, Manifest } from 'vite' import { normalizePath } from 'vite' import { fromComment } from 'convert-source-map' import { expect } from 'vitest' @@ -18,6 +18,7 @@ export * from './vitestSetup' export const ports = { cli: 9510, 'cli-module': 9511, + json: 9512, 'legacy/ssr': 9520, lib: 9521, 'optimize-missing-deps': 9522, @@ -152,6 +153,15 @@ export function readManifest(base = ''): Manifest { ) } +export function readDepOptimizationMetadata(): DepOptimizationMetadata { + return JSON.parse( + fs.readFileSync( + path.join(testDir, 'node_modules/.vite/deps/_metadata.json'), + 'utf-8', + ), + ) +} + /** * Poll a getter until the value it returns includes the expected value. */ @@ -307,6 +317,9 @@ export const formatSourcemapForSnapshot = (map: any): any => { delete m.file delete m.names m.sources = m.sources.map((source) => source.replace(root, '/root')) + if (m.sourceRoot) { + m.sourceRoot = m.sourceRoot.replace(root, '/root') + } return m } diff --git a/playground/transform-plugin/package.json b/playground/transform-plugin/package.json index dfe4f9637b7a52..5ec3132d97cd29 100644 --- a/playground/transform-plugin/package.json +++ b/playground/transform-plugin/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-transform-plugin", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/tsconfig-json-load-error/package.json b/playground/tsconfig-json-load-error/package.json index e970c3920977ac..f6cd05f58f58c5 100644 --- a/playground/tsconfig-json-load-error/package.json +++ b/playground/tsconfig-json-load-error/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-tsconfig-json-load-error", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/tsconfig-json/package.json b/playground/tsconfig-json/package.json index db1807dbe92723..9950d62ccb5994 100644 --- a/playground/tsconfig-json/package.json +++ b/playground/tsconfig-json/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-tsconfig-json", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/vitestSetup.ts b/playground/vitestSetup.ts index 8b4afb8c26eb4a..f8e9279ec6e022 100644 --- a/playground/vitestSetup.ts +++ b/playground/vitestSetup.ts @@ -63,7 +63,7 @@ export let testDir: string export let testName: string /** * current test using vite inline config - * when using server.js is not possible to get the config + * when using serve.[jt]s is not possible to get the config */ export let viteConfig: InlineConfig | undefined diff --git a/playground/wasm/package.json b/playground/wasm/package.json index f1b8b5f758b19c..5727e415155ed8 100644 --- a/playground/wasm/package.json +++ b/playground/wasm/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-wasm", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite", "build": "vite build", diff --git a/playground/worker/__tests__/es/es-worker.spec.ts b/playground/worker/__tests__/es/es-worker.spec.ts index dfa2462f61a551..e20ecede337ff1 100644 --- a/playground/worker/__tests__/es/es-worker.spec.ts +++ b/playground/worker/__tests__/es/es-worker.spec.ts @@ -113,6 +113,11 @@ test('module worker', async () => { 'A string', true, ) + await untilUpdated( + () => page.textContent('.worker-import-meta-url-without-extension'), + 'A string', + true, + ) await untilUpdated( () => page.textContent('.shared-worker-import-meta-url'), 'A string', diff --git a/playground/worker/__tests__/iife/iife-worker.spec.ts b/playground/worker/__tests__/iife/iife-worker.spec.ts index f3e5f230a9b1ed..b3ec815b78ca22 100644 --- a/playground/worker/__tests__/iife/iife-worker.spec.ts +++ b/playground/worker/__tests__/iife/iife-worker.spec.ts @@ -98,6 +98,11 @@ test('module worker', async () => { /A\sstring.*\/iife\/.+url-worker\.js/, true, ) + await untilUpdated( + () => page.textContent('.worker-import-meta-url-without-extension'), + 'A string', + true, + ) await untilUpdated( () => page.textContent('.shared-worker-import-meta-url'), 'A string', diff --git a/playground/worker/index.html b/playground/worker/index.html index ff26fbcbba3206..20e4a99ca69876 100644 --- a/playground/worker/index.html +++ b/playground/worker/index.html @@ -56,6 +56,12 @@

format iife:

+

+ new Worker(new URL('./url-worker', import.meta.url), { type: 'module' }) + .worker-import-meta-url-without-extension +

+ +

new SharedWorker(new URL('./url-shared-worker.js', import.meta.url), { type: 'module' }) diff --git a/playground/worker/package.json b/playground/worker/package.json index 5624c361890903..90d4068a580f4a 100644 --- a/playground/worker/package.json +++ b/playground/worker/package.json @@ -2,6 +2,7 @@ "name": "@vitejs/test-worker", "private": true, "version": "0.0.0", + "type": "module", "scripts": { "dev": "vite --config ./vite.config-iife.js", "build": "vite --config ./vite.config-iife.js build", diff --git a/playground/worker/vite.config-es.js b/playground/worker/vite.config-es.js index 3c7bf2fca9880f..bd82434b99ab89 100644 --- a/playground/worker/vite.config-es.js +++ b/playground/worker/vite.config-es.js @@ -1,7 +1,7 @@ -import vite from 'vite' +import { defineConfig } from 'vite' import workerPluginTestPlugin from './worker-plugin-test-plugin' -export default vite.defineConfig({ +export default defineConfig({ base: '/es/', resolve: { alias: { diff --git a/playground/worker/vite.config-iife.js b/playground/worker/vite.config-iife.js index a0759906534f66..c98f7433383ef4 100644 --- a/playground/worker/vite.config-iife.js +++ b/playground/worker/vite.config-iife.js @@ -1,7 +1,7 @@ -import vite from 'vite' +import { defineConfig } from 'vite' import workerPluginTestPlugin from './worker-plugin-test-plugin' -export default vite.defineConfig({ +export default defineConfig({ base: '/iife/', resolve: { alias: { diff --git a/playground/worker/vite.config-relative-base-iife.js b/playground/worker/vite.config-relative-base-iife.js index 28a6103faf9932..ec3e0bbbab83c6 100644 --- a/playground/worker/vite.config-relative-base-iife.js +++ b/playground/worker/vite.config-relative-base-iife.js @@ -1,7 +1,7 @@ -import vite from 'vite' +import { defineConfig } from 'vite' import workerPluginTestPlugin from './worker-plugin-test-plugin' -export default vite.defineConfig({ +export default defineConfig({ base: './', resolve: { alias: { diff --git a/playground/worker/vite.config-relative-base.js b/playground/worker/vite.config-relative-base.js index 4d02a3e79e8c44..65624071cd0cb4 100644 --- a/playground/worker/vite.config-relative-base.js +++ b/playground/worker/vite.config-relative-base.js @@ -1,7 +1,7 @@ -import vite from 'vite' +import { defineConfig } from 'vite' import workerPluginTestPlugin from './worker-plugin-test-plugin' -export default vite.defineConfig({ +export default defineConfig({ base: './', resolve: { alias: { diff --git a/playground/worker/vite.config-sourcemap.js b/playground/worker/vite.config-sourcemap.js index 5524dc2e856ddc..89178e952ef03b 100644 --- a/playground/worker/vite.config-sourcemap.js +++ b/playground/worker/vite.config-sourcemap.js @@ -1,4 +1,4 @@ -import vite from 'vite' +import { defineConfig } from 'vite' import workerPluginTestPlugin from './worker-plugin-test-plugin' /** @param {boolean | 'inline' | 'hidden' | 'sourcemap'} sourcemap */ @@ -15,7 +15,7 @@ export default (sourcemap) => { const typeName = typeof sourcemap === 'boolean' ? 'sourcemap' : 'sourcemap-' + sourcemap - return vite.defineConfig({ + return defineConfig({ base: `/iife-${typeName}/`, resolve: { alias: { diff --git a/playground/worker/worker-plugin-test-plugin.js b/playground/worker/worker-plugin-test-plugin.js index 35a054a5405180..ecfa240e53649a 100644 --- a/playground/worker/worker-plugin-test-plugin.js +++ b/playground/worker/worker-plugin-test-plugin.js @@ -1,4 +1,4 @@ -module.exports = () => ({ +export default () => ({ name: 'plugin-for-worker', transform(code, id) { if (id.includes('worker/modules/test-plugin.js')) { diff --git a/playground/worker/worker/main-module.js b/playground/worker/worker/main-module.js index e19f8f4ec3af3a..11180f4e63d379 100644 --- a/playground/worker/worker/main-module.js +++ b/playground/worker/worker/main-module.js @@ -90,6 +90,15 @@ wResolve.addEventListener('message', (ev) => text('.worker-import-meta-url-resolve', JSON.stringify(ev.data)), ) +// url import worker without extension +const wWithoutExt = new Worker( + new URL('../url-worker', import.meta.url), + /* @vite-ignore */ workerOptions, +) +wWithoutExt.addEventListener('message', (ev) => + text('.worker-import-meta-url-without-extension', JSON.stringify(ev.data)), +) + const genWorkerName = () => 'module' const w2 = new SharedWorker( new URL('../url-shared-worker.js', import.meta.url), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e807f54d74b89..4f378f0d4668c0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: '@types/babel__core': specifier: ^7.20.0 version: 7.20.0 + '@types/babel__preset-env': + specifier: ^7.9.2 + version: 7.9.2 '@types/babel__standalone': specifier: ^7.1.4 version: 7.1.4 @@ -87,8 +90,8 @@ importers: specifier: ^5.59.0 version: 5.59.0(eslint@8.38.0)(typescript@5.0.2) '@vitejs/release-scripts': - specifier: ^1.1.0 - version: 1.1.0 + specifier: ^1.2.0 + version: 1.2.0 conventional-changelog-cli: specifier: ^2.2.2 version: 2.2.2 @@ -159,8 +162,8 @@ importers: specifier: workspace:* version: link:packages/vite vitepress: - specifier: ^1.0.0-alpha.73 - version: 1.0.0-alpha.73 + specifier: 1.0.0-beta.1 + version: 1.0.0-beta.1 vitest: specifier: ^0.30.1 version: 0.30.1 @@ -255,8 +258,8 @@ importers: specifier: ^4.0.4 version: 4.0.4(rollup@3.21.0) '@rollup/plugin-commonjs': - specifier: ^24.1.0 - version: 24.1.0(rollup@3.21.0) + specifier: ^25.0.0 + version: 25.0.0(rollup@3.21.0) '@rollup/plugin-dynamic-import-vars': specifier: ^2.0.3 version: 2.0.3(rollup@3.21.0) @@ -389,9 +392,6 @@ importers: sirv: specifier: ^2.0.3 version: 2.0.3(patch_hash=z45f224eewh2pgpijxcc3aboqm) - source-map-js: - specifier: ^1.0.2 - version: 1.0.2 source-map-support: specifier: ^0.5.21 version: 0.5.21 @@ -808,6 +808,12 @@ importers: '@vitejs/test-dep-not-js': specifier: file:./dep-not-js version: file:playground/optimize-deps/dep-not-js + '@vitejs/test-dep-optimize-exports-with-glob': + specifier: file:./dep-optimize-exports-with-glob + version: file:playground/optimize-deps/dep-optimize-exports-with-glob + '@vitejs/test-dep-optimize-with-glob': + specifier: file:./dep-optimize-with-glob + version: file:playground/optimize-deps/dep-optimize-with-glob '@vitejs/test-dep-relative-to-main': specifier: file:./dep-relative-to-main version: file:playground/optimize-deps/dep-relative-to-main @@ -915,6 +921,10 @@ importers: playground/optimize-deps/dep-not-js: {} + playground/optimize-deps/dep-optimize-exports-with-glob: {} + + playground/optimize-deps/dep-optimize-with-glob: {} + playground/optimize-deps/dep-relative-to-main: {} playground/optimize-deps/dep-with-builtin-module-cjs: {} @@ -1025,6 +1035,12 @@ importers: '@vitejs/test-resolve-exports-with-module': specifier: link:./exports-with-module version: link:exports-with-module + '@vitejs/test-resolve-exports-with-module-condition': + specifier: link:./exports-with-module-condition + version: link:exports-with-module-condition + '@vitejs/test-resolve-exports-with-module-condition-required': + specifier: link:./exports-with-module-condition-required + version: link:exports-with-module-condition-required '@vitejs/test-resolve-imports-pkg': specifier: link:./imports-path/other-pkg version: link:imports-path/other-pkg @@ -1086,6 +1102,14 @@ importers: playground/resolve/exports-with-module: {} + playground/resolve/exports-with-module-condition: {} + + playground/resolve/exports-with-module-condition-required: + dependencies: + '@vitejs/test-resolve-exports-with-module-condition': + specifier: link:../exports-with-module-condition + version: link:../exports-with-module-condition + playground/resolve/imports-path/other-pkg: {} playground/resolve/inline-package: {} @@ -1365,24 +1389,24 @@ packages: resolution: {integrity: sha512-+u76oB43nOHrF4DDWRLWDCtci7f3QJoEBigemIdIeTi1ODqjx6Tad9NCVnPRwewWlKkVab5PlK8DCtPTyX7S8g==} dev: true - /@algolia/autocomplete-core@1.7.4: - resolution: {integrity: sha512-daoLpQ3ps/VTMRZDEBfU8ixXd+amZcNJ4QSP3IERGyzqnL5Ch8uSRFt/4G8pUvW9c3o6GA4vtVv4I4lmnkdXyg==} + /@algolia/autocomplete-core@1.8.2: + resolution: {integrity: sha512-mTeshsyFhAqw/ebqNsQpMtbnjr+qVOSKXArEj4K0d7sqc8It1XD0gkASwecm9mF/jlOQ4Z9RNg1HbdA8JPdRwQ==} dependencies: - '@algolia/autocomplete-shared': 1.7.4 + '@algolia/autocomplete-shared': 1.8.2 dev: true - /@algolia/autocomplete-preset-algolia@1.7.4(algoliasearch@4.13.1): - resolution: {integrity: sha512-s37hrvLEIfcmKY8VU9LsAXgm2yfmkdHT3DnA3SgHaY93yjZ2qL57wzb5QweVkYuEBZkT2PIREvRoLXC2sxTbpQ==} + /@algolia/autocomplete-preset-algolia@1.8.2(algoliasearch@4.13.1): + resolution: {integrity: sha512-J0oTx4me6ZM9kIKPuL3lyU3aB8DEvpVvR6xWmHVROx5rOYJGQcZsdG4ozxwcOyiiu3qxMkIbzntnV1S1VWD8yA==} peerDependencies: '@algolia/client-search': '>= 4.9.1 < 6' algoliasearch: '>= 4.9.1 < 6' dependencies: - '@algolia/autocomplete-shared': 1.7.4 + '@algolia/autocomplete-shared': 1.8.2 algoliasearch: 4.13.1 dev: true - /@algolia/autocomplete-shared@1.7.4: - resolution: {integrity: sha512-2VGCk7I9tA9Ge73Km99+Qg87w0wzW4tgUruvWAn/gfey1ZXgmxZtyIRBebk35R1O8TbK77wujVtCnpsGpRy1kg==} + /@algolia/autocomplete-shared@1.8.2: + resolution: {integrity: sha512-b6Z/X4MczChMcfhk6kfRmBzPgjoPzuS9KGR4AFsiLulLNRAAqhP+xZTKtMnZGhLuc61I20d5WqlId02AZvcO6g==} dev: true /@algolia/cache-browser-local-storage@4.13.1: @@ -2644,14 +2668,14 @@ packages: dependencies: '@jridgewell/trace-mapping': 0.3.9 - /@docsearch/css@3.3.3: - resolution: {integrity: sha512-6SCwI7P8ao+se1TUsdZ7B4XzL+gqeQZnBc+2EONZlcVa0dVrk0NjETxozFKgMv0eEGH8QzP1fkN+A1rH61l4eg==} + /@docsearch/css@3.4.0: + resolution: {integrity: sha512-Hg8Xfma+rFwRi6Y/pfei4FJoQ1hdVURmmNs/XPoMTCPAImU+d5yxj+M+qdLtNjWRpfWziU4dQcqY94xgFBn2dg==} dev: true - /@docsearch/js@3.3.3: - resolution: {integrity: sha512-2xAv2GFuHzzmG0SSZgf8wHX0qZX8n9Y1ZirKUk5Wrdc+vH9CL837x2hZIUdwcPZI9caBA+/CzxsS68O4waYjUQ==} + /@docsearch/js@3.4.0: + resolution: {integrity: sha512-uOtOHZJv+5PQmL68+srVzlGhLejnEBJgZl1bR87Zh/uK5RUI7p6el1R8hGTl2F8K2tCloNRxTMtXyYUNbMV+qw==} dependencies: - '@docsearch/react': 3.3.3 + '@docsearch/react': 3.4.0 preact: 10.7.3 transitivePeerDependencies: - '@algolia/client-search' @@ -2660,8 +2684,8 @@ packages: - react-dom dev: true - /@docsearch/react@3.3.3: - resolution: {integrity: sha512-pLa0cxnl+G0FuIDuYlW+EBK6Rw2jwLw9B1RHIeS4N4s2VhsfJ/wzeCi3CWcs5yVfxLd5ZK50t//TMA5e79YT7Q==} + /@docsearch/react@3.4.0: + resolution: {integrity: sha512-ufrp5879XYGojgS30ZAp8H4qIMbahRHB9M85VDBP36Xgz5QjYM54i1URKj5e219F7gqTtOivfztFTij6itc0MQ==} peerDependencies: '@types/react': '>= 16.8.0 < 19.0.0' react: '>= 16.8.0 < 19.0.0' @@ -2674,9 +2698,9 @@ packages: react-dom: optional: true dependencies: - '@algolia/autocomplete-core': 1.7.4 - '@algolia/autocomplete-preset-algolia': 1.7.4(algoliasearch@4.13.1) - '@docsearch/css': 3.3.3 + '@algolia/autocomplete-core': 1.8.2 + '@algolia/autocomplete-preset-algolia': 1.8.2(algoliasearch@4.13.1) + '@docsearch/css': 3.4.0 algoliasearch: 4.13.1 transitivePeerDependencies: - '@algolia/client-search' @@ -3401,6 +3425,24 @@ packages: rollup: 3.21.0 dev: true + /@rollup/plugin-commonjs@25.0.0(rollup@3.21.0): + resolution: {integrity: sha512-hoho2Kay9TZrLu0bnDsTTCaj4Npa+THk9snajP/XDNb9a9mmjTjh52EQM9sKl3HD1LsnihX7js+eA2sd2uKAhw==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.68.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@rollup/pluginutils': 5.0.2(rollup@3.21.0) + commondir: 1.0.1 + estree-walker: 2.0.2 + glob: 8.0.3 + is-reference: 1.2.1 + magic-string: 0.27.0 + rollup: 3.21.0 + dev: true + /@rollup/plugin-dynamic-import-vars@2.0.3(rollup@3.21.0): resolution: {integrity: sha512-0zQV0TDDewilU+7ZLmwc0u44SkeRxSxMdINBuX5isrQGJ6EdTjVL1TcnOZ9In99byaSGAQnHmSFw+6hm0E/jrw==} engines: {node: '>=14.0.0'} @@ -3567,6 +3609,10 @@ packages: '@babel/types': 7.21.4 dev: true + /@types/babel__preset-env@7.9.2: + resolution: {integrity: sha512-epEgKQiqTDZdPgYwtriYK1GVAGcyVZVvvw2UatX3+95mogKGimebApcMEWLF12uhUbNIvX284CSQEavnV/OIgw==} + dev: true + /@types/babel__standalone@7.1.4: resolution: {integrity: sha512-HijIDmcNl3Wmo0guqjYkQvMzyRCM6zMCkYcdG8f+2X7mPBNa9ikSeaQlWs2Yg18KN1klOJzyupX5BPOf+7ahaw==} dependencies: @@ -3737,8 +3783,8 @@ packages: '@types/node': 18.15.12 dev: true - /@types/web-bluetooth@0.0.16: - resolution: {integrity: sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==} + /@types/web-bluetooth@0.0.17: + resolution: {integrity: sha512-4p9vcSmxAayx72yn70joFoL44c9MO/0+iVEBIQXe3v2h2SiAsEIo/G5v6ObFWvNKRFjbrVadNf9LqEEZeQPzdA==} dev: true /@types/ws@8.5.4: @@ -3888,15 +3934,26 @@ packages: vue: 3.2.47 dev: true - /@vitejs/release-scripts@1.1.0: - resolution: {integrity: sha512-pxP72AGDRGu6vufj8vrdmFll++N0K7aNDSWWYzPb28NgE5RjOdo99uLgJEpl3Ee/wEOnHKT2zJ9HN2GN44SUPQ==} + /@vitejs/plugin-vue@4.2.3(vite@packages+vite)(vue@3.3.4): + resolution: {integrity: sha512-R6JDUfiZbJA9cMiguQ7jxALsgiprjBeHL5ikpXfJCH62pPHtI+JdJ5xWj6Ev73yXSlYl86+blXn1kZHQ7uElxw==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + vite: ^4.0.0 + vue: ^3.2.25 + dependencies: + vite: link:packages/vite + vue: 3.3.4 + dev: true + + /@vitejs/release-scripts@1.2.0: + resolution: {integrity: sha512-HdLOS/BQtavOis+VvT1517y7a5jYEMuBIybnL1F1Pd7vIXkFYPdo0vSKtnDBILOHhFT27SYist4BFkppDvsBnA==} dependencies: - execa: 6.1.0 + execa: 7.1.1 minimist: 1.2.8 picocolors: 1.0.0 prompts: 2.4.2 publint: 0.1.11 - semver: 7.3.8 + semver: 7.5.1 dev: true /@vitest/expect@0.30.1: @@ -3946,12 +4003,28 @@ packages: estree-walker: 2.0.2 source-map: 0.6.1 + /@vue/compiler-core@3.3.4: + resolution: {integrity: sha512-cquyDNvZ6jTbf/+x+AgM2Arrp6G4Dzbb0R64jiG804HRMfRiFXWI6kqUVqZ6ZR0bQhIoQjB4+2bhNtVwndW15g==} + dependencies: + '@babel/parser': 7.21.4 + '@vue/shared': 3.3.4 + estree-walker: 2.0.2 + source-map-js: 1.0.2 + dev: true + /@vue/compiler-dom@3.2.47: resolution: {integrity: sha512-dBBnEHEPoftUiS03a4ggEig74J2YBZ2UIeyfpcRM2tavgMWo4bsEfgCGsu+uJIL/vax9S+JztH8NmQerUo7shQ==} dependencies: '@vue/compiler-core': 3.2.47 '@vue/shared': 3.2.47 + /@vue/compiler-dom@3.3.4: + resolution: {integrity: sha512-wyM+OjOVpuUukIq6p5+nwHYtj9cFroz9cwkfmP9O1nzH68BenTTv0u7/ndggT8cIQlnBeOo6sUT/gvHcIkLA5w==} + dependencies: + '@vue/compiler-core': 3.3.4 + '@vue/shared': 3.3.4 + dev: true + /@vue/compiler-sfc@3.2.47: resolution: {integrity: sha512-rog05W+2IFfxjMcFw10tM9+f7i/+FFpZJJ5XHX72NP9eC2uRD+42M3pYcQqDXVYoj74kHMSEdQ/WmCjt8JFksQ==} dependencies: @@ -3966,12 +4039,34 @@ packages: postcss: 8.4.23 source-map: 0.6.1 + /@vue/compiler-sfc@3.3.4: + resolution: {integrity: sha512-6y/d8uw+5TkCuzBkgLS0v3lSM3hJDntFEiUORM11pQ/hKvkhSKZrXW6i69UyXlJQisJxuUEJKAWEqWbWsLeNKQ==} + dependencies: + '@babel/parser': 7.21.4 + '@vue/compiler-core': 3.3.4 + '@vue/compiler-dom': 3.3.4 + '@vue/compiler-ssr': 3.3.4 + '@vue/reactivity-transform': 3.3.4 + '@vue/shared': 3.3.4 + estree-walker: 2.0.2 + magic-string: 0.30.0 + postcss: 8.4.23 + source-map-js: 1.0.2 + dev: true + /@vue/compiler-ssr@3.2.47: resolution: {integrity: sha512-wVXC+gszhulcMD8wpxMsqSOpvDZ6xKXSVWkf50Guf/S+28hTAXPDYRTbLQ3EDkOP5Xz/+SY37YiwDquKbJOgZw==} dependencies: '@vue/compiler-dom': 3.2.47 '@vue/shared': 3.2.47 + /@vue/compiler-ssr@3.3.4: + resolution: {integrity: sha512-m0v6oKpup2nMSehwA6Uuu+j+wEwcy7QmwMkVNVfrV9P2qE5KshC6RwOCq8fjGS/Eak/uNb8AaWekfiXxbBB6gQ==} + dependencies: + '@vue/compiler-dom': 3.3.4 + '@vue/shared': 3.3.4 + dev: true + /@vue/devtools-api@6.4.5: resolution: {integrity: sha512-JD5fcdIuFxU4fQyXUu3w2KpAJHzTVdN+p4iOX2lMWSHMOoQdMAcpFLZzm9Z/2nmsoZ1a96QEhZ26e50xLBsgOQ==} dev: false @@ -3988,17 +4083,40 @@ packages: estree-walker: 2.0.2 magic-string: 0.25.9 + /@vue/reactivity-transform@3.3.4: + resolution: {integrity: sha512-MXgwjako4nu5WFLAjpBnCj/ieqcjE2aJBINUNQzkZQfzIZA4xn+0fV1tIYBJvvva3N3OvKGofRLvQIwEQPpaXw==} + dependencies: + '@babel/parser': 7.21.4 + '@vue/compiler-core': 3.3.4 + '@vue/shared': 3.3.4 + estree-walker: 2.0.2 + magic-string: 0.30.0 + dev: true + /@vue/reactivity@3.2.47: resolution: {integrity: sha512-7khqQ/75oyyg+N/e+iwV6lpy1f5wq759NdlS1fpAhFXa8VeAIKGgk2E/C4VF59lx5b+Ezs5fpp/5WsRYXQiKxQ==} dependencies: '@vue/shared': 3.2.47 + /@vue/reactivity@3.3.4: + resolution: {integrity: sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==} + dependencies: + '@vue/shared': 3.3.4 + dev: true + /@vue/runtime-core@3.2.47: resolution: {integrity: sha512-RZxbLQIRB/K0ev0K9FXhNbBzT32H9iRtYbaXb0ZIz2usLms/D55dJR2t6cIEUn6vyhS3ALNvNthI+Q95C+NOpA==} dependencies: '@vue/reactivity': 3.2.47 '@vue/shared': 3.2.47 + /@vue/runtime-core@3.3.4: + resolution: {integrity: sha512-R+bqxMN6pWO7zGI4OMlmvePOdP2c93GsHFM/siJI7O2nxFRzj55pLwkpCedEY+bTMgp5miZ8CxfIZo3S+gFqvA==} + dependencies: + '@vue/reactivity': 3.3.4 + '@vue/shared': 3.3.4 + dev: true + /@vue/runtime-dom@3.2.47: resolution: {integrity: sha512-ArXrFTjS6TsDei4qwNvgrdmHtD930KgSKGhS5M+j8QxXrDJYLqYw4RRcDy1bz1m1wMmb6j+zGLifdVHtkXA7gA==} dependencies: @@ -4006,6 +4124,14 @@ packages: '@vue/shared': 3.2.47 csstype: 2.6.20 + /@vue/runtime-dom@3.3.4: + resolution: {integrity: sha512-Aj5bTJ3u5sFsUckRghsNjVTtxZQ1OyMWCr5dZRAPijF/0Vy4xEoRCwLyHXcj4D0UFbJ4lbx3gPTgg06K/GnPnQ==} + dependencies: + '@vue/runtime-core': 3.3.4 + '@vue/shared': 3.3.4 + csstype: 3.1.2 + dev: true + /@vue/server-renderer@3.2.47(vue@3.2.47): resolution: {integrity: sha512-dN9gc1i8EvmP9RCzvneONXsKfBRgqFeFZLurmHOveL7oH6HiFXJw5OGu294n1nHc/HMgTy6LulU/tv5/A7f/LA==} peerDependencies: @@ -4015,29 +4141,93 @@ packages: '@vue/shared': 3.2.47 vue: 3.2.47 + /@vue/server-renderer@3.3.4(vue@3.3.4): + resolution: {integrity: sha512-Q6jDDzR23ViIb67v+vM1Dqntu+HUexQcsWKhhQa4ARVzxOY2HbC7QRW/ggkDBd5BU+uM1sV6XOAP0b216o34JQ==} + peerDependencies: + vue: 3.3.4 + dependencies: + '@vue/compiler-ssr': 3.3.4 + '@vue/shared': 3.3.4 + vue: 3.3.4 + dev: true + /@vue/shared@3.2.47: resolution: {integrity: sha512-BHGyyGN3Q97EZx0taMQ+OLNuZcW3d37ZEVmEAyeoA9ERdGvm9Irc/0Fua8SNyOtV1w6BS4q25wbMzJujO9HIfQ==} - /@vueuse/core@10.1.0(vue@3.2.47): - resolution: {integrity: sha512-3Znoa5m5RO+z4/C9w6DRaKTR3wCVJvD5rav8HTDGsr+7rOZRHtcgFJ8NcCs0ZvIpmev2kExTa311ns5j2RbzDQ==} + /@vue/shared@3.3.4: + resolution: {integrity: sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ==} + dev: true + + /@vueuse/core@10.1.2(vue@3.3.4): + resolution: {integrity: sha512-roNn8WuerI56A5uiTyF/TEYX0Y+VKlhZAF94unUfdhbDUI+NfwQMn4FUnUscIRUhv3344qvAghopU4bzLPNFlA==} + dependencies: + '@types/web-bluetooth': 0.0.17 + '@vueuse/metadata': 10.1.2 + '@vueuse/shared': 10.1.2(vue@3.3.4) + vue-demi: 0.14.0(vue@3.3.4) + transitivePeerDependencies: + - '@vue/composition-api' + - vue + dev: true + + /@vueuse/integrations@10.1.2(focus-trap@7.4.3)(vue@3.3.4): + resolution: {integrity: sha512-wUpG3Wv6LiWerOwCzOAM0iGhNQ4vfFUTkhj/xQy7TLXduh2M3D8N08aS0KqlxsejY6R8NLxydDIM+68QfHZZ8Q==} + peerDependencies: + async-validator: '*' + axios: '*' + change-case: '*' + drauu: '*' + focus-trap: '*' + fuse.js: '*' + idb-keyval: '*' + jwt-decode: '*' + nprogress: '*' + qrcode: '*' + sortablejs: '*' + universal-cookie: '*' + peerDependenciesMeta: + async-validator: + optional: true + axios: + optional: true + change-case: + optional: true + drauu: + optional: true + focus-trap: + optional: true + fuse.js: + optional: true + idb-keyval: + optional: true + jwt-decode: + optional: true + nprogress: + optional: true + qrcode: + optional: true + sortablejs: + optional: true + universal-cookie: + optional: true dependencies: - '@types/web-bluetooth': 0.0.16 - '@vueuse/metadata': 10.1.0 - '@vueuse/shared': 10.1.0(vue@3.2.47) - vue-demi: 0.14.0(vue@3.2.47) + '@vueuse/core': 10.1.2(vue@3.3.4) + '@vueuse/shared': 10.1.2(vue@3.3.4) + focus-trap: 7.4.3 + vue-demi: 0.14.0(vue@3.3.4) transitivePeerDependencies: - '@vue/composition-api' - vue dev: true - /@vueuse/metadata@10.1.0: - resolution: {integrity: sha512-cM28HjDEw5FIrPE9rgSPFZvQ0ZYnOLAOr8hl1XM6tFl80U3WAR5ROdnAqiYybniwP5gt9MKKAJAqd/ab2aHkqg==} + /@vueuse/metadata@10.1.2: + resolution: {integrity: sha512-3mc5BqN9aU2SqBeBuWE7ne4OtXHoHKggNgxZR2K+zIW4YLsy6xoZ4/9vErQs6tvoKDX6QAqm3lvsrv0mczAwIQ==} dev: true - /@vueuse/shared@10.1.0(vue@3.2.47): - resolution: {integrity: sha512-2X52ogu12i9DkKOQ01yeb/BKg9UO87RNnpm5sXkQvyORlbq8ONS5l39MYkjkeVWWjdT0teJru7a2S41dmHmqjQ==} + /@vueuse/shared@10.1.2(vue@3.3.4): + resolution: {integrity: sha512-1uoUTPBlgyscK9v6ScGeVYDDzlPSFXBlxuK7SfrDGyUTBiznb3mNceqhwvZHjtDRELZEN79V5uWPTF1VDV8svA==} dependencies: - vue-demi: 0.14.0(vue@3.2.47) + vue-demi: 0.14.0(vue@3.3.4) transitivePeerDependencies: - '@vue/composition-api' - vue @@ -5055,6 +5245,10 @@ packages: /csstype@2.6.20: resolution: {integrity: sha512-/WwNkdXfckNgw6S5R125rrW8ez139lBHWouiBvX8dfMFtcn6V81REDqnH7+CRpRipfYlyU1CmOnOxrmGcFOjeA==} + /csstype@3.1.2: + resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} + dev: true + /d@1.0.1: resolution: {integrity: sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==} dependencies: @@ -5959,21 +6153,6 @@ packages: resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} dev: true - /execa@6.1.0: - resolution: {integrity: sha512-QVWlX2e50heYJcCPG0iWtf8r0xjEYfz/OYLGDYH+IyjWezzPNxz63qNFOu0l4YftGWuizFVZHHs8PrLU5p2IDA==} - engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dependencies: - cross-spawn: 7.0.3 - get-stream: 6.0.1 - human-signals: 3.0.1 - is-stream: 3.0.0 - merge-stream: 2.0.0 - npm-run-path: 5.1.0 - onetime: 6.0.0 - signal-exit: 3.0.7 - strip-final-newline: 3.0.0 - dev: true - /execa@7.1.1: resolution: {integrity: sha512-wH0eMf/UXckdUYnO21+HDztteVv05rq2GXksxT4fCGeHkBhw1DROXh40wcjMcRqDOWE7iPJ4n3M7e2+YFP+76Q==} engines: {node: ^14.18.0 || ^16.14.0 || >=18.0.0} @@ -6149,6 +6328,12 @@ packages: resolution: {integrity: sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==} dev: true + /focus-trap@7.4.3: + resolution: {integrity: sha512-BgSSbK4GPnS2VbtZ50VtOv1Sti6DIkj3+LkVjiWMNjLeAp1SH1UlLx3ULu/DCu4vq5R4/uvTm+zrvsMsuYmGLg==} + dependencies: + tabbable: 6.1.2 + dev: true + /follow-redirects@1.15.0(debug@4.3.4): resolution: {integrity: sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==} engines: {node: '>=4.0'} @@ -6607,11 +6792,6 @@ packages: - supports-color dev: false - /human-signals@3.0.1: - resolution: {integrity: sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ==} - engines: {node: '>=12.20.0'} - dev: true - /human-signals@4.3.0: resolution: {integrity: sha512-zyzVyMjpGBX2+6cDVZeFPCdtOtdsxOeseRhB9tkQ6xXmGUNrcnBzdEKPy3VPNYz+4gy1oukVOXcrJCunSyc6QQ==} engines: {node: '>=14.18.0'} @@ -7569,8 +7749,8 @@ packages: engines: {node: '>=8'} dev: true - /minisearch@6.0.1: - resolution: {integrity: sha512-Ly1w0nHKnlhAAh6/BF/+9NgzXfoJxaJ8nhopFhQ3NcvFJrFIL+iCg9gw9e9UMBD+XIsp/RyznJ/o5UIe5Kw+kg==} + /minisearch@6.1.0: + resolution: {integrity: sha512-PNxA/X8pWk+TiqPbsoIYH0GQ5Di7m6326/lwU/S4mlo4wGQddIcf/V//1f9TB0V4j59b57b+HZxt8h3iMROGvg==} dev: true /minizlib@2.1.2: @@ -8990,6 +9170,14 @@ packages: dependencies: lru-cache: 6.0.0 + /semver@7.5.1: + resolution: {integrity: sha512-Wvss5ivl8TMRZXXESstBA4uR5iXgEN/VC5/sOcuXdVLzcdkz4HWetIoRfG5gb5X+ij/G9rw9YoGn3QoQ8OCSpw==} + engines: {node: '>=10'} + hasBin: true + dependencies: + lru-cache: 6.0.0 + dev: true + /send@0.18.0: resolution: {integrity: sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==} engines: {node: '>= 0.8.0'} @@ -9060,8 +9248,8 @@ packages: resolution: {integrity: sha512-Vpfqwm4EnqGdlsBFNmHhxhElJYrdfcxPThu+ryKS5J8L/fhAwLazFZtq+S+TWZ9ANj2piSQLGj6NQg+lKPmxrw==} dev: true - /shiki@0.14.1: - resolution: {integrity: sha512-+Jz4nBkCBe0mEDqo1eKRcCdjRtrCjozmcbTUjbPTX7OOJfEbTZzlUWlZtGe3Gb5oV1/jnojhG//YZc3rs9zSEw==} + /shiki@0.14.2: + resolution: {integrity: sha512-ltSZlSLOuSY0M0Y75KA+ieRaZ0Trf5Wl3gutE7jzLuIcWxLp5i/uEnLoQWNvgKXQ5OMpGkJnVMRLAuzjc0LJ2A==} dependencies: ansi-sequence-parser: 1.1.0 jsonc-parser: 3.2.0 @@ -9422,6 +9610,10 @@ packages: resolution: {integrity: sha512-8ftwWd+XnQtZ/aGbatrN4QFNGrKJzmbtixW+ODpci7pyoTajg4sonPP8aFLESAcuVxaC1FyDESt+SpfFCH9rZQ==} dev: false + /tabbable@6.1.2: + resolution: {integrity: sha512-qCN98uP7i9z0fIS4amQ5zbGBOq+OSigYeGvPy7NDk8Y9yncqDZ9pRPgfsc2PJIVM9RrJj7GIfuRgmjoUU9zTHQ==} + dev: true + /tailwindcss@3.3.1(ts-node@10.9.1): resolution: {integrity: sha512-Vkiouc41d4CEq0ujXl6oiGFQ7bA3WEhUZdTgXAhtKxSy49OmKs8rEfQmupsfF0IGW8fv2iQkp1EVUuapCFrZ9g==} engines: {node: '>=12.13.0'} @@ -9960,27 +10152,40 @@ packages: - supports-color dev: true - /vitepress@1.0.0-alpha.73: - resolution: {integrity: sha512-BWK7b5yYxdA3SeBnUV+ly8vJU2MFcQhjooycLDc2AsSd07uGp+WO6J6gBmjwHuOz5hgcNa+/VxGWKKwBycdbnA==} + /vitepress@1.0.0-beta.1: + resolution: {integrity: sha512-V2yyCwQ+v9fh7rbnGDLp8M7vHa9sLElexXf/JHtBOsOwv7ed9wt1QI4WUagYgKR3TeoJT9v2s6f0UaQSne0EvQ==} hasBin: true dependencies: - '@docsearch/css': 3.3.3 - '@docsearch/js': 3.3.3 - '@vitejs/plugin-vue': 4.1.0(vite@packages+vite)(vue@3.2.47) + '@docsearch/css': 3.4.0 + '@docsearch/js': 3.4.0 + '@vitejs/plugin-vue': 4.2.3(vite@packages+vite)(vue@3.3.4) '@vue/devtools-api': 6.5.0 - '@vueuse/core': 10.1.0(vue@3.2.47) + '@vueuse/core': 10.1.2(vue@3.3.4) + '@vueuse/integrations': 10.1.2(focus-trap@7.4.3)(vue@3.3.4) body-scroll-lock: 4.0.0-beta.0 + focus-trap: 7.4.3 mark.js: 8.11.1 - minisearch: 6.0.1 - shiki: 0.14.1 + minisearch: 6.1.0 + shiki: 0.14.2 vite: link:packages/vite - vue: 3.2.47 + vue: 3.3.4 transitivePeerDependencies: - '@algolia/client-search' - '@types/react' - '@vue/composition-api' + - async-validator + - axios + - change-case + - drauu + - fuse.js + - idb-keyval + - jwt-decode + - nprogress + - qrcode - react - react-dom + - sortablejs + - universal-cookie dev: true /vitest@0.30.1: @@ -10057,7 +10262,7 @@ packages: resolution: {integrity: sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg==} dev: true - /vue-demi@0.14.0(vue@3.2.47): + /vue-demi@0.14.0(vue@3.3.4): resolution: {integrity: sha512-gt58r2ogsNQeVoQ3EhoUAvUsH9xviydl0dWJj7dabBC/2L4uBId7ujtCwDRD0JhkGsV1i0CtfLAeyYKBht9oWg==} engines: {node: '>=12'} hasBin: true @@ -10069,7 +10274,7 @@ packages: '@vue/composition-api': optional: true dependencies: - vue: 3.2.47 + vue: 3.3.4 dev: true /vue-router@4.1.6(vue@3.2.47): @@ -10090,6 +10295,16 @@ packages: '@vue/server-renderer': 3.2.47(vue@3.2.47) '@vue/shared': 3.2.47 + /vue@3.3.4: + resolution: {integrity: sha512-VTyEYn3yvIeY1Py0WaYGZsXnz3y5UnGi62GjVEqvEGPl6nxbOrCXbVOTQWBEJUqAyTUk2uJ5JLVnYJ6ZzGbrSw==} + dependencies: + '@vue/compiler-dom': 3.3.4 + '@vue/compiler-sfc': 3.3.4 + '@vue/runtime-dom': 3.3.4 + '@vue/server-renderer': 3.3.4(vue@3.3.4) + '@vue/shared': 3.3.4 + dev: true + /vuex@4.1.0(vue@3.2.47): resolution: {integrity: sha512-hmV6UerDrPcgbSy9ORAtNXDr9M4wlNP4pEFKye4ujJF8oqgFFuxDCdOLS3eNoRTtq5O3hoBDh9Doj1bQMYHRbQ==} peerDependencies: @@ -10488,6 +10703,18 @@ packages: version: 1.0.0 dev: false + file:playground/optimize-deps/dep-optimize-exports-with-glob: + resolution: {directory: playground/optimize-deps/dep-optimize-exports-with-glob, type: directory} + name: '@vitejs/test-dep-optimize-exports-with-glob' + version: 1.0.0 + dev: false + + file:playground/optimize-deps/dep-optimize-with-glob: + resolution: {directory: playground/optimize-deps/dep-optimize-with-glob, type: directory} + name: '@vitejs/test-dep-optimize-with-glob' + version: 1.0.0 + dev: false + file:playground/optimize-deps/dep-relative-to-main: resolution: {directory: playground/optimize-deps/dep-relative-to-main, type: directory} name: '@vitejs/test-dep-relative-to-main' diff --git a/scripts/publishCI.ts b/scripts/publishCI.ts index a6d83385739ae6..873b2cec5bbc0a 100644 --- a/scripts/publishCI.ts +++ b/scripts/publishCI.ts @@ -1,3 +1,3 @@ import { publish } from '@vitejs/release-scripts' -publish({ defaultPackage: 'vite' }) +publish({ defaultPackage: 'vite', provenance: true })