Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	docs/1.getting-started/12.upgrade.md
#	docs/2.guide/3.going-further/1.experimental-features.md
#	docs/3.api/3.utils/navigate-to.md
  • Loading branch information
Ivan Bochkarev committed Oct 23, 2024
2 parents a4a9f5b + c69f366 commit ba6cdba
Show file tree
Hide file tree
Showing 76 changed files with 1,345 additions and 1,154 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:lts@sha256:fffa89e023a3351904c04284029105d9e2ac7020886d683775a298569591e5bb
FROM node:lts@sha256:a5e0ed56f2c20b9689e0f7dd498cac7e08d2a3a283e92d9304e7b9b83e3c6ff3

RUN apt-get update && \
apt-get install -fy libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdbus-1-3 libdrm2 libxkbcommon0 libatspi2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 && \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: pnpm build

- name: Run benchmarks
uses: CodSpeedHQ/action@ab07afd34cbbb7a1306e8d14b7cc44e029eee37a # v3.0.0
uses: CodSpeedHQ/action@b587655f756aab640e742fec141261bc6f0a569d # v3.0.1
with:
run: pnpm vitest bench
token: ${{ secrets.CODSPEED_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Initialize CodeQL
uses: github/codeql-action/init@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/init@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
config: |
paths:
Expand All @@ -91,7 +91,7 @@ jobs:
queries: +security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/analyze@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
with:
category: "/language:javascript-typescript"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: 'Dependency Review'
uses: actions/dependency-review-action@5a2ce3f5b92ee19cbb1541a4984c76d921601d7c # v4.3.4
uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5
2 changes: 1 addition & 1 deletion .github/workflows/docs-check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
# Cache lychee results (e.g. to avoid hitting rate limits)
- name: Restore lychee cache
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: .lycheecache
key: cache-lychee-${{ github.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@c36620d31ac7c881962c3d9dd939c40ec9434f2b # v3.26.12
uses: github/codeql-action/upload-sarif@662472033e021d55d94146f66f6058822b0b39fd # v3.27.0
if: github.repository == 'nuxt/nuxt' && success()
with:
sarif_file: results.sarif
40 changes: 40 additions & 0 deletions docs/1.getting-started/12.upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default defineNuxtConfig({
// app: 'app'
// },
// experimental: {
// scanPageMeta: 'after-resolve',
// sharedPrerenderData: false,
// compileTemplate: true,
// resetAsyncDataToUndefined: true,
Expand Down Expand Up @@ -235,6 +236,45 @@ export default defineNuxtConfig({
})
```

#### Scan Page Meta After Resolution

🚦 **Impact Level**: Minimal

##### What Changed

We now scan page metadata (defined in `definePageMeta`) _after_ calling the `pages:extend` hook rather than before.

##### Reasons for Change

This was to allow scanning metadata for pages that users wanted to add in `pages:extend`. We still offer an opportunity to change or override page metadata in a new `pages:resolved` hook.

##### Migration Steps

If you want to override page metadata, do that in `pages:resolved` rather than in `pages:extend`.

```diff
export default defineNuxtConfig({
hooks: {
- 'pages:extend'(pages) {
+ 'pages:resolved'(pages) {
const myPage = pages.find(page => page.path === '/')
myPage.meta ||= {}
myPage.meta.layout = 'overridden-layout'
}
}
})
```

Alternatively, you can revert to the previous behaviour with:

```ts twoslash [nuxt.config.ts]
export default defineNuxtConfig({
experimental: {
scanPageMeta: true
}
})
```

#### Общие данные пререндера

🚦 **Уровень воздействия**: Средний
Expand Down
2 changes: 2 additions & 0 deletions docs/2.guide/3.going-further/1.experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ globalThis.Buffer = globalThis.Buffer || Buffer

Это работает только со статическими данными или строками/массивами, а не с переменными или условными присваиваниями. Дополнительную информацию и контекст см. в [оригинальном issue](https://github.com/nuxt/nuxt/issues/24770).

It is also possible to scan page metadata only after all routes have been registered in `pages:extend`. Then another hook, `pages:resolved` will be called. To enable this behavior, set `scanPageMeta: 'after-resolve'`.

Вы можете отключить эту возможность, если она вызывает проблемы в вашем проекте.

```ts twoslash [nuxt.config.ts]
Expand Down
1 change: 1 addition & 0 deletions docs/2.guide/3.going-further/1.features.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default defineNuxtConfig({
app: 'app'
},
experimental: {
scanPageMeta: 'after-resolve',
sharedPrerenderData: false,
compileTemplate: true,
resetAsyncDataToUndefined: true,
Expand Down
7 changes: 7 additions & 0 deletions docs/3.api/3.utils/define-page-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface PageMeta {
redirect?: RouteRecordRedirectOption
name?: string
path?: string
props?: RouteRecordRaw['props']
alias?: string | string[]
pageTransition?: boolean | TransitionProps
layoutTransition?: boolean | TransitionProps
Expand Down Expand Up @@ -63,6 +64,12 @@ interface PageMeta {

Вы можете определить [пользовательское регулярное выражение](#использование-пользовательского-регулярного-выражения), если у вас более сложный шаблон, чем имя файла.

**`props`**

- **Type**: [`RouteRecordRaw['props']`](https://router.vuejs.org/guide/essentials/passing-props)

Allows accessing the route `params` as props passed to the page component.

**`alias`**

- **тип**: `string | string[]`
Expand Down
13 changes: 13 additions & 0 deletions docs/3.api/3.utils/navigate-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ interface NavigateToOptions {

`to` может быть простой строкой или объектом маршрута, на который нужно перенаправить. Если передать `undefined` или `null`, то по умолчанию будет указано `'/'`.

#### Example

```ts
// Passing the URL directly will redirect to the '/blog' page
await navigateTo('/blog')

// Using the route object, will redirect to the route with the name 'blog'
await navigateTo({ name: 'blog' })

// Redirects to the 'product' route while passing a parameter (id = 1) using the route object.
await navigateTo({ name: 'product', params: { id: 1 } })
```

### `options` (опционально)

**Тип**: `NavigateToOptions`
Expand Down
4 changes: 2 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import { addPluginTemplate, addRouteMiddleware } from 'nuxt/kit'

export default defineNuxtConfig({
typescript: { shim: process.env.DOCS_TYPECHECK === 'true' },
pages: process.env.DOCS_TYPECHECK === 'true',
modules: [
function () {
if (!process.env.DOCS_TYPECHECK) { return }
Expand All @@ -18,4 +16,6 @@ export default defineNuxtConfig({
})
},
],
pages: process.env.DOCS_TYPECHECK === 'true',
typescript: { shim: process.env.DOCS_TYPECHECK === 'true' },
})
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@nuxt/ui-templates": "workspace:*",
"@nuxt/vite-builder": "workspace:*",
"@nuxt/webpack-builder": "workspace:*",
"@types/node": "20.16.11",
"@types/node": "20.16.14",
"@vue/compiler-core": "3.5.12",
"@vue/compiler-dom": "3.5.12",
"@vue/shared": "3.5.12",
Expand All @@ -57,24 +57,24 @@
"typescript": "5.6.3",
"ufo": "1.5.4",
"unbuild": "3.0.0-rc.11",
"vite": "5.4.8",
"vite": "5.4.9",
"vue": "3.5.12"
},
"devDependencies": {
"@eslint/js": "9.12.0",
"@nuxt/eslint-config": "0.5.7",
"@eslint/js": "9.13.0",
"@nuxt/eslint-config": "0.6.0",
"@nuxt/kit": "workspace:*",
"@nuxt/rspack-builder": "workspace:*",
"@nuxt/test-utils": "3.14.3",
"@nuxt/test-utils": "3.14.4",
"@nuxt/webpack-builder": "workspace:*",
"@testing-library/vue": "8.1.0",
"@types/eslint__js": "8.42.3",
"@types/node": "20.16.11",
"@types/node": "20.16.14",
"@types/semver": "7.5.8",
"@unhead/schema": "1.11.7",
"@unhead/vue": "1.11.7",
"@unhead/schema": "1.11.10",
"@unhead/vue": "1.11.10",
"@vitejs/plugin-vue": "5.1.4",
"@vitest/coverage-v8": "2.1.2",
"@vitest/coverage-v8": "2.1.3",
"@vue/test-utils": "2.4.6",
"autoprefixer": "10.4.20",
"case-police": "0.7.0",
Expand All @@ -83,36 +83,36 @@
"cssnano": "7.0.6",
"destr": "2.0.3",
"devalue": "5.1.1",
"eslint": "9.12.0",
"eslint": "9.13.0",
"eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-perfectionist": "3.8.0",
"eslint-plugin-perfectionist": "3.9.1",
"eslint-typegen": "0.3.2",
"h3": "npm:h3-nightly@2.0.0-1718872656.6765a6e",
"happy-dom": "15.7.4",
"jiti": "2.3.3",
"markdownlint-cli": "0.42.0",
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
"nuxi": "3.14.0",
"nuxi": "3.15.0",
"nuxt": "workspace:*",
"nuxt-content-twoslash": "0.1.1",
"ofetch": "1.4.1",
"pathe": "1.1.2",
"playwright-core": "1.48.0",
"playwright-core": "1.48.1",
"rimraf": "6.0.1",
"semver": "7.6.3",
"sherif": "1.0.0",
"sherif": "1.0.1",
"std-env": "3.7.0",
"tinyexec": "0.3.0",
"tinyexec": "0.3.1",
"tinyglobby": "0.2.9",
"typescript": "5.6.3",
"ufo": "1.5.4",
"vitest": "2.1.2",
"vitest": "2.1.3",
"vitest-environment-nuxt": "1.0.1",
"vue": "3.5.12",
"vue-router": "4.4.5",
"vue-tsc": "2.1.6"
},
"packageManager": "pnpm@9.12.1",
"packageManager": "pnpm@9.12.2",
"engines": {
"node": "^16.10.0 || >=18.0.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"untyped": "^1.5.1"
},
"devDependencies": {
"@rspack/core": "1.0.10",
"@rspack/core": "1.0.14",
"@types/hash-sum": "1.0.2",
"@types/semver": "7.5.8",
"nitro": "npm:nitro-nightly@3.0.0-beta-28665895.e727afda",
"unbuild": "3.0.0-rc.11",
"vite": "5.4.8",
"vitest": "2.1.2",
"vite": "5.4.9",
"vitest": "2.1.3",
"webpack": "5.95.0"
},
"engines": {
Expand Down
6 changes: 4 additions & 2 deletions packages/kit/src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { readPackageJSON } from 'pkg-types'
import type { Nuxt, NuxtCompatibility, NuxtCompatibilityIssues } from '@nuxt/schema'
import { useNuxt } from './context'

const SEMANTIC_VERSION_RE = /-\d+\.[0-9a-f]+/
export function normalizeSemanticVersion (version: string) {
return version.replace(/-\d+\.[0-9a-f]+/, '') // Remove edge prefix
return version.replace(SEMANTIC_VERSION_RE, '') // Remove edge prefix
}

const builderMap = {
Expand Down Expand Up @@ -104,6 +105,7 @@ export function isNuxt3 (nuxt: Nuxt = useNuxt()) {
return isNuxtMajorVersion(3, nuxt)
}

const NUXT_VERSION_RE = /^v/g
/**
* Get nuxt version
*/
Expand All @@ -112,5 +114,5 @@ export function getNuxtVersion (nuxt: Nuxt | any = useNuxt() /* TODO: LegacyNuxt
if (typeof rawVersion !== 'string') {
throw new TypeError('Cannot determine nuxt version! Is current instance passed?')
}
return rawVersion.replace(/^v/g, '')
return rawVersion.replace(NUXT_VERSION_RE, '')
}
3 changes: 2 additions & 1 deletion packages/kit/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Component, ComponentsDir } from '@nuxt/schema'
import { useNuxt } from './context'
import { assertNuxtCompatibility } from './compatibility'
import { logger } from './logger'
import { MODE_RE } from './utils'

/**
* Register a directory to be scanned for components and imported only when used.
Expand All @@ -28,7 +29,7 @@ export async function addComponent (opts: AddComponentOptions) {
nuxt.options.components = nuxt.options.components || []

if (!opts.mode) {
const [, mode = 'all'] = opts.filePath.match(/\.(server|client)(\.\w+)*$/) || []
const [, mode = 'all'] = opts.filePath.match(MODE_RE) || []
opts.mode = mode as 'all' | 'client' | 'server'
}

Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { useNuxt } from './context'
import { logger } from './logger'
import { addTemplate } from './template'

const LAYOUT_RE = /["']/g
export function addLayout (template: NuxtTemplate | string, name?: string) {
const nuxt = useNuxt()
const { filename, src } = addTemplate(template)
const layoutName = kebabCase(name || parse(filename).name).replace(/["']/g, '')
const layoutName = kebabCase(name || parse(filename).name).replace(LAYOUT_RE, '')

// Nuxt 3 adds layouts on app
nuxt.hook('app:templates', (app) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { normalize } from 'pathe'
import { useNuxt } from './context'
import { toArray } from './utils'

const HANDLER_METHOD_RE = /\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/
/**
* normalize handler object
*
*/
function normalizeHandlerMethod (handler: NitroEventHandler) {
// retrieve method from handler file name
const [, method = undefined] = handler.handler.match(/\.(get|head|patch|post|put|delete|connect|options|trace)(\.\w+)*$/) || []
const [, method = undefined] = handler.handler.match(HANDLER_METHOD_RE) || []
return {
method: method as 'get' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace' | undefined,
...handler,
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { NuxtPlugin, NuxtPluginTemplate } from '@nuxt/schema'
import { useNuxt } from './context'
import { addTemplate } from './template'
import { resolveAlias } from './resolve'
import { MODE_RE } from './utils'

/**
* Normalize a nuxt plugin object
Expand All @@ -27,7 +28,7 @@ export function normalizePlugin (plugin: NuxtPlugin | string): NuxtPlugin {
plugin.mode = 'server'
}
if (!plugin.mode) {
const [, mode = 'all'] = plugin.src.match(/\.(server|client)(\.\w+)*$/) || []
const [, mode = 'all'] = plugin.src.match(MODE_RE) || []
plugin.mode = mode as 'all' | 'client' | 'server'
}

Expand Down
Loading

0 comments on commit ba6cdba

Please sign in to comment.