Merge branch 'main' into docs/kit

This commit is contained in:
Andrey Yolkin 2023-08-22 23:55:39 +03:00 committed by GitHub
commit 6ec5389158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 458 additions and 480 deletions

View File

@ -19,7 +19,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -15,7 +15,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -23,7 +23,7 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -40,7 +40,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"
@ -77,7 +77,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"
@ -116,7 +116,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"
@ -144,7 +144,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"
@ -180,7 +180,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: "pnpm" cache: "pnpm"
@ -254,7 +254,7 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"
@ -293,7 +293,7 @@ jobs:
with: with:
fetch-depth: 0 fetch-depth: 0
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -23,7 +23,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
cache: "pnpm" cache: "pnpm"

View File

@ -22,7 +22,7 @@ jobs:
steps: steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -27,7 +27,7 @@ jobs:
fetch-depth: 0 # All history fetch-depth: 0 # All history
- name: fetch tags - name: fetch tags
run: git fetch --depth=1 origin "+refs/tags/*:refs/tags/*" run: git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 16 node-version: 16
registry-url: 'https://registry.npmjs.org' registry-url: 'https://registry.npmjs.org'

View File

@ -35,7 +35,7 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- run: corepack enable - run: corepack enable
- uses: actions/setup-node@bea5baf987ba7aa777a8a0b4ace377a21c45c381 # v3.8.0 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with: with:
node-version: 20 node-version: 20
cache: "pnpm" cache: "pnpm"

View File

@ -59,6 +59,10 @@ npx nuxi@latest init <project-name>
pnpm dlx nuxi@latest init <project-name> pnpm dlx nuxi@latest init <project-name>
``` ```
```bash [bun]
bunx nuxi@latest init <project-name>
```
:: ::
Open your project folder in Visual Studio Code: Open your project folder in Visual Studio Code:

View File

@ -74,12 +74,12 @@ export const useLocale = () => useState<string>('locale', () => useDefaultLocale
export const useDefaultLocale = (fallback = 'en-US') => { export const useDefaultLocale = (fallback = 'en-US') => {
const locale = ref(fallback) const locale = ref(fallback)
if (import.meta.server) { if (process.server) {
const reqLocale = useRequestHeaders()['accept-language']?.split(',')[0] const reqLocale = useRequestHeaders()['accept-language']?.split(',')[0]
if (reqLocale) { if (reqLocale) {
locale.value = reqLocale locale.value = reqLocale
} }
} else if (import.meta.client) { } else if (process.client) {
const navLang = navigator.language const navLang = navigator.language
if (navLang) { if (navLang) {
locale.value = navLang locale.value = navLang

View File

@ -34,7 +34,20 @@ By default, only the `~/components` directory is scanned. If you want to add oth
```ts [nuxt.config.ts] ```ts [nuxt.config.ts]
export default defineNuxtConfig({ export default defineNuxtConfig({
components: [ components: [
// ~/calendar-module/components/event/Update.vue => <EventUpdate />
{ path: '~/calendar-module/components' },
// ~/user-module/components/account/UserDeleteDialog.vue => <UserDeleteDialog />
{ path: '~/user-module/components', pathPrefix: false },
// ~/components/special-components/Btn.vue => <SpecialBtn />
{ path: '~/components/special-components', prefix: 'Special' }, { path: '~/components/special-components', prefix: 'Special' },
// It's important that this comes last if you have overrides you wish to apply
// to sub-directories of `~/components`.
//
// ~/components/Btn.vue => <Btn />
// ~/components/base/Btn.vue => <BaseBtn />
'~/components' '~/components'
] ]
}) })
@ -299,6 +312,8 @@ Now you can register server-only components with the `.server` suffix and use th
</template> </template>
``` ```
Server-only components use `<NuxtIsland>` under the hood, meaning that `lazy` prop and `#fallback` slot are both passed down to `<NuxtIsland>`.
::alert{type=info} ::alert{type=info}
Slots can be interactive and are wrapped within a `<div>` with `display: contents;` Slots can be interactive and are wrapped within a `<div>` with `display: contents;`
:: ::

View File

@ -38,6 +38,10 @@ Install the `@nuxt/content` module in your project:
pnpm add -D @nuxt/content pnpm add -D @nuxt/content
``` ```
```bash [bun]
bun add -D @nuxt/content
```
:: ::
Then, add `@nuxt/content` to the `modules` section of `nuxt.config.ts`: Then, add `@nuxt/content` to the `modules` section of `nuxt.config.ts`:

View File

@ -125,12 +125,12 @@ However, if you want to avoid this behaviour you can do so:
```js ```js
export default defineNuxtRouteMiddleware(to => { export default defineNuxtRouteMiddleware(to => {
// skip middleware on server // skip middleware on server
if (import.meta.server) return if (process.server) return
// skip middleware on client side entirely // skip middleware on client side entirely
if (import.meta.client) return if (process.client) return
// or only skip middleware on initial client load // or only skip middleware on initial client load
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
if (import.meta.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) return if (process.client && nuxtApp.isHydrating && nuxtApp.payload.serverRendered) return
}) })
``` ```

View File

@ -62,7 +62,7 @@ export default defineNuxtPlugin({
``` ```
::alert ::alert
If you are using an object-syntax plugin, the properties may be statically analyzed in future to produce a more optimized build. So you should not define them at runtime. For example, setting `enforce: import.meta.server ? 'pre' : 'post'` would defeat any future optimization Nuxt is able to do for your plugins. If you are using an object-syntax plugin, the properties may be statically analyzed in future to produce a more optimized build. So you should not define them at runtime. For example, setting `enforce: process.server ? 'pre' : 'post'` would defeat any future optimization Nuxt is able to do for your plugins.
:: ::
## Plugin Registration Order ## Plugin Registration Order

View File

@ -94,7 +94,7 @@ The entire runtime config is available on the server-side, but it is read-only t
<script setup lang="ts"> <script setup lang="ts">
const config = useRuntimeConfig() const config = useRuntimeConfig()
console.log('Runtime config:', config) console.log('Runtime config:', config)
if (import.meta.server) { if (process.server) {
console.log('API secret:', config.apiSecret) console.log('API secret:', config.apiSecret)
} }
</script> </script>

View File

@ -138,6 +138,6 @@ import { createMemoryHistory } from 'vue-router'
// https://router.vuejs.org/api/interfaces/routeroptions.html // https://router.vuejs.org/api/interfaces/routeroptions.html
export default <RouterConfig> { export default <RouterConfig> {
history: base => import.meta.client ? createMemoryHistory(base) : null /* default */ history: base => process.client ? createMemoryHistory(base) : null /* default */
} }
``` ```

View File

@ -45,7 +45,7 @@ export default defineNuxtPlugin((nuxtApp) => {
}) })
nuxtApp.hook('vue:error', (..._args) => { nuxtApp.hook('vue:error', (..._args) => {
console.log('vue:error') console.log('vue:error')
// if (import.meta.client) { // if (process.client) {
// console.log(..._args) // console.log(..._args)
// } // }
}) })
@ -105,7 +105,7 @@ When accessing the same `payload.data` from [ssrcontext](#ssrcontext), you can a
export const useColor = () => useState<string>('color', () => 'pink') export const useColor = () => useState<string>('color', () => 'pink')
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
if (import.meta.server) { if (process.server) {
const color = useColor() const color = useColor()
} }
}) })
@ -137,7 +137,7 @@ export default defineComponent({
setup (_props, { slots, emit }) { setup (_props, { slots, emit }) {
const nuxtApp = useNuxtApp() const nuxtApp = useNuxtApp()
onErrorCaptured((err) => { onErrorCaptured((err) => {
if (import.meta.client && !nuxtApp.isHydrating) { if (process.client && !nuxtApp.isHydrating) {
// ... // ...
} }
}) })

View File

@ -45,7 +45,7 @@
"@nuxt/webpack-builder": "workspace:*", "@nuxt/webpack-builder": "workspace:*",
"@nuxtjs/eslint-config-typescript": "12.0.0", "@nuxtjs/eslint-config-typescript": "12.0.0",
"@types/fs-extra": "11.0.1", "@types/fs-extra": "11.0.1",
"@types/node": "18.17.5", "@types/node": "18.17.6",
"@types/semver": "7.5.0", "@types/semver": "7.5.0",
"case-police": "0.6.1", "case-police": "0.6.1",
"chalk": "5.3.0", "chalk": "5.3.0",
@ -54,15 +54,15 @@
"consola": "3.2.3", "consola": "3.2.3",
"devalue": "4.3.2", "devalue": "4.3.2",
"eslint": "8.47.0", "eslint": "8.47.0",
"eslint-plugin-import": "2.28.0", "eslint-plugin-import": "2.28.1",
"eslint-plugin-jsdoc": "41.1.2", "eslint-plugin-jsdoc": "41.1.2",
"eslint-plugin-no-only-tests": "3.1.0", "eslint-plugin-no-only-tests": "3.1.0",
"execa": "7.2.0", "execa": "7.2.0",
"fs-extra": "11.1.1", "fs-extra": "11.1.1",
"globby": "13.2.2", "globby": "13.2.2",
"h3": "1.8.0", "h3": "1.8.0",
"happy-dom": "10.10.0", "happy-dom": "10.10.4",
"jiti": "1.19.1", "jiti": "1.19.3",
"markdownlint-cli": "^0.33.0", "markdownlint-cli": "^0.33.0",
"nitropack": "2.5.2", "nitropack": "2.5.2",
"nuxi": "workspace:*", "nuxi": "workspace:*",
@ -70,10 +70,10 @@
"nuxt-vitest": "0.10.2", "nuxt-vitest": "0.10.2",
"ofetch": "1.1.1", "ofetch": "1.1.1",
"pathe": "1.1.1", "pathe": "1.1.1",
"playwright-core": "1.37.0", "playwright-core": "1.37.1",
"rimraf": "5.0.1", "rimraf": "5.0.1",
"semver": "7.5.4", "semver": "7.5.4",
"std-env": "3.3.3", "std-env": "3.4.0",
"typescript": "5.1.6", "typescript": "5.1.6",
"ufo": "1.2.0", "ufo": "1.2.0",
"vite": "4.4.9", "vite": "4.4.9",

View File

@ -27,7 +27,7 @@
"globby": "^13.2.2", "globby": "^13.2.2",
"hash-sum": "^2.0.0", "hash-sum": "^2.0.0",
"ignore": "^5.2.4", "ignore": "^5.2.4",
"jiti": "^1.19.1", "jiti": "^1.19.3",
"knitwork": "^1.0.0", "knitwork": "^1.0.0",
"mlly": "^1.4.0", "mlly": "^1.4.0",
"pathe": "^1.1.1", "pathe": "^1.1.1",

View File

@ -37,7 +37,7 @@
"flat": "5.0.2", "flat": "5.0.2",
"giget": "1.1.2", "giget": "1.1.2",
"h3": "1.8.0", "h3": "1.8.0",
"jiti": "1.19.1", "jiti": "1.19.3",
"listhen": "1.3.0", "listhen": "1.3.0",
"mlly": "1.4.0", "mlly": "1.4.0",
"mri": "1.2.0", "mri": "1.2.0",

View File

@ -6,7 +6,8 @@ import { findup } from './fs'
export const packageManagerLocks = { export const packageManagerLocks = {
yarn: 'yarn.lock', yarn: 'yarn.lock',
npm: 'package-lock.json', npm: 'package-lock.json',
pnpm: 'pnpm-lock.yaml' pnpm: 'pnpm-lock.yaml',
bun: 'bun.lockb'
} }
type PackageManager = keyof typeof packageManagerLocks type PackageManager = keyof typeof packageManagerLocks

View File

@ -58,9 +58,9 @@
"@nuxt/telemetry": "^2.4.1", "@nuxt/telemetry": "^2.4.1",
"@nuxt/ui-templates": "^1.3.1", "@nuxt/ui-templates": "^1.3.1",
"@nuxt/vite-builder": "workspace:../vite", "@nuxt/vite-builder": "workspace:../vite",
"@unhead/dom": "^1.3.4", "@unhead/dom": "^1.3.5",
"@unhead/ssr": "^1.3.4", "@unhead/ssr": "^1.3.5",
"@unhead/vue": "^1.3.4", "@unhead/vue": "^1.3.5",
"@vue/shared": "^3.3.4", "@vue/shared": "^3.3.4",
"acorn": "8.10.0", "acorn": "8.10.0",
"c12": "^1.4.2", "c12": "^1.4.2",
@ -76,7 +76,7 @@
"globby": "^13.2.2", "globby": "^13.2.2",
"h3": "^1.8.0", "h3": "^1.8.0",
"hookable": "^5.5.3", "hookable": "^5.5.3",
"jiti": "^1.19.1", "jiti": "^1.19.3",
"klona": "^2.0.6", "klona": "^2.0.6",
"knitwork": "^1.0.0", "knitwork": "^1.0.0",
"magic-string": "^0.30.2", "magic-string": "^0.30.2",
@ -91,7 +91,7 @@
"pkg-types": "^1.0.3", "pkg-types": "^1.0.3",
"prompts": "^2.4.2", "prompts": "^2.4.2",
"scule": "^1.0.0", "scule": "^1.0.0",
"std-env": "^3.3.3", "std-env": "^3.4.0",
"strip-literal": "^1.3.0", "strip-literal": "^1.3.0",
"ufo": "^1.2.0", "ufo": "^1.2.0",
"ultrahtml": "^1.3.0", "ultrahtml": "^1.3.0",
@ -112,7 +112,7 @@
"@types/estree": "1.0.1", "@types/estree": "1.0.1",
"@types/fs-extra": "11.0.1", "@types/fs-extra": "11.0.1",
"@types/prompts": "2.4.4", "@types/prompts": "2.4.4",
"@vitejs/plugin-vue": "4.2.3", "@vitejs/plugin-vue": "4.3.1",
"unbuild": "latest", "unbuild": "latest",
"vite": "4.4.9", "vite": "4.4.9",
"vitest": "0.33.0" "vitest": "0.33.0"

View File

@ -30,11 +30,11 @@
"@types/file-loader": "5.0.1", "@types/file-loader": "5.0.1",
"@types/pug": "2.0.6", "@types/pug": "2.0.6",
"@types/sass-loader": "8.0.5", "@types/sass-loader": "8.0.5",
"@unhead/schema": "1.3.4", "@unhead/schema": "1.3.5",
"@vitejs/plugin-vue": "4.2.3", "@vitejs/plugin-vue": "4.3.1",
"@vitejs/plugin-vue-jsx": "3.0.1", "@vitejs/plugin-vue-jsx": "3.0.2",
"@vue/compiler-core": "3.3.4", "@vue/compiler-core": "3.3.4",
"esbuild-loader": "4.0.0", "esbuild-loader": "4.0.1",
"h3": "1.8.0", "h3": "1.8.0",
"ignore": "5.2.4", "ignore": "5.2.4",
"nitropack": "2.5.2", "nitropack": "2.5.2",
@ -55,7 +55,7 @@
"pathe": "^1.1.1", "pathe": "^1.1.1",
"pkg-types": "^1.0.3", "pkg-types": "^1.0.3",
"postcss-import-resolver": "^2.0.0", "postcss-import-resolver": "^2.0.0",
"std-env": "^3.3.3", "std-env": "^3.4.0",
"ufo": "^1.2.0", "ufo": "^1.2.0",
"unimport": "^3.1.3", "unimport": "^3.1.3",
"untyped": "^1.4.0" "untyped": "^1.4.0"

View File

@ -34,7 +34,7 @@
}, },
"devDependencies": { "devDependencies": {
"@jest/globals": "29.6.2", "@jest/globals": "29.6.2",
"playwright-core": "1.37.0", "playwright-core": "1.37.1",
"unbuild": "latest", "unbuild": "latest",
"vitest": "0.33.0" "vitest": "0.33.0"
}, },

View File

@ -28,8 +28,8 @@
"dependencies": { "dependencies": {
"@nuxt/kit": "workspace:../kit", "@nuxt/kit": "workspace:../kit",
"@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-replace": "^5.0.2",
"@vitejs/plugin-vue": "^4.2.3", "@vitejs/plugin-vue": "^4.3.1",
"@vitejs/plugin-vue-jsx": "^3.0.1", "@vitejs/plugin-vue-jsx": "^3.0.2",
"autoprefixer": "^10.4.15", "autoprefixer": "^10.4.15",
"clear": "^0.1.0", "clear": "^0.1.0",
"consola": "^3.2.3", "consola": "^3.2.3",
@ -53,13 +53,13 @@
"postcss-import": "^15.1.0", "postcss-import": "^15.1.0",
"postcss-url": "^10.1.3", "postcss-url": "^10.1.3",
"rollup-plugin-visualizer": "^5.9.2", "rollup-plugin-visualizer": "^5.9.2",
"std-env": "^3.3.3", "std-env": "^3.4.0",
"strip-literal": "^1.3.0", "strip-literal": "^1.3.0",
"ufo": "^1.2.0", "ufo": "^1.2.0",
"unplugin": "^1.4.0", "unplugin": "^1.4.0",
"vite": "^4.4.9", "vite": "^4.4.9",
"vite-node": "^0.33.0", "vite-node": "^0.33.0",
"vite-plugin-checker": "^0.6.1", "vite-plugin-checker": "^0.6.2",
"vue-bundle-renderer": "^2.0.0" "vue-bundle-renderer": "^2.0.0"
}, },
"peerDependencies": { "peerDependencies": {

View File

@ -141,14 +141,26 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
} }
}) })
/*
* track scopes with unique keys. for example
* ```js
* // root scope, marked as ''
* function a () { // '0'
* function b () {} // '0-0'
* function c () {} // '0-1'
* }
* function d () {} // '1'
* // ''
* ```
* */
class ScopeTracker { class ScopeTracker {
// the top of the stack is not a part of current key, it is used for next level
scopeIndexStack: number[] scopeIndexStack: number[]
curScopeKey: string curScopeKey: string
constructor () { constructor () {
// top level
this.scopeIndexStack = [0] this.scopeIndexStack = [0]
this.curScopeKey = '0' this.curScopeKey = ''
} }
getKey () { getKey () {
@ -173,8 +185,7 @@ class ScopedVarsCollector {
constructor () { constructor () {
this.all = new Map() this.all = new Map()
// top level this.curScopeKey = ''
this.curScopeKey = '0'
} }
refresh (scopeKey: string) { refresh (scopeKey: string) {
@ -192,7 +203,7 @@ class ScopedVarsCollector {
hasVar (scopeKey: string, name: string) { hasVar (scopeKey: string, name: string) {
const indices = scopeKey.split('-').map(Number) const indices = scopeKey.split('-').map(Number)
for (let i = indices.length; i > 0; i--) { for (let i = indices.length; i >= 0; i--) {
if (this.all.get(indices.slice(0, i).join('-'))?.has(name)) { if (this.all.get(indices.slice(0, i).join('-'))?.has(name)) {
return true return true
} }

View File

@ -26,7 +26,7 @@
"css-minimizer-webpack-plugin": "^5.0.1", "css-minimizer-webpack-plugin": "^5.0.1",
"cssnano": "^6.0.1", "cssnano": "^6.0.1",
"defu": "^6.1.2", "defu": "^6.1.2",
"esbuild-loader": "^4.0.0", "esbuild-loader": "^4.0.1",
"escape-string-regexp": "^5.0.0", "escape-string-regexp": "^5.0.0",
"estree-walker": "^3.0.3", "estree-walker": "^3.0.3",
"file-loader": "^6.2.0", "file-loader": "^6.2.0",
@ -47,7 +47,7 @@
"postcss-loader": "^7.3.3", "postcss-loader": "^7.3.3",
"postcss-url": "^10.1.3", "postcss-url": "^10.1.3",
"pug-plain-loader": "^1.1.0", "pug-plain-loader": "^1.1.0",
"std-env": "^3.3.3", "std-env": "^3.4.0",
"time-fix-plugin": "^2.0.7", "time-fix-plugin": "^2.0.7",
"ufo": "^1.2.0", "ufo": "^1.2.0",
"unplugin": "^1.4.0", "unplugin": "^1.4.0",

File diff suppressed because it is too large Load Diff

View File

@ -35,7 +35,7 @@ describe.skipIf(process.env.SKIP_BUNDLE_SIZE === 'true' || process.env.ECOSYSTEM
expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"64.6k"') expect.soft(roundToKilobytes(serverStats.totalBytes)).toMatchInlineSnapshot('"64.6k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2352k"') expect.soft(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2348k"')
const packages = modules.files const packages = modules.files
.filter(m => m.endsWith('package.json')) .filter(m => m.endsWith('package.json'))

View File

@ -10,7 +10,7 @@
}, },
"devDependencies": { "devDependencies": {
"ofetch": "latest", "ofetch": "latest",
"vitest": "latest", "vitest": "0.33.0",
"vue-router": "latest", "vue-router": "latest",
"vue": "latest" "vue": "latest"
} }

View File

@ -0,0 +1,5 @@
function useAsyncData (s?: any) { return s }
export const ShouldNotBeKeyed = (() => {
return useAsyncData()
})()

View File

@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ShouldNotBeKeyed } from '~/other-composables-folder/local'
function localScopedComposables () { function localScopedComposables () {
const _assert = (key?: string) => key ?? 'was not keyed' const _assert = (key?: string) => key ?? 'was not keyed'
@ -39,11 +41,15 @@ function localScopedComposables () {
})()] })()]
} }
function fromNonComponentFile () {
return [_assert(ShouldNotBeKeyed)]
}
function useCustomKeyedComposable (arg?: string) { function useCustomKeyedComposable (arg?: string) {
return _assert(arg) return _assert(arg)
} }
return [...basic(), ...hoisting(), ...complex(), ...deeperScope(), useCustomKeyedComposable()] return [...basic(), ...hoisting(), ...complex(), ...deeperScope(), ...fromNonComponentFile(), useCustomKeyedComposable()]
} }
const skippedLocalScopedComposables = localScopedComposables().every(res => res === 'was not keyed') const skippedLocalScopedComposables = localScopedComposables().every(res => res === 'was not keyed')
</script> </script>