From 65380c6bc9f422b8e98fac34742a2819f044eddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20=C4=8Cern=C3=BD?= <112722215+cernymatej@users.noreply.github.com> Date: Tue, 7 Jan 2025 05:49:59 +0100 Subject: [PATCH 1/3] fix(nuxt): collect all identifiers before extracting page metadata (#30478) --- packages/nuxt/src/pages/plugins/page-meta.ts | 13 +++++++++++-- packages/nuxt/test/page-metadata.test.ts | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/pages/plugins/page-meta.ts b/packages/nuxt/src/pages/plugins/page-meta.ts index 95350d48df..a5972f4e44 100644 --- a/packages/nuxt/src/pages/plugins/page-meta.ts +++ b/packages/nuxt/src/pages/plugins/page-meta.ts @@ -173,7 +173,9 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions = {}) => createUnp } } - const scopeTracker = new ScopeTracker() + const scopeTracker = new ScopeTracker({ + keepExitedScopes: true, + }) function processDeclaration (scopeTrackerNode: ScopeTrackerNode | null) { if (scopeTrackerNode?.type === 'Variable') { @@ -210,7 +212,13 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions = {}) => createUnp } } - parseAndWalk(code, id, { + const ast = parseAndWalk(code, id, { + scopeTracker, + }) + + scopeTracker.freeze() + + walk(ast, { scopeTracker, enter: (node) => { if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier') { return } @@ -221,6 +229,7 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions = {}) => createUnp if (!meta) { return } walk(meta, { + scopeTracker, enter (node, parent) { if ( isNotReferencePosition(node, parent) diff --git a/packages/nuxt/test/page-metadata.test.ts b/packages/nuxt/test/page-metadata.test.ts index 734e498a69..60247fd4e1 100644 --- a/packages/nuxt/test/page-metadata.test.ts +++ b/packages/nuxt/test/page-metadata.test.ts @@ -497,6 +497,8 @@ function recursive () { recursive() } +const route = useRoute() + definePageMeta({ middleware: [ () => { @@ -513,9 +515,19 @@ definePageMeta({ prop = 'prop' test () {} } + + console.log(hoisted.value) }, ], + validate: (route) => { + return route.params.id === 'test' + } }) + +// the order of a ref relative to the 'definePageMeta' call should be preserved (in contrast to a simple const) +// this tests whether the extraction handles all variables in the upper scope +const hoisted = ref('hoisted') + ` const res = compileScript(parse(sfc).descriptor, { id: 'component.vue' }) @@ -534,6 +546,7 @@ definePageMeta({ function recursive () { recursive() } + const hoisted = ref('hoisted') const __nuxt_page_meta = { middleware: [ () => { @@ -550,8 +563,13 @@ definePageMeta({ prop = 'prop' test () {} } + + console.log(hoisted.value) }, ], + validate: (route) => { + return route.params.id === 'test' + } } export default __nuxt_page_meta" `) From 4c66a7994dbf29fd5676fa293a6bf36a84d21414 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 7 Jan 2025 08:00:32 +0000 Subject: [PATCH 2/3] chore: control dependency import into `nuxt/app` --- eslint.config.mjs | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/eslint.config.mjs b/eslint.config.mjs index c2e9cb9761..453da60e47 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -166,6 +166,55 @@ export default createConfigForNuxt({ 'no-console': 'off', }, }, + // manually specify dependencies for nuxt browser app + { + files: ['packages/nuxt/src/app/**', 'packages/nuxt/src/(components,head,imports,pages)/runtime/**'], + name: 'local/client-packages', + rules: { + '@typescript-eslint/no-restricted-imports': ['error', { + 'patterns': [ + { + allowTypeImports: true, + group: [ + // disallow everything + '[@a-z]*', + // except certain dependencies + ...[ + // vue ecosystem + '@unhead', + '@vue', + '@vue/shared', + 'vue/server-renderer', + 'vue', + 'vue-router', + // other deps + 'devalue', + 'klona', + // unjs ecosystem + 'defu', + 'ufo', + 'h3', + 'destr', + 'consola', + 'hookable', + 'unctx', + 'cookie-es', + 'perfect-debounce', + 'radix3', + 'ohash', + 'pathe', + 'uncrypto', + // internal deps + 'nuxt/app', + ].map(r => `!${r}`), + '!#[a-z]*/**', // aliases + '!.*/**', // relative imports + ], + }, + ], + }], + }, + }, { files: ['**/fixtures/**', '**/fixture/**'], name: 'local/disables/fixtures', From 41cdaf670247004eab95395910b4a59e87e38bd9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:38:14 +0000 Subject: [PATCH 3/3] chore(deps): update node.js to 1f09742 (main) (#30494) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8a3d0b82ac..1b57ec4a8a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,4 @@ -FROM node:lts@sha256:0e910f435308c36ea60b4cfd7b80208044d77a074d16b768a81901ce938a62dc +FROM node:lts@sha256:1f097426a7ddd1c5d0eacfe0402fdf91e38e4ecc37d23780428f6b87145ad2aa 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 && \