From f209158352b09d1986aa320e29ff36353b91c358 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 5 Apr 2024 20:08:32 +0200 Subject: [PATCH] chore: cleanup eslint rules with latest `@nuxt/eslint-config` (#26653) --- .gitignore | 2 + eslint.config.mjs | 447 ++++---- nuxt.config.ts | 6 +- package.json | 14 +- packages/kit/build.config.ts | 6 +- packages/kit/src/build.ts | 4 +- packages/kit/src/compatibility.ts | 6 +- packages/kit/src/components.ts | 2 +- packages/kit/src/ignore.test.ts | 6 +- packages/kit/src/index.ts | 2 +- packages/kit/src/internal/cjs.ts | 4 +- packages/kit/src/internal/template.ts | 2 +- packages/kit/src/layout.ts | 6 +- packages/kit/src/loader/config.ts | 6 +- packages/kit/src/loader/nuxt.ts | 4 +- packages/kit/src/module/compatibility.test.ts | 26 +- packages/kit/src/module/compatibility.ts | 4 +- packages/kit/src/module/define.ts | 10 +- packages/kit/src/module/install.ts | 2 +- packages/kit/src/nitro.ts | 2 +- packages/kit/src/resolve.ts | 2 +- packages/kit/src/template.ts | 18 +- packages/kit/test/generate-types.spec.ts | 8 +- packages/kit/test/load-nuxt-config.bench.ts | 2 +- packages/nuxt/build.config.ts | 12 +- packages/nuxt/config.cjs | 3 +- packages/nuxt/config.d.ts | 1 + packages/nuxt/src/app/compat/capi.ts | 1 - packages/nuxt/src/app/compat/idle-callback.ts | 2 +- packages/nuxt/src/app/compat/interval.ts | 2 +- .../app/components/client-fallback.client.ts | 16 +- .../app/components/client-fallback.server.ts | 20 +- .../nuxt/src/app/components/client-only.ts | 4 +- packages/nuxt/src/app/components/dev-only.ts | 2 +- .../src/app/components/island-renderer.ts | 8 +- .../src/app/components/nuxt-error-boundary.ts | 4 +- .../src/app/components/nuxt-error-page.vue | 4 +- .../nuxt/src/app/components/nuxt-island.ts | 32 +- .../nuxt/src/app/components/nuxt-layout.ts | 37 +- packages/nuxt/src/app/components/nuxt-link.ts | 50 +- .../app/components/nuxt-loading-indicator.ts | 22 +- .../nuxt/src/app/components/nuxt-stubs.ts | 6 +- .../nuxt-teleport-island-component.ts | 20 +- .../components/nuxt-teleport-island-slot.ts | 20 +- .../nuxt/src/app/components/route-provider.ts | 10 +- .../src/app/components/server-placeholder.ts | 2 +- .../app/components/test-component-wrapper.ts | 6 +- packages/nuxt/src/app/components/utils.ts | 7 +- .../nuxt/src/app/composables/asyncData.ts | 30 +- .../nuxt/src/app/composables/component.ts | 4 +- packages/nuxt/src/app/composables/cookie.ts | 4 +- packages/nuxt/src/app/composables/error.ts | 16 +- packages/nuxt/src/app/composables/fetch.ts | 18 +- packages/nuxt/src/app/composables/index.ts | 2 +- .../src/app/composables/loading-indicator.ts | 2 +- packages/nuxt/src/app/composables/manifest.ts | 2 +- packages/nuxt/src/app/composables/payload.ts | 10 +- packages/nuxt/src/app/composables/preload.ts | 2 +- packages/nuxt/src/app/composables/preview.ts | 10 +- packages/nuxt/src/app/composables/router.ts | 11 +- packages/nuxt/src/app/composables/state.ts | 8 +- packages/nuxt/src/app/entry.ts | 2 +- packages/nuxt/src/app/index.ts | 4 +- packages/nuxt/src/app/nuxt.ts | 13 +- .../src/app/plugins/check-if-layout-used.ts | 4 +- .../src/app/plugins/chunk-reload.client.ts | 2 +- .../plugins/cross-origin-prefetch.client.ts | 14 +- packages/nuxt/src/app/plugins/debug.ts | 2 +- .../nuxt/src/app/plugins/dev-server-logs.ts | 6 +- .../nuxt/src/app/plugins/payload.client.ts | 2 +- .../nuxt/src/app/plugins/preload.server.ts | 4 +- .../src/app/plugins/restore-state.client.ts | 4 +- .../src/app/plugins/revive-payload.client.ts | 10 +- .../src/app/plugins/revive-payload.server.ts | 4 +- packages/nuxt/src/app/plugins/router.ts | 26 +- packages/nuxt/src/app/types.ts | 2 - .../src/components/client-fallback-auto-id.ts | 7 +- .../nuxt/src/components/islandsTransform.ts | 15 +- packages/nuxt/src/components/loader.ts | 4 +- packages/nuxt/src/components/module.ts | 50 +- .../components/runtime/client-component.ts | 6 +- .../components/runtime/server-component.ts | 14 +- packages/nuxt/src/components/scan.ts | 6 +- packages/nuxt/src/components/templates.ts | 20 +- packages/nuxt/src/components/transform.ts | 32 +- packages/nuxt/src/components/tree-shake.ts | 16 +- packages/nuxt/src/core/app.ts | 16 +- packages/nuxt/src/core/builder.ts | 10 +- .../nuxt/src/core/external-config-files.ts | 12 +- packages/nuxt/src/core/features.ts | 4 +- packages/nuxt/src/core/modules.ts | 2 +- packages/nuxt/src/core/nitro.ts | 100 +- packages/nuxt/src/core/nuxt.ts | 80 +- .../nuxt/src/core/plugins/async-context.ts | 4 +- packages/nuxt/src/core/plugins/dev-only.ts | 4 +- .../src/core/plugins/import-protection.ts | 10 +- .../nuxt/src/core/plugins/layer-aliasing.ts | 10 +- .../nuxt/src/core/plugins/plugin-metadata.ts | 21 +- .../src/core/plugins/resolve-deep-imports.ts | 4 +- packages/nuxt/src/core/plugins/tree-shake.ts | 4 +- packages/nuxt/src/core/plugins/unctx.ts | 4 +- .../src/core/runtime/nitro/cache-driver.ts | 4 +- .../src/core/runtime/nitro/dev-server-logs.ts | 4 +- packages/nuxt/src/core/runtime/nitro/error.ts | 8 +- .../nuxt/src/core/runtime/nitro/renderer.ts | 102 +- packages/nuxt/src/core/schema.ts | 28 +- packages/nuxt/src/core/templates.ts | 72 +- packages/nuxt/src/head/module.ts | 14 +- packages/nuxt/src/head/runtime/components.ts | 81 +- .../nuxt/src/head/runtime/plugins/unhead.ts | 6 +- .../runtime/plugins/vueuse-head-polyfill.ts | 2 +- packages/nuxt/src/imports/module.ts | 24 +- packages/nuxt/src/imports/presets.ts | 68 +- packages/nuxt/src/imports/transform.ts | 4 +- packages/nuxt/src/pages/module.ts | 64 +- packages/nuxt/src/pages/plugins/page-meta.ts | 16 +- .../nuxt/src/pages/plugins/route-injection.ts | 4 +- packages/nuxt/src/pages/route-rules.ts | 4 +- .../nuxt/src/pages/runtime/composables.ts | 2 +- .../src/pages/runtime/page-placeholder.ts | 2 +- packages/nuxt/src/pages/runtime/page.ts | 28 +- .../runtime/plugins/check-if-page-unused.ts | 6 +- .../pages/runtime/plugins/prefetch.client.ts | 2 +- .../nuxt/src/pages/runtime/plugins/router.ts | 22 +- .../nuxt/src/pages/runtime/router.options.ts | 4 +- packages/nuxt/src/pages/runtime/validate.ts | 4 +- packages/nuxt/src/pages/utils.ts | 18 +- packages/nuxt/test/app.test.ts | 16 +- packages/nuxt/test/auto-imports.test.ts | 7 +- .../nuxt/test/components-transform.test.ts | 14 +- packages/nuxt/test/devonly.test.ts | 1 + .../components/client/ComponentWithProps.vue | 2 +- packages/nuxt/test/import-protection.test.ts | 8 +- packages/nuxt/test/islandTransform.test.ts | 6 +- packages/nuxt/test/load-nuxt.bench.ts | 4 +- packages/nuxt/test/load-nuxt.test.ts | 6 +- packages/nuxt/test/naming.test.ts | 4 +- packages/nuxt/test/nuxt-link.test.ts | 26 +- packages/nuxt/test/pages.test.ts | 288 ++--- packages/nuxt/test/plugin-metadata.test.ts | 24 +- packages/nuxt/test/scan-components.test.ts | 58 +- packages/nuxt/test/treeshake-client.test.ts | 50 +- packages/nuxt/types.d.mts | 2 +- packages/schema/build.config.ts | 12 +- packages/schema/src/config/adhoc.ts | 6 +- packages/schema/src/config/app.ts | 36 +- packages/schema/src/config/build.ts | 50 +- packages/schema/src/config/common.ts | 58 +- packages/schema/src/config/dev.ts | 4 +- packages/schema/src/config/experimental.ts | 28 +- packages/schema/src/config/generate.ts | 4 +- packages/schema/src/config/index.ts | 2 +- packages/schema/src/config/internal.ts | 2 +- packages/schema/src/config/nitro.ts | 8 +- packages/schema/src/config/postcss.ts | 8 +- packages/schema/src/config/router.ts | 6 +- packages/schema/src/config/typescript.ts | 10 +- packages/schema/src/config/vite.ts | 60 +- packages/schema/src/config/webpack.ts | 52 +- packages/schema/src/types/builder-env/vite.ts | 10 +- packages/schema/src/types/config.ts | 41 +- packages/schema/src/types/nuxt.ts | 2 +- packages/vite/build.config.ts | 8 +- packages/vite/src/client.ts | 46 +- packages/vite/src/css.ts | 8 +- packages/vite/src/dev-bundler.ts | 20 +- packages/vite/src/manifest.ts | 6 +- packages/vite/src/plugins/analyze.ts | 6 +- packages/vite/src/plugins/chunk-error.ts | 4 +- packages/vite/src/plugins/composable-keys.ts | 12 +- packages/vite/src/plugins/dev-ssr-css.ts | 2 +- packages/vite/src/plugins/paths.ts | 4 +- packages/vite/src/plugins/public-dirs.ts | 8 +- packages/vite/src/plugins/ssr-styles.ts | 26 +- packages/vite/src/plugins/type-check.ts | 4 +- packages/vite/src/plugins/virtual.ts | 4 +- .../vite/src/runtime/vite-node-shared.mjs | 2 +- packages/vite/src/runtime/vite-node.mjs | 13 +- packages/vite/src/server.ts | 42 +- packages/vite/src/utils/external.ts | 8 +- packages/vite/src/utils/logger.ts | 6 +- packages/vite/src/utils/warmup.ts | 2 +- packages/vite/src/utils/wpfs.ts | 2 +- packages/vite/src/vite-node.ts | 26 +- packages/vite/src/vite.ts | 46 +- packages/vite/test/composable-keys.test.ts | 2 +- packages/webpack/build.config.ts | 8 +- packages/webpack/src/configs/client.ts | 14 +- packages/webpack/src/configs/server.ts | 10 +- packages/webpack/src/plugins/chunk.ts | 4 +- packages/webpack/src/plugins/dynamic-base.ts | 6 +- packages/webpack/src/plugins/vue/client.ts | 6 +- packages/webpack/src/plugins/vue/server.ts | 14 +- packages/webpack/src/plugins/vue/util.ts | 2 +- packages/webpack/src/presets/assets.ts | 20 +- packages/webpack/src/presets/base.ts | 40 +- packages/webpack/src/presets/esbuild.ts | 12 +- packages/webpack/src/presets/node.ts | 10 +- packages/webpack/src/presets/nuxt.ts | 2 +- packages/webpack/src/presets/pug.ts | 14 +- packages/webpack/src/presets/style.ts | 24 +- packages/webpack/src/presets/vue.ts | 8 +- packages/webpack/src/utils/config.ts | 2 +- packages/webpack/src/utils/postcss.ts | 12 +- packages/webpack/src/webpack.ts | 8 +- playground/nuxt.config.ts | 2 +- pnpm-lock.yaml | 989 ++++++++---------- scripts/_utils.ts | 16 +- scripts/bump-edge.ts | 4 +- scripts/update-changelog.ts | 16 +- test/basic.test.ts | 132 +-- test/bundle.test.ts | 4 +- test/fixtures/basic-types/app.config.ts | 4 +- .../basic-types/components/WithTypes.vue | 2 +- .../basic-types/extends/bar/app.config.ts | 2 +- .../extends/bar/pages/override.vue | 2 +- .../basic-types/middleware/global.global.ts | 2 +- .../modules/auto-registered/index.ts | 6 +- test/fixtures/basic-types/modules/example.ts | 8 +- .../basic-types/modules/page-extend.ts | 6 +- .../basic-types/modules/runtime/page.vue | 2 +- .../basic-types/modules/test/index.ts | 4 +- test/fixtures/basic-types/nuxt.config.ts | 42 +- test/fixtures/basic-types/nuxt.schema.ts | 4 +- .../basic-types/pages/custom-name.vue | 4 +- .../fixtures/basic-types/plugins/injection.ts | 4 +- .../basic-types/server/api/hey/index.get.ts | 2 +- .../basic-types/server/api/hey/index.post.ts | 2 +- test/fixtures/basic-types/server/api/union.ts | 2 +- test/fixtures/basic-types/types.ts | 50 +- test/fixtures/basic/app.config.ts | 4 +- .../basic/components/BreaksServer.client.ts | 2 +- .../components/ClientOnlyScript.client.vue | 6 +- .../basic/components/FunctionalComponent.ts | 2 +- .../basic/components/Nested/Counter.vue | 4 +- test/fixtures/basic/components/Tsx.tsx | 14 +- .../basic/components/client/Binding.client.ts | 4 +- .../client/MultiRootNodeScript.client.vue | 2 +- .../basic/components/client/Script.client.vue | 8 +- .../client/StringChildStateful.client.vue | 2 +- .../StringChildStatefulScript.client.vue | 4 +- .../components/clientFallback/NonStateful.vue | 2 +- .../components/clientFallback/Stateful.vue | 4 +- .../components/islands/LongAsyncComponent.vue | 1 + .../components/islands/PureComponent.vue | 2 +- .../basic/composables/async-context.ts | 2 +- test/fixtures/basic/error.vue | 3 +- test/fixtures/basic/extends/bar/app.config.ts | 2 +- .../basic/extends/bar/app/router.options.ts | 2 +- .../fixtures/basic/extends/bar/nuxt.config.ts | 2 +- .../basic/extends/bar/pages/override.vue | 2 +- test/fixtures/basic/layouts/custom.vue | 2 +- test/fixtures/basic/layouts/custom2.vue | 2 +- test/fixtures/basic/layouts/with-props.vue | 2 +- .../fixtures/basic/middleware/abort.global.ts | 2 +- .../basic/modules/auto-registered/index.ts | 10 +- test/fixtures/basic/modules/example.ts | 6 +- test/fixtures/basic/modules/functional.ts | 2 +- .../basic/modules/import-components/index.ts | 16 +- .../import-components/runtime/components.ts | 4 +- .../modules/lazy-import-components/index.ts | 10 +- .../runtime/components.ts | 2 +- .../basic/modules/page-extend/index.ts | 10 +- .../modules/page-extend/pages/big-page.vue | 2 +- test/fixtures/basic/modules/runtime/page.vue | 2 +- test/fixtures/basic/modules/subpath/module.ts | 2 +- test/fixtures/basic/modules/test/index.ts | 4 +- test/fixtures/basic/nuxt.config.ts | 78 +- .../other-components-folder/named-export.ts | 2 +- test/fixtures/basic/pages/[...slug].vue | 2 +- test/fixtures/basic/pages/async-parent.vue | 2 +- .../basic/pages/async-parent/child.vue | 2 +- test/fixtures/basic/pages/auth.vue | 2 +- test/fixtures/basic/pages/chunk-error.vue | 2 +- .../pages/client-only-page/index.client.vue | 2 +- test/fixtures/basic/pages/cookies.vue | 2 +- .../pages/fixed-keyed-child-parent/[foo].vue | 2 +- .../basic/pages/head-script-setup.vue | 22 +- test/fixtures/basic/pages/head.vue | 14 +- .../fixtures/basic/pages/hydration/layout.vue | 4 +- .../pages/hydration/spa-redirection/start.vue | 2 +- test/fixtures/basic/pages/index.vue | 4 +- test/fixtures/basic/pages/instance/error.vue | 2 +- test/fixtures/basic/pages/internal-layout.vue | 2 +- .../basic/pages/invalid-root/fine.vue | 2 +- test/fixtures/basic/pages/islands.vue | 2 +- .../basic/pages/keyed-child-parent/[foo].vue | 2 +- .../basic/pages/keyed-composables/index.vue | 2 +- .../basic/pages/keyed-composables/local.vue | 4 +- .../basic/pages/layout-switch/start.vue | 2 +- .../basic/pages/layouts/with-props.vue | 2 +- .../basic/pages/legacy-async-data-fail.vue | 2 +- .../basic/pages/legacy/async-data.vue | 4 +- .../basic/pages/legacy/async-data/index.vue | 4 +- .../pages/legacy/async-data/index/index.vue | 4 +- .../pages/middleware-abort-non-fatal.vue | 4 +- .../fixtures/basic/pages/middleware-abort.vue | 4 +- .../basic/pages/navigate-to-error.vue | 2 +- .../basic/pages/navigate-to-forbidden.vue | 2 +- .../basic/pages/navigate-to-redirect.vue | 2 +- test/fixtures/basic/pages/no-auth.vue | 2 +- .../basic/pages/nuxt-link/trailing-slash.vue | 6 +- .../pages/preview/with-custom-enable.vue | 2 +- .../basic/pages/preview/with-custom-state.vue | 2 +- .../basic/pages/preview/with-use-fetch.vue | 4 +- test/fixtures/basic/pages/redirect.vue | 2 +- .../basic/pages/route-rules/inline.vue | 4 +- test/fixtures/basic/pages/suspense.vue | 2 +- test/fixtures/basic/pages/vueuse-head.vue | 4 +- .../basic/pages/with-computed-layout.vue | 2 +- .../basic/pages/with-dynamic-layout.vue | 2 +- test/fixtures/basic/pages/with-layout.vue | 2 +- test/fixtures/basic/pages/with-layout2.vue | 2 +- .../basic/pages/wrapper-expose/layout.vue | 2 +- .../pages/wrapper-expose/page/another.vue | 2 +- .../basic/pages/wrapper-expose/page/index.vue | 2 +- test/fixtures/basic/plugins/add-route.ts | 2 +- test/fixtures/basic/plugins/async-plugin.ts | 6 +- test/fixtures/basic/plugins/context-error.ts | 4 +- .../plugins/custom-type-assertion.client.ts | 2 +- .../fixtures/basic/plugins/dependsOnPlugin.ts | 2 +- test/fixtures/basic/plugins/my-plugin.ts | 6 +- test/fixtures/basic/plugins/register.ts | 2 +- .../basic/plugins/server-only.server.ts | 4 +- test/fixtures/basic/server/api/app-config.ts | 2 +- .../fixtures/basic/server/api/auto-imports.ts | 2 +- .../basic/server/api/hey/index.get.ts | 2 +- .../basic/server/api/hey/index.post.ts | 2 +- test/fixtures/basic/server/api/preview.ts | 2 +- test/fixtures/basic/server/api/union.ts | 2 +- test/fixtures/minimal-types/nuxt.config.ts | 2 +- test/fixtures/minimal-types/types.ts | 8 +- test/fixtures/minimal/app.vue | 2 +- test/fixtures/minimal/nuxt.config.ts | 18 +- test/fixtures/remote-provider/index.ts | 5 +- .../components/Helloworld.vue | 2 +- .../runtime-compiler/components/Name.ts | 6 +- .../components/ShowTemplate.vue | 16 +- test/fixtures/runtime-compiler/nuxt.config.ts | 6 +- .../fixtures/runtime-compiler/pages/index.vue | 14 +- .../server/api/full-component.get.ts | 2 +- test/fixtures/suspense/nuxt.config.ts | 6 +- test/hmr.test.ts | 22 +- test/mocks/nuxt-config.ts | 2 +- test/nuxt/client.test.ts | 6 +- test/nuxt/composables.test.ts | 24 +- test/nuxt/nuxt-island.test.ts | 74 +- test/nuxt/plugin.test.ts | 52 +- test/prepare.ts | 6 +- test/runtime-compiler.test.ts | 5 +- test/setup-env.ts | 2 +- test/setup-runtime.ts | 10 +- test/setup.ts | 2 +- test/suspense.test.ts | 6 +- test/utils.ts | 12 +- vitest.config.ts | 14 +- vitest.nuxt.config.ts | 20 +- 357 files changed, 2713 insertions(+), 2952 deletions(-) diff --git a/.gitignore b/.gitignore index 35388c4fd2..815f0415e7 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,5 @@ Temporary Items fixtures-temp .pnpm-store +eslint-typegen.d.ts +.eslintcache diff --git a/eslint.config.mjs b/eslint.config.mjs index 9287eddea3..48a0090600 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,280 +1,215 @@ -// Configs -// import standard from "eslint-config-standard" -// import nuxt from '@nuxt/eslint-config' - -// Plugins -import path from 'node:path' -import { fileURLToPath } from 'node:url' -import jsdoc from 'eslint-plugin-jsdoc' -import esImport from 'eslint-plugin-import' -import unicorn from 'eslint-plugin-unicorn' +// @ts-check +import { createConfigForNuxt } from '@nuxt/eslint-config/flat' +// @ts-expect-error missing types import noOnlyTests from 'eslint-plugin-no-only-tests' +import typegen from 'eslint-typegen' +// @ts-expect-error missing types +import perfectionist from 'eslint-plugin-perfectionist' -/** - * eslintrc compatibility - * @see https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config - * @see https://github.com/eslint/eslintrc#usage-esm - */ -import { FlatCompat } from '@eslint/eslintrc' -import js from '@eslint/js' - -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) - -const compat = new FlatCompat({ - baseDirectory: __dirname, - recommendedConfig: js.configs.recommended +export default createConfigForNuxt({ + features: { + stylistic: { + commaDangle: 'always-multiline', + }, + tooling: true, + }, }) - -// TODO: Type definition? -export default [ - { - ignores: [ - '**/dist/**', - '**/.nuxt/**', - '**/.nuxt-*/**', - '**/.output/**', - '**/.output-*/**', - '**/public/**', - '**/node_modules/**', - 'packages/schema/schema', - - // TODO: remove when fully migrated to flat config - '**/*.d.mts' - ] - }, - // standard, - ...compat.extends('eslint-config-standard'), - jsdoc.configs['flat/recommended'], - // nuxt, - ...compat.extends('@nuxt/eslint-config'), - esImport.configs.typescript, - { - rules: { - 'import/export': 'off' - } - }, - { - files: ['**/*.vue', '**/*.ts', '**/*.mts', '**/*.js', '**/*.cjs', '**/*.mjs'], - languageOptions: { - globals: { - NodeJS: 'readonly', - $fetch: 'readonly' - } + .prepend( + { + // Ignores have to be a separate object to be treated as global ignores + // Don't add other attributes to this object + ignores: [ + 'packages/schema/schema/**', + ], }, - plugins: { - jsdoc, - import: esImport, - unicorn, - 'no-only-tests': noOnlyTests + { + languageOptions: { + globals: { + $fetch: 'readonly', + NodeJS: 'readonly', + }, + }, + name: 'local/settings', + settings: { + jsdoc: { + ignoreInternal: true, + tagNamePreference: { + note: 'note', + warning: 'warning', + }, + }, + }, }, + ) + + .override('nuxt/javascript', { rules: { - // Imports should come first - 'import/first': 'error', - // Other import rules - 'import/no-mutable-exports': 'error', - // Allow unresolved imports - 'import/no-unresolved': 'off', - // Allow paren-less arrow functions only when there's no braces - 'arrow-parens': ['error', 'as-needed', { requireForBlockBody: true }], - // Allow async-await - 'generator-star-spacing': 'off', - // Prefer const over let - 'prefer-const': ['error', { destructuring: 'any', ignoreReadBeforeAssign: false }], - // No single if in an "else" block - 'no-lonely-if': 'error', - // Force curly braces for control flow, - // including if blocks with a single statement - curly: ['error', 'all'], - // No async function without await - 'require-await': 'error', - // Force dot notation when possible + 'curly': ['error', 'all'], // Including if blocks with a single statement 'dot-notation': 'error', - - 'no-var': 'error', - // Force object shorthand where possible - 'object-shorthand': 'error', - // No useless destructuring/importing/exporting renames - 'no-useless-rename': 'error', - /**********************/ - /* Unicorn Rules */ - /**********************/ - // Pass error message when throwing errors - 'unicorn/error-message': 'error', - // Uppercase regex escapes - 'unicorn/escape-case': 'error', - // Array.isArray instead of instanceof - 'unicorn/no-array-instanceof': 'error', - // Prevent deprecated `new Buffer()` - 'unicorn/no-new-buffer': 'error', - // Keep regex literals safe! - 'unicorn/no-unsafe-regex': 'off', - // Lowercase number formatting for octal, hex, binary (0x12 instead of 0X12) - 'unicorn/number-literal-case': 'error', - // ** instead of Math.pow() - 'unicorn/prefer-exponentiation-operator': 'error', - // includes over indexOf when checking for existence - 'unicorn/prefer-includes': 'error', - // String methods startsWith/endsWith instead of more complicated stuff - 'unicorn/prefer-starts-ends-with': 'error', - // textContent instead of innerText - 'unicorn/prefer-text-content': 'error', - // Enforce throwing type error when throwing error while checking typeof - 'unicorn/prefer-type-error': 'error', - // Use new when throwing error - 'unicorn/throw-new-error': 'error', - 'sort-imports': [ - 'error', - { - ignoreDeclarationSort: true - } - ], - 'no-only-tests/no-only-tests': 'error', - 'unicorn/prefer-node-protocol': 'error', 'no-console': ['warn', { allow: ['warn', 'error', 'debug'] }], - 'vue/one-component-per-file': 'off', - 'vue/require-default-prop': 'off', + 'no-lonely-if': 'error', // No single if in an "else" block + 'no-useless-rename': 'error', + 'object-shorthand': 'error', + 'prefer-const': ['error', { destructuring: 'any', ignoreReadBeforeAssign: false }], + 'require-await': 'error', + 'sort-imports': ['error', { ignoreDeclarationSort: true }], + }, + }) - // Vue stylistic rules from `@antfu/eslint-config` - 'vue/array-bracket-spacing': ['error', 'never'], - 'vue/arrow-spacing': ['error', { after: true, before: true }], - 'vue/block-spacing': ['error', 'always'], - 'vue/block-tag-newline': [ - 'error', - { - multiline: 'always', - singleline: 'always' - } - ], - 'vue/brace-style': ['error', 'stroustrup', { allowSingleLine: true }], - 'vue/comma-dangle': ['error', 'always-multiline'], - 'vue/comma-spacing': ['error', { after: true, before: false }], - 'vue/comma-style': ['error', 'last'], - 'vue/html-comment-content-spacing': [ - 'error', - 'always', - { - exceptions: ['-'] - } - ], - 'vue/key-spacing': ['error', { afterColon: true, beforeColon: false }], - 'vue/keyword-spacing': ['error', { after: true, before: true }], - 'vue/object-curly-newline': 'off', - 'vue/object-curly-spacing': ['error', 'always'], - 'vue/object-property-newline': [ - 'error', - { allowMultiplePropertiesPerLine: true } - ], - 'vue/operator-linebreak': ['error', 'before'], - 'vue/padding-line-between-blocks': ['error', 'always'], - 'vue/quote-props': ['error', 'consistent-as-needed'], - 'vue/space-in-parens': ['error', 'never'], - 'vue/template-curly-spacing': 'error', - - 'jsdoc/require-jsdoc': 'off', - 'jsdoc/require-param': 'off', - 'jsdoc/require-returns': 'off', - 'jsdoc/require-param-type': 'off', - 'import/order': [ - 'error', - { - pathGroups: [ - { - pattern: '#vue-router', - group: 'external' - } - ] - } - ], - 'import/no-restricted-paths': [ - 'error', - { - zones: [ - { - from: 'packages/nuxt/src/!(core)/**/*', - target: 'packages/nuxt/src/core', - message: 'core should not directly import from modules.' - }, - { - from: 'packages/nuxt/src/!(app)/**/*', - target: 'packages/nuxt/src/app', - message: 'app should not directly import from modules.' - }, - { - from: 'packages/nuxt/src/app/**/index.ts', - target: 'packages/nuxt/src', - message: 'should not import from barrel/index files' - }, - { - from: 'packages/nitro', - target: 'packages/!(nitro)/**/*', - message: 'nitro should not directly import other packages.' - } - ] - } - ], - '@typescript-eslint/consistent-type-imports': [ - 'error', - { - disallowTypeAnnotations: false - } - ], + .override('nuxt/typescript/rules', { + rules: { '@typescript-eslint/ban-ts-comment': [ 'error', { 'ts-expect-error': 'allow-with-description', - 'ts-ignore': true - } + 'ts-ignore': true, + }, ], - '@typescript-eslint/prefer-ts-expect-error': 'error', + '@typescript-eslint/no-dynamic-delete': 'off', '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', + ignoreRestSiblings: true, varsIgnorePattern: '^_', - ignoreRestSiblings: true - } + }, ], - 'jsdoc/check-tag-names': [ - 'error', - { - definedTags: ['__NO_SIDE_EFFECTS__'] - } - ] + '@typescript-eslint/triple-slash-reference': 'off', + '@typescript-eslint/unified-signatures': 'off', + ...{ + // TODO: Discuss if we want to enable this + '@typescript-eslint/ban-types': 'off', + // TODO: Discuss if we want to enable this + '@typescript-eslint/no-explicit-any': 'off', + // TODO: Discuss if we want to enable this + '@typescript-eslint/no-invalid-void-type': 'off', + }, }, - settings: { - jsdoc: { - ignoreInternal: true, - tagNamePreference: { - warning: 'warning', - note: 'note' - } - } - } - }, - { - files: ['packages/schema/**'], + }) + + .override('nuxt/tooling/unicorn', { rules: { - 'jsdoc/valid-types': 'off', - 'jsdoc/check-tag-names': [ - 'error', - { - definedTags: ['experimental'] - } - ] - } - }, - { - files: ['packages/nuxt/src/app/**', 'test/**', '**/runtime/**', '**/*.test.ts'], + 'unicorn/no-new-array': 'off', + 'unicorn/prefer-dom-node-text-content': 'off', + }, + }) + + .override('nuxt/vue/rules', { rules: { - 'no-console': 'off' - } - }, - { - files: ['test/fixtures/**'], + + }, + }) + + // Stylistic rules + .override('nuxt/stylistic', { rules: { - '@typescript-eslint/no-unused-vars': 'off', - 'vue/valid-v-for': 'off' - } - } -] + '@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }], + '@stylistic/indent-binary-ops': 'off', + '@stylistic/max-statements-per-line': 'off', + '@stylistic/operator-linebreak': 'off', + '@stylistic/quote-props': ['error', 'consistent'], + '@stylistic/space-before-function-paren': ['error', 'always'], + }, + }) + + // Append local rules + .append( + { + files: ['**/*.vue', '**/*.ts', '**/*.mts', '**/*.js', '**/*.cjs', '**/*.mjs'], + name: 'local/rules', + rules: { + 'import/no-restricted-paths': [ + 'error', + { + zones: [ + { + from: 'packages/nuxt/src/!(core)/**/*', + message: 'core should not directly import from modules.', + target: 'packages/nuxt/src/core', + }, + { + from: 'packages/nuxt/src/!(app)/**/*', + message: 'app should not directly import from modules.', + target: 'packages/nuxt/src/app', + }, + { + from: 'packages/nuxt/src/app/**/index.ts', + message: 'should not import from barrel/index files', + target: 'packages/nuxt/src', + }, + { + from: 'packages/nitro', + message: 'nitro should not directly import other packages.', + target: 'packages/!(nitro)/**/*', + }, + ], + }, + ], + 'import/order': [ + 'error', + { + pathGroups: [ + { + group: 'external', + pattern: '#vue-router', + }, + ], + }, + ], + 'jsdoc/check-tag-names': [ + 'error', + { + definedTags: [ + 'experimental', + '__NO_SIDE_EFFECTS__', + ], + }, + ], + }, + }, + { + files: ['packages/nuxt/src/app/**', 'test/**', '**/runtime/**', '**/*.test.ts'], + name: 'local/disables/client-console', + rules: { + 'no-console': 'off', + }, + }, + { + files: ['**/fixtures/**', '**/fixture/**'], + name: 'local/disables/fixtures', + rules: { + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/triple-slash-reference': 'off', + 'vue/multi-word-component-names': 'off', + 'vue/valid-v-for': 'off', + }, + }, + { + files: ['test/**', '**/*.test.ts'], + name: 'local/disables/tests', + plugins: { + 'no-only-tests': noOnlyTests, + }, + rules: { + '@typescript-eslint/no-explicit-any': 'off', + 'no-console': 'off', + 'no-only-tests/no-only-tests': 'error', + }, + }, + // Sort rule keys in eslint config + { + files: ['**/eslint.config.mjs'], + name: 'local/sort-eslint-config', + plugins: { + perfectionist, + }, + rules: { + 'perfectionist/sort-objects': 'error', + }, + }, + ) + + // Generate type definitions for the eslint config + .onResolved((configs) => { + return typegen(configs) + }) diff --git a/nuxt.config.ts b/nuxt.config.ts index cae1734649..694788ebb0 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -9,8 +9,8 @@ export default defineNuxtConfig({ function () { addPluginTemplate({ filename: 'plugins/my-plugin.mjs', - getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })' + getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })', }) - } - ] + }, + ], }) diff --git a/package.json b/package.json index 1c8d81fd52..9ed413920a 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ "cleanup": "rimraf 'packages/**/node_modules' 'playground/node_modules' 'node_modules'", "dev": "pnpm play", "dev:prepare": "pnpm --filter './packages/**' prepack --stub", - "lint": "eslint .", - "lint:fix": "eslint . --fix", + "lint": "eslint . --cache", + "lint:fix": "eslint . --cache --fix", "lint:docs": "markdownlint ./docs && case-police 'docs/**/*.md' *.md", "lint:docs:fix": "markdownlint ./docs --fix && case-police 'docs/**/*.md' *.md --fix", "lint:knip": "pnpx knip", @@ -44,13 +44,13 @@ "magic-string": "^0.30.9" }, "devDependencies": { - "@eslint/eslintrc": "3.0.2", "@eslint/js": "8.57.0", - "@nuxt/eslint-config": "0.2.0", + "@nuxt/eslint-config": "0.3.0", "@nuxt/kit": "workspace:*", "@nuxt/test-utils": "3.12.0", "@nuxt/webpack-builder": "workspace:*", "@testing-library/vue": "8.0.3", + "@types/eslint__js": "^8.42.3", "@types/fs-extra": "11.0.4", "@types/node": "20.12.4", "@types/semver": "7.5.8", @@ -61,11 +61,9 @@ "consola": "3.2.3", "devalue": "4.3.2", "eslint": "8.57.0", - "eslint-config-standard": "17.1.0", - "eslint-plugin-import": "2.29.1", - "eslint-plugin-jsdoc": "48.2.2", "eslint-plugin-no-only-tests": "3.1.0", - "eslint-plugin-unicorn": "52.0.0", + "eslint-plugin-perfectionist": "^2.8.0", + "eslint-typegen": "^0.2.0", "execa": "8.0.1", "fs-extra": "11.2.0", "globby": "14.0.1", diff --git a/packages/kit/build.config.ts b/packages/kit/build.config.ts index a2f84767f8..10db295927 100644 --- a/packages/kit/build.config.ts +++ b/packages/kit/build.config.ts @@ -3,14 +3,14 @@ import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ declaration: true, entries: [ - 'src/index' + 'src/index', ], externals: [ '@nuxt/schema', 'nitropack', 'webpack', 'vite', - 'h3' + 'h3', ], - failOnWarn: false + failOnWarn: false, }) diff --git a/packages/kit/src/build.ts b/packages/kit/src/build.ts index 92c066eb2d..0a186f63b7 100644 --- a/packages/kit/src/build.ts +++ b/packages/kit/src/build.ts @@ -42,7 +42,7 @@ export interface ExtendViteConfigOptions extends ExtendConfigOptions {} */ export function extendWebpackConfig ( fn: ((config: WebpackConfig) => void), - options: ExtendWebpackConfigOptions = {} + options: ExtendWebpackConfigOptions = {}, ) { const nuxt = useNuxt() @@ -74,7 +74,7 @@ export function extendWebpackConfig ( */ export function extendViteConfig ( fn: ((config: ViteConfig) => void), - options: ExtendViteConfigOptions = {} + options: ExtendViteConfigOptions = {}, ) { const nuxt = useNuxt() diff --git a/packages/kit/src/compatibility.ts b/packages/kit/src/compatibility.ts index d3d6e55875..77f33180c6 100644 --- a/packages/kit/src/compatibility.ts +++ b/packages/kit/src/compatibility.ts @@ -18,7 +18,7 @@ export async function checkNuxtCompatibility (constraints: NuxtCompatibility, nu if (!satisfies(normalizeSemanticVersion(nuxtVersion), constraints.nuxt, { includePrerelease: true })) { issues.push({ name: 'nuxt', - message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\`` + message: `Nuxt version \`${constraints.nuxt}\` is required but currently using \`${nuxtVersion}\``, }) } } @@ -30,12 +30,12 @@ export async function checkNuxtCompatibility (constraints: NuxtCompatibility, nu if (bridgeRequirement === true && !hasBridge) { issues.push({ name: 'bridge', - message: 'Nuxt bridge is required' + message: 'Nuxt bridge is required', }) } else if (bridgeRequirement === false && hasBridge) { issues.push({ name: 'bridge', - message: 'Nuxt bridge is not supported' + message: 'Nuxt bridge is not supported', }) } } diff --git a/packages/kit/src/components.ts b/packages/kit/src/components.ts index 410f2feae4..49bc6d91e2 100644 --- a/packages/kit/src/components.ts +++ b/packages/kit/src/components.ts @@ -49,7 +49,7 @@ export async function addComponent (opts: AddComponentOptions) { shortPath: opts.filePath, priority: 0, meta: {}, - ...opts + ...opts, } nuxt.hook('components:extend', (components: Component[]) => { diff --git a/packages/kit/src/ignore.test.ts b/packages/kit/src/ignore.test.ts index a37b65c82c..d19933a65e 100644 --- a/packages/kit/src/ignore.test.ts +++ b/packages/kit/src/ignore.test.ts @@ -5,7 +5,7 @@ describe('resolveGroupSyntax', () => { it('should resolve single group syntax', () => { expect(resolveGroupSyntax('**/*.{spec}.{js,ts}')).toStrictEqual([ '**/*.spec.js', - '**/*.spec.ts' + '**/*.spec.ts', ]) }) @@ -14,13 +14,13 @@ describe('resolveGroupSyntax', () => { '**/*.spec.js', '**/*.spec.ts', '**/*.test.js', - '**/*.test.ts' + '**/*.test.ts', ]) }) it('should do nothing with normal globs', () => { expect(resolveGroupSyntax('**/*.spec.js')).toStrictEqual([ - '**/*.spec.js' + '**/*.spec.js', ]) }) }) diff --git a/packages/kit/src/index.ts b/packages/kit/src/index.ts index 9f70bb4bfc..fb2350660f 100644 --- a/packages/kit/src/index.ts +++ b/packages/kit/src/index.ts @@ -30,7 +30,7 @@ export { requireModule, importModule, tryImportModule, - tryRequireModule + tryRequireModule, } from './internal/cjs' export type { ResolveModuleOptions, RequireModuleOptions } from './internal/cjs' export { tryResolveModule } from './internal/esm' diff --git a/packages/kit/src/internal/cjs.ts b/packages/kit/src/internal/cjs.ts index 0b9b2d1d2b..7e30acfec7 100644 --- a/packages/kit/src/internal/cjs.ts +++ b/packages/kit/src/internal/cjs.ts @@ -66,14 +66,14 @@ export function getModulePaths (paths?: string[] | string) { global.__NUXT_PREPATHS__, paths || [], process.cwd(), - global.__NUXT_PATHS__ + global.__NUXT_PATHS__, ).filter(Boolean) as string[] } /** @deprecated Do not use CJS utils */ export function resolveModule (id: string, opts: ResolveModuleOptions = {}) { return normalize(_require.resolve(id, { - paths: getModulePaths(opts.paths) + paths: getModulePaths(opts.paths), })) } diff --git a/packages/kit/src/internal/template.ts b/packages/kit/src/internal/template.ts index 1831e6a854..9349f704df 100644 --- a/packages/kit/src/internal/template.ts +++ b/packages/kit/src/internal/template.ts @@ -9,7 +9,7 @@ import { toArray } from '../utils' /** @deprecated */ // TODO: Remove support for compiling ejs templates in v4 -export async function compileTemplate (template: NuxtTemplate, ctx: any) { +export async function compileTemplate (template: NuxtTemplate, ctx: any) { const data = { ...ctx, options: template.options } if (template.src) { try { diff --git a/packages/kit/src/layout.ts b/packages/kit/src/layout.ts index 91e50310c4..bf86c443c9 100644 --- a/packages/kit/src/layout.ts +++ b/packages/kit/src/layout.ts @@ -16,7 +16,7 @@ export function addLayout (this: any, template: NuxtTemplate | string, name?: st const layout = (nuxt.options as any).layouts[layoutName] if (layout) { return logger.warn( - `Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.` + `Not overriding \`${layoutName}\` (provided by \`${layout}\`) with \`${src || filename}\`.`, ) } (nuxt.options as any).layouts[layoutName] = `./${filename}` @@ -31,12 +31,12 @@ export function addLayout (this: any, template: NuxtTemplate | string, name?: st if (layoutName in app.layouts) { const relativePath = relative(nuxt.options.srcDir, app.layouts[layoutName].file) return logger.warn( - `Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.` + `Not overriding \`${layoutName}\` (provided by \`~/${relativePath}\`) with \`${src || filename}\`.`, ) } app.layouts[layoutName] = { file: join('#build', filename), - name: layoutName + name: layoutName, } }) } diff --git a/packages/kit/src/loader/config.ts b/packages/kit/src/loader/config.ts index a4bce4f0c4..0b30d81ffc 100644 --- a/packages/kit/src/loader/config.ts +++ b/packages/kit/src/loader/config.ts @@ -17,7 +17,7 @@ export async function loadNuxtConfig (opts: LoadNuxtConfigOptions): Promise { throw new Error(`Cannot find any nuxt version from ${opts.cwd}`) } const pkg = await readPackageJSON(nearestNuxtPkg) - const majorVersion = pkg.version ? parseInt(pkg.version.split('.')[0]) : '' + const majorVersion = pkg.version ? Number.parseInt(pkg.version.split('.')[0]) : '' const rootDir = pathToFileURL(opts.cwd || process.cwd()).href @@ -51,7 +51,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { for: opts.dev ? 'dev' : 'build', configOverrides: opts.overrides, ready: opts.ready, - envConfig: opts.dotenv // TODO: Backward format conversion + envConfig: opts.dotenv, // TODO: Backward format conversion }) // Mock new hookable methods diff --git a/packages/kit/src/module/compatibility.test.ts b/packages/kit/src/module/compatibility.test.ts index ce20f54f02..d298f800b9 100644 --- a/packages/kit/src/module/compatibility.test.ts +++ b/packages/kit/src/module/compatibility.test.ts @@ -10,21 +10,21 @@ describe('nuxt module compatibility', () => { modules: [ defineNuxtModule({ meta: { - name: 'nuxt-module-foo' - } + name: 'nuxt-module-foo', + }, }), [ defineNuxtModule({ meta: { - name: 'module-instance-with-options' - } + name: 'module-instance-with-options', + }, }), { - foo: 'bar' - } - ] - ] - } + foo: 'bar', + }, + ], + ], + }, }) expect(hasNuxtModule('nuxt-module-foo', nuxt)).toStrictEqual(true) expect(hasNuxtModule('module-instance-with-options', nuxt)).toStrictEqual(true) @@ -35,8 +35,8 @@ describe('nuxt module compatibility', () => { const module = defineNuxtModule({ meta: { name: 'nuxt-module-foo', - version: '1.0.0' - } + version: '1.0.0', + }, }) expect(await getNuxtModuleVersion(module, nuxt)).toEqual('1.0.0') await nuxt.close() @@ -46,8 +46,8 @@ describe('nuxt module compatibility', () => { const module = defineNuxtModule({ meta: { name: 'nuxt-module-foo', - version: '1.0.0' - } + version: '1.0.0', + }, }) expect(await hasNuxtModuleCompatibility(module, '^1.0.0', nuxt)).toStrictEqual(true) expect(await hasNuxtModuleCompatibility(module, '^2.0.0', nuxt)).toStrictEqual(false) diff --git a/packages/kit/src/module/compatibility.ts b/packages/kit/src/module/compatibility.ts index 666f4b4085..446e7e3fce 100644 --- a/packages/kit/src/module/compatibility.ts +++ b/packages/kit/src/module/compatibility.ts @@ -20,7 +20,7 @@ function resolveNuxtModuleEntryName (m: NuxtOptions['modules'][number]): string * This will check both the installed modules and the modules to be installed. Note * that it cannot detect if a module is _going to be_ installed programmatically by another module. */ -export function hasNuxtModule (moduleName: string, nuxt: Nuxt = useNuxt()) : boolean { +export function hasNuxtModule (moduleName: string, nuxt: Nuxt = useNuxt()): boolean { // check installed modules return nuxt.options._installedModules.some(({ meta }) => meta.name === moduleName) || // check modules to be installed @@ -36,7 +36,7 @@ export async function hasNuxtModuleCompatibility (module: string | NuxtModule, s return false } return satisfies(normalizeSemanticVersion(version), semverVersion, { - includePrerelease: true + includePrerelease: true, }) } diff --git a/packages/kit/src/module/define.ts b/packages/kit/src/module/define.ts index 360d1a14db..3327ca4ad5 100644 --- a/packages/kit/src/module/define.ts +++ b/packages/kit/src/module/define.ts @@ -89,8 +89,8 @@ export function defineNuxtModule (definition: Mo // Return module install result return defu(res, { timings: { - setup: setupTime - } + setup: setupTime, + }, }) } @@ -138,10 +138,10 @@ function nuxt2Shims (nuxt: Nuxt) { plugins: nuxt.options.plugins, templates: [ ...templates.templatesFiles, - ...virtualTemplates + ...virtualTemplates, ], - templateVars: templates.templateVars - } + templateVars: templates.templateVars, + }, } for await (const template of virtualTemplates) { const contents = await compileTemplate({ ...template, src: '' }, context) diff --git a/packages/kit/src/module/install.ts b/packages/kit/src/module/install.ts index fc3d97bd66..b17cee47ca 100644 --- a/packages/kit/src/module/install.ts +++ b/packages/kit/src/module/install.ts @@ -46,7 +46,7 @@ export async function installModule (moduleToInstall: string | NuxtModule, inlin nuxt.options._installedModules.push({ meta: defu(await nuxtModule.getMeta?.(), buildTimeModuleMeta), timings: res.timings, - entryPath: typeof moduleToInstall === 'string' ? resolveAlias(moduleToInstall) : undefined + entryPath: typeof moduleToInstall === 'string' ? resolveAlias(moduleToInstall) : undefined, }) } diff --git a/packages/kit/src/nitro.ts b/packages/kit/src/nitro.ts index eddcb91f14..72b3ca93f3 100644 --- a/packages/kit/src/nitro.ts +++ b/packages/kit/src/nitro.ts @@ -14,7 +14,7 @@ function normalizeHandlerMethod (handler: NitroEventHandler) { return { method, ...handler, - handler: normalize(handler.handler) + handler: normalize(handler.handler), } } diff --git a/packages/kit/src/resolve.ts b/packages/kit/src/resolve.ts index a768ba6509..bbcbba0734 100644 --- a/packages/kit/src/resolve.ts +++ b/packages/kit/src/resolve.ts @@ -127,7 +127,7 @@ export function createResolver (base: string | URL): Resolver { return { resolve: (...path) => resolve(base as string, ...path), - resolvePath: (path, opts) => resolvePath(path, { cwd: base as string, ...opts }) + resolvePath: (path, opts) => resolvePath(path, { cwd: base as string, ...opts }), } } diff --git a/packages/kit/src/template.ts b/packages/kit/src/template.ts index a73e7e941b..4fe428ccb9 100644 --- a/packages/kit/src/template.ts +++ b/packages/kit/src/template.ts @@ -119,7 +119,7 @@ export async function _generateTypes (nuxt: Nuxt) { const modulePaths = await resolveNuxtModule(rootDirWithSlash, nuxt.options._installedModules .filter(m => m.entryPath) - .map(m => getDirectory(m.entryPath)) + .map(m => getDirectory(m.entryPath)), ) const tsConfig: TSConfig = defu(nuxt.options.typescript?.tsConfig, { @@ -142,7 +142,7 @@ export async function _generateTypes (nuxt: Nuxt) { noEmit: true, resolveJsonModule: true, allowSyntheticDefaultImports: true, - paths: {} + paths: {}, }, include: [ './nuxt.d.ts', @@ -153,19 +153,19 @@ export async function _generateTypes (nuxt: Nuxt) { .filter(srcOrCwd => !srcOrCwd.startsWith(rootDirWithSlash) || srcOrCwd.includes('node_modules')) .map(srcOrCwd => join(relative(nuxt.options.buildDir, srcOrCwd), '**/*')), ...nuxt.options.typescript.includeWorkspace && nuxt.options.workspaceDir !== nuxt.options.rootDir ? [join(relative(nuxt.options.buildDir, nuxt.options.workspaceDir), '**/*')] : [], - ...modulePaths.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime')) + ...modulePaths.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime')), ], exclude: [ ...nuxt.options.modulesDir.map(m => relativeWithDot(nuxt.options.buildDir, m)), ...modulePaths.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime/server')), // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186 - relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, 'dist')) - ] + relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, 'dist')), + ], } satisfies TSConfig) const aliases: Record = { ...nuxt.options.alias, - '#build': nuxt.options.buildDir + '#build': nuxt.options.buildDir, } // Exclude bridge alias types to support Volar @@ -215,7 +215,7 @@ export async function _generateTypes (nuxt: Nuxt) { const references: TSReference[] = await Promise.all([ ...nuxt.options.modules, - ...nuxt.options._modules + ...nuxt.options._modules, ] .filter(f => typeof f === 'string') .map(async id => ({ types: (await readPackageJSON(id, { url: nodeModulePaths }).catch(() => null))?.name || id }))) @@ -246,12 +246,12 @@ export async function _generateTypes (nuxt: Nuxt) { ...declarations, '', 'export {}', - '' + '', ].join('\n') return { declaration, - tsConfig + tsConfig, } } diff --git a/packages/kit/test/generate-types.spec.ts b/packages/kit/test/generate-types.spec.ts index cc48e78489..7ac10ba8d1 100644 --- a/packages/kit/test/generate-types.spec.ts +++ b/packages/kit/test/generate-types.spec.ts @@ -14,7 +14,7 @@ const mockNuxt = { srcDir: '/my-app', alias: { '~': '/my-app', - 'some-custom-alias': '/my-app/some-alias' + 'some-custom-alias': '/my-app/some-alias', }, typescript: { includeWorkspace: false }, buildDir: '/my-app/.nuxt', @@ -22,9 +22,9 @@ const mockNuxt = { modules: [], _layers: [{ config: { srcDir: '/my-app' } }], _installedModules: [], - _modules: [] + _modules: [], }, - callHook: () => {} + callHook: () => {}, } satisfies DeepPartial as unknown as Nuxt const mockNuxtWithOptions = (options: NuxtConfig) => defu({ options }, mockNuxt) as Nuxt @@ -49,7 +49,7 @@ describe('tsConfig generation', () => { it('should add exclude for module paths', async () => { const { tsConfig } = await _generateTypes(mockNuxtWithOptions({ - modulesDir: ['/my-app/modules/test/node_modules', '/my-app/modules/node_modules', '/my-app/node_modules/@some/module/node_modules'] + modulesDir: ['/my-app/modules/test/node_modules', '/my-app/modules/node_modules', '/my-app/node_modules/@some/module/node_modules'], })) expect(tsConfig.exclude).toMatchInlineSnapshot(` [ diff --git a/packages/kit/test/load-nuxt-config.bench.ts b/packages/kit/test/load-nuxt-config.bench.ts index bcee6a730b..ee8ff33eeb 100644 --- a/packages/kit/test/load-nuxt-config.bench.ts +++ b/packages/kit/test/load-nuxt-config.bench.ts @@ -9,7 +9,7 @@ const fixtures = { 'basic test fixture': 'test/fixtures/basic', 'basic test fixture (types)': 'test/fixtures/basic-types', 'minimal test fixture': 'test/fixtures/minimal', - 'minimal test fixture (types)': 'test/fixtures/minimal-types' + 'minimal test fixture (types)': 'test/fixtures/minimal-types', } describe('loadNuxtConfig', () => { diff --git a/packages/nuxt/build.config.ts b/packages/nuxt/build.config.ts index dfaf1d97a0..1f8a82cf20 100644 --- a/packages/nuxt/build.config.ts +++ b/packages/nuxt/build.config.ts @@ -13,23 +13,23 @@ export default defineBuildConfig({ 'core', 'head', 'components', - 'pages' - ].map(name => ({ input: `src/${name}/runtime/`, outDir: `dist/${name}/runtime`, format: 'esm', ext: 'js' } as BuildEntry)) + 'pages', + ].map(name => ({ input: `src/${name}/runtime/`, outDir: `dist/${name}/runtime`, format: 'esm', ext: 'js' } as BuildEntry)), ], hooks: { 'mkdist:entry:options' (_ctx, _entry, mkdistOptions) { mkdistOptions.addRelativeDeclarationExtensions = true - } + }, }, dependencies: [ 'nuxi', 'vue-router', - 'ofetch' + 'ofetch', ], externals: [ 'nuxt', 'nuxt/schema', '@vue/shared', - '@unhead/vue' - ] + '@unhead/vue', + ], }) diff --git a/packages/nuxt/config.cjs b/packages/nuxt/config.cjs index c21b9a6499..f4540f1290 100644 --- a/packages/nuxt/config.cjs +++ b/packages/nuxt/config.cjs @@ -1,8 +1,7 @@ -/* eslint-disable jsdoc/require-jsdoc */ function defineNuxtConfig (config) { return config } module.exports = { - defineNuxtConfig + defineNuxtConfig, } diff --git a/packages/nuxt/config.d.ts b/packages/nuxt/config.d.ts index e78965c0a3..a9272be362 100644 --- a/packages/nuxt/config.d.ts +++ b/packages/nuxt/config.d.ts @@ -1,5 +1,6 @@ import type { NuxtConfig } from 'nuxt/schema' import type { ConfigLayerMeta, DefineConfig } from 'c12' + export { NuxtConfig } from 'nuxt/schema' export interface DefineNuxtConfig extends DefineConfig {} diff --git a/packages/nuxt/src/app/compat/capi.ts b/packages/nuxt/src/app/compat/capi.ts index cd0736eeb7..2ef0b9f749 100644 --- a/packages/nuxt/src/app/compat/capi.ts +++ b/packages/nuxt/src/app/compat/capi.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line import/export export * from 'vue' export const install = () => {} diff --git a/packages/nuxt/src/app/compat/idle-callback.ts b/packages/nuxt/src/app/compat/idle-callback.ts index 01779dc1fe..12e01230e7 100644 --- a/packages/nuxt/src/app/compat/idle-callback.ts +++ b/packages/nuxt/src/app/compat/idle-callback.ts @@ -6,7 +6,7 @@ export const requestIdleCallback: Window['requestIdleCallback'] = import.meta.se const start = Date.now() const idleDeadline = { didTimeout: false, - timeRemaining: () => Math.max(0, 50 - (Date.now() - start)) + timeRemaining: () => Math.max(0, 50 - (Date.now() - start)), } return setTimeout(() => { cb(idleDeadline) }, 1) })) diff --git a/packages/nuxt/src/app/compat/interval.ts b/packages/nuxt/src/app/compat/interval.ts index 4251c9f9a2..36017305c1 100644 --- a/packages/nuxt/src/app/compat/interval.ts +++ b/packages/nuxt/src/app/compat/interval.ts @@ -8,7 +8,7 @@ export const setInterval = import.meta.client if (import.meta.dev) { throw createError({ statusCode: 500, - message: intervalError + message: intervalError, }) } diff --git a/packages/nuxt/src/app/components/client-fallback.client.ts b/packages/nuxt/src/app/components/client-fallback.client.ts index d1f249ba3f..f92dfb7a31 100644 --- a/packages/nuxt/src/app/components/client-fallback.client.ts +++ b/packages/nuxt/src/app/components/client-fallback.client.ts @@ -6,26 +6,26 @@ export default defineComponent({ inheritAttrs: false, props: { uid: { - type: String + type: String, }, fallbackTag: { type: String, - default: () => 'div' + default: () => 'div', }, fallback: { type: String, - default: () => '' + default: () => '', }, placeholder: { - type: String + type: String, }, placeholderTag: { - type: String + type: String, }, keepFallback: { type: Boolean, - default: () => false - } + default: () => false, + }, }, emits: ['ssr-error'], setup (props, ctx) { @@ -49,5 +49,5 @@ export default defineComponent({ } return ctx.slots.default?.() } - } + }, }) diff --git a/packages/nuxt/src/app/components/client-fallback.server.ts b/packages/nuxt/src/app/components/client-fallback.server.ts index 3b07745b38..4e8dfe864c 100644 --- a/packages/nuxt/src/app/components/client-fallback.server.ts +++ b/packages/nuxt/src/app/components/client-fallback.server.ts @@ -1,6 +1,6 @@ import { defineComponent, getCurrentInstance, onErrorCaptured, ref } from 'vue' import { ssrRenderAttrs, ssrRenderSlot, ssrRenderVNode } from 'vue/server-renderer' -// eslint-disable-next-line + import { isPromise } from '@vue/shared' import { useState } from '../composables/state' import { useNuxtApp } from '../nuxt' @@ -11,31 +11,31 @@ const NuxtClientFallbackServer = defineComponent({ inheritAttrs: false, props: { uid: { - type: String + type: String, }, fallbackTag: { type: String, - default: () => 'div' + default: () => 'div', }, fallback: { type: String, - default: () => '' + default: () => '', }, placeholder: { - type: String + type: String, }, placeholderTag: { - type: String + type: String, }, keepFallback: { type: Boolean, - default: () => false - } + default: () => false, + }, }, emits: { 'ssr-error' (_error: unknown) { return true - } + }, }, async setup (props, ctx) { const vm = getCurrentInstance() @@ -86,7 +86,7 @@ const NuxtClientFallbackServer = defineComponent({ push(ctx.ssrVNodes.getBuffer()) push('') } - } + }, }) export default NuxtClientFallbackServer diff --git a/packages/nuxt/src/app/components/client-only.ts b/packages/nuxt/src/app/components/client-only.ts index ec002d460d..5483dbe0c6 100644 --- a/packages/nuxt/src/app/components/client-only.ts +++ b/packages/nuxt/src/app/components/client-only.ts @@ -8,7 +8,7 @@ export const clientOnlySymbol: InjectionKey = Symbol.for('nuxt:client-o export default defineComponent({ name: 'ClientOnly', inheritAttrs: false, - // eslint-disable-next-line vue/require-prop-types + props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'], setup (_, { slots, attrs }) { const mounted = ref(false) @@ -28,7 +28,7 @@ export default defineComponent({ const fallbackTag = props.fallbackTag || props.placeholderTag || 'span' return createElementBlock(fallbackTag, attrs, fallbackStr) } - } + }, }) const cache = new WeakMap() diff --git a/packages/nuxt/src/app/components/dev-only.ts b/packages/nuxt/src/app/components/dev-only.ts index 6c8ec7c5e9..a1446dd3dd 100644 --- a/packages/nuxt/src/app/components/dev-only.ts +++ b/packages/nuxt/src/app/components/dev-only.ts @@ -7,5 +7,5 @@ export default defineComponent({ return () => props.slots.default?.() } return () => props.slots.fallback?.() - } + }, }) diff --git a/packages/nuxt/src/app/components/island-renderer.ts b/packages/nuxt/src/app/components/island-renderer.ts index 6fc2fd479d..59e767f867 100644 --- a/packages/nuxt/src/app/components/island-renderer.ts +++ b/packages/nuxt/src/app/components/island-renderer.ts @@ -10,8 +10,8 @@ export default defineComponent({ props: { context: { type: Object as () => { name: string, props?: Record }, - required: true - } + required: true, + }, }, setup (props) { const component = islandComponents[props.context.name] as ReturnType @@ -19,7 +19,7 @@ export default defineComponent({ if (!component) { throw createError({ statusCode: 404, - statusMessage: `Island component not found: ${props.context.name}` + statusMessage: `Island component not found: ${props.context.name}`, }) } @@ -28,5 +28,5 @@ export default defineComponent({ }) return () => createVNode(component || 'span', { ...props.context.props, 'data-island-uid': '' }) - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-error-boundary.ts b/packages/nuxt/src/app/components/nuxt-error-boundary.ts index 77659e2c29..ea54ff8393 100644 --- a/packages/nuxt/src/app/components/nuxt-error-boundary.ts +++ b/packages/nuxt/src/app/components/nuxt-error-boundary.ts @@ -5,7 +5,7 @@ export default defineComponent({ emits: { error (_error: unknown) { return true - } + }, }, setup (_props, { slots, emit }) { const error = ref(null) @@ -25,5 +25,5 @@ export default defineComponent({ } return () => error.value ? slots.error?.({ error, clearError }) : slots.default?.() - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-error-page.vue b/packages/nuxt/src/app/components/nuxt-error-page.vue index 50308e6604..1d000df300 100644 --- a/packages/nuxt/src/app/components/nuxt-error-page.vue +++ b/packages/nuxt/src/app/components/nuxt-error-page.vue @@ -6,7 +6,7 @@ import { defineAsyncComponent } from 'vue' const props = defineProps({ - error: Object + error: Object, }) // Deliberately prevent reactive update when error is cleared @@ -26,7 +26,7 @@ const stacktrace = _error.stack text, internal: (line.includes('node_modules') && !line.includes('.cache')) || line.includes('internal') || - line.includes('new Promise') + line.includes('new Promise'), } }).map(i => `${i.text}`).join('\n') : '' diff --git a/packages/nuxt/src/app/components/nuxt-island.ts b/packages/nuxt/src/app/components/nuxt-island.ts index efed027d50..503d3e34a8 100644 --- a/packages/nuxt/src/app/components/nuxt-island.ts +++ b/packages/nuxt/src/app/components/nuxt-island.ts @@ -48,25 +48,25 @@ export default defineComponent({ props: { name: { type: String, - required: true + required: true, }, lazy: Boolean, props: { type: Object, - default: () => undefined + default: () => undefined, }, context: { type: Object, - default: () => ({}) + default: () => ({}), }, source: { type: String, - default: () => undefined + default: () => undefined, }, dangerouslyLoadClientComponents: { type: Boolean, - default: false - } + default: false, + }, }, emits: ['error'], async setup (props, { slots, expose, emit }) { @@ -99,9 +99,9 @@ export default defineComponent({ ...(import.meta.server && import.meta.prerender) ? {} : { params: { ...props.context, props: props.props ? JSON.stringify(props.props) : undefined } }, - result: toRevive + result: toRevive, }, - ...result + ...result, } } @@ -168,7 +168,7 @@ export default defineComponent({ // $fetch handles the app.baseURL in dev const r = await eventFetch(withQuery(((import.meta.dev && import.meta.client) || props.source) ? url : joinURL(config.app.baseURL ?? '', url), { ...props.context, - props: props.props ? JSON.stringify(props.props) : undefined + props: props.props ? JSON.stringify(props.props) : undefined, })) const result = import.meta.server || !import.meta.dev ? await r.json() : (r as FetchResponse)._data // TODO: support passing on more headers @@ -219,7 +219,7 @@ export default defineComponent({ } expose({ - refresh: () => fetchComponent(true) + refresh: () => fetchComponent(true), }) if (import.meta.hot) { @@ -261,7 +261,7 @@ export default defineComponent({ teleports.push(createVNode(Teleport, // use different selectors for even and odd teleportKey to force trigger the teleport { to: import.meta.client ? `${isKeyOdd ? 'div' : ''}[data-island-uid="${uid.value}"][data-island-slot="${slot}"]` : `uid=${uid.value};slot=${slot}` }, - { default: () => (payloads.slots?.[slot].props?.length ? payloads.slots[slot].props : [{}]).map((data: any) => slots[slot]?.(data)) }) + { default: () => (payloads.slots?.[slot].props?.length ? payloads.slots[slot].props : [{}]).map((data: any) => slots[slot]?.(data)) }), ) } } @@ -275,7 +275,7 @@ export default defineComponent({ replaced = replaced.replaceAll(`data-island-slot="${slot}">`, full => full + slots[slot]) } teleports.push(createVNode(Teleport, { to: `uid=${uid.value};client=${id}` }, { - default: () => [createStaticVNode(replaced, 1)] + default: () => [createStaticVNode(replaced, 1)], })) } } @@ -286,9 +286,9 @@ export default defineComponent({ // use different selectors for even and odd teleportKey to force trigger the teleport const vnode = createVNode(Teleport, { to: `${isKeyOdd ? 'div' : ''}[data-island-uid='${uid.value}'][data-island-component="${id}"]` }, { default: () => { - return [h(component, props, Object.fromEntries(Object.entries(slots || {}).map(([k, v]) => ([k, () => createStaticVNode(`
${v}
`, 1) + return [h(component, props, Object.fromEntries(Object.entries(slots || {}).map(([k, v]) => ([k, () => createStaticVNode(`
${v}
`, 1), ]))))] - } + }, }) teleports.push(vnode) } @@ -297,8 +297,8 @@ export default defineComponent({ } return h(Fragment, teleports) - }, _cache, 1) + }, _cache, 1), ] } - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-layout.ts b/packages/nuxt/src/app/components/nuxt-layout.ts index 7509f2f9ff..e7af6597fc 100644 --- a/packages/nuxt/src/app/components/nuxt-layout.ts +++ b/packages/nuxt/src/app/components/nuxt-layout.ts @@ -2,7 +2,6 @@ import type { DefineComponent, MaybeRef, VNode } from 'vue' import { Suspense, Transition, computed, defineComponent, h, inject, mergeProps, nextTick, onMounted, provide, ref, unref } from 'vue' import type { RouteLocationNormalizedLoaded } from 'vue-router' -// eslint-disable-next-line import/no-restricted-paths import type { PageMeta } from '../../pages/runtime/composables' import { useRoute, useRouter } from '../composables/router' @@ -23,7 +22,7 @@ const LayoutLoader = defineComponent({ inheritAttrs: false, props: { name: String, - layoutProps: Object + layoutProps: Object, }, async setup (props, context) { // This is a deliberate hack - this component must always be called with an explicit key to ensure @@ -32,7 +31,7 @@ const LayoutLoader = defineComponent({ const LayoutComponent = await layouts[props.name]().then((r: any) => r.default || r) return () => h(LayoutComponent, props.layoutProps, context.slots) - } + }, }) export default defineComponent({ @@ -41,12 +40,12 @@ export default defineComponent({ props: { name: { type: [String, Boolean, Object] as unknown as () => unknown extends PageMeta['layout'] ? MaybeRef : PageMeta['layout'], - default: null + default: null, }, fallback: { type: [String, Object] as unknown as () => unknown extends PageMeta['layout'] ? MaybeRef : PageMeta['layout'], - default: null - } + default: null, + }, }, setup (props, context) { const nuxtApp = useNuxtApp() @@ -94,12 +93,12 @@ export default defineComponent({ key: layout.value || undefined, name: layout.value, shouldProvide: !props.name, - hasTransition: !!transitionProps - }, context.slots) - }) + hasTransition: !!transitionProps, + }, context.slots), + }), }).default() } - } + }, }) as unknown as DefineComponent<{ name?: (unknown extends PageMeta['layout'] ? MaybeRef : PageMeta['layout']) | undefined }> @@ -109,17 +108,17 @@ const LayoutProvider = defineComponent({ inheritAttrs: false, props: { name: { - type: [String, Boolean] as unknown as () => string | false + type: [String, Boolean] as unknown as () => string | false, }, layoutProps: { - type: Object + type: Object, }, hasTransition: { - type: Boolean + type: Boolean, }, shouldProvide: { - type: Boolean - } + type: Boolean, + }, }, setup (props, context) { // Prevent reactivity when the page will be rerendered in a different suspense fork @@ -127,7 +126,7 @@ const LayoutProvider = defineComponent({ const name = props.name if (props.shouldProvide) { provide(LayoutMetaSymbol, { - isCurrent: (route: RouteLocationNormalizedLoaded) => name === (route.meta.layout ?? 'default') + isCurrent: (route: RouteLocationNormalizedLoaded) => name === (route.meta.layout ?? 'default'), }) } @@ -159,7 +158,7 @@ const LayoutProvider = defineComponent({ vnode = h( LayoutLoader, { key: name, layoutProps: props.layoutProps, name }, - context.slots + context.slots, ) return vnode @@ -168,8 +167,8 @@ const LayoutProvider = defineComponent({ return h( LayoutLoader, { key: name, layoutProps: props.layoutProps, name }, - context.slots + context.slots, ) } - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-link.ts b/packages/nuxt/src/app/components/nuxt-link.ts index 659001884b..62446eb563 100644 --- a/packages/nuxt/src/app/components/nuxt-link.ts +++ b/packages/nuxt/src/app/components/nuxt-link.ts @@ -4,7 +4,7 @@ import type { ComputedRef, DefineComponent, InjectionKey, PropType, - VNodeProps + VNodeProps, } from 'vue' import { computed, defineComponent, h, inject, onBeforeUnmount, onMounted, provide, ref, resolveComponent } from 'vue' import type { RouteLocation, RouteLocationRaw, Router, RouterLinkProps } from '#vue-router' @@ -114,7 +114,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { const resolvedPath = { ...to, name: undefined, // named routes would otherwise always override trailing slash behavior - path: applyTrailingSlashBehavior(path, options.trailingSlash) + path: applyTrailingSlashBehavior(path, options.trailingSlash), } return resolvedPath @@ -127,85 +127,85 @@ export function defineNuxtLink (options: NuxtLinkOptions) { to: { type: [String, Object] as PropType, default: undefined, - required: false + required: false, }, href: { type: [String, Object] as PropType, default: undefined, - required: false + required: false, }, // Attributes target: { type: String as PropType, default: undefined, - required: false + required: false, }, rel: { type: String as PropType, default: undefined, - required: false + required: false, }, noRel: { type: Boolean as PropType, default: undefined, - required: false + required: false, }, // Prefetching prefetch: { type: Boolean as PropType, default: undefined, - required: false + required: false, }, noPrefetch: { type: Boolean as PropType, default: undefined, - required: false + required: false, }, // Styling activeClass: { type: String as PropType, default: undefined, - required: false + required: false, }, exactActiveClass: { type: String as PropType, default: undefined, - required: false + required: false, }, prefetchedClass: { type: String as PropType, default: undefined, - required: false + required: false, }, // Vue Router's `` additional props replace: { type: Boolean as PropType, default: undefined, - required: false + required: false, }, ariaCurrentValue: { type: String as PropType, default: undefined, - required: false + required: false, }, // Edge cases handling external: { type: Boolean as PropType, default: undefined, - required: false + required: false, }, // Slot API custom: { type: Boolean as PropType, default: undefined, - required: false - } + required: false, + }, }, setup (props, { slots }) { const router = useRouter() @@ -269,7 +269,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { const path = typeof to.value === 'string' ? to.value : router.resolve(to.value).fullPath await Promise.all([ nuxtApp.hooks.callHook('link:prefetch', path).catch(() => {}), - !isExternal.value && preloadRouteComponents(to.value as string, router).catch(() => {}) + !isExternal.value && preloadRouteComponents(to.value as string, router).catch(() => {}), ]) prefetched.value = true }) @@ -303,7 +303,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { exactActiveClass: props.exactActiveClass || options.exactActiveClass, replace: props.replace, ariaCurrentValue: props.ariaCurrentValue, - custom: props.custom + custom: props.custom, } // `custom` API cannot support fallthrough attributes as the slot @@ -319,7 +319,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { return h( resolveComponent('RouterLink'), routerLinkProps, - slots.default + slots.default, ) } @@ -344,7 +344,7 @@ export function defineNuxtLink (options: NuxtLinkOptions) { * A fallback rel of `noopener noreferrer` is applied for external links or links that open in a new tab. * This solves a reverse tabnapping security flaw in browsers pre-2021 as well as improving privacy. */ - (isAbsoluteUrl.value || hasTarget.value) ? 'noopener noreferrer' : '' + (isAbsoluteUrl.value || hasTarget.value) ? 'noopener noreferrer' : '', ) || null // https://router.vuejs.org/api/#custom @@ -372,20 +372,20 @@ export function defineNuxtLink (options: NuxtLinkOptions) { matched: [], redirectedFrom: undefined, meta: {}, - href + href, } satisfies RouteLocation & { href: string } }, rel, target, isExternal: isExternal.value, isActive: false, - isExactActive: false + isExactActive: false, }) } return h('a', { ref: el, href, rel, target }, slots.default?.()) } - } + }, }) as unknown as DefineComponent } @@ -441,7 +441,7 @@ function useObserver (): { observe: ObserveFn } | undefined { } const _observer = nuxtApp._observer = { - observe + observe, } return _observer diff --git a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts index 2ccc49767c..2b51dd6584 100644 --- a/packages/nuxt/src/app/components/nuxt-loading-indicator.ts +++ b/packages/nuxt/src/app/components/nuxt-loading-indicator.ts @@ -6,34 +6,34 @@ export default defineComponent({ props: { throttle: { type: Number, - default: 200 + default: 200, }, duration: { type: Number, - default: 2000 + default: 2000, }, height: { type: Number, - default: 3 + default: 3, }, color: { type: [String, Boolean], - default: 'repeating-linear-gradient(to right,#00dc82 0%,#34cdfe 50%,#0047e1 100%)' + default: 'repeating-linear-gradient(to right,#00dc82 0%,#34cdfe 50%,#0047e1 100%)', }, estimatedProgress: { type: Function as unknown as () => (duration: number, elapsed: number) => number, - required: false - } + required: false, + }, }, setup (props, { slots, expose }) { const { progress, isLoading, start, finish, clear } = useLoadingIndicator({ duration: props.duration, throttle: props.throttle, - estimatedProgress: props.estimatedProgress + estimatedProgress: props.estimatedProgress, }) expose({ - progress, isLoading, start, finish, clear + progress, isLoading, start, finish, clear, }) return () => h('div', { @@ -52,8 +52,8 @@ export default defineComponent({ transform: `scaleX(${progress.value}%)`, transformOrigin: 'left', transition: 'transform 0.1s, height 0.4s, opacity 0.4s', - zIndex: 999999 - } + zIndex: 999999, + }, }, slots) - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-stubs.ts b/packages/nuxt/src/app/components/nuxt-stubs.ts index c2adc56412..5a3d20c10d 100644 --- a/packages/nuxt/src/app/components/nuxt-stubs.ts +++ b/packages/nuxt/src/app/components/nuxt-stubs.ts @@ -4,14 +4,14 @@ function renderStubMessage (name: string) { throw createError({ fatal: true, statusCode: 500, - statusMessage: `${name} is provided by @nuxt/image. Check your console to install it or run 'npx nuxi@latest module add @nuxt/image'` + statusMessage: `${name} is provided by @nuxt/image. Check your console to install it or run 'npx nuxi@latest module add @nuxt/image'`, }) } export const NuxtImg = { - setup: () => renderStubMessage('') + setup: () => renderStubMessage(''), } export const NuxtPicture = { - setup: () => renderStubMessage('') + setup: () => renderStubMessage(''), } diff --git a/packages/nuxt/src/app/components/nuxt-teleport-island-component.ts b/packages/nuxt/src/app/components/nuxt-teleport-island-component.ts index 75adbdfaf4..002a2441a0 100644 --- a/packages/nuxt/src/app/components/nuxt-teleport-island-component.ts +++ b/packages/nuxt/src/app/components/nuxt-teleport-island-component.ts @@ -5,7 +5,7 @@ import { useNuxtApp } from '../nuxt' import { paths } from '#build/components-chunk' type ExtendedComponent = Component & { - __file: string, + __file: string __name: string } @@ -21,11 +21,11 @@ export default defineComponent({ props: { to: { type: String, - required: true + required: true, }, nuxtClient: { type: Boolean, - default: false + default: false, }, /** * ONLY used in dev mode since we use build:manifest result in production @@ -33,8 +33,8 @@ export default defineComponent({ */ rootDir: { type: String, - default: null - } + default: null, + }, }, setup (props, { slots }) { const nuxtApp = useNuxtApp() @@ -47,19 +47,19 @@ export default defineComponent({ return () => { const slot = slots.default!()[0] - const slotType = (slot.type as ExtendedComponent) + const slotType = slot.type as ExtendedComponent const name = (slotType.__name || slotType.name) as string islandContext.components[props.to] = { chunk: import.meta.dev ? '_nuxt/' + paths[name] : paths[name], - props: slot.props || {} + props: slot.props || {}, } return [h('div', { - style: 'display: contents;', + 'style': 'display: contents;', 'data-island-uid': '', - 'data-island-component': props.to + 'data-island-component': props.to, }, []), h(Teleport, { to: props.to }, slot)] } - } + }, }) diff --git a/packages/nuxt/src/app/components/nuxt-teleport-island-slot.ts b/packages/nuxt/src/app/components/nuxt-teleport-island-slot.ts index fd3d52002a..9f9fefc8b1 100644 --- a/packages/nuxt/src/app/components/nuxt-teleport-island-slot.ts +++ b/packages/nuxt/src/app/components/nuxt-teleport-island-slot.ts @@ -12,14 +12,14 @@ export default defineComponent({ props: { name: { type: String, - required: true + required: true, }, /** * must be an array to handle v-for */ props: { - type: Object as () => Array - } + type: Object as () => Array, + }, }, setup (props, { slots }) { const nuxtApp = useNuxtApp() @@ -30,7 +30,7 @@ export default defineComponent({ const componentName = inject(NuxtTeleportIslandSymbol, false) islandContext.slots[props.name] = { - props: (props.props || []) as unknown[] + props: (props.props || []) as unknown[], } return () => { @@ -38,18 +38,18 @@ export default defineComponent({ if (nuxtApp.ssrContext?.islandContext && slots.default) { vnodes.push(h('div', { - style: 'display: contents;', + 'style': 'display: contents;', 'data-island-uid': '', - 'data-island-slot': props.name + 'data-island-slot': props.name, }, { // Teleport in slot to not be hydrated client-side with the staticVNode - default: () => [createVNode(Teleport, { to: `island-slot=${componentName};${props.name}` }, slots.default?.())] + default: () => [createVNode(Teleport, { to: `island-slot=${componentName};${props.name}` }, slots.default?.())], })) } else { vnodes.push(h('div', { - style: 'display: contents;', + 'style': 'display: contents;', 'data-island-uid': '', - 'data-island-slot': props.name + 'data-island-slot': props.name, })) } @@ -59,5 +59,5 @@ export default defineComponent({ return vnodes } - } + }, }) diff --git a/packages/nuxt/src/app/components/route-provider.ts b/packages/nuxt/src/app/components/route-provider.ts index 6f57fb82f6..de4ae64a47 100644 --- a/packages/nuxt/src/app/components/route-provider.ts +++ b/packages/nuxt/src/app/components/route-provider.ts @@ -7,15 +7,15 @@ export const RouteProvider = defineComponent({ props: { vnode: { type: Object as () => VNode, - required: true + required: true, }, route: { type: Object as () => RouteLocationNormalizedLoaded, - required: true + required: true, }, vnodeRef: Object as () => Ref, renderKey: String, - trackRootNodes: Boolean + trackRootNodes: Boolean, }, setup (props) { // Prevent reactivity when the page will be rerendered in a different suspense fork @@ -26,7 +26,7 @@ export const RouteProvider = defineComponent({ const route = {} as RouteLocation for (const key in props.route) { Object.defineProperty(route, key, { - get: () => previousKey === props.renderKey ? props.route[key as keyof RouteLocationNormalizedLoaded] : previousRoute[key as keyof RouteLocationNormalizedLoaded] + get: () => previousKey === props.renderKey ? props.route[key as keyof RouteLocationNormalizedLoaded] : previousRoute[key as keyof RouteLocationNormalizedLoaded], }) } @@ -52,5 +52,5 @@ export const RouteProvider = defineComponent({ return h(props.vnode, { ref: props.vnodeRef }) } - } + }, }) diff --git a/packages/nuxt/src/app/components/server-placeholder.ts b/packages/nuxt/src/app/components/server-placeholder.ts index eaa38e3282..accbfb9857 100644 --- a/packages/nuxt/src/app/components/server-placeholder.ts +++ b/packages/nuxt/src/app/components/server-placeholder.ts @@ -4,5 +4,5 @@ export default defineComponent({ name: 'ServerPlaceholder', render () { return createElementBlock('div') - } + }, }) diff --git a/packages/nuxt/src/app/components/test-component-wrapper.ts b/packages/nuxt/src/app/components/test-component-wrapper.ts index fd185150cc..31520ae0b9 100644 --- a/packages/nuxt/src/app/components/test-component-wrapper.ts +++ b/packages/nuxt/src/app/components/test-component-wrapper.ts @@ -20,8 +20,8 @@ export default (url: string) => defineComponent({ return () => [ h('div', 'Component Test Wrapper for ' + query.path), h('div', { id: 'nuxt-component-root' }, [ - h(comp, { ...attrs, ...props, ...urlProps }) - ]) + h(comp, { ...attrs, ...props, ...urlProps }), + ]), ] - } + }, }) diff --git a/packages/nuxt/src/app/components/utils.ts b/packages/nuxt/src/app/components/utils.ts index 1411c2c329..a5e918a89d 100644 --- a/packages/nuxt/src/app/components/utils.ts +++ b/packages/nuxt/src/app/components/utils.ts @@ -36,7 +36,7 @@ export function isChangingPage (to: RouteLocationNormalized, from: RouteLocation if (generateRouteKey(to) !== generateRouteKey(from)) { return true } const areComponentsSame = to.matched.every((comp, index) => - comp.components && comp.components.default === from.matched[index]?.components?.default + comp.components && comp.components.default === from.matched[index]?.components?.default, ) if (areComponentsSame) { return false @@ -44,7 +44,6 @@ export function isChangingPage (to: RouteLocationNormalized, from: RouteLocation return true } -// eslint-disable-next-line no-use-before-define export type SSRBuffer = SSRBufferItem[] & { hasAsync?: boolean } export type SSRBufferItem = string | SSRBuffer | Promise @@ -71,7 +70,7 @@ export function createBuffer () { if (isPromise(item) || (isArray(item) && item.hasAsync)) { buffer.hasAsync = true } - } + }, } } @@ -95,7 +94,7 @@ export function vforToArray (source: any): any[] { } else if (isObject(source)) { if (source[Symbol.iterator as any]) { return Array.from(source as Iterable, item => - item + item, ) } else { const keys = Object.keys(source) diff --git a/packages/nuxt/src/app/composables/asyncData.ts b/packages/nuxt/src/app/composables/asyncData.ts index 3fdb7a0bfa..d9fd2ae1d5 100644 --- a/packages/nuxt/src/app/composables/asyncData.ts +++ b/packages/nuxt/src/app/composables/asyncData.ts @@ -17,19 +17,19 @@ export type _Transform = (input: Input) => Output | P export type PickFrom> = T extends Array ? T : T extends Record - ? keyof T extends K[number] - ? T // Exact same keys as the target, skip Pick - : K[number] extends never - ? T - : Pick - : T + ? keyof T extends K[number] + ? T // Exact same keys as the target, skip Pick + : K[number] extends never + ? T + : Pick + : T export type KeysOf = Array< T extends T // Include all keys of union types, not just common keys - ? keyof T extends string - ? keyof T - : never - : never + ? keyof T extends string + ? keyof T + : never + : never > export type KeyOfRes = KeysOf> @@ -223,8 +223,8 @@ export function useAsyncData< const promise = nuxtApp.runWithContext(_handler) - nuxtApp.ssrContext!._sharedPrerenderCache!.set(key, promise) - return promise + nuxtApp.ssrContext!._sharedPrerenderCache!.set(key, promise) + return promise } // Used to get default values @@ -257,7 +257,7 @@ export function useAsyncData< data: _ref(options.getCachedData!(key, nuxtApp) ?? options.default!()), pending: ref(!hasCachedData()), error: toRef(nuxtApp.payload._errors, key), - status: ref('idle') + status: ref('idle'), } } @@ -477,8 +477,8 @@ export function useNuxtData (key: string): { data: Ref { promises.length = 0 }) - } + }, } as DefineComponent } diff --git a/packages/nuxt/src/app/composables/cookie.ts b/packages/nuxt/src/app/composables/cookie.ts index 15f7ee0110..7f5b6cd267 100644 --- a/packages/nuxt/src/app/composables/cookie.ts +++ b/packages/nuxt/src/app/composables/cookie.ts @@ -29,7 +29,7 @@ const CookieDefaults = { path: '/', watch: true, decode: val => destr(decodeURIComponent(val)), - encode: val => encodeURIComponent(typeof val === 'string' ? val : JSON.stringify(val)) + encode: val => encodeURIComponent(typeof val === 'string' ? val : JSON.stringify(val)), } satisfies CookieOptions const store = import.meta.client && cookieStore ? window.cookieStore : undefined @@ -220,7 +220,7 @@ function cookieRef (value: T | undefined, delay: number, shouldWatch: boolean internalRef.value = newValue trigger() - } + }, } }) } diff --git a/packages/nuxt/src/app/composables/error.ts b/packages/nuxt/src/app/composables/error.ts index dc4dd8e6a2..2a76c389a0 100644 --- a/packages/nuxt/src/app/composables/error.ts +++ b/packages/nuxt/src/app/composables/error.ts @@ -14,9 +14,9 @@ export interface NuxtError extends H3Error {} /** @since 3.0.0 */ export const showError = ( error: string | Error | (Partial> & { - status?: number; - statusText?: string; - }) + status?: number + statusText?: string + }), ) => { const nuxtError = createError(error) @@ -52,22 +52,22 @@ export const clearError = async (options: { redirect?: string } = {}) => { /** @since 3.0.0 */ export const isNuxtError = ( - error?: string | object + error?: string | object, ): error is NuxtError => !!error && typeof error === 'object' && NUXT_ERROR_SIGNATURE in error /** @since 3.0.0 */ export const createError = ( error: string | Error | (Partial> & { - status?: number; - statusText?: string; - }) + status?: number + statusText?: string + }), ) => { const nuxtError: NuxtError = createH3Error(error) Object.defineProperty(nuxtError, NUXT_ERROR_SIGNATURE, { value: true, configurable: false, - writable: false + writable: false, }) return nuxtError diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index 4403415c2f..d7b50ab717 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -21,7 +21,7 @@ type ComputedOptions> = { } interface NitroFetchOptions = AvailableRouterMethod> extends FetchOptions { - method?: M; + method?: M } type ComputedFetchOptions> = ComputedOptions> @@ -32,7 +32,7 @@ export interface UseFetchOptions< PickKeys extends KeysOf = KeysOf, DefaultT = null, R extends NitroFetchRequest = string & {}, - M extends AvailableRouterMethod = AvailableRouterMethod + M extends AvailableRouterMethod = AvailableRouterMethod, > extends Omit, 'watch'>, ComputedFetchOptions { key?: string $fetch?: typeof globalThis.$fetch @@ -90,7 +90,7 @@ export function useFetch< > ( request: Ref | ReqT | (() => ReqT), arg1?: string | UseFetchOptions<_ResT, DataT, PickKeys, DefaultT, ReqT, Method>, - arg2?: string + arg2?: string, ) { const [opts = {}, autoKey] = typeof arg1 === 'string' ? [{}, arg1] : [arg1, arg2] @@ -127,7 +127,7 @@ export function useFetch< const _fetchOptions = reactive({ ...fetchDefaults, ...fetchOptions, - cache: typeof opts.cache === 'boolean' ? undefined : opts.cache + cache: typeof opts.cache === 'boolean' ? undefined : opts.cache, }) const _asyncDataOptions: AsyncDataOptions<_ResT, DataT, PickKeys, DefaultT> = { @@ -140,7 +140,7 @@ export function useFetch< getCachedData, deep, dedupe, - watch: watch === false ? [] : [_fetchOptions, _request, ...(watch || [])] + watch: watch === false ? [] : [_fetchOptions, _request, ...(watch || [])], } if (import.meta.dev && import.meta.client) { @@ -220,7 +220,7 @@ export function useLazyFetch< > ( request: Ref | ReqT | (() => ReqT), arg1?: string | Omit, 'lazy'>, - arg2?: string + arg2?: string, ) { const [opts = {}, autoKey] = typeof arg1 === 'string' ? [{}, arg1] : [arg1, arg2] @@ -231,16 +231,16 @@ export function useLazyFetch< return useFetch(request, { ...opts, - lazy: true + lazy: true, }, // @ts-expect-error we pass an extra argument with the resolved auto-key to prevent another from being injected autoKey) } -function generateOptionSegments <_ResT, DataT, DefaultT> (opts: UseFetchOptions<_ResT, DataT, any, DefaultT, any, any>) { +function generateOptionSegments<_ResT, DataT, DefaultT> (opts: UseFetchOptions<_ResT, DataT, any, DefaultT, any, any>) { const segments: Array> = [ toValue(opts.method as MaybeRef | undefined)?.toUpperCase() || 'GET', - toValue(opts.baseURL) + toValue(opts.baseURL), ] for (const _obj of [opts.params || opts.query]) { const obj = toValue(_obj) diff --git a/packages/nuxt/src/app/composables/index.ts b/packages/nuxt/src/app/composables/index.ts index 7b0810d0b0..d5058ecb92 100644 --- a/packages/nuxt/src/app/composables/index.ts +++ b/packages/nuxt/src/app/composables/index.ts @@ -9,7 +9,7 @@ export { /** @deprecated Import `useSeoMeta` from `#imports` instead. This may be removed in a future minor version. */ useSeoMeta, /** @deprecated Import `useServerSeoMeta` from `#imports` instead. This may be removed in a future minor version. */ - useServerSeoMeta + useServerSeoMeta, } from '@unhead/vue' export { defineNuxtComponent } from './component' diff --git a/packages/nuxt/src/app/composables/loading-indicator.ts b/packages/nuxt/src/app/composables/loading-indicator.ts index 7037f74438..5bae3c98b5 100644 --- a/packages/nuxt/src/app/composables/loading-indicator.ts +++ b/packages/nuxt/src/app/composables/loading-indicator.ts @@ -148,7 +148,7 @@ function createLoadingIndicator (opts: Partial = {}) { start, set, finish, - clear + clear, } } diff --git a/packages/nuxt/src/app/composables/manifest.ts b/packages/nuxt/src/app/composables/manifest.ts index 40bfdcd536..13a60e8d82 100644 --- a/packages/nuxt/src/app/composables/manifest.ts +++ b/packages/nuxt/src/app/composables/manifest.ts @@ -46,7 +46,7 @@ export function getAppManifest (): Promise { export async function getRouteRules (url: string) { if (import.meta.server) { const _routeRulesMatcher = toRouteMatcher( - createRadixRouter({ routes: useRuntimeConfig().nitro!.routeRules }) + createRadixRouter({ routes: useRuntimeConfig().nitro!.routeRules }), ) return defu({} as Record, ..._routeRulesMatcher.matchAll(url).reverse()) } diff --git a/packages/nuxt/src/app/composables/payload.ts b/packages/nuxt/src/app/composables/payload.ts index 97edda896d..4e8cd677d4 100644 --- a/packages/nuxt/src/app/composables/payload.ts +++ b/packages/nuxt/src/app/composables/payload.ts @@ -44,8 +44,8 @@ export function preloadPayload (url: string, opts: LoadPayloadOptions = {}) { const payloadURL = _getPayloadURL(url, opts) useHead({ link: [ - { rel: 'modulepreload', href: payloadURL } - ] + { rel: 'modulepreload', href: payloadURL }, + ], }) } @@ -109,7 +109,7 @@ export async function getNuxtClientPayload () { payloadCache = { ...inlineData, ...externalData, - ...window.__NUXT__ + ...window.__NUXT__, } return payloadCache @@ -125,7 +125,7 @@ export async function parsePayload (payload: string) { */ export function definePayloadReducer ( name: string, - reduce: (data: any) => any + reduce: (data: any) => any, ) { if (import.meta.server) { useNuxtApp().ssrContext!._payloadReducers[name] = reduce @@ -140,7 +140,7 @@ export function definePayloadReducer ( */ export function definePayloadReviver ( name: string, - revive: (data: any) => any | undefined + revive: (data: any) => any | undefined, ) { if (import.meta.dev && getCurrentInstance()) { console.warn('[nuxt] [definePayloadReviver] This function must be called in a Nuxt plugin that is `unshift`ed to the beginning of the Nuxt plugins array.') diff --git a/packages/nuxt/src/app/composables/preload.ts b/packages/nuxt/src/app/composables/preload.ts index ac94bbede6..d7b747b279 100644 --- a/packages/nuxt/src/app/composables/preload.ts +++ b/packages/nuxt/src/app/composables/preload.ts @@ -36,7 +36,7 @@ function _loadAsyncComponent (component: Component) { } /** @since 3.0.0 */ -export async function preloadRouteComponents (to: RouteLocationRaw, router: Router & { _routePreloaded?: Set; _preloadPromises?: Array> } = useRouter()): Promise { +export async function preloadRouteComponents (to: RouteLocationRaw, router: Router & { _routePreloaded?: Set, _preloadPromises?: Array> } = useRouter()): Promise { if (import.meta.server) { return } const { path, matched } = router.resolve(to) diff --git a/packages/nuxt/src/app/composables/preview.ts b/packages/nuxt/src/app/composables/preview.ts index 697ddaad5d..94f8a896d1 100644 --- a/packages/nuxt/src/app/composables/preview.ts +++ b/packages/nuxt/src/app/composables/preview.ts @@ -11,8 +11,8 @@ interface Preview { } interface PreviewModeOptions { - shouldEnable?: (state: Preview['state']) => boolean, - getState?: (state: Preview['state']) => S, + shouldEnable?: (state: Preview['state']) => boolean + getState?: (state: Preview['state']) => S } type EnteredState = Record | null | undefined | void @@ -23,13 +23,13 @@ let unregisterRefreshHook: (() => any) | undefined export function usePreviewMode (options: PreviewModeOptions = {}) { const preview = useState('_preview-state', () => ({ enabled: false, - state: {} + state: {}, })) if (preview.value._initialized) { return { enabled: toRef(preview.value, 'enabled'), - state: preview.value.state as S extends void ? Preview['state'] : (NonNullable & Preview['state']) + state: preview.value.state as S extends void ? Preview['state'] : (NonNullable & Preview['state']), } } @@ -67,7 +67,7 @@ export function usePreviewMode (options: PreviewModeOpti return { enabled: toRef(preview.value, 'enabled'), - state: preview.value.state as S extends void ? Preview['state'] : (NonNullable & Preview['state']) + state: preview.value.state as S extends void ? Preview['state'] : (NonNullable & Preview['state']), } } diff --git a/packages/nuxt/src/app/composables/router.ts b/packages/nuxt/src/app/composables/router.ts index bf935e63d7..c7e0e2ac80 100644 --- a/packages/nuxt/src/app/composables/router.ts +++ b/packages/nuxt/src/app/composables/router.ts @@ -4,7 +4,6 @@ import type { NavigationFailure, NavigationGuard, RouteLocationNormalized, Route import { sanitizeStatusCode } from 'h3' import { hasProtocol, isScriptProtocol, joinURL, parseURL, withQuery } from 'ufo' -// eslint-disable-next-line import/no-restricted-paths import type { PageMeta } from '../../pages/runtime/composables' import { useNuxtApp, useRuntimeConfig } from '../nuxt' @@ -98,10 +97,10 @@ export type OpenWindowFeatures = { popup?: boolean noopener?: boolean noreferrer?: boolean -} & XOR<{width?: number}, {innerWidth?: number}> - & XOR<{height?: number}, {innerHeight?: number}> - & XOR<{left?: number}, {screenX?: number}> - & XOR<{top?: number}, {screenY?: number}> +} & XOR<{ width?: number }, { innerWidth?: number }> + & XOR<{ height?: number }, { innerHeight?: number }> + & XOR<{ left?: number }, { screenX?: number }> + & XOR<{ top?: number }, { screenY?: number }> export type OpenOptions = { target: '_blank' | '_parent' | '_self' | '_top' | (string & {}) @@ -170,7 +169,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na nuxtApp.ssrContext!._renderResponse = { statusCode: sanitizeStatusCode(options?.redirectCode || 302, 302), body: ``, - headers: { location } + headers: { location }, } return response } diff --git a/packages/nuxt/src/app/composables/state.ts b/packages/nuxt/src/app/composables/state.ts index 595bb06626..beaa193afb 100644 --- a/packages/nuxt/src/app/composables/state.ts +++ b/packages/nuxt/src/app/composables/state.ts @@ -10,9 +10,9 @@ const useStateKeyPrefix = '$s' * @param key a unique key ensuring that data fetching can be properly de-duplicated across requests * @param init a function that provides initial value for the state when it's not initiated */ -export function useState (key?: string, init?: (() => T | Ref)): Ref -export function useState (init?: (() => T | Ref)): Ref -export function useState (...args: any): Ref { +export function useState (key?: string, init?: (() => T | Ref)): Ref +export function useState (init?: (() => T | Ref)): Ref +export function useState (...args: any): Ref { const autoKey = typeof args[args.length - 1] === 'string' ? args.pop() : undefined if (typeof args[0] !== 'string') { args.unshift(autoKey) } const [_key, init] = args as [string, (() => T | Ref)] @@ -40,7 +40,7 @@ export function useState (...args: any): Ref { /** @since 3.6.0 */ export function clearNuxtState ( - keys?: string | string[] | ((key: string) => boolean) + keys?: string | string[] | ((key: string) => boolean), ): void { const nuxtApp = useNuxtApp() const _allKeys = Object.keys(nuxtApp.payload.state) diff --git a/packages/nuxt/src/app/entry.ts b/packages/nuxt/src/app/entry.ts index f912909a1c..8c33ccae87 100644 --- a/packages/nuxt/src/app/entry.ts +++ b/packages/nuxt/src/app/entry.ts @@ -52,7 +52,7 @@ if (import.meta.client) { if (vueAppPromise) { return vueAppPromise } const isSSR = Boolean( window.__NUXT__?.serverRendered || - document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true' + document.getElementById('__NUXT_DATA__')?.dataset.ssr === 'true', ) const vueApp = isSSR ? createSSRApp(RootComponent) : createApp(RootComponent) diff --git a/packages/nuxt/src/app/index.ts b/packages/nuxt/src/app/index.ts index 1acc4ad82e..9f8fc9103e 100644 --- a/packages/nuxt/src/app/index.ts +++ b/packages/nuxt/src/app/index.ts @@ -1,9 +1,9 @@ /// export * from './nuxt' -// eslint-disable-next-line import/no-restricted-paths + export * from './composables/index' -// eslint-disable-next-line import/no-restricted-paths + export * from './components/index' export * from './config' export * from './compat/idle-callback' diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index 95734eb125..2c8a7839ab 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-use-before-define */ import { effectScope, getCurrentInstance, hasInjectionContext, reactive } from 'vue' import type { App, EffectScope, Ref, VNode, onErrorCaptured } from 'vue' import type { RouteLocationNormalizedLoaded } from '#vue-router' @@ -23,7 +22,7 @@ import type { ViewTransition } from './plugins/view-transitions.client' import type { NuxtAppLiterals } from '#app' const nuxtAppCtx = /* @__PURE__ */ getContext('nuxt-app', { - asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server + asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server, }) type HookResult = Promise | void @@ -236,17 +235,17 @@ export function createNuxtApp (options: CreateOptions) { globalName: 'nuxt', versions: { get nuxt () { return __NUXT_VERSION__ }, - get vue () { return nuxtApp.vueApp.version } + get vue () { return nuxtApp.vueApp.version }, }, payload: reactive({ data: {}, state: {}, once: new Set(), _errors: {}, - ...(import.meta.client ? window.__NUXT__ ?? {} : { serverRendered: true }) + ...(import.meta.client ? window.__NUXT__ ?? {} : { serverRendered: true }), }), static: { - data: {} + data: {}, }, runWithContext: (fn: any) => nuxtApp._scope.run(() => callWithNuxt(nuxtApp, fn)), isHydrating: import.meta.client, @@ -271,7 +270,7 @@ export function createNuxtApp (options: CreateOptions) { _asyncDataPromises: {}, _asyncData: {}, _payloadRevivers: {}, - ...options + ...options, } as any as NuxtApp nuxtApp.hooks = createHooks() @@ -319,7 +318,7 @@ export function createNuxtApp (options: CreateOptions) { // Expose client runtime-config to the payload nuxtApp.ssrContext!.config = { public: options.ssrContext!.runtimeConfig.public, - app: options.ssrContext!.runtimeConfig.app + app: options.ssrContext!.runtimeConfig.app, } } diff --git a/packages/nuxt/src/app/plugins/check-if-layout-used.ts b/packages/nuxt/src/app/plugins/check-if-layout-used.ts index 9cf7192ea9..64a357cc66 100644 --- a/packages/nuxt/src/app/plugins/check-if-layout-used.ts +++ b/packages/nuxt/src/app/plugins/check-if-layout-used.ts @@ -23,6 +23,6 @@ export default defineNuxtPlugin({ } }, env: { - islands: false - } + islands: false, + }, }) diff --git a/packages/nuxt/src/app/plugins/chunk-reload.client.ts b/packages/nuxt/src/app/plugins/chunk-reload.client.ts index 7b802c57f0..e8eb5e2e48 100644 --- a/packages/nuxt/src/app/plugins/chunk-reload.client.ts +++ b/packages/nuxt/src/app/plugins/chunk-reload.client.ts @@ -30,5 +30,5 @@ export default defineNuxtPlugin({ reloadAppAtPath(to) } }) - } + }, }) diff --git a/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts b/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts index c386328c09..3ae277ab47 100644 --- a/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts +++ b/packages/nuxt/src/app/plugins/cross-origin-prefetch.client.ts @@ -16,23 +16,23 @@ export default defineNuxtPlugin({ { source: 'list', urls: [...externalURLs.value], - requires: ['anonymous-client-ip-when-cross-origin'] - } - ] - }) + requires: ['anonymous-client-ip-when-cross-origin'], + }, + ], + }), } } const head = useHead({ - script: [generateRules()] + script: [generateRules()], }) nuxtApp.hook('link:prefetch', (url) => { const { protocol } = parseURL(url) if (protocol && ['http:', 'https:'].includes(protocol)) { externalURLs.value.add(url) head?.patch({ - script: [generateRules()] + script: [generateRules()], }) } }) - } + }, }) diff --git a/packages/nuxt/src/app/plugins/debug.ts b/packages/nuxt/src/app/plugins/debug.ts index 69a989a586..ccb841672c 100644 --- a/packages/nuxt/src/app/plugins/debug.ts +++ b/packages/nuxt/src/app/plugins/debug.ts @@ -6,5 +6,5 @@ export default defineNuxtPlugin({ enforce: 'pre', setup (nuxtApp) { createDebugger(nuxtApp.hooks, { tag: 'nuxt-app' }) - } + }, }) diff --git a/packages/nuxt/src/app/plugins/dev-server-logs.ts b/packages/nuxt/src/app/plugins/dev-server-logs.ts index edeb39ae8f..cccb105794 100644 --- a/packages/nuxt/src/app/plugins/dev-server-logs.ts +++ b/packages/nuxt/src/app/plugins/dev-server-logs.ts @@ -20,8 +20,8 @@ export default defineNuxtPlugin((nuxtApp) => { const logger = createConsola({ formatOptions: { colors: true, - date: true - } + date: true, + }, }) const hydrationLogs = new Set() consola.wrapConsole() @@ -32,7 +32,7 @@ export default defineNuxtPlugin((nuxtApp) => { } catch { // silently ignore - the worst case is a user gets log twice } - } + }, }) nuxtApp.hook('dev:ssr-logs', (logs) => { for (const log of logs) { diff --git a/packages/nuxt/src/app/plugins/payload.client.ts b/packages/nuxt/src/app/plugins/payload.client.ts index 452fa841cf..c50b3bd45a 100644 --- a/packages/nuxt/src/app/plugins/payload.client.ts +++ b/packages/nuxt/src/app/plugins/payload.client.ts @@ -32,5 +32,5 @@ export default defineNuxtPlugin({ setTimeout(getAppManifest, 1000) } }) - } + }, }) diff --git a/packages/nuxt/src/app/plugins/preload.server.ts b/packages/nuxt/src/app/plugins/preload.server.ts index e5d291a704..18c8931f08 100644 --- a/packages/nuxt/src/app/plugins/preload.server.ts +++ b/packages/nuxt/src/app/plugins/preload.server.ts @@ -8,7 +8,7 @@ export default defineNuxtPlugin({ const { _registeredComponents } = this.$nuxt.ssrContext const { __moduleIdentifier } = this.$options _registeredComponents.add(__moduleIdentifier) - } + }, }) - } + }, }) diff --git a/packages/nuxt/src/app/plugins/restore-state.client.ts b/packages/nuxt/src/app/plugins/restore-state.client.ts index 1914cf48d4..bc53feef73 100644 --- a/packages/nuxt/src/app/plugins/restore-state.client.ts +++ b/packages/nuxt/src/app/plugins/restore-state.client.ts @@ -15,6 +15,6 @@ export default defineNuxtPlugin({ } catch { // don't throw an error if we have issues reading sessionStorage } - } - } + }, + }, }) diff --git a/packages/nuxt/src/app/plugins/revive-payload.client.ts b/packages/nuxt/src/app/plugins/revive-payload.client.ts index 89f98a5809..7deec66618 100644 --- a/packages/nuxt/src/app/plugins/revive-payload.client.ts +++ b/packages/nuxt/src/app/plugins/revive-payload.client.ts @@ -14,7 +14,7 @@ const revivers: Record any> = { ShallowRef: data => shallowRef(data), ShallowReactive: data => shallowReactive(data), Ref: data => ref(data), - Reactive: data => reactive(data) + Reactive: data => reactive(data), } if (componentIslands) { @@ -23,7 +23,7 @@ if (componentIslands) { if (!nuxtApp.isHydrating) { nuxtApp.payload.data[key] = nuxtApp.payload.data[key] || $fetch(`/__nuxt_island/${key}.json`, { responseType: 'json', - ...params ? { params } : {} + ...params ? { params } : {}, }).then((r) => { nuxtApp.payload.data[key] = r return r @@ -34,9 +34,9 @@ if (componentIslands) { state: {}, head: { link: [], - style: [] + style: [], }, - ...result + ...result, } } } @@ -51,5 +51,5 @@ export default defineNuxtPlugin({ Object.assign(nuxtApp.payload, await nuxtApp.runWithContext(getNuxtClientPayload)) // For backwards compatibility - TODO: remove later window.__NUXT__ = nuxtApp.payload - } + }, }) diff --git a/packages/nuxt/src/app/plugins/revive-payload.server.ts b/packages/nuxt/src/app/plugins/revive-payload.server.ts index 39180b9dc9..f2cb08983d 100644 --- a/packages/nuxt/src/app/plugins/revive-payload.server.ts +++ b/packages/nuxt/src/app/plugins/revive-payload.server.ts @@ -13,7 +13,7 @@ const reducers: Record any> = { ShallowRef: data => isRef(data) && isShallow(data) && data.value, ShallowReactive: data => isReactive(data) && isShallow(data) && toRaw(data), Ref: data => isRef(data) && data.value, - Reactive: data => isReactive(data) && toRaw(data) + Reactive: data => isReactive(data) && toRaw(data), } if (componentIslands) { @@ -26,5 +26,5 @@ export default defineNuxtPlugin({ for (const reducer in reducers) { definePayloadReducer(reducer, reducers[reducer as keyof typeof reducers]) } - } + }, }) diff --git a/packages/nuxt/src/app/plugins/router.ts b/packages/nuxt/src/app/plugins/router.ts index bb47ea4b17..38c93085d4 100644 --- a/packages/nuxt/src/app/plugins/router.ts +++ b/packages/nuxt/src/app/plugins/router.ts @@ -41,7 +41,7 @@ function getRouteFromPath (fullPath: string | Partial) { fullPath = stringifyParsedURL({ pathname: fullPath.path || '', search: stringifyQuery(fullPath.query || {}), - hash: fullPath.hash || '' + hash: fullPath.hash || '', }) } @@ -57,7 +57,7 @@ function getRouteFromPath (fullPath: string | Partial) { matched: [], redirectedFrom: undefined, meta: {}, - href: fullPath + href: fullPath, } } @@ -112,7 +112,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ 'navigate:before': [], 'resolve:before': [], 'navigate:after': [], - error: [] + 'error': [], } const registerHook = (hook: T, guard: RouterHooks[T]) => { @@ -191,7 +191,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ if (index !== -1) { routes.splice(index, 1) } - } + }, } nuxtApp.vueApp.component('RouterLink', defineComponent({ @@ -199,14 +199,14 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ props: { to: { type: String, - required: true + required: true, }, custom: Boolean, replace: Boolean, // Not implemented activeClass: String, exactActiveClass: String, - ariaCurrentValue: String + ariaCurrentValue: String, }, setup: (props, { slots }) => { const navigate = () => handleNavigation(props.to!, props.replace) @@ -216,7 +216,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ ? slots.default?.({ href: props.to, navigate, route }) : h('a', { href: props.to, onClick: (e: MouseEvent) => { e.preventDefault(); return navigate() } }, slots) } - } + }, })) if (import.meta.client) { @@ -231,7 +231,7 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ // Handle middleware nuxtApp._middleware = nuxtApp._middleware || { global: [], - named: {} + named: {}, } const initialLayout = nuxtApp.payload.state._layout @@ -271,8 +271,8 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ statusCode: 404, statusMessage: `Page Not Found: ${initialURL}`, data: { - path: initialURL - } + path: initialURL, + }, }) delete nuxtApp._processingMiddleware return nuxtApp.runWithContext(() => showError(error)) @@ -295,8 +295,8 @@ export default defineNuxtPlugin<{ route: Route, router: Router }>({ return { provide: { route, - router - } + router, + }, } - } + }, }) diff --git a/packages/nuxt/src/app/types.ts b/packages/nuxt/src/app/types.ts index 2a7df92c5e..795e92384e 100644 --- a/packages/nuxt/src/app/types.ts +++ b/packages/nuxt/src/app/types.ts @@ -1,9 +1,7 @@ -// eslint-disable-next-line import/no-restricted-paths export type { PageMeta } from '../pages/runtime/index' export interface NuxtAppLiterals { [key: string]: string } -// eslint-disable-next-line import/no-restricted-paths export type { NuxtIslandContext, NuxtIslandResponse, NuxtRenderHTMLContext } from '../core/runtime/nitro/renderer' diff --git a/packages/nuxt/src/components/client-fallback-auto-id.ts b/packages/nuxt/src/components/client-fallback-auto-id.ts index 3f01c80c25..19b5a39984 100644 --- a/packages/nuxt/src/components/client-fallback-auto-id.ts +++ b/packages/nuxt/src/components/client-fallback-auto-id.ts @@ -4,9 +4,10 @@ import MagicString from 'magic-string' import { isAbsolute, relative } from 'pathe' import { hash } from 'ohash' import { isVue } from '../core/utils' + interface LoaderOptions { sourcemap?: boolean - transform?: ComponentsOptions['transform'], + transform?: ComponentsOptions['transform'] rootDir: string } const CLIENT_FALLBACK_RE = /<(NuxtClientFallback|nuxt-client-fallback)( [^>]*)?>/ @@ -45,9 +46,9 @@ export const clientFallbackAutoIdPlugin = createUnplugin((options: LoaderOptions code: s.toString(), map: options.sourcemap ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index a5fe8f33a8..c331478fa7 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -53,7 +53,7 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran const components = options.getComponents() const islands = components.filter(component => - component.island || (component.mode === 'server' && !components.some(c => c.pascalName === component.pascalName && c.mode === 'client')) + component.island || (component.mode === 'server' && !components.some(c => c.pascalName === component.pascalName && c.mode === 'client')), ) const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href)) return islands.some(c => c.filePath === pathname) @@ -129,17 +129,16 @@ export const islandsTransform = createUnplugin((options: ServerOnlyComponentTran }) if (!isVite && hasNuxtClient) { - // eslint-disable-next-line no-console console.warn(`nuxt-client attribute and client components within islands is only supported with Vite. file: ${id}`) } if (s.hasChanged()) { return { code: s.toString(), - map: s.generateMap({ source: id, includeContent: true }) + map: s.generateMap({ source: id, includeContent: true }), } } - } + }, } }) @@ -187,8 +186,8 @@ export const componentsChunkPlugin = createUnplugin((options: ComponentChunkOpti config.build = defu(config.build, { rollupOptions: { input: {}, - output: {} - } + output: {}, + }, }) const rollupOptions = config.build.rollupOptions! @@ -228,7 +227,7 @@ export const componentsChunkPlugin = createUnplugin((options: ComponentChunkOpti } fs.writeFileSync(join(buildDir, 'components-chunk.mjs'), `export const paths = ${JSON.stringify(pathAssociation, null, 2)}`) - } - } + }, + }, } }) diff --git a/packages/nuxt/src/components/loader.ts b/packages/nuxt/src/components/loader.ts index 1f372adfb3..628638ffad 100644 --- a/packages/nuxt/src/components/loader.ts +++ b/packages/nuxt/src/components/loader.ts @@ -99,10 +99,10 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => { code: s.toString(), map: options.sourcemap ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/components/module.ts b/packages/nuxt/src/components/module.ts index 0394c5fb1b..61c7686e7a 100644 --- a/packages/nuxt/src/components/module.ts +++ b/packages/nuxt/src/components/module.ts @@ -25,15 +25,15 @@ export type getComponentsT = (mode?: 'client' | 'server' | 'all') => Component[] export default defineNuxtModule({ meta: { name: 'components', - configKey: 'components' + configKey: 'components', }, defaults: { - dirs: [] + dirs: [], }, setup (componentOptions, nuxt) { let componentDirs: ComponentsDir[] = [] const context = { - components: [] as Component[] + components: [] as Component[], } const getComponents: getComponentsT = (mode) => { @@ -50,12 +50,12 @@ export default defineNuxtModule({ return [ { priority: options?.priority || 0, path: resolve(cwd, 'components/islands'), island: true }, { priority: options?.priority || 0, path: resolve(cwd, 'components/global'), global: true }, - { priority: options?.priority || 0, path: resolve(cwd, 'components') } + { priority: options?.priority || 0, path: resolve(cwd, 'components') }, ] } if (typeof dir === 'string') { return [ - { priority: options?.priority || 0, path: resolve(cwd, resolveAlias(dir)) } + { priority: options?.priority || 0, path: resolve(cwd, resolveAlias(dir)) }, ] } if (!dir) { @@ -65,7 +65,7 @@ export default defineNuxtModule({ return dirs.map(_dir => ({ priority: options?.priority || 0, ..._dir, - path: resolve(cwd, resolveAlias(_dir.path)) + path: resolve(cwd, resolveAlias(_dir.path)), })) } @@ -100,15 +100,15 @@ export default defineNuxtModule({ ignore: [ '**/*{M,.m,-m}ixin.{js,ts,jsx,tsx}', // ignore mixins '**/*.d.{cts,mts,ts}', // .d.ts files - ...(dirOptions.ignore || []) + ...(dirOptions.ignore || []), ], - transpile: (transpile === 'auto' ? dirPath.includes('node_modules') : transpile) + transpile: (transpile === 'auto' ? dirPath.includes('node_modules') : transpile), } }).filter(d => d.enabled) componentDirs = [ ...componentDirs.filter(dir => !dir.path.includes('node_modules')), - ...componentDirs.filter(dir => dir.path.includes('node_modules')) + ...componentDirs.filter(dir => dir.path.includes('node_modules')), ] nuxt.options.build!.transpile!.push(...componentDirs.filter(dir => dir.transpile).map(dir => dir.path)) @@ -179,7 +179,7 @@ export default defineNuxtModule({ _raw: true, mode: 'server', filePath: serverPlaceholderPath, - chunkName: 'components/' + component.kebabName + chunkName: 'components/' + component.kebabName, }) } if (component.mode === 'server' && !nuxt.options.ssr && !newComponents.some(other => other.pascalName === component.pascalName && other.mode === 'client')) { @@ -206,8 +206,8 @@ export default defineNuxtModule({ 'components.plugin.mjs', 'components.d.ts', 'components.server.mjs', - 'components.client.mjs' - ].includes(template.filename) + 'components.client.mjs', + ].includes(template.filename), }) } }) @@ -219,19 +219,19 @@ export default defineNuxtModule({ if (nuxt.options.experimental.treeshakeClientOnly && isServer) { config.plugins.push(TreeShakeTemplatePlugin.vite({ sourcemap: !!nuxt.options.sourcemap[mode], - getComponents + getComponents, })) } config.plugins.push(clientFallbackAutoIdPlugin.vite({ sourcemap: !!nuxt.options.sourcemap[mode], - rootDir: nuxt.options.rootDir + rootDir: nuxt.options.rootDir, })) config.plugins.push(loaderPlugin.vite({ sourcemap: !!nuxt.options.sourcemap[mode], getComponents, mode, transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined, - experimentalComponentIslands: !!nuxt.options.experimental.componentIslands + experimentalComponentIslands: !!nuxt.options.experimental.componentIslands, })) if (nuxt.options.experimental.componentIslands) { @@ -242,7 +242,7 @@ export default defineNuxtModule({ if (!nuxt.options.dev) { config.plugins.push(componentsChunkPlugin.vite({ getComponents, - buildDir: nuxt.options.buildDir + buildDir: nuxt.options.buildDir, })) } else { fs.writeFileSync(join(nuxt.options.buildDir, 'components-chunk.mjs'), `export const paths = ${JSON.stringify( @@ -250,7 +250,7 @@ export default defineNuxtModule({ if (c.filePath.endsWith('.vue') || c.filePath.endsWith('.js') || c.filePath.endsWith('.ts')) { return Object.assign(acc, { [c.pascalName]: `/@fs/${c.filePath}` }) } const filePath = fs.existsSync(`${c.filePath}.vue`) ? `${c.filePath}.vue` : fs.existsSync(`${c.filePath}.js`) ? `${c.filePath}.js` : `${c.filePath}.ts` return Object.assign(acc, { [c.pascalName]: `/@fs/${filePath}` }) - }, {} as Record) + }, {} as Record), )}`) } } @@ -260,7 +260,7 @@ export default defineNuxtModule({ getComponents, rootDir: nuxt.options.rootDir, isDev: nuxt.options.dev, - selectiveClient + selectiveClient, })) } } @@ -274,10 +274,10 @@ export default defineNuxtModule({ if (comp?.mode === 'server') { ctx.server.ws.send({ event: `nuxt-server-component:${comp.pascalName}`, - type: 'custom' + type: 'custom', }) } - } + }, }) } }) @@ -288,25 +288,25 @@ export default defineNuxtModule({ if (nuxt.options.experimental.treeshakeClientOnly && mode === 'server') { config.plugins.push(TreeShakeTemplatePlugin.webpack({ sourcemap: !!nuxt.options.sourcemap[mode], - getComponents + getComponents, })) } config.plugins.push(clientFallbackAutoIdPlugin.webpack({ sourcemap: !!nuxt.options.sourcemap[mode], - rootDir: nuxt.options.rootDir + rootDir: nuxt.options.rootDir, })) config.plugins.push(loaderPlugin.webpack({ sourcemap: !!nuxt.options.sourcemap[mode], getComponents, mode, transform: typeof nuxt.options.components === 'object' && !Array.isArray(nuxt.options.components) ? nuxt.options.components.transform : undefined, - experimentalComponentIslands: !!nuxt.options.experimental.componentIslands + experimentalComponentIslands: !!nuxt.options.experimental.componentIslands, })) if (nuxt.options.experimental.componentIslands) { if (mode === 'server') { config.plugins.push(islandsTransform.webpack({ - getComponents + getComponents, })) } else { fs.writeFileSync(join(nuxt.options.buildDir, 'components-chunk.mjs'), 'export const paths = {}') @@ -314,5 +314,5 @@ export default defineNuxtModule({ } }) }) - } + }, }) diff --git a/packages/nuxt/src/components/runtime/client-component.ts b/packages/nuxt/src/components/runtime/client-component.ts index 97558c8946..8fc181930a 100644 --- a/packages/nuxt/src/components/runtime/client-component.ts +++ b/packages/nuxt/src/components/runtime/client-component.ts @@ -11,9 +11,9 @@ export const createClientPage = (loader: AsyncComponentLoader) => { setup (_, { attrs }) { return () => h('div', [ h(ClientOnly, undefined, { - default: () => h(page, attrs) - }) + default: () => h(page, attrs), + }), ]) - } + }, }) } diff --git a/packages/nuxt/src/components/runtime/server-component.ts b/packages/nuxt/src/components/runtime/server-component.ts index 4b52e46a00..bea615b2dc 100644 --- a/packages/nuxt/src/components/runtime/server-component.ts +++ b/packages/nuxt/src/components/runtime/server-component.ts @@ -14,7 +14,7 @@ export const createServerComponent = (name: string) => { const islandRef = ref(null) expose({ - refresh: () => islandRef.value?.refresh() + refresh: () => islandRef.value?.refresh(), }) return () => { @@ -25,10 +25,10 @@ export const createServerComponent = (name: string) => { ref: islandRef, onError: (err) => { emit('error', err) - } + }, }, slots) } - } + }, }) } @@ -42,7 +42,7 @@ export const createIslandPage = (name: string) => { const islandRef = ref(null) expose({ - refresh: () => islandRef.value?.refresh() + refresh: () => islandRef.value?.refresh(), }) const route = useRoute() @@ -54,10 +54,10 @@ export const createIslandPage = (name: string) => { name: `page:${name}`, lazy: props.lazy, ref: islandRef, - context: { url: path } - }, slots) + context: { url: path }, + }, slots), ]) } - } + }, }) } diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index 7bc26a6c57..4f21454e6a 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -69,7 +69,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr */ const prefixParts = ([] as string[]).concat( dir.prefix ? splitByCase(dir.prefix) : [], - (dir.pathPrefix !== false) ? splitByCase(relative(dir.path, dirname(filePath))) : [] + (dir.pathPrefix !== false) ? splitByCase(relative(dir.path, dirname(filePath))) : [], ) /** @@ -118,7 +118,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr shortPath, export: 'default', // by default, give priority to scanned components - priority: dir.priority ?? 1 + priority: dir.priority ?? 1, } if (typeof dir.extendComponent === 'function') { @@ -160,6 +160,6 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr function warnAboutDuplicateComponent (componentName: string, filePath: string, duplicatePath: string) { logger.warn(`Two component files resolving to the same name \`${componentName}\`:\n` + `\n - ${filePath}` + - `\n - ${duplicatePath}` + `\n - ${duplicatePath}`, ) } diff --git a/packages/nuxt/src/components/templates.ts b/packages/nuxt/src/components/templates.ts index 44c166eb07..f574d85140 100644 --- a/packages/nuxt/src/components/templates.ts +++ b/packages/nuxt/src/components/templates.ts @@ -13,7 +13,7 @@ const createImportMagicComments = (options: ImportMagicCommentsOptions) => { return [ `webpackChunkName: "${chunkName}"`, prefetch === true || typeof prefetch === 'number' ? `webpackPrefetch: ${prefetch}` : false, - preload === true || typeof preload === 'number' ? `webpackPreload: ${preload}` : false + preload === true || typeof preload === 'number' ? `webpackPreload: ${preload}` : false, ].filter(Boolean).join(', ') } @@ -58,14 +58,14 @@ export default defineNuxtPlugin({ } }) ` - } + }, } export const componentNamesTemplate: NuxtTemplate = { filename: 'component-names.mjs', getContents ({ app }) { return `export const componentNames = ${JSON.stringify(app.components.filter(c => !c.island).map(c => c.pascalName))}` - } + }, } export const componentsIslandsTemplate: NuxtTemplate = { @@ -76,7 +76,7 @@ export const componentsIslandsTemplate: NuxtTemplate = { const islands = components.filter(component => component.island || // .server components without a corresponding .client component will need to be rendered as an island - (component.mode === 'server' && !components.some(c => c.pascalName === component.pascalName && c.mode === 'client')) + (component.mode === 'server' && !components.some(c => c.pascalName === component.pascalName && c.mode === 'client')), ) const pageExports = pages?.filter(p => (p.mode === 'server' && p.file && p.name)).map((p) => { @@ -91,11 +91,11 @@ export const componentsIslandsTemplate: NuxtTemplate = { const exp = c.export === 'default' ? 'c.default || c' : `c['${c.export}']` const comment = createImportMagicComments(c) return ` "${c.pascalName}": defineAsyncComponent(${genDynamicImport(c.filePath, { comment })}.then(c => ${exp}))` - } + }, ).concat(pageExports).join(',\n'), - '}' + '}', ].join('\n') - } + }, } export const componentsTypeTemplate = { @@ -106,7 +106,7 @@ export const componentsTypeTemplate = { c.pascalName, `typeof ${genDynamicImport(isAbsolute(c.filePath) ? relative(buildDir, c.filePath).replace(/(?<=\w)\.(?!vue)\w+$/g, '') - : c.filePath.replace(/(?<=\w)\.(?!vue)\w+$/g, ''), { wrapper: false })}['${c.export}']` + : c.filePath.replace(/(?<=\w)\.(?!vue)\w+$/g, ''), { wrapper: false })}['${c.export}']`, ]) return ` @@ -132,11 +132,11 @@ ${componentTypes.map(([pascalName, type]) => `export const Lazy${pascalName}: ${ export const componentNames: string[] ` - } + }, } satisfies NuxtTemplate export const componentsMetadataTemplate: NuxtTemplate = { filename: 'components.json', write: true, - getContents: ({ app }) => JSON.stringify(app.components, null, 2) + getContents: ({ app }) => JSON.stringify(app.components, null, 2), } diff --git a/packages/nuxt/src/components/transform.ts b/packages/nuxt/src/components/transform.ts index 38acd08b3b..f11f9ce555 100644 --- a/packages/nuxt/src/components/transform.ts +++ b/packages/nuxt/src/components/transform.ts @@ -18,10 +18,10 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT imports: [ { name: 'componentNames', - from: '#build/component-names' - } + from: '#build/component-names', + }, ], - virtualImports: ['#components'] + virtualImports: ['#components'], }) function getComponentsImports (): Import[] { @@ -37,13 +37,13 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT { as: c.pascalName, from: withMode(mode), - name: c.export || 'default' + name: c.export || 'default', }, { as: 'Lazy' + c.pascalName, from: withMode([mode, 'async'].filter(Boolean).join(',')), - name: c.export || 'default' - } + name: c.export || 'default', + }, ] }) } @@ -67,36 +67,36 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT return { code: [ 'import { defineAsyncComponent } from "vue"', - `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r[${JSON.stringify(componentExport)}] || r.default || r))` + `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => r[${JSON.stringify(componentExport)}] || r.default || r))`, ].join('\n'), - map: null + map: null, } } else if (mode === 'client') { return { code: [ genImport(bare, [{ name: componentExport, as: '__component' }]), 'import { createClientOnly } from "#app/components/client-only"', - `${exportWording} createClientOnly(__component)` + `${exportWording} createClientOnly(__component)`, ].join('\n'), - map: null + map: null, } } else if (mode === 'client,async') { return { code: [ 'import { defineAsyncComponent } from "vue"', 'import { createClientOnly } from "#app/components/client-only"', - `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => createClientOnly(r[${JSON.stringify(componentExport)}] || r.default || r)))` + `${exportWording} defineAsyncComponent(() => import(${JSON.stringify(bare)}).then(r => createClientOnly(r[${JSON.stringify(componentExport)}] || r.default || r)))`, ].join('\n'), - map: null + map: null, } } else if (mode === 'server' || mode === 'server,async') { const name = query.nuxt_component_name return { code: [ `import { createServerComponent } from ${JSON.stringify(serverComponentRuntime)}`, - `${exportWording} createServerComponent(${JSON.stringify(name)})` + `${exportWording} createServerComponent(${JSON.stringify(name)})`, ].join('\n'), - map: null + map: null, } } else { throw new Error(`Unknown component mode: ${mode}, this might be an internal bug of Nuxt.`) @@ -118,8 +118,8 @@ export function createTransformPlugin (nuxt: Nuxt, getComponents: getComponentsT code: result.code, map: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client ? result.s.generateMap({ hires: true }) - : undefined + : undefined, } - } + }, })) } diff --git a/packages/nuxt/src/components/tree-shake.ts b/packages/nuxt/src/components/tree-shake.ts index 915b794b2f..f6034d023c 100644 --- a/packages/nuxt/src/components/tree-shake.ts +++ b/packages/nuxt/src/components/tree-shake.ts @@ -81,13 +81,13 @@ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplat componentsToRemoveSet.add(nameToRemove) } } - } + }, }) } } } } - } + }, }) const componentsToRemove = [...componentsToRemoveSet] @@ -107,10 +107,10 @@ export const TreeShakeTemplatePlugin = createUnplugin((options: TreeShakeTemplat code: s.toString(), map: options.sourcemap ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) @@ -142,7 +142,7 @@ function removeFromSetupReturn (codeAst: Program, name: string, magicString: Mag } } } - } + }, }) } @@ -209,10 +209,10 @@ function isComponentNotCalledInSetup (codeAst: Node, name: string): string | voi // dev only with $setup or _ctx found = (node.property.type === 'Literal' && node.property.value === name) || (node.property.type === 'Identifier' && node.property.name === name) } - } + }, }) } - } + }, }) if (!found) { return name } } @@ -250,7 +250,7 @@ function removeVariableDeclarator (codeAst: Node, name: string, magicString: Mag } } } - } + }, }) } diff --git a/packages/nuxt/src/core/app.ts b/packages/nuxt/src/core/app.ts index ccfffa8abf..021085aac2 100644 --- a/packages/nuxt/src/core/app.ts +++ b/packages/nuxt/src/core/app.ts @@ -16,7 +16,7 @@ export function createApp (nuxt: Nuxt, options: Partial = {}): NuxtApp extensions: nuxt.options.extensions, plugins: [], components: [], - templates: [] + templates: [], } as unknown as NuxtApp) as NuxtApp } @@ -97,8 +97,8 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) { app.mainComponent = await findPath( nuxt.options._layers.flatMap(layer => [ join(layer.config.srcDir, 'App'), - join(layer.config.srcDir, 'app') - ]) + join(layer.config.srcDir, 'app'), + ]), ) } if (!app.mainComponent) { @@ -113,7 +113,7 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) { // Resolve error component if (!app.errorComponent) { app.errorComponent = (await findPath( - nuxt.options._layers.map(layer => join(layer.config.srcDir, 'error')) + nuxt.options._layers.map(layer => join(layer.config.srcDir, 'error')), )) ?? resolve(nuxt.options.appDir, 'components/nuxt-error-page.vue') } @@ -160,9 +160,9 @@ export async function resolveApp (nuxt: Nuxt, app: NuxtApp) { ...config.srcDir ? await resolveFiles(config.srcDir, [ `${pluginDir}/*{${nuxt.options.extensions.join(',')}}`, - `${pluginDir}/*/index{${nuxt.options.extensions.join(',')}}` // TODO: remove, only scan top-level plugins #18418 + `${pluginDir}/*/index{${nuxt.options.extensions.join(',')}}`, // TODO: remove, only scan top-level plugins #18418 ]) - : [] + : [], ].map(plugin => normalizePlugin(plugin as NuxtPlugin))) } @@ -200,7 +200,7 @@ function resolvePaths> (items: Item[], key: { [ if (!item[key]) { return item } return { ...item, - [key]: await resolvePath(resolveAlias(item[key])) + [key]: await resolvePath(resolveAlias(item[key])), } })) } @@ -214,7 +214,7 @@ export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) { const code = plugin.src in nuxt.vfs ? nuxt.vfs[plugin.src] : await fsp.readFile(plugin.src!, 'utf-8') _plugins.push({ ...await extractMetadata(code, IS_TSX.test(plugin.src) ? 'tsx' : 'ts'), - ...plugin + ...plugin, }) } catch (e) { const relativePluginSrc = relative(nuxt.options.rootDir, plugin.src) diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index 80b96abd8e..c354b0927d 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -56,7 +56,7 @@ export async function build (nuxt: Nuxt) { const watchEvents: Record = { create: 'add', delete: 'unlink', - update: 'change' + update: 'change', } async function watch (nuxt: Nuxt) { @@ -80,8 +80,8 @@ function createWatcher () { ignoreInitial: true, ignored: [ isIgnored, - 'node_modules' - ] + 'node_modules', + ], }) // TODO: consider moving to emit absolute path in 3.8 or 4.0 @@ -164,8 +164,8 @@ async function createParcelWatcher () { }, { ignore: [ ...nuxt.options.ignore, - 'node_modules' - ] + 'node_modules', + ], }) watcher.then((subscription) => { if (nuxt.options.debug) { diff --git a/packages/nuxt/src/core/external-config-files.ts b/packages/nuxt/src/core/external-config-files.ts index 517c88ecba..6c6d5d0d21 100644 --- a/packages/nuxt/src/core/external-config-files.ts +++ b/packages/nuxt/src/core/external-config-files.ts @@ -30,7 +30,7 @@ async function checkViteConfig () { return await checkAndWarnAboutConfigFileExistence({ fileName: 'vite.config', extensions: ['.js', '.mjs', '.ts', '.cjs', '.mts', '.cts'], - createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.vite\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#vite\`.` + createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.vite\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#vite\`.`, }) } @@ -39,7 +39,7 @@ async function checkWebpackConfig () { return await checkAndWarnAboutConfigFileExistence({ fileName: 'webpack.config', extensions: ['.js', '.mjs', '.ts', '.cjs', '.mts', '.cts', 'coffee'], - createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.webpack\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#webpack-1\`.` + createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.webpack\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#webpack-1\`.`, }) } @@ -48,7 +48,7 @@ async function checkNitroConfig () { return await checkAndWarnAboutConfigFileExistence({ fileName: 'nitro.config', extensions: ['.ts', '.mts'], - createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.nitro\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#nitro\`.` + createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.nitro\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#nitro\`.`, }) } @@ -56,13 +56,13 @@ async function checkPostCSSConfig () { return await checkAndWarnAboutConfigFileExistence({ fileName: 'postcss.config', extensions: ['.js', '.cjs'], - createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.postcss\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#postcss\`.` + createWarningMessage: foundFile => `Using \`${foundFile}\` is not supported together with Nuxt. Use \`options.postcss\` instead. You can read more in \`https://nuxt.com/docs/api/nuxt-config#postcss\`.`, }) } interface CheckAndWarnAboutConfigFileExistenceOptions { - fileName: string, - extensions: string[], + fileName: string + extensions: string[] createWarningMessage: (foundFile: string) => string } diff --git a/packages/nuxt/src/core/features.ts b/packages/nuxt/src/core/features.ts index 46eb34de34..2e1bba0106 100644 --- a/packages/nuxt/src/core/features.ts +++ b/packages/nuxt/src/core/features.ts @@ -26,7 +26,7 @@ async function promptToInstall (name: string, installCommand: () => Promise addDependency(name, { cwd: options.rootDir, - dev: true + dev: true, }), options) } diff --git a/packages/nuxt/src/core/modules.ts b/packages/nuxt/src/core/modules.ts index 401aa9c41d..6a9577f37d 100644 --- a/packages/nuxt/src/core/modules.ts +++ b/packages/nuxt/src/core/modules.ts @@ -10,7 +10,7 @@ export const addModuleTranspiles = (opts: AddModuleTranspilesOptions = {}) => { const modules = [ ...opts.additionalModules || [], ...nuxt.options.modules, - ...nuxt.options._modules + ...nuxt.options._modules, ] .map(m => typeof m === 'string' ? m : Array.isArray(m) ? m[0] : m.src) .filter(m => typeof m === 'string') diff --git a/packages/nuxt/src/core/nitro.ts b/packages/nuxt/src/core/nitro.ts index 96a36dd181..24f82eab8a 100644 --- a/packages/nuxt/src/core/nitro.ts +++ b/packages/nuxt/src/core/nitro.ts @@ -23,7 +23,7 @@ import { ImportProtectionPlugin, nuxtImportProtections } from './plugins/import- const logLevelMapReverse = { silent: 0, info: 3, - verbose: 3 + verbose: 3, } satisfies Record export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { @@ -33,7 +33,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const excludePaths = nuxt.options._layers .flatMap(l => [ l.cwd.match(/(?<=\/)node_modules\/(.+)$/)?.[1], - l.cwd.match(/\.pnpm\/.+\/node_modules\/(.+)$/)?.[1] + l.cwd.match(/\.pnpm\/.+\/node_modules\/(.+)$/)?.[1], ]) .filter((dir): dir is string => Boolean(dir)) .map(dir => escapeRE(dir)) @@ -46,7 +46,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const modules = await resolveNuxtModule(rootDirWithSlash, nuxt.options._installedModules .filter(m => m.entryPath) - .map(m => m.entryPath) + .map(m => m.entryPath), ) const nitroConfig: NitroConfig = defu(_nitroConfig, { @@ -58,11 +58,11 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { buildDir: nuxt.options.buildDir, experimental: { asyncContext: nuxt.options.experimental.asyncContext, - typescriptBundlerResolution: nuxt.options.future.typescriptBundlerResolution || nuxt.options.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === 'bundler' || _nitroConfig.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === 'bundler' + typescriptBundlerResolution: nuxt.options.future.typescriptBundlerResolution || nuxt.options.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === 'bundler' || _nitroConfig.typescript?.tsConfig?.compilerOptions?.moduleResolution?.toLowerCase() === 'bundler', }, framework: { name: 'nuxt', - version: nuxtVersion + version: nuxtVersion, }, imports: { autoImport: nuxt.options.imports.autoImport as boolean, @@ -70,31 +70,31 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { { as: '__buildAssetsURL', name: 'buildAssetsURL', - from: resolve(distDir, 'core/runtime/nitro/paths') + from: resolve(distDir, 'core/runtime/nitro/paths'), }, { as: '__publicAssetsURL', name: 'publicAssetsURL', - from: resolve(distDir, 'core/runtime/nitro/paths') + from: resolve(distDir, 'core/runtime/nitro/paths'), }, { // TODO: Remove after https://github.com/unjs/nitro/issues/1049 as: 'defineAppConfig', name: 'defineAppConfig', from: resolve(distDir, 'core/runtime/nitro/config'), - priority: -1 - } + priority: -1, + }, ], - exclude: [...excludePattern, /[\\/]\.git[\\/]/] + exclude: [...excludePattern, /[\\/]\.git[\\/]/], }, esbuild: { - options: { exclude: excludePattern } + options: { exclude: excludePattern }, }, analyze: !nuxt.options.test && nuxt.options.build.analyze && (nuxt.options.build.analyze === true || nuxt.options.build.analyze.enabled) ? { template: 'treemap', projectRoot: nuxt.options.rootDir, - filename: join(nuxt.options.analyzeDir, '{name}.html') + filename: join(nuxt.options.analyzeDir, '{name}.html'), } : false, scanDirs: nuxt.options._layers.map(layer => (layer.config.serverDir || layer.config.srcDir) && resolve(layer.cwd, layer.config.serverDir || resolve(layer.config.srcDir, 'server'))).filter(Boolean), @@ -106,10 +106,10 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { baseURL: nuxt.options.app.baseURL, virtual: { '#internal/nuxt.config.mjs': () => nuxt.vfs['#build/nuxt.config'], - '#spa-template': async () => `export const template = ${JSON.stringify(await spaLoadingTemplate(nuxt))}` + '#spa-template': async () => `export const template = ${JSON.stringify(await spaLoadingTemplate(nuxt))}`, }, routeRules: { - '/__nuxt_error': { cache: false } + '/__nuxt_error': { cache: false }, }, runtimeConfig: { ...nuxt.options.runtimeConfig, @@ -117,17 +117,17 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { ...nuxt.options.runtimeConfig.app, baseURL: nuxt.options.runtimeConfig.app.baseURL.startsWith('./') ? nuxt.options.runtimeConfig.app.baseURL.slice(1) - : nuxt.options.runtimeConfig.app.baseURL + : nuxt.options.runtimeConfig.app.baseURL, }, nitro: { envPrefix: 'NUXT_', // TODO: address upstream issue with defu types...? - ...nuxt.options.runtimeConfig.nitro satisfies RuntimeConfig['nitro'] as any - } + ...nuxt.options.runtimeConfig.nitro satisfies RuntimeConfig['nitro'] as any, + }, }, appConfig: nuxt.options.appConfig, appConfigFiles: nuxt.options._layers.map( - layer => resolve(layer.config.srcDir, 'app.config') + layer => resolve(layer.config.srcDir, 'app.config'), ), typescript: { strict: true, @@ -136,14 +136,14 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { tsConfig: { include: [ join(nuxt.options.buildDir, 'types/nitro-nuxt.d.ts'), - ...modules.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime/server')) + ...modules.map(m => join(relativeWithDot(nuxt.options.buildDir, m), 'runtime/server')), ], exclude: [ ...nuxt.options.modulesDir.map(m => relativeWithDot(nuxt.options.buildDir, m)), // nitro generate output: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/core/nitro.ts#L186 - relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, 'dist')) - ] - } + relativeWithDot(nuxt.options.buildDir, resolve(nuxt.options.rootDir, 'dist')), + ], + }, }, publicAssets: [ nuxt.options.dev @@ -151,17 +151,17 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { : { dir: join(nuxt.options.buildDir, 'dist/client', nuxt.options.app.buildAssetsDir), maxAge: 31536000 /* 1 year */, - baseURL: nuxt.options.app.buildAssetsDir + baseURL: nuxt.options.app.buildAssetsDir, }, ...nuxt.options._layers .map(layer => join(layer.config.srcDir, (layer.config.rootDir === nuxt.options.rootDir ? nuxt.options : layer.config).dir?.public || 'public')) .filter(dir => existsSync(dir)) - .map(dir => ({ dir })) + .map(dir => ({ dir })), ], prerender: { failOnError: true, concurrency: cpus().length * 4 || 4, - routes: ([] as string[]).concat(nuxt.options.generate.routes) + routes: ([] as string[]).concat(nuxt.options.generate.routes), }, sourceMap: nuxt.options.sourcemap.server, externals: { @@ -171,13 +171,13 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { : [ ...nuxt.options.experimental.externalVue ? [] : ['vue', '@vue/'], '@nuxt/', - nuxt.options.buildDir + nuxt.options.buildDir, ]), ...nuxt.options.build.transpile.filter((i): i is string => typeof i === 'string'), 'nuxt/dist', 'nuxt3/dist', 'nuxt-nightly/dist', - distDir + distDir, ], traceInclude: [ // force include files used in generated code from the runtime-compiler @@ -187,10 +187,10 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { const serverRendererPath = resolve(path, 'vue/server-renderer/index.js') if (existsSync(serverRendererPath)) { targets.push(serverRendererPath) } return targets - }, []) + }, []), ] - : [] - ] + : [], + ], }, alias: { // Vue 3 mocks @@ -201,7 +201,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { '@babel/parser': 'unenv/runtime/mock/proxy', '@vue/compiler-core': 'unenv/runtime/mock/proxy', '@vue/compiler-dom': 'unenv/runtime/mock/proxy', - '@vue/compiler-ssr': 'unenv/runtime/mock/proxy' + '@vue/compiler-ssr': 'unenv/runtime/mock/proxy', }, '@vue/devtools-api': 'vue-devtools-stub', @@ -209,7 +209,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { '#internal/nuxt/paths': resolve(distDir, 'core/runtime/nitro/paths'), // Nuxt aliases - ...nuxt.options.alias + ...nuxt.options.alias, }, replace: { 'process.env.NUXT_NO_SSR': nuxt.options.ssr === false, @@ -220,13 +220,13 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { 'process.env.NUXT_ASYNC_CONTEXT': !!nuxt.options.experimental.asyncContext, 'process.env.NUXT_SHARED_DATA': !!nuxt.options.experimental.sharedPrerenderData, 'process.dev': nuxt.options.dev, - __VUE_PROD_DEVTOOLS__: false + '__VUE_PROD_DEVTOOLS__': false, }, rollupConfig: { output: {}, - plugins: [] + plugins: [], }, - logLevel: logLevelMapReverse[nuxt.options.logLevel] + logLevel: logLevelMapReverse[nuxt.options.logLevel], } satisfies NitroConfig) // Resolve user-provided paths @@ -252,14 +252,14 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { { dir: join(tempDir, 'meta'), maxAge: 31536000 /* 1 year */, - baseURL: joinURL(manifestPrefix, 'meta') + baseURL: joinURL(manifestPrefix, 'meta'), }, // latest build { dir: tempDir, maxAge: 1, - baseURL: manifestPrefix - } + baseURL: manifestPrefix, + }, ) nuxt.options.alias['#app-manifest'] = join(tempDir, `meta/${buildId}.json`) @@ -308,7 +308,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { // Add pages prerendered but not covered by route rules const prerenderedRoutes = new Set() const routeRulesMatcher = toRouteMatcher( - createRadixRouter({ routes: routeRules }) + createRadixRouter({ routes: routeRules }), ) if (nitro._prerenderedRoutes?.length) { const payloadSuffix = nuxt.options.experimental.renderJsonPayloads ? '/_payload.json' : '/_payload.js' @@ -327,13 +327,13 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { id: buildId, timestamp: buildTimestamp, matcher: exportMatcher(routeRulesMatcher), - prerendered: nuxt.options.dev ? [] : [...prerenderedRoutes] + prerendered: nuxt.options.dev ? [] : [...prerenderedRoutes], } await fsp.mkdir(join(tempDir, 'meta'), { recursive: true }) await fsp.writeFile(join(tempDir, 'latest.json'), JSON.stringify({ id: buildId, - timestamp: buildTimestamp + timestamp: buildTimestamp, })) await fsp.writeFile(join(tempDir, `meta/${buildId}.json`), JSON.stringify(manifest)) }) @@ -362,7 +362,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { nitroConfig.handlers = nitroConfig.handlers || [] nitroConfig.handlers.push({ handler: resolve(distDir, 'core/runtime/nitro/no-ssr'), - middleware: true + middleware: true, }) } @@ -373,8 +373,8 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { ImportProtectionPlugin.rollup({ rootDir: nuxt.options.rootDir, patterns: nuxtImportProtections(nuxt, { isNitro: true }), - exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/] - }) + exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/], + }), ) // Extend nitro config with hook @@ -422,8 +422,8 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { 'internal:nuxt:prerender': { // TODO: resolve upstream where file URLs are not being resolved/inlined correctly driver: isWindows ? pathToFileURL(cacheDriverPath).href : cacheDriverPath, - base: cacheDir - } + base: cacheDir, + }, }) // Expose nitro to modules and kit @@ -446,12 +446,12 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { if (Array.isArray(config.resolve!.alias)) { config.resolve!.alias.push({ find: 'vue', - replacement: 'vue/dist/vue.esm-bundler' + replacement: 'vue/dist/vue.esm-bundler', }) } else { config.resolve!.alias = { ...config.resolve!.alias, - vue: 'vue/dist/vue.esm-bundler' + vue: 'vue/dist/vue.esm-bundler', } } } @@ -462,7 +462,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { if (Array.isArray(clientConfig!.resolve!.alias)) { clientConfig!.resolve!.alias.push({ name: 'vue', - alias: 'vue/dist/vue.esm-bundler' + alias: 'vue/dist/vue.esm-bundler', }) } else { clientConfig!.resolve!.alias!.vue = 'vue/dist/vue.esm-bundler' @@ -477,7 +477,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) { nitro.options.handlers.unshift({ route: '/__nuxt_error', lazy: true, - handler: resolve(distDir, 'core/runtime/nitro/renderer') + handler: resolve(distDir, 'core/runtime/nitro/renderer'), }) if (!nuxt.options.dev && nuxt.options.experimental.noVueServer) { diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index 03c151b638..06e962b211 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -10,13 +10,13 @@ import { readPackageJSON, resolvePackageJSON } from 'pkg-types' import escapeRE from 'escape-string-regexp' import fse from 'fs-extra' import { withoutLeadingSlash } from 'ufo' -/* eslint-disable import/no-restricted-paths */ + import defu from 'defu' import pagesModule from '../pages/module' import metaModule from '../head/module' import componentsModule from '../components/module' import importsModule from '../imports/module' -/* eslint-enable */ + import { distDir, pkgDir } from '../dirs' import { version } from '../../package.json' import { ImportProtectionPlugin, nuxtImportProtections } from './plugins/import-protection' @@ -46,18 +46,18 @@ export function createNuxt (options: NuxtOptions): Nuxt { ready: () => initNuxt(nuxt), close: () => Promise.resolve(hooks.callHook('close', nuxt)), vfs: {}, - apps: {} + apps: {}, } return nuxt } const nightlies = { - nitropack: 'nitropack-nightly', - h3: 'h3-nightly', - nuxt: 'nuxt-nightly', + 'nitropack': 'nitropack-nightly', + 'h3': 'h3-nightly', + 'nuxt': 'nuxt-nightly', '@nuxt/schema': '@nuxt/schema-nightly', - '@nuxt/kit': '@nuxt/kit-nightly' + '@nuxt/kit': '@nuxt/kit-nightly', } async function initNuxt (nuxt: Nuxt) { @@ -98,7 +98,7 @@ async function initNuxt (nuxt: Nuxt) { // Set nitro resolutions for types that might be obscured with shamefully-hoist=false nuxt.options.nitro.typescript = defu(nuxt.options.nitro.typescript, { - tsConfig: { compilerOptions: { paths: { ...paths } } } + tsConfig: { compilerOptions: { paths: { ...paths } } }, }) // Add nuxt types @@ -132,7 +132,7 @@ async function initNuxt (nuxt: Nuxt) { rootDir: nuxt.options.rootDir, // Exclude top-level resolutions by plugins exclude: [join(nuxt.options.srcDir, 'index.html')], - patterns: nuxtImportProtections(nuxt) + patterns: nuxtImportProtections(nuxt), } addVitePlugin(() => ImportProtectionPlugin.vite(config)) addWebpackPlugin(() => ImportProtectionPlugin.webpack(config)) @@ -147,7 +147,7 @@ async function initNuxt (nuxt: Nuxt) { dev: nuxt.options.dev, root: nuxt.options.srcDir, // skip top-level layer (user's project) as the aliases will already be correctly resolved - layers: nuxt.options._layers.slice(1) + layers: nuxt.options._layers.slice(1), })) addWebpackPlugin(() => LayerAliasingPlugin.webpack({ sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client, @@ -155,7 +155,7 @@ async function initNuxt (nuxt: Nuxt) { root: nuxt.options.srcDir, // skip top-level layer (user's project) as the aliases will already be correctly resolved layers: nuxt.options._layers.slice(1), - transform: true + transform: true, })) } @@ -165,8 +165,8 @@ async function initNuxt (nuxt: Nuxt) { sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client, transformerOptions: { ...nuxt.options.optimization.asyncTransforms, - helperModule: await tryResolveModule('unctx', nuxt.options.modulesDir) ?? 'unctx' - } + helperModule: await tryResolveModule('unctx', nuxt.options.modulesDir) ?? 'unctx', + }, } satisfies UnctxTransformPluginOptions addVitePlugin(() => UnctxTransformPlugin.vite(options)) addWebpackPlugin(() => UnctxTransformPlugin.webpack(options)) @@ -174,7 +174,7 @@ async function initNuxt (nuxt: Nuxt) { // Add composable tree-shaking optimisations const serverTreeShakeOptions: TreeShakeComposablesPluginOptions = { sourcemap: !!nuxt.options.sourcemap.server, - composables: nuxt.options.optimization.treeShake.composables.server + composables: nuxt.options.optimization.treeShake.composables.server, } if (Object.keys(serverTreeShakeOptions.composables).length) { addVitePlugin(() => TreeShakeComposablesPlugin.vite(serverTreeShakeOptions), { client: false }) @@ -182,7 +182,7 @@ async function initNuxt (nuxt: Nuxt) { } const clientTreeShakeOptions: TreeShakeComposablesPluginOptions = { sourcemap: !!nuxt.options.sourcemap.client, - composables: nuxt.options.optimization.treeShake.composables.client + composables: nuxt.options.optimization.treeShake.composables.client, } if (Object.keys(clientTreeShakeOptions.composables).length) { addVitePlugin(() => TreeShakeComposablesPlugin.vite(clientTreeShakeOptions), { server: false }) @@ -206,11 +206,11 @@ async function initNuxt (nuxt: Nuxt) { addServerPlugin(resolve(distDir, 'core/runtime/nitro/dev-server-logs')) nuxt.options.nitro = defu(nuxt.options.nitro, { externals: { - inline: [/#internal\/dev-server-logs-options/] + inline: [/#internal\/dev-server-logs-options/], }, virtual: { - '#internal/dev-server-logs-options': () => `export const rootDir = ${JSON.stringify(nuxt.options.rootDir)};` - } + '#internal/dev-server-logs-options': () => `export const rootDir = ${JSON.stringify(nuxt.options.rootDir)};`, + }, }) } @@ -236,7 +236,7 @@ async function initNuxt (nuxt: Nuxt) { // Transpile layers within node_modules nuxt.options.build.transpile.push( - ...nuxt.options._layers.filter(i => i.cwd.includes('node_modules')).map(i => i.cwd as string) + ...nuxt.options._layers.filter(i => i.cwd.includes('node_modules')).map(i => i.cwd as string), ) // Init user modules @@ -258,7 +258,7 @@ async function initNuxt (nuxt: Nuxt) { const modulesDir = (config.rootDir === nuxt.options.rootDir ? nuxt.options : config).dir?.modules || 'modules' const layerModules = await resolveFiles(config.srcDir, [ `${modulesDir}/*{${nuxt.options.extensions.join(',')}}`, - `${modulesDir}/*/index{${nuxt.options.extensions.join(',')}}` + `${modulesDir}/*/index{${nuxt.options.extensions.join(',')}}`, ]) for (const mod of layerModules) { watchedPaths.add(mod) @@ -275,55 +275,55 @@ async function initNuxt (nuxt: Nuxt) { addComponent({ name: 'NuxtWelcome', priority: 10, // built-in that we do not expect the user to override - filePath: (await tryResolveModule('@nuxt/ui-templates/templates/welcome.vue', nuxt.options.modulesDir))! + filePath: (await tryResolveModule('@nuxt/ui-templates/templates/welcome.vue', nuxt.options.modulesDir))!, }) addComponent({ name: 'NuxtLayout', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/nuxt-layout') + filePath: resolve(nuxt.options.appDir, 'components/nuxt-layout'), }) // Add addComponent({ name: 'NuxtErrorBoundary', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/nuxt-error-boundary') + filePath: resolve(nuxt.options.appDir, 'components/nuxt-error-boundary'), }) // Add addComponent({ name: 'ClientOnly', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/client-only') + filePath: resolve(nuxt.options.appDir, 'components/client-only'), }) // Add addComponent({ name: 'DevOnly', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/dev-only') + filePath: resolve(nuxt.options.appDir, 'components/dev-only'), }) // Add addComponent({ name: 'ServerPlaceholder', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/server-placeholder') + filePath: resolve(nuxt.options.appDir, 'components/server-placeholder'), }) // Add addComponent({ name: 'NuxtLink', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/nuxt-link') + filePath: resolve(nuxt.options.appDir, 'components/nuxt-link'), }) // Add addComponent({ name: 'NuxtLoadingIndicator', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/nuxt-loading-indicator') + filePath: resolve(nuxt.options.appDir, 'components/nuxt-loading-indicator'), }) // Add @@ -333,7 +333,7 @@ async function initNuxt (nuxt: Nuxt) { _raw: true, priority: 10, // built-in that we do not expect the user to override filePath: resolve(nuxt.options.appDir, 'components/client-fallback.client'), - mode: 'client' + mode: 'client', }) addComponent({ @@ -341,7 +341,7 @@ async function initNuxt (nuxt: Nuxt) { _raw: true, priority: 10, // built-in that we do not expect the user to override filePath: resolve(nuxt.options.appDir, 'components/client-fallback.server'), - mode: 'server' + mode: 'server', }) } @@ -350,7 +350,7 @@ async function initNuxt (nuxt: Nuxt) { addComponent({ name: 'NuxtIsland', priority: 10, // built-in that we do not expect the user to override - filePath: resolve(nuxt.options.appDir, 'components/nuxt-island') + filePath: resolve(nuxt.options.appDir, 'components/nuxt-island'), }) if (!nuxt.options.ssr && nuxt.options.experimental.componentIslands !== 'auto') { @@ -368,7 +368,7 @@ async function initNuxt (nuxt: Nuxt) { priority: -1, filePath: resolve(nuxt.options.appDir, 'components/nuxt-stubs'), // @ts-expect-error TODO: refactor to nuxi - _internal_install: '@nuxt/image' + _internal_install: '@nuxt/image', }) } @@ -414,10 +414,10 @@ async function initNuxt (nuxt: Nuxt) { '@nuxt/vite-builder': 'vite/client', '@nuxt/webpack-builder': 'webpack/module', // simpler overrides from `typescript.builder` for better DX - vite: 'vite/client', - webpack: 'webpack/module', + 'vite': 'vite/client', + 'webpack': 'webpack/module', // default 'merged' builder environment for module authors - shared: '@nuxt/schema/builder-env' + 'shared': '@nuxt/schema/builder-env', } nuxt.hook('prepare:types', ({ references }) => { @@ -451,7 +451,7 @@ async function initNuxt (nuxt: Nuxt) { addRouteMiddleware({ name: 'manifest-route-rule', path: resolve(nuxt.options.appDir, 'middleware/manifest-route-rule'), - global: true + global: true, }) addPlugin(resolve(nuxt.options.appDir, 'plugins/check-outdated-build.client')) @@ -535,7 +535,7 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { if (options.builder === '@nuxt/webpack-builder') { if (!await import('./features').then(r => r.ensurePackageInstalled('@nuxt/webpack-builder', { rootDir: options.rootDir, - searchPaths: options.modulesDir + searchPaths: options.modulesDir, }))) { logger.warn('Failed to install `@nuxt/webpack-builder`, please install it manually, or change the `builder` option to vite in `nuxt.config`') } @@ -547,15 +547,15 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise { transform: { include: options._layers .filter(i => i.cwd && i.cwd.includes('node_modules')) - .map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd!.split('node_modules/').pop()!)}(\\/|$)(?!node_modules\\/)`)) - } + .map(i => new RegExp(`(^|\\/)${escapeRE(i.cwd!.split('node_modules/').pop()!)}(\\/|$)(?!node_modules\\/)`)), + }, }]) options._modules.push(schemaModule) options.modulesDir.push(resolve(options.workspaceDir, 'node_modules')) options.modulesDir.push(resolve(pkgDir, 'node_modules')) options.build.transpile.push( '@nuxt/ui-templates', // this exposes vue SFCs - 'std-env' // we need to statically replace process.env when used in runtime code + 'std-env', // we need to statically replace process.env when used in runtime code ) options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi') options.alias['@vue/composition-api'] = resolve(options.appDir, 'compat/capi') diff --git a/packages/nuxt/src/core/plugins/async-context.ts b/packages/nuxt/src/core/plugins/async-context.ts index fd997070dd..28f71c9c73 100644 --- a/packages/nuxt/src/core/plugins/async-context.ts +++ b/packages/nuxt/src/core/plugins/async-context.ts @@ -21,9 +21,9 @@ export const AsyncContextInjectionPlugin = (nuxt: Nuxt) => createUnplugin(() => code: s.toString(), map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/dev-only.ts b/packages/nuxt/src/core/plugins/dev-only.ts index 6adc7a375a..35437ad777 100644 --- a/packages/nuxt/src/core/plugins/dev-only.ts +++ b/packages/nuxt/src/core/plugins/dev-only.ts @@ -33,9 +33,9 @@ export const DevOnlyPlugin = createUnplugin((options: DevOnlyPluginOptions) => { code: s.toString(), map: options.sourcemap ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/import-protection.ts b/packages/nuxt/src/core/plugins/import-protection.ts index f9f1578d23..cd740d9828 100644 --- a/packages/nuxt/src/core/plugins/import-protection.ts +++ b/packages/nuxt/src/core/plugins/import-protection.ts @@ -18,12 +18,12 @@ export const nuxtImportProtections = (nuxt: { options: NuxtOptions }, options: { patterns.push([ /^(nuxt|nuxt3|nuxt-nightly)$/, - '`nuxt`, `nuxt3` or `nuxt-nightly` cannot be imported directly.' + (options.isNitro ? '' : ' Instead, import runtime Nuxt composables from `#app` or `#imports`.') + '`nuxt`, `nuxt3` or `nuxt-nightly` cannot be imported directly.' + (options.isNitro ? '' : ' Instead, import runtime Nuxt composables from `#app` or `#imports`.'), ]) patterns.push([ /^((|~|~~|@|@@)\/)?nuxt\.config(\.|$)/, - 'Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module.' + 'Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module.', ]) patterns.push([/(^|node_modules\/)@vue\/composition-api/]) @@ -31,7 +31,7 @@ export const nuxtImportProtections = (nuxt: { options: NuxtOptions }, options: { for (const mod of nuxt.options.modules.filter(m => typeof m === 'string')) { patterns.push([ new RegExp(`^${escapeRE(mod as string)}$`), - 'Importing directly from module entry-points is not allowed.' + 'Importing directly from module entry-points is not allowed.', ]) } @@ -48,7 +48,7 @@ export const nuxtImportProtections = (nuxt: { options: NuxtOptions }, options: { if (!options.isNitro) { patterns.push([ new RegExp(escapeRE(relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, nuxt.options.serverDir || 'server'))) + '\\/(api|routes|middleware|plugins)\\/'), - 'Importing from server is not allowed in the Vue part of your app.' + 'Importing from server is not allowed in the Vue part of your app.', ]) } @@ -88,6 +88,6 @@ export const ImportProtectionPlugin = createUnplugin(function (options: ImportPr return _require.resolve('unenv/runtime/mock/proxy') } return null - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/layer-aliasing.ts b/packages/nuxt/src/core/plugins/layer-aliasing.ts index 250bdcc50b..852cb0f281 100644 --- a/packages/nuxt/src/core/plugins/layer-aliasing.ts +++ b/packages/nuxt/src/core/plugins/layer-aliasing.ts @@ -25,7 +25,7 @@ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions '~': layer.config?.alias?.['~'] || srcDir, '@': layer.config?.alias?.['@'] || srcDir, '~~': layer.config?.alias?.['~~'] || rootDir, - '@@': layer.config?.alias?.['@@'] || rootDir + '@@': layer.config?.alias?.['@@'] || rootDir, } } const layers = Object.keys(aliases).sort((a, b) => b.length - a.length) @@ -46,8 +46,8 @@ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions if (resolvedId !== id) { return await this.resolve(resolvedId, importer, { skipSelf: true }) } - } - } + }, + }, }, // webpack-only transform @@ -69,9 +69,9 @@ export const LayerAliasingPlugin = createUnplugin((options: LayerAliasingOptions if (s.hasChanged()) { return { code: s.toString(), - map: options.sourcemap ? s.generateMap({ hires: true }) : undefined + map: options.sourcemap ? s.generateMap({ hires: true }) : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/plugin-metadata.ts b/packages/nuxt/src/core/plugins/plugin-metadata.ts index 596372f83f..331c5b8d9d 100644 --- a/packages/nuxt/src/core/plugins/plugin-metadata.ts +++ b/packages/nuxt/src/core/plugins/plugin-metadata.ts @@ -11,7 +11,6 @@ import MagicString from 'magic-string' import { normalize } from 'pathe' import { logger } from '@nuxt/kit' -// eslint-disable-next-line import/no-restricted-paths import type { ObjectPlugin, PluginMeta } from '#app' const internalOrderMap = { @@ -32,13 +31,13 @@ const internalOrderMap = { // +20: post (user) <-- post mapped to this 'user-post': 20, // +30: post-all (nuxt) - 'nuxt-post-all': 30 + 'nuxt-post-all': 30, } export const orderMap: Record, number> = { pre: internalOrderMap['user-pre'], default: internalOrderMap['user-default'], - post: internalOrderMap['user-post'] + post: internalOrderMap['user-post'], } const metaCache: Record> = {} @@ -50,7 +49,7 @@ export async function extractMetadata (code: string, loader = 'ts' as 'ts' | 'ts const js = await transform(code, { loader }) walk(parse(js.code, { sourceType: 'module', - ecmaVersion: 'latest' + ecmaVersion: 'latest', }) as Node, { enter (_node) { if (_node.type !== 'CallExpression' || (_node as CallExpression).callee.type !== 'Identifier') { return } @@ -77,7 +76,7 @@ export async function extractMetadata (code: string, loader = 'ts' as 'ts' | 'ts meta.order = meta.order || orderMap[meta.enforce || 'default'] || orderMap.default delete meta.enforce - } + }, }) metaCache[code] = meta return meta as Omit @@ -88,7 +87,7 @@ const keys: Record = { name: 'name', order: 'order', enforce: 'enforce', - dependsOn: 'dependsOn' + dependsOn: 'dependsOn', } function isMetadataKey (key: string): key is PluginMetaKey { return key in keys @@ -134,7 +133,7 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { s.overwrite(0, code.length, 'export default () => {}') return { code: s.toString(), - map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null + map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null, } } @@ -144,7 +143,7 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { try { walk(this.parse(code, { sourceType: 'module', - ecmaVersion: 'latest' + ecmaVersion: 'latest', }) as Node, { enter (_node) { if (_node.type === 'ImportSpecifier' && (_node.imported.name === 'defineNuxtPlugin' || _node.imported.name === 'definePayloadPlugin')) { @@ -193,7 +192,7 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { } } } - } + }, }) } catch (e) { logger.error(e) @@ -207,9 +206,9 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => { if (s.hasChanged()) { return { code: s.toString(), - map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null + map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null, } } - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/resolve-deep-imports.ts b/packages/nuxt/src/core/plugins/resolve-deep-imports.ts index 3bf20e1983..b965141196 100644 --- a/packages/nuxt/src/core/plugins/resolve-deep-imports.ts +++ b/packages/nuxt/src/core/plugins/resolve-deep-imports.ts @@ -21,11 +21,11 @@ export function resolveDeepImportsPlugin (nuxt: Nuxt): Plugin { return await this.resolve?.(id, dir || pkgDir, { skipSelf: true }) ?? await resolvePath(id, { url: [dir || pkgDir, ...nuxt.options.modulesDir], // TODO: respect nitro runtime conditions - conditions: options.ssr ? ['node', 'import', 'require'] : ['import', 'require'] + conditions: options.ssr ? ['node', 'import', 'require'] : ['import', 'require'], }).catch(() => { logger.debug('Could not resolve id', id, importer) return null }) - } + }, } } diff --git a/packages/nuxt/src/core/plugins/tree-shake.ts b/packages/nuxt/src/core/plugins/tree-shake.ts index f6e3427e4a..950ec8edbc 100644 --- a/packages/nuxt/src/core/plugins/tree-shake.ts +++ b/packages/nuxt/src/core/plugins/tree-shake.ts @@ -40,9 +40,9 @@ export const TreeShakeComposablesPlugin = createUnplugin((options: TreeShakeComp code: s.toString(), map: options.sourcemap ? s.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/core/plugins/unctx.ts b/packages/nuxt/src/core/plugins/unctx.ts index 5a0ebe782a..f935adc112 100644 --- a/packages/nuxt/src/core/plugins/unctx.ts +++ b/packages/nuxt/src/core/plugins/unctx.ts @@ -28,9 +28,9 @@ export const UnctxTransformPlugin = createUnplugin((options: UnctxTransformPlugi code: TRANSFORM_MARKER + result.code, map: options.sourcemap ? result.magicString.generateMap({ hires: true }) - : undefined + : undefined, } } - } + }, } }) diff --git a/packages/nuxt/src/core/runtime/nitro/cache-driver.ts b/packages/nuxt/src/core/runtime/nitro/cache-driver.ts index b76153a859..60587fa21f 100644 --- a/packages/nuxt/src/core/runtime/nitro/cache-driver.ts +++ b/packages/nuxt/src/core/runtime/nitro/cache-driver.ts @@ -13,7 +13,7 @@ export default defineDriver((opts: { base: string }) => { async setItem (key, value, opts) { await Promise.all([ fs.setItem(normalizeFsKey(key), value, opts), - lru.setItem(key, value, opts) + lru.setItem(key, value, opts), ]) }, async hasItem (key, opts) { @@ -21,6 +21,6 @@ export default defineDriver((opts: { base: string }) => { }, async getItem (key, opts) { return await lru.getItem(key, opts) || await fs.getItem(normalizeFsKey(key), opts) - } + }, } }) diff --git a/packages/nuxt/src/core/runtime/nitro/dev-server-logs.ts b/packages/nuxt/src/core/runtime/nitro/dev-server-logs.ts index 11e6a3be28..194ca2dc38 100644 --- a/packages/nuxt/src/core/runtime/nitro/dev-server-logs.ts +++ b/packages/nuxt/src/core/runtime/nitro/dev-server-logs.ts @@ -36,7 +36,7 @@ export default (nitroApp: NitroApp) => { // Pass along filename to allow the client to display more info about where log comes from filename: extractFilenameFromStack(stack), // Clean up file names in stack trace - stack: normalizeFilenames(stack) + stack: normalizeFilenames(stack), } // retain log to be include in the next render @@ -84,7 +84,7 @@ function onConsoleLog (callback: (log: LogObject) => void) { consola.addReporter({ log (logObj) { callback(logObj) - } + }, }) consola.wrapConsole() } diff --git a/packages/nuxt/src/core/runtime/nitro/error.ts b/packages/nuxt/src/core/runtime/nitro/error.ts index 731699e94d..03c030371c 100644 --- a/packages/nuxt/src/core/runtime/nitro/error.ts +++ b/packages/nuxt/src/core/runtime/nitro/error.ts @@ -21,7 +21,7 @@ export default async function errorhandler (error: H3Error, ? `
${stack.map(i => `${i.text}`).join('\n')}
` : '', // TODO: check and validate error.data for serialisation into query - data: error.data as any + data: error.data as any, } satisfies Partial & { url: string } // Console output @@ -31,7 +31,7 @@ export default async function errorhandler (error: H3Error, '[request error]', error.unhandled && '[unhandled]', error.fatal && '[fatal]', - Number(errorObject.statusCode) !== 200 && `[${errorObject.statusCode}]` + Number(errorObject.statusCode) !== 200 && `[${errorObject.statusCode}]`, ].filter(Boolean).join(' ') console.error(tags, errorObject.message + '\n' + stack.map(l => ' ' + l.text).join(' \n')) } @@ -60,8 +60,8 @@ export default async function errorhandler (error: H3Error, withQuery(joinURL(useRuntimeConfig(event).app.baseURL, '/__nuxt_error'), errorObject), { headers: { ...reqHeaders, 'x-nuxt-error': 'true' }, - redirect: 'manual' - } + redirect: 'manual', + }, ).catch(() => null) // Fallback to static rendered error page diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 1b367f432d..4db7ead879 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -4,7 +4,7 @@ import { getPrefetchLinks, getPreloadLinks, getRequestDependencies, - renderResourceHeaders + renderResourceHeaders, } from 'vue-bundle-renderer/runtime' import type { RenderResponse } from 'nitropack' import type { Manifest } from 'vite' @@ -26,7 +26,7 @@ import { useNitroApp } from '#internal/nitro/app' // @ts-expect-error virtual file import unheadPlugins from '#internal/unhead-plugins.mjs' -// eslint-disable-next-line import/no-restricted-paths + import type { NuxtPayload, NuxtSSRContext } from '#app' // @ts-expect-error virtual file import { appHead, appRootId, appRootTag, appTeleportId, appTeleportTag, componentIslands } from '#internal/nuxt.config.mjs' @@ -88,9 +88,9 @@ export interface NuxtIslandResponse { } export interface NuxtRenderResponse { - body: string, - statusCode: number, - statusMessage?: string, + body: string + statusCode: number + statusMessage?: string headers: Record } @@ -103,7 +103,7 @@ const getClientManifest: () => Promise = () => import('#build/dist/ser const getEntryIds: () => Promise = () => getClientManifest().then(r => Object.values(r).filter(r => // @ts-expect-error internal key set by CSS inlining configuration - r._globalCSS + r._globalCSS, ).map(r => r.src!)) // @ts-expect-error file will be produced after app build @@ -125,7 +125,7 @@ const getSSRRenderer = lazyCachedFunction(async () => { const options = { manifest, renderToString, - buildAssetsURL + buildAssetsURL, } // Create renderer const renderer = createRenderer(createSSRApp, options) @@ -154,7 +154,7 @@ const getSPARenderer = lazyCachedFunction(async () => { const options = { manifest, renderToString: () => spaTemplate, - buildAssetsURL + buildAssetsURL, } // Create SPA renderer and cache the result for all requests const renderer = createRenderer(() => () => {}, options) @@ -168,18 +168,18 @@ const getSPARenderer = lazyCachedFunction(async () => { serverRendered: false, data: {}, state: {}, - once: new Set() + once: new Set(), } ssrContext.config = { public: config.public, - app: config.app + app: config.app, } return Promise.resolve(result) } return { rendererContext: renderer.rendererContext, - renderToString + renderToString, } }) @@ -197,11 +197,11 @@ const sharedPrerenderCache = import.meta.prerender && process.env.NUXT_SHARED_DA }, async set (key: string, value: Promise): Promise { sharedPrerenderKeys.add(key) - sharedPrerenderPromises!.set(key, value) - useStorage('internal:nuxt:prerender:shared').setItem(key, await value as any) + sharedPrerenderPromises!.set(key, value) + useStorage('internal:nuxt:prerender:shared').setItem(key, await value as any) // free up memory after the promise is resolved - .finally(() => sharedPrerenderPromises!.delete(key)) - } + .finally(() => sharedPrerenderPromises!.delete(key)) + }, } : null @@ -227,7 +227,7 @@ async function getIslandContext (event: H3Event): Promise { name: componentName, props: destr(context.props) || {}, slots: {}, - components: {} + components: {}, } return ctx @@ -254,13 +254,13 @@ export default defineRenderHandler(async (event): Promise subscription.unsubscribe()) } @@ -78,11 +78,11 @@ export default defineNuxtModule({ } const filesToWatch = await Promise.all(nuxt.options._layers.map(layer => - resolver.resolve(layer.config.rootDir, 'nuxt.schema.*') + resolver.resolve(layer.config.rootDir, 'nuxt.schema.*'), )) const watcher = chokidar.watch(filesToWatch, { ...nuxt.options.watchers.chokidar, - ignoreInitial: true + ignoreInitial: true, }) watcher.on('all', onChange) nuxt.hook('close', () => watcher.close()) @@ -108,7 +108,7 @@ export default defineNuxtModule({ logger.warn( 'Unable to load schema from', filePath, - err + err, ) continue } @@ -121,7 +121,7 @@ export default defineNuxtModule({ // Resolve and merge schemas const schemas = await Promise.all( - schemaDefs.map(schemaDef => resolveUntypedSchema(schemaDef)) + schemaDefs.map(schemaDef => resolveUntypedSchema(schemaDef)), ) // Merge after normalization @@ -140,13 +140,13 @@ export default defineNuxtModule({ await writeFile( resolve(nuxt.options.buildDir, 'schema/nuxt.schema.json'), JSON.stringify(schema, null, 2), - 'utf8' + 'utf8', ) const _types = generateTypes(schema, { addExport: true, interfaceName: 'NuxtCustomSchema', partial: true, - allowExtraKeys: false + allowExtraKeys: false, }) const types = _types + @@ -168,10 +168,10 @@ declare module 'nuxt/schema' { ` const typesPath = resolve( nuxt.options.buildDir, - 'schema/nuxt.schema.d.ts' + 'schema/nuxt.schema.d.ts', ) await writeFile(typesPath, types, 'utf8') await nuxt.hooks.callHook('schema:written') } - } + }, }) diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 49c9f7c6bd..2234e60dca 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -23,37 +23,37 @@ export const vueShim: NuxtTemplate = { ' import { DefineComponent } from \'vue\'', ' const component: DefineComponent<{}, {}, any>', ' export default component', - '}' + '}', ].join('\n') - } + }, } // TODO: Use an alias export const appComponentTemplate: NuxtTemplate = { filename: 'app-component.mjs', - getContents: ctx => genExport(ctx.app.mainComponent!, ['default']) + getContents: ctx => genExport(ctx.app.mainComponent!, ['default']), } // TODO: Use an alias export const rootComponentTemplate: NuxtTemplate = { filename: 'root-component.mjs', // TODO: fix upstream in vite - this ensures that vite generates a module graph for islands // but should not be necessary (and has a warmup performance cost). See https://github.com/nuxt/nuxt/pull/24584. - getContents: ctx => (ctx.nuxt.options.dev ? "import '#build/components.islands.mjs';\n" : '') + genExport(ctx.app.rootComponent!, ['default']) + getContents: ctx => (ctx.nuxt.options.dev ? 'import \'#build/components.islands.mjs\';\n' : '') + genExport(ctx.app.rootComponent!, ['default']), } // TODO: Use an alias export const errorComponentTemplate: NuxtTemplate = { filename: 'error-component.mjs', - getContents: ctx => genExport(ctx.app.errorComponent!, ['default']) + getContents: ctx => genExport(ctx.app.errorComponent!, ['default']), } // TODO: Use an alias export const testComponentWrapperTemplate: NuxtTemplate = { filename: 'test-component-wrapper.mjs', - getContents: ctx => genExport(resolve(ctx.nuxt.options.appDir, 'components/test-component-wrapper'), ['default']) + getContents: ctx => genExport(resolve(ctx.nuxt.options.appDir, 'components/test-component-wrapper'), ['default']), } export const cssTemplate: NuxtTemplate = { filename: 'css.mjs', - getContents: ctx => ctx.nuxt.options.css.map(i => genImport(i)).join('\n') + getContents: ctx => ctx.nuxt.options.css.map(i => genImport(i)).join('\n'), } export const clientPluginTemplate: NuxtTemplate = { @@ -71,9 +71,9 @@ export const clientPluginTemplate: NuxtTemplate = { } return [ ...imports, - `export default ${genArrayFromRaw(exports)}` + `export default ${genArrayFromRaw(exports)}`, ].join('\n') - } + }, } export const serverPluginTemplate: NuxtTemplate = { @@ -91,9 +91,9 @@ export const serverPluginTemplate: NuxtTemplate = { } return [ ...imports, - `export default ${genArrayFromRaw(exports)}` + `export default ${genArrayFromRaw(exports)}`, ].join('\n') - } + }, } export const pluginsDeclaration: NuxtTemplate = { @@ -136,7 +136,7 @@ declare module 'vue' { export { } ` - } + }, } const adHocModules = ['router', 'pages', 'imports', 'meta', 'components', 'nuxt-config-schema'] @@ -145,7 +145,7 @@ export const schemaTemplate: NuxtTemplate = { getContents: async ({ nuxt }) => { const moduleInfo = nuxt.options._installedModules.map(m => ({ ...m.meta, - importName: m.entryPath || m.meta?.name + importName: m.entryPath || m.meta?.name, })).filter(m => m.configKey && m.name && !adHocModules.includes(m.name)) const relativeRoot = relative(resolve(nuxt.options.buildDir, 'types'), nuxt.options.rootDir) @@ -158,11 +158,11 @@ export const schemaTemplate: NuxtTemplate = { } } return [ - "import { NuxtModule, RuntimeConfig } from 'nuxt/schema'", - "declare module 'nuxt/schema' {", + 'import { NuxtModule, RuntimeConfig } from \'nuxt/schema\'', + 'declare module \'nuxt/schema\' {', ' interface NuxtConfig {', ...modules.map(([configKey, importName]) => - ` [${configKey}]?: typeof ${genDynamicImport(importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record` + ` [${configKey}]?: typeof ${genDynamicImport(importName, { wrapper: false })}.default extends NuxtModule ? Partial : Record`, ), modules.length > 0 ? ` modules?: (undefined | null | false | NuxtModule | string | [NuxtModule | string, Record] | ${modules.map(([configKey, importName]) => `[${genString(importName)}, Exclude]`).join(' | ')})[],` : '', ' }', @@ -172,7 +172,7 @@ export const schemaTemplate: NuxtTemplate = { addExport: false, addDefaults: false, allowExtraKeys: false, - indentation: 2 + indentation: 2, }), generateTypes(await resolveSchema(nuxt.options.runtimeConfig.public as Record), { @@ -180,16 +180,16 @@ export const schemaTemplate: NuxtTemplate = { addExport: false, addDefaults: false, allowExtraKeys: false, - indentation: 2 + indentation: 2, }), '}', `declare module 'vue' { interface ComponentCustomProperties { $config: RuntimeConfig } - }` + }`, ].join('\n') - } + }, } // Add layouts template @@ -200,9 +200,9 @@ export const layoutTemplate: NuxtTemplate = { return [name, genDynamicImport(file, { interopDefault: true })] })) return [ - `export default ${layoutsObject}` + `export default ${layoutsObject}`, ].join('\n') - } + }, } // Add middleware template @@ -215,9 +215,9 @@ export const middlewareTemplate: NuxtTemplate = { return [ ...globalMiddleware.map(mw => genImport(mw.path, genSafeVariableName(mw.name))), `export const globalMiddleware = ${genArrayFromRaw(globalMiddleware.map(mw => genSafeVariableName(mw.name)))}`, - `export const namedMiddleware = ${namedMiddlewareObject}` + `export const namedMiddleware = ${namedMiddlewareObject}`, ].join('\n') - } + }, } export const nitroSchemaTemplate: NuxtTemplate = { @@ -253,14 +253,14 @@ declare module 'nitropack' { } } ` - } + }, } export const clientConfigTemplate: NuxtTemplate = { filename: 'nitro.client.mjs', getContents: () => ` export const useRuntimeConfig = () => window?.__NUXT__?.config || {} -` +`, } export const appConfigDeclarationTemplate: NuxtTemplate = { @@ -296,7 +296,7 @@ declare module '@nuxt/schema' { interface AppConfig extends MergedAppConfig { } } ` - } + }, } export const appConfigTemplate: NuxtTemplate = { @@ -320,7 +320,7 @@ ${app.configs.map((id: string, index: number) => `import ${`cfg${index}`} from $ export default /*@__PURE__*/ defuFn(${app.configs.map((_id: string, index: number) => `cfg${index}`).concat(['inlineConfig']).join(', ')}) ` - } + }, } export const publicPathTemplate: NuxtTemplate = { @@ -348,9 +348,9 @@ export const publicPathTemplate: NuxtTemplate = { 'if (import.meta.client) {', ' globalThis.__buildAssetsURL = buildAssetsURL', ' globalThis.__publicAssetsURL = publicAssetsURL', - '}' + '}', ].filter(Boolean).join('\n') - } + }, } export const dollarFetchTemplate: NuxtTemplate = { @@ -358,14 +358,14 @@ export const dollarFetchTemplate: NuxtTemplate = { getContents () { return [ 'import { $fetch } from \'ofetch\'', - "import { baseURL } from '#internal/nuxt/paths'", + 'import { baseURL } from \'#internal/nuxt/paths\'', 'if (!globalThis.$fetch) {', ' globalThis.$fetch = $fetch.create({', ' baseURL: baseURL()', ' })', - '}' + '}', ].join('\n') - } + }, } // Allow direct access to specific exposed nuxt.config @@ -375,7 +375,7 @@ export const nuxtConfigTemplate: NuxtTemplate = { const fetchDefaults = { ...ctx.nuxt.options.experimental.defaults.useFetch, baseURL: undefined, - headers: undefined + headers: undefined, } const shouldEnableComponentIslands = ctx.nuxt.options.experimental.componentIslands && ( ctx.nuxt.options.dev || ctx.nuxt.options.experimental.componentIslands !== 'auto' || ctx.app.pages?.some(p => p.mode === 'server') || ctx.app.components?.some(c => c.mode === 'server' && !ctx.app.components.some(other => other.pascalName === c.pascalName && other.mode === 'client')) @@ -396,7 +396,7 @@ export const nuxtConfigTemplate: NuxtTemplate = { `export const asyncDataDefaults = ${JSON.stringify(ctx.nuxt.options.experimental.defaults.useAsyncData)}`, `export const fetchDefaults = ${JSON.stringify(fetchDefaults)}`, `export const vueAppRootContainer = ${ctx.nuxt.options.app.rootId ? `'#${ctx.nuxt.options.app.rootId}'` : `'body > ${ctx.nuxt.options.app.rootTag}'`}`, - `export const viewTransition = ${ctx.nuxt.options.experimental.viewTransition}` + `export const viewTransition = ${ctx.nuxt.options.experimental.viewTransition}`, ].join('\n\n') - } + }, } diff --git a/packages/nuxt/src/head/module.ts b/packages/nuxt/src/head/module.ts index 646f206aa1..c254d01037 100644 --- a/packages/nuxt/src/head/module.ts +++ b/packages/nuxt/src/head/module.ts @@ -6,7 +6,7 @@ const components = ['NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head' export default defineNuxtModule({ meta: { - name: 'meta' + name: 'meta', }, async setup (options, nuxt) { const runtimeDir = resolve(distDir, 'head/runtime') @@ -24,14 +24,14 @@ export default defineNuxtModule({ // built-in that we do not expect the user to override priority: 10, // kebab case version of these tags is not valid - kebabName: componentName + kebabName: componentName, }) } // allow @unhead/vue server composables to be tree-shaken from the client bundle if (!nuxt.options.dev) { nuxt.options.optimization.treeShake.composables.client['@unhead/vue'] = [ - 'useServerHead', 'useServerSeoMeta', 'useServerHeadSafe' + 'useServerHead', 'useServerSeoMeta', 'useServerHeadSafe', ] } @@ -45,8 +45,8 @@ export default defineNuxtModule({ 'useHeadSafe', 'useServerHead', 'useServerSeoMeta', - 'useServerHeadSafe' - ] + 'useServerHeadSafe', + ], }) // Opt-out feature allowing dependencies using @vueuse/head to work @@ -65,7 +65,7 @@ export default defineNuxtModule({ } return `import { CapoPlugin } from ${JSON.stringify(unheadVue)}; export default import.meta.server ? [CapoPlugin({ track: true })] : [];` - } + }, }) // template is only exposed in nuxt context, expose in nitro context as well @@ -75,5 +75,5 @@ export default import.meta.server ? [CapoPlugin({ track: true })] : [];` // Add library-specific plugin addPlugin({ src: resolve(runtimeDir, 'plugins/unhead') }) - } + }, }) diff --git a/packages/nuxt/src/head/runtime/components.ts b/packages/nuxt/src/head/runtime/components.ts index f2bbfe2261..7c3f4b8140 100644 --- a/packages/nuxt/src/head/runtime/components.ts +++ b/packages/nuxt/src/head/runtime/components.ts @@ -1,4 +1,3 @@ -/* eslint-disable vue/multi-word-component-names */ import { defineComponent } from 'vue' import type { PropType, SetupContext } from 'vue' import { useHead } from '@unhead/vue' @@ -9,7 +8,7 @@ import type { LinkRelationship, Props, ReferrerPolicy, - Target + Target, } from './types' const removeUndefinedProps = (props: Props) => { @@ -33,24 +32,24 @@ const globalProps = { autocapitalize: String, autofocus: { type: Boolean, - default: undefined + default: undefined, }, class: [String, Object, Array], contenteditable: { type: Boolean, - default: undefined + default: undefined, }, contextmenu: String, dir: String, draggable: { type: Boolean, - default: undefined + default: undefined, }, enterkeyhint: String, exportparts: String, hidden: { type: Boolean, - default: undefined + default: undefined, }, id: String, inputmode: String, @@ -66,12 +65,12 @@ const globalProps = { slot: String, spellcheck: { type: Boolean, - default: undefined + default: undefined, }, style: String, tabindex: String, title: String, - translate: String + translate: String, } //