nuxtseo-shared 5.3.4 → 5.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/devtools.mjs CHANGED
@@ -141,7 +141,10 @@ function toolchainInstalled(rootDir) {
141
141
  }
142
142
  }
143
143
  async function devAddArgs(rootDir) {
144
- const pm = await detectPackageManager(rootDir).catch(() => null);
144
+ const pm = await detectPackageManager(rootDir).catch((error) => {
145
+ console.warn(`[nuxt-seo] could not detect the package manager in "${rootDir}", falling back to npm:`, error);
146
+ return null;
147
+ });
145
148
  const name = pm?.name ?? "npm";
146
149
  if (name === "npm")
147
150
  return { command: "npm", args: ["install", "--save-dev", TOOLCHAIN_PACKAGE] };
package/dist/kit.d.mts CHANGED
@@ -4,6 +4,29 @@ import { NitroConfig } from 'nitropack/types';
4
4
  import { NuxtPage, NuxtModule } from 'nuxt/schema';
5
5
  import { useLogger } from '@nuxt/kit';
6
6
 
7
+ type NitroRuntimeCompatibility = {
8
+ _tag: 'nitro-v2';
9
+ eventContextModule: 'h3';
10
+ eventContextType: 'H3EventContext';
11
+ eventType: `import('h3').H3Event`;
12
+ nitroTypesModule: 'nitropack';
13
+ } | {
14
+ _tag: 'nitro-v3';
15
+ eventContextModule: 'srvx';
16
+ eventContextType: 'ServerRequestContext';
17
+ eventType: `import('nitro/h3').H3Event`;
18
+ nitroTypesModule: 'nitro/types';
19
+ };
20
+ interface NitroTypeAugmentations {
21
+ eventContext?: string;
22
+ nitroInterfaces?: Record<string, string>;
23
+ routeConfig?: string;
24
+ routeRules?: string;
25
+ runtimeHooks?: string;
26
+ }
27
+ declare function renderNitroTypeAugmentations(compatibility: NitroRuntimeCompatibility, augmentations: NitroTypeAugmentations): string;
28
+ declare function setupNitroRuntimeCompatibility(nuxt?: Nuxt): NitroRuntimeCompatibility;
29
+
7
30
  interface NuxtSeoModuleDetection {
8
31
  name: string;
9
32
  version?: string;
@@ -75,5 +98,5 @@ type UnheadMajor = 2 | 3;
75
98
  */
76
99
  declare function resolveHostUnheadMajor(rootDir: string): Promise<UnheadMajor>;
77
100
 
78
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, useModuleLogger };
79
- export type { NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
101
+ export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
102
+ export type { NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
package/dist/kit.d.ts CHANGED
@@ -4,6 +4,29 @@ import { NitroConfig } from 'nitropack/types';
4
4
  import { NuxtPage, NuxtModule } from 'nuxt/schema';
5
5
  import { useLogger } from '@nuxt/kit';
6
6
 
7
+ type NitroRuntimeCompatibility = {
8
+ _tag: 'nitro-v2';
9
+ eventContextModule: 'h3';
10
+ eventContextType: 'H3EventContext';
11
+ eventType: `import('h3').H3Event`;
12
+ nitroTypesModule: 'nitropack';
13
+ } | {
14
+ _tag: 'nitro-v3';
15
+ eventContextModule: 'srvx';
16
+ eventContextType: 'ServerRequestContext';
17
+ eventType: `import('nitro/h3').H3Event`;
18
+ nitroTypesModule: 'nitro/types';
19
+ };
20
+ interface NitroTypeAugmentations {
21
+ eventContext?: string;
22
+ nitroInterfaces?: Record<string, string>;
23
+ routeConfig?: string;
24
+ routeRules?: string;
25
+ runtimeHooks?: string;
26
+ }
27
+ declare function renderNitroTypeAugmentations(compatibility: NitroRuntimeCompatibility, augmentations: NitroTypeAugmentations): string;
28
+ declare function setupNitroRuntimeCompatibility(nuxt?: Nuxt): NitroRuntimeCompatibility;
29
+
7
30
  interface NuxtSeoModuleDetection {
8
31
  name: string;
9
32
  version?: string;
@@ -75,5 +98,5 @@ type UnheadMajor = 2 | 3;
75
98
  */
76
99
  declare function resolveHostUnheadMajor(rootDir: string): Promise<UnheadMajor>;
77
100
 
78
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, useModuleLogger };
79
- export type { NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
101
+ export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
102
+ export type { NitroRuntimeCompatibility, NitroTypeAugmentations, NuxtContentVersion, NuxtSeoModuleDetection, UnheadMajor };
package/dist/kit.mjs CHANGED
@@ -1,9 +1,134 @@
1
1
  import { pathToFileURL } from 'node:url';
2
- import { useNuxt, createResolver, addTemplate, loadNuxtModuleInstance, tryUseNuxt, hasNuxtModule, hasNuxtModuleCompatibility, useLogger } from '@nuxt/kit';
2
+ import { getNuxtVersion, addTypeTemplate, useNuxt, createResolver, addTemplate, loadNuxtModuleInstance, tryUseNuxt, hasNuxtModule, hasNuxtModuleCompatibility, useLogger } from '@nuxt/kit';
3
3
  import { relative, dirname } from 'pathe';
4
4
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
5
5
  import { provider, env } from 'std-env';
6
6
 
7
+ const NITRO_RUNTIME_MODULE = "#nuxtseo/nitro";
8
+ const H3_RUNTIME_MODULE = "#nuxtseo/h3";
9
+ const TYPE_TEMPLATE_FILENAME = "types/nuxtseo-nitro.d.ts";
10
+ const legacySetupMarker = Symbol.for("nuxtseo:nitro-runtime-compatibility");
11
+ const typeSetupMarker = Symbol.for("nuxtseo:nitro-runtime-compatibility:request-context-types");
12
+ const runtimeSetupMarker = Symbol.for("nuxtseo:nitro-runtime-compatibility:request-context");
13
+ const nitroV2Compatibility = {
14
+ _tag: "nitro-v2",
15
+ eventContextModule: "h3",
16
+ eventContextType: "H3EventContext",
17
+ eventType: `import('h3').H3Event`,
18
+ nitroTypesModule: "nitropack"
19
+ };
20
+ const nitroV3Compatibility = {
21
+ _tag: "nitro-v3",
22
+ eventContextModule: "srvx",
23
+ eventContextType: "ServerRequestContext",
24
+ eventType: `import('nitro/h3').H3Event`,
25
+ nitroTypesModule: "nitro/types"
26
+ };
27
+ const nitroV2Runtime = `export {
28
+ defineNitroPlugin,
29
+ useNitroApp,
30
+ useEvent,
31
+ useRuntimeConfig,
32
+ defineCachedFunction,
33
+ defineCachedEventHandler,
34
+ useStorage,
35
+ defineTask,
36
+ runTask,
37
+ } from 'nitropack/runtime'
38
+ `;
39
+ const nitroV3Runtime = `export { definePlugin as defineNitroPlugin } from 'nitro'
40
+ export { useNitroApp } from 'nitro/app'
41
+ export { useRequest as useEvent } from 'nitro/context'
42
+ import { useRuntimeConfig as _useRuntimeConfig } from 'nitro/runtime-config'
43
+ export function useRuntimeConfig(_event) { return _useRuntimeConfig() }
44
+ export { defineCachedFunction, defineCachedHandler as defineCachedEventHandler } from 'nitro/cache'
45
+ export { useStorage } from 'nitro/storage'
46
+ export { defineTask, runTask } from 'nitro/task'
47
+ `;
48
+ const nitroV3RuntimeTypes = `export { definePlugin as defineNitroPlugin } from 'nitro'
49
+ export { useNitroApp } from 'nitro/app'
50
+ export { useRequest as useEvent } from 'nitro/context'
51
+ export function useRuntimeConfig(event?: import('nitro/h3').H3Event): ReturnType<typeof import('nitro/runtime-config').useRuntimeConfig>
52
+ export { defineCachedFunction, defineCachedHandler as defineCachedEventHandler } from 'nitro/cache'
53
+ export { useStorage } from 'nitro/storage'
54
+ export { defineTask, runTask } from 'nitro/task'
55
+ `;
56
+ function indent(value, spaces) {
57
+ const padding = " ".repeat(spaces);
58
+ return value.split("\n").map((line) => `${padding}${line}`).join("\n");
59
+ }
60
+ function renderInterface(name, contents) {
61
+ if (!contents?.trim())
62
+ return void 0;
63
+ return ` interface ${name} {
64
+ ${indent(contents.trim(), 4)}
65
+ }`;
66
+ }
67
+ function renderRuntimeDeclarations(compatibility) {
68
+ const nitroRuntime = compatibility._tag === "nitro-v3" ? nitroV3RuntimeTypes : nitroV2Runtime;
69
+ const h3Runtime = compatibility._tag === "nitro-v3" ? `export * from 'nitro/h3'
70
+ ` : `export * from 'h3'
71
+ `;
72
+ return `declare module '${NITRO_RUNTIME_MODULE}' {
73
+ ${indent(nitroRuntime.trim(), 2)}
74
+ }
75
+
76
+ declare module '${H3_RUNTIME_MODULE}' {
77
+ ${indent(h3Runtime.trim(), 2)}
78
+ }
79
+ `;
80
+ }
81
+ function applyNitroRuntimeCompatibility(nuxt, compatibility) {
82
+ const nuxtOptions = nuxt.options;
83
+ const nitroOptions = nuxtOptions.nitro ||= {};
84
+ nitroOptions.alias ||= {};
85
+ nitroOptions.virtual ||= {};
86
+ nitroOptions.alias[H3_RUNTIME_MODULE] = compatibility._tag === "nitro-v3" ? "nitro/h3" : "h3";
87
+ nitroOptions.virtual[NITRO_RUNTIME_MODULE] = compatibility._tag === "nitro-v3" ? nitroV3Runtime : nitroV2Runtime;
88
+ }
89
+ function renderNitroTypeAugmentations(compatibility, augmentations) {
90
+ const nitroInterfaces = [
91
+ renderInterface("NitroRouteRules", augmentations.routeRules),
92
+ renderInterface("NitroRouteConfig", augmentations.routeConfig),
93
+ renderInterface("NitroRuntimeHooks", augmentations.runtimeHooks),
94
+ ...Object.entries(augmentations.nitroInterfaces || {}).map(([name, contents]) => renderInterface(name, contents))
95
+ ].filter((value) => Boolean(value));
96
+ const declarations = [];
97
+ if (nitroInterfaces.length) {
98
+ const nitroTypeModules = compatibility._tag === "nitro-v2" ? ["nitropack", "nitropack/types"] : [compatibility.nitroTypesModule];
99
+ declarations.push(...nitroTypeModules.map((module) => `declare module '${module}' {
100
+ ${nitroInterfaces.join("\n")}
101
+ }`));
102
+ }
103
+ if (augmentations.eventContext?.trim()) {
104
+ declarations.push(`declare module '${compatibility.eventContextModule}' {
105
+ ${renderInterface(compatibility.eventContextType, augmentations.eventContext)}
106
+ }`);
107
+ }
108
+ return declarations.join("\n\n");
109
+ }
110
+ function setupNitroRuntimeCompatibility(nuxt = useNuxt()) {
111
+ const major = Number.parseInt(getNuxtVersion(nuxt), 10);
112
+ const compatibility = major >= 5 ? nitroV3Compatibility : nitroV2Compatibility;
113
+ applyNitroRuntimeCompatibility(nuxt, compatibility);
114
+ const nuxtWithLegacyMarker = nuxt;
115
+ nuxtWithLegacyMarker[legacySetupMarker] = true;
116
+ const nuxtWithRuntimeMarker = nuxt;
117
+ if (!nuxtWithRuntimeMarker[runtimeSetupMarker]) {
118
+ nuxtWithRuntimeMarker[runtimeSetupMarker] = true;
119
+ nuxt.hooks.hookOnce("modules:done", () => applyNitroRuntimeCompatibility(nuxt, compatibility));
120
+ }
121
+ const nuxtWithTypeMarker = nuxt;
122
+ if (!nuxtWithTypeMarker[typeSetupMarker]) {
123
+ nuxtWithTypeMarker[typeSetupMarker] = true;
124
+ addTypeTemplate({
125
+ filename: TYPE_TEMPLATE_FILENAME,
126
+ getContents: async () => renderRuntimeDeclarations(compatibility)
127
+ }, { nitro: true, nuxt: true });
128
+ }
129
+ return compatibility;
130
+ }
131
+
7
132
  function normalizePackageUrl(rootDir) {
8
133
  const url = rootDir.startsWith("file:") ? rootDir : pathToFileURL(rootDir.endsWith("/") ? rootDir : `${rootDir}/`).href;
9
134
  return url.endsWith("/") ? url : `${url}/`;
@@ -157,4 +282,4 @@ async function resolveHostUnheadMajor(rootDir) {
157
282
  return 3;
158
283
  }
159
284
 
160
- export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, useModuleLogger };
285
+ export { createNitroPromise, createPagesPromise, detectNuxtSeoModules, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, renderNitroTypeAugmentations, resolveHostUnheadMajor, resolveNitroPreset, resolveNuxtContentVersion, resolvePackageMajor, setupNitroRuntimeCompatibility, useModuleLogger };
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "5.3.4",
7
+ "version": "5.3.7",
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
9
+ "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
11
11
  }
12
12
  }
package/dist/server.d.mts CHANGED
@@ -1,7 +1,20 @@
1
- import { H3Event } from 'h3';
2
- import { NitroRouteRules } from 'nitropack';
3
-
1
+ interface NitroRouteRulesRuntimeConfig<TRouteRules extends object> {
2
+ app?: {
3
+ baseURL?: string;
4
+ };
5
+ nitro?: {
6
+ routeRules?: Record<string, TRouteRules>;
7
+ };
8
+ }
4
9
  declare function withoutQuery(path: string): string;
5
- declare function createNitroRouteRuleMatcher(e?: H3Event): (pathOrUrl: string) => NitroRouteRules;
10
+ declare function createNitroRouteRuleMatcher<TRouteRules extends object = Record<string, unknown>>(runtimeConfig: NitroRouteRulesRuntimeConfig<object>): (pathOrUrl: string) => TRouteRules;
11
+ declare function normalizeNitroMatchedRouteRules<TMatchedRouteRules extends Record<string, {
12
+ options: unknown;
13
+ }> = Record<string, {
14
+ options: unknown;
15
+ }>>(matchedRouteRules?: TMatchedRouteRules): {
16
+ [Key in keyof TMatchedRouteRules]: TMatchedRouteRules[Key]['options'];
17
+ };
6
18
 
7
- export { createNitroRouteRuleMatcher, withoutQuery };
19
+ export { createNitroRouteRuleMatcher, normalizeNitroMatchedRouteRules, withoutQuery };
20
+ export type { NitroRouteRulesRuntimeConfig };
package/dist/server.d.ts CHANGED
@@ -1,7 +1,20 @@
1
- import { H3Event } from 'h3';
2
- import { NitroRouteRules } from 'nitropack';
3
-
1
+ interface NitroRouteRulesRuntimeConfig<TRouteRules extends object> {
2
+ app?: {
3
+ baseURL?: string;
4
+ };
5
+ nitro?: {
6
+ routeRules?: Record<string, TRouteRules>;
7
+ };
8
+ }
4
9
  declare function withoutQuery(path: string): string;
5
- declare function createNitroRouteRuleMatcher(e?: H3Event): (pathOrUrl: string) => NitroRouteRules;
10
+ declare function createNitroRouteRuleMatcher<TRouteRules extends object = Record<string, unknown>>(runtimeConfig: NitroRouteRulesRuntimeConfig<object>): (pathOrUrl: string) => TRouteRules;
11
+ declare function normalizeNitroMatchedRouteRules<TMatchedRouteRules extends Record<string, {
12
+ options: unknown;
13
+ }> = Record<string, {
14
+ options: unknown;
15
+ }>>(matchedRouteRules?: TMatchedRouteRules): {
16
+ [Key in keyof TMatchedRouteRules]: TMatchedRouteRules[Key]['options'];
17
+ };
6
18
 
7
- export { createNitroRouteRuleMatcher, withoutQuery };
19
+ export { createNitroRouteRuleMatcher, normalizeNitroMatchedRouteRules, withoutQuery };
20
+ export type { NitroRouteRulesRuntimeConfig };
package/dist/server.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { defu } from 'defu';
2
- import { useRuntimeConfig } from 'nitropack/runtime';
3
2
  import { toRouteMatcher, createRouter } from 'radix3';
4
3
  import { withoutTrailingSlash, parseURL, withoutBase } from 'ufo';
5
4
 
@@ -7,11 +6,9 @@ function withoutQuery(path) {
7
6
  const queryIndex = path.indexOf("?");
8
7
  return queryIndex === -1 ? path : path.slice(0, queryIndex);
9
8
  }
10
- let cachedRouteRuleMatcher;
11
- function createNitroRouteRuleMatcher(e) {
12
- if (!import.meta.dev && !e && cachedRouteRuleMatcher)
13
- return cachedRouteRuleMatcher;
14
- const { nitro, app } = useRuntimeConfig(e);
9
+ function createNitroRouteRuleMatcher(runtimeConfig) {
10
+ const { nitro, app } = runtimeConfig;
11
+ const baseURL = app?.baseURL || "/";
15
12
  const _routeRulesMatcher = toRouteMatcher(
16
13
  createRouter({
17
14
  routes: Object.fromEntries(
@@ -19,15 +16,17 @@ function createNitroRouteRuleMatcher(e) {
19
16
  )
20
17
  })
21
18
  );
22
- const matcher = (pathOrUrl) => {
23
- const path = pathOrUrl[0] === "/" ? pathOrUrl : parseURL(pathOrUrl, app.baseURL).pathname;
19
+ return (pathOrUrl) => {
20
+ const path = pathOrUrl[0] === "/" ? pathOrUrl : parseURL(pathOrUrl, baseURL).pathname;
24
21
  return defu({}, ..._routeRulesMatcher.matchAll(
25
- withoutBase(withoutTrailingSlash(withoutQuery(path)), app.baseURL)
22
+ withoutBase(withoutTrailingSlash(withoutQuery(path)), baseURL)
26
23
  ).reverse());
27
24
  };
28
- if (!import.meta.dev && !e)
29
- cachedRouteRuleMatcher = matcher;
30
- return matcher;
25
+ }
26
+ function normalizeNitroMatchedRouteRules(matchedRouteRules) {
27
+ return Object.fromEntries(
28
+ Object.entries(matchedRouteRules || {}).map(([key, rule]) => [key, rule.options])
29
+ );
31
30
  }
32
31
 
33
- export { createNitroRouteRuleMatcher, withoutQuery };
32
+ export { createNitroRouteRuleMatcher, normalizeNitroMatchedRouteRules, withoutQuery };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxtseo-shared",
3
3
  "type": "module",
4
- "version": "5.3.4",
4
+ "version": "5.3.7",
5
5
  "description": "Shared utilities for Nuxt SEO modules.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -64,8 +64,8 @@
64
64
  "dist"
65
65
  ],
66
66
  "peerDependencies": {
67
- "@nuxt/schema": "^3.16.0 || ^4.0.0",
68
- "nuxt": "^3.16.0 || ^4.0.0",
67
+ "@nuxt/schema": "^3.16.0 || ^4.0.0 || ^5.0.0",
68
+ "nuxt": "^3.16.0 || ^4.0.0 || ^5.0.0",
69
69
  "nuxt-site-config": "^3.2.0 || ^4.0.0",
70
70
  "vue": "^3.5.0",
71
71
  "zod": "^3.23.0 || ^4.0.0"
@@ -81,11 +81,11 @@
81
81
  "dependencies": {
82
82
  "@clack/prompts": "^1.7.0",
83
83
  "@nuxt/devtools-kit": "4.0.0-alpha.7",
84
- "@nuxt/kit": "^4.5.0",
84
+ "@nuxt/kit": "^4.5.1",
85
85
  "birpc": "^4.0.0",
86
86
  "consola": "^3.4.2",
87
87
  "defu": "^6.1.7",
88
- "nypm": "^0.6.8",
88
+ "nypm": "^0.6.9",
89
89
  "ofetch": "^1.5.1",
90
90
  "pathe": "^2.0.3",
91
91
  "pkg-types": "^2.3.1",
@@ -96,24 +96,26 @@
96
96
  },
97
97
  "devDependencies": {
98
98
  "@arethetypeswrong/cli": "^0.18.5",
99
- "@nuxt/module-builder": "^1.0.2",
100
- "@nuxt/schema": "^4.5.0",
101
- "@nuxtjs/i18n": "^10.4.1",
99
+ "@nuxt/module-builder": "^1.0.3",
100
+ "@nuxt/schema": "^4.5.1",
101
+ "@nuxt/test-utils": "^4.1.0",
102
+ "@nuxtjs/i18n": "^10.6.0",
102
103
  "h3": "^1.15.11",
103
104
  "nitropack": "^2.13.4",
104
- "nuxt": "^4.5.0",
105
+ "nuxt": "^4.5.1",
105
106
  "nuxt-site-config": "^4.1.2",
106
107
  "typescript": "6.0.3",
107
108
  "vitest": "^4.1.10",
108
109
  "vue": "^3.5.40",
109
- "vue-tsc": "^3.3.7"
110
+ "vue-tsc": "^3.3.9"
110
111
  },
111
112
  "scripts": {
112
113
  "build": "nuxt-module-build build",
113
114
  "dev:prepare": "nuxt-module-build prepare",
114
115
  "stub": "nuxt-module-build build --stub",
115
116
  "test": "vitest",
116
- "test:run": "vitest run",
117
+ "test:run": "vitest run && pnpm test:nuxt5",
118
+ "test:nuxt5": "pnpm --dir test/fixtures/nitro-compat-nuxt5 install --frozen-lockfile && pnpm --dir test/fixtures/nitro-compat-nuxt5 test",
117
119
  "test:attw": "attw --pack --profile esm-only",
118
120
  "typecheck": "nuxt typecheck ."
119
121
  }