nuxtseo-shared 0.1.1 → 0.1.3

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.
Files changed (48) hide show
  1. package/dist/content.d.mts +39 -39
  2. package/dist/content.mjs +56 -29
  3. package/dist/devtools.d.mts +10 -10
  4. package/dist/devtools.mjs +37 -43
  5. package/dist/i18n.d.mts +29 -17
  6. package/dist/i18n.mjs +109 -108
  7. package/dist/index.d.mts +3 -7
  8. package/dist/index.mjs +3 -7
  9. package/dist/kit.d.mts +22 -12
  10. package/dist/kit.mjs +79 -73
  11. package/dist/layer-devtools/app.config.ts +27 -0
  12. package/dist/layer-devtools/assets/css/global.css +377 -0
  13. package/dist/layer-devtools/components/DevtoolsError.vue +78 -0
  14. package/dist/layer-devtools/components/DevtoolsLoading.vue +8 -0
  15. package/dist/layer-devtools/components/DevtoolsProductionError.vue +41 -0
  16. package/dist/layer-devtools/components/OCodeBlock.vue +23 -0
  17. package/{src/client → dist/layer-devtools}/components/OSectionBlock.vue +13 -22
  18. package/dist/layer-devtools/composables/rpc.ts +39 -0
  19. package/dist/layer-devtools/composables/shiki.ts +46 -0
  20. package/dist/layer-devtools/composables/state.ts +33 -0
  21. package/dist/layer-devtools/nuxt.config.ts +22 -0
  22. package/dist/module.d.mts +14 -0
  23. package/dist/module.mjs +33 -0
  24. package/dist/pro.d.mts +6 -7
  25. package/dist/pro.mjs +64 -64
  26. package/dist/telemetry.d.mts +11 -0
  27. package/dist/telemetry.mjs +49 -0
  28. package/package.json +22 -47
  29. package/dist/client/composables/rpc.d.mts +0 -21
  30. package/dist/client/composables/rpc.d.ts +0 -21
  31. package/dist/client/composables/rpc.mjs +0 -25
  32. package/dist/client/composables/shiki.d.mts +0 -13
  33. package/dist/client/composables/shiki.d.ts +0 -13
  34. package/dist/client/composables/shiki.mjs +0 -39
  35. package/dist/client/index.d.mts +0 -7
  36. package/dist/client/index.d.ts +0 -7
  37. package/dist/client/index.mjs +0 -6
  38. package/dist/content.d.ts +0 -82
  39. package/dist/devtools.d.ts +0 -14
  40. package/dist/i18n.d.ts +0 -32
  41. package/dist/index.d.ts +0 -7
  42. package/dist/kit.d.ts +0 -32
  43. package/dist/pro.d.ts +0 -18
  44. package/dist/runtime/server/kit.d.mts +0 -7
  45. package/dist/runtime/server/kit.d.ts +0 -7
  46. package/dist/runtime/server/kit.mjs +0 -27
  47. package/src/client/components/OCodeBlock.vue +0 -28
  48. /package/{src/client → dist/layer-devtools}/components/NuxtSeoLogo.vue +0 -0
@@ -1,18 +1,19 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
 
3
+ //#region src/content.d.ts
3
4
  type ZodInstance = typeof z;
4
5
  type ZodTypeAny = z.ZodTypeAny;
5
6
  interface ContentSchemaOptions {
6
- /**
7
- * Pass the `z` instance from `@nuxt/content` to ensure `.editor()` works
8
- * across Zod versions. When omitted, the module's bundled `z` is used.
9
- */
10
- z?: ZodInstance;
7
+ /**
8
+ * Pass the `z` instance from `@nuxt/content` to ensure `.editor()` works
9
+ * across Zod versions. When omitted, the module's bundled `z` is used.
10
+ */
11
+ z?: ZodInstance;
11
12
  }
12
13
  interface ContentEditorConfig {
13
- hidden?: boolean;
14
- input?: 'media' | 'icon' | 'textarea';
15
- iconLibraries?: string[];
14
+ hidden?: boolean;
15
+ input?: 'media' | 'icon' | 'textarea';
16
+ iconLibraries?: string[];
16
17
  }
17
18
  /**
18
19
  * Apply Nuxt Content `.editor()` metadata to a zod schema field.
@@ -25,23 +26,23 @@ declare function withEditor<T extends ZodTypeAny>(schema: T, config: ContentEdit
25
26
  */
26
27
  declare function withEditorHidden<T extends ZodTypeAny>(schema: T): T;
27
28
  interface DefineContentSchemaConfig<TSchema extends ZodTypeAny> {
28
- /**
29
- * The field name used in frontmatter (e.g. 'robots', 'sitemap', 'ogImage').
30
- */
31
- fieldName: string;
32
- /**
33
- * Build the zod schema for this field. Receives the zod instance
34
- * (either the user's `@nuxt/content` patched version or the module's bundled one).
35
- */
36
- buildSchema: (z: ZodInstance) => TSchema;
37
- /**
38
- * Module label for deprecation warnings (e.g. 'robots', 'sitemap').
39
- */
40
- label: string;
41
- /**
42
- * Documentation URL for migration guidance.
43
- */
44
- docsUrl?: string;
29
+ /**
30
+ * The field name used in frontmatter (e.g. 'robots', 'sitemap', 'ogImage').
31
+ */
32
+ fieldName: string;
33
+ /**
34
+ * Build the zod schema for this field. Receives the zod instance
35
+ * (either the user's `@nuxt/content` patched version or the module's bundled one).
36
+ */
37
+ buildSchema: (z: ZodInstance) => TSchema;
38
+ /**
39
+ * Module label for deprecation warnings (e.g. 'robots', 'sitemap').
40
+ */
41
+ label: string;
42
+ /**
43
+ * Documentation URL for migration guidance.
44
+ */
45
+ docsUrl?: string;
45
46
  }
46
47
  /**
47
48
  * Factory for creating a module's `define*Schema()` and deprecated `as*Collection()` exports.
@@ -66,17 +67,16 @@ interface DefineContentSchemaConfig<TSchema extends ZodTypeAny> {
66
67
  * export { defineSchema as defineRobotsSchema, asCollection as asRobotsCollection, schema }
67
68
  */
68
69
  declare function createContentSchemaFactory<TSchema extends ZodTypeAny>(config: DefineContentSchemaConfig<TSchema>, defaultZ: ZodInstance): {
69
- defineSchema: (options?: ContentSchemaOptions) => TSchema;
70
- asCollection: <T>(collection: any) => T;
71
- schema: z.ZodObject<{
72
- [x: string]: TSchema;
73
- }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
74
- [x: string]: TSchema;
75
- }>, any> extends infer T ? { [k in keyof T]: T[k]; } : never, z.baseObjectInputType<{
76
- [x: string]: TSchema;
77
- }> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never>;
78
- fieldSchema: TSchema;
70
+ defineSchema: (options?: ContentSchemaOptions) => TSchema;
71
+ asCollection: <T>(collection: any) => T;
72
+ schema: z.ZodObject<{
73
+ [x: string]: TSchema;
74
+ }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
75
+ [x: string]: TSchema;
76
+ }>, any> extends infer T ? { [k in keyof T]: T[k] } : never, z.baseObjectInputType<{
77
+ [x: string]: TSchema;
78
+ }> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1] } : never>;
79
+ fieldSchema: TSchema;
79
80
  };
80
-
81
- export { createContentSchemaFactory, withEditor, withEditorHidden };
82
- export type { ContentEditorConfig, ContentSchemaOptions, DefineContentSchemaConfig };
81
+ //#endregion
82
+ export { ContentEditorConfig, ContentSchemaOptions, DefineContentSchemaConfig, createContentSchemaFactory, withEditor, withEditorHidden };
package/dist/content.mjs CHANGED
@@ -1,38 +1,65 @@
1
+ //#region src/content.ts
2
+ /**
3
+ * Apply Nuxt Content `.editor()` metadata to a zod schema field.
4
+ * No-ops gracefully when `.editor()` is not patched onto ZodType (outside Nuxt Content).
5
+ */
1
6
  function withEditor(schema, config) {
2
- if (typeof schema.editor === "function")
3
- return schema.editor(config);
4
- return schema;
7
+ if (typeof schema.editor === "function") return schema.editor(config);
8
+ return schema;
5
9
  }
10
+ /**
11
+ * Hide a zod schema field from the Nuxt Content / Studio editor.
12
+ * Only use for fields that genuinely don't work in a form (freeform JSON, deeply nested arrays).
13
+ */
6
14
  function withEditorHidden(schema) {
7
- return withEditor(schema, { hidden: true });
15
+ return withEditor(schema, { hidden: true });
8
16
  }
17
+ /**
18
+ * Factory for creating a module's `define*Schema()` and deprecated `as*Collection()` exports.
19
+ *
20
+ * Each module provides its own schema builder. The factory handles:
21
+ * - Zod instance passthrough for `@nuxt/content` version compatibility
22
+ * - Consistent `DefineSchemaOptions` interface
23
+ * - Deprecated `asXxxCollection()` wrapper with migration warning
24
+ *
25
+ * @example
26
+ * // In @nuxtjs/robots/content.ts
27
+ * import { z } from 'zod'
28
+ * import { createContentSchemaFactory } from 'nuxtseo-shared/content'
29
+ *
30
+ * const { defineSchema, asCollection, schema } = createContentSchemaFactory({
31
+ * fieldName: 'robots',
32
+ * label: 'robots',
33
+ * docsUrl: 'https://nuxtseo.com/robots/guides/content',
34
+ * buildSchema: (z) => z.enum(['index, follow', 'noindex', 'nofollow', 'noindex, nofollow', 'none']).optional(),
35
+ * }, z)
36
+ *
37
+ * export { defineSchema as defineRobotsSchema, asCollection as asRobotsCollection, schema }
38
+ */
9
39
  function createContentSchemaFactory(config, defaultZ) {
10
- const { fieldName, buildSchema, label, docsUrl } = config;
11
- const defaultSchema = buildSchema(defaultZ);
12
- const schemaObject = defaultZ.object({ [fieldName]: defaultSchema });
13
- function defineSchema(options) {
14
- const _z = options?.z ?? defaultZ;
15
- if (_z === defaultZ)
16
- return defaultSchema;
17
- return buildSchema(_z);
18
- }
19
- function asCollection(collection) {
20
- const migrationHint = docsUrl ? ` See ${docsUrl}` : "";
21
- console.warn(`[${label}] \`as${capitalize(label)}Collection()\` is deprecated. Use \`define${capitalize(label)}Schema()\` in your collection schema instead.${migrationHint}`);
22
- if (collection.type === "page") {
23
- collection.schema = collection.schema ? schemaObject.extend(collection.schema.shape) : schemaObject;
24
- }
25
- return collection;
26
- }
27
- return {
28
- defineSchema,
29
- asCollection,
30
- schema: schemaObject,
31
- fieldSchema: defaultSchema
32
- };
40
+ const { fieldName, buildSchema, label, docsUrl } = config;
41
+ const defaultSchema = buildSchema(defaultZ);
42
+ const schemaObject = defaultZ.object({ [fieldName]: defaultSchema });
43
+ function defineSchema(options) {
44
+ const _z = options?.z ?? defaultZ;
45
+ if (_z === defaultZ) return defaultSchema;
46
+ return buildSchema(_z);
47
+ }
48
+ function asCollection(collection) {
49
+ const migrationHint = docsUrl ? ` See ${docsUrl}` : "";
50
+ console.warn(`[${label}] \`as${capitalize(label)}Collection()\` is deprecated. Use \`define${capitalize(label)}Schema()\` in your collection schema instead.${migrationHint}`);
51
+ if (collection.type === "page") collection.schema = collection.schema ? schemaObject.extend(collection.schema.shape) : schemaObject;
52
+ return collection;
53
+ }
54
+ return {
55
+ defineSchema,
56
+ asCollection,
57
+ schema: schemaObject,
58
+ fieldSchema: defaultSchema
59
+ };
33
60
  }
34
61
  function capitalize(s) {
35
- return s.charAt(0).toUpperCase() + s.slice(1);
62
+ return s.charAt(0).toUpperCase() + s.slice(1);
36
63
  }
37
-
64
+ //#endregion
38
65
  export { createContentSchemaFactory, withEditor, withEditorHidden };
@@ -1,14 +1,14 @@
1
- import { Resolver } from '@nuxt/kit';
2
- import { Nuxt } from 'nuxt/schema';
1
+ import { Resolver } from "@nuxt/kit";
2
+ import { Nuxt } from "nuxt/schema";
3
3
 
4
+ //#region src/devtools.d.ts
4
5
  interface DevToolsUIConfig {
5
- route: string;
6
- name: string;
7
- title: string;
8
- icon: string;
9
- devPort?: number;
6
+ route: string;
7
+ name: string;
8
+ title: string;
9
+ icon: string;
10
+ devPort?: number;
10
11
  }
11
12
  declare function setupDevToolsUI(config: DevToolsUIConfig, resolve: Resolver['resolve'], nuxt?: Nuxt): void;
12
-
13
- export { setupDevToolsUI };
14
- export type { DevToolsUIConfig };
13
+ //#endregion
14
+ export { DevToolsUIConfig, setupDevToolsUI };
package/dist/devtools.mjs CHANGED
@@ -1,46 +1,40 @@
1
- import { existsSync } from 'node:fs';
2
- import { addCustomTab } from '@nuxt/devtools-kit';
3
- import { useNuxt } from '@nuxt/kit';
4
-
1
+ import { existsSync } from "node:fs";
2
+ import { addCustomTab } from "@nuxt/devtools-kit";
3
+ import { useNuxt } from "@nuxt/kit";
4
+ //#region src/devtools.ts
5
5
  function setupDevToolsUI(config, resolve, nuxt = useNuxt()) {
6
- const { route, name, title, icon, devPort = 3030 } = config;
7
- const clientPath = resolve("./client");
8
- const isProductionBuild = existsSync(clientPath);
9
- if (isProductionBuild) {
10
- nuxt.hook("vite:serverCreated", async (server) => {
11
- const sirv = await import('sirv').then((r) => r.default || r);
12
- server.middlewares.use(
13
- route,
14
- sirv(clientPath, { dev: true, single: true })
15
- );
16
- });
17
- } else {
18
- nuxt.hook("vite:extendConfig", (config2) => {
19
- Object.assign(config2, {
20
- server: {
21
- ...config2.server,
22
- proxy: {
23
- ...config2.server?.proxy,
24
- [route]: {
25
- target: `http://localhost:${devPort}${route}`,
26
- changeOrigin: true,
27
- followRedirects: true,
28
- rewrite: (p) => p.replace(route, "")
29
- }
30
- }
31
- }
32
- });
33
- });
34
- }
35
- addCustomTab({
36
- name,
37
- title,
38
- icon,
39
- view: {
40
- type: "iframe",
41
- src: route
42
- }
43
- });
6
+ const { route, name, title, icon, devPort = 3030 } = config;
7
+ const clientPath = resolve("./client");
8
+ if (existsSync(clientPath)) nuxt.hook("vite:serverCreated", async (server) => {
9
+ const sirv = await import("sirv").then((r) => r.default || r);
10
+ server.middlewares.use(route, sirv(clientPath, {
11
+ dev: true,
12
+ single: true
13
+ }));
14
+ });
15
+ else nuxt.hook("vite:extendConfig", (config) => {
16
+ Object.assign(config, { server: {
17
+ ...config.server,
18
+ proxy: {
19
+ ...config.server?.proxy,
20
+ [route]: {
21
+ target: `http://localhost:${devPort}${route}`,
22
+ changeOrigin: true,
23
+ followRedirects: true,
24
+ rewrite: (p) => p.replace(route, "")
25
+ }
26
+ }
27
+ } });
28
+ });
29
+ addCustomTab({
30
+ name,
31
+ title,
32
+ icon,
33
+ view: {
34
+ type: "iframe",
35
+ src: route
36
+ }
37
+ });
44
38
  }
45
-
39
+ //#endregion
46
40
  export { setupDevToolsUI };
package/dist/i18n.d.mts CHANGED
@@ -1,32 +1,44 @@
1
- import { LocaleObject, NuxtI18nOptions } from '@nuxtjs/i18n';
1
+ import { LocaleObject, NuxtI18nOptions } from "@nuxtjs/i18n";
2
2
 
3
+ //#region src/i18n.d.ts
4
+ declare const I18N_MODULES: readonly ["@nuxtjs/i18n", "nuxt-i18n-micro"];
5
+ type I18nModuleName = typeof I18N_MODULES[number];
3
6
  type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
4
7
  type NormalisedLocale = LocaleObject & {
5
- _sitemap: string;
6
- _hreflang: string;
8
+ _sitemap: string;
9
+ _hreflang: string;
7
10
  };
8
11
  interface AutoI18nConfig {
9
- locales: NormalisedLocale[];
10
- defaultLocale: string;
11
- strategy: Strategies;
12
- differentDomains?: boolean;
13
- pages?: Record<string, Record<string, string | false>>;
12
+ locales: NormalisedLocale[];
13
+ defaultLocale: string;
14
+ strategy: Strategies;
15
+ differentDomains?: boolean;
16
+ pages?: Record<string, Record<string, string | false>>;
14
17
  }
15
18
  interface StrategyProps {
16
- localeCode: string;
17
- pageLocales: string;
18
- nuxtI18nConfig: NuxtI18nOptions;
19
- forcedStrategy?: Strategies;
20
- normalisedLocales: AutoI18nConfig['locales'];
19
+ localeCode: string;
20
+ pageLocales: string;
21
+ nuxtI18nConfig: NuxtI18nOptions;
22
+ forcedStrategy?: Strategies;
23
+ normalisedLocales: AutoI18nConfig['locales'];
21
24
  }
22
25
  declare function generatePathForI18nPages(ctx: StrategyProps): string;
23
26
  declare function splitPathForI18nLocales(path: string, autoI18n: AutoI18nConfig): string | string[];
24
27
  declare function normalizeLocales(nuxtI18nConfig: NuxtI18nOptions): AutoI18nConfig['locales'];
25
28
  declare function mapPathForI18nPages(path: string, autoI18n: AutoI18nConfig): string[] | false;
29
+ interface I18nModuleResolution {
30
+ module: I18nModuleName;
31
+ isMicro: boolean;
32
+ }
33
+ /**
34
+ * Detect which i18n module is installed (@nuxtjs/i18n or nuxt-i18n-micro).
35
+ *
36
+ * Returns `false` when neither is installed.
37
+ */
38
+ declare function resolveI18nModule(): false | I18nModuleResolution;
26
39
  declare function resolveI18nConfig(logger?: {
27
- warn: (msg: string) => void;
40
+ warn: (msg: string) => void;
28
41
  }): Promise<false | AutoI18nConfig>;
29
42
  declare function mergeOnKey<T extends Record<string, any>>(arr: T[], key: keyof T): T[];
30
-
31
- export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, splitPathForI18nLocales };
32
- export type { AutoI18nConfig, NormalisedLocale, Strategies, StrategyProps };
43
+ //#endregion
44
+ export { AutoI18nConfig, I18nModuleResolution, NormalisedLocale, Strategies, StrategyProps, generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales };
package/dist/i18n.mjs CHANGED
@@ -1,121 +1,122 @@
1
- import { hasNuxtModule, getNuxtModuleVersion, hasNuxtModuleCompatibility } from '@nuxt/kit';
2
- import { joinURL, withHttps, withBase, withLeadingSlash } from 'ufo';
3
- import { getNuxtModuleOptions } from './kit.mjs';
4
- import 'pathe';
5
- import 'std-env';
6
-
1
+ import { getNuxtModuleOptions } from "./kit.mjs";
2
+ import { getNuxtModuleVersion, hasNuxtModule, hasNuxtModuleCompatibility } from "@nuxt/kit";
3
+ import { joinURL, withBase, withHttps, withLeadingSlash } from "ufo";
4
+ //#region src/i18n.ts
5
+ const I18N_MODULES = ["@nuxtjs/i18n", "nuxt-i18n-micro"];
7
6
  const SLASH_PATTERN = /^\/|\/$/g;
8
7
  function generatePathForI18nPages(ctx) {
9
- const { localeCode, pageLocales, nuxtI18nConfig, forcedStrategy, normalisedLocales } = ctx;
10
- const locale = normalisedLocales.find((l) => l.code === localeCode);
11
- let path = pageLocales;
12
- switch (forcedStrategy ?? nuxtI18nConfig.strategy) {
13
- case "prefix_except_default":
14
- case "prefix_and_default":
15
- path = localeCode === nuxtI18nConfig.defaultLocale ? pageLocales : joinURL(localeCode, pageLocales);
16
- break;
17
- case "prefix":
18
- path = joinURL(localeCode, pageLocales);
19
- break;
20
- }
21
- return locale?.domain ? withHttps(withBase(path, locale.domain)) : path;
8
+ const { localeCode, pageLocales, nuxtI18nConfig, forcedStrategy, normalisedLocales } = ctx;
9
+ const locale = normalisedLocales.find((l) => l.code === localeCode);
10
+ let path = pageLocales;
11
+ switch (forcedStrategy ?? nuxtI18nConfig.strategy) {
12
+ case "prefix_except_default":
13
+ case "prefix_and_default":
14
+ path = localeCode === nuxtI18nConfig.defaultLocale ? pageLocales : joinURL(localeCode, pageLocales);
15
+ break;
16
+ case "prefix":
17
+ path = joinURL(localeCode, pageLocales);
18
+ break;
19
+ }
20
+ return locale?.domain ? withHttps(withBase(path, locale.domain)) : path;
22
21
  }
23
22
  function splitPathForI18nLocales(path, autoI18n) {
24
- const locales = autoI18n.strategy === "prefix_except_default" ? autoI18n.locales.filter((l) => l.code !== autoI18n.defaultLocale) : autoI18n.locales;
25
- if (!path || path.startsWith("/_"))
26
- return path;
27
- const hasLocalePrefix = locales.some((l) => path.startsWith(`/${l.code}/`) || path === `/${l.code}`);
28
- if (hasLocalePrefix)
29
- return path;
30
- return [
31
- path,
32
- ...locales.map((l) => `/${l.code}${path}`)
33
- ];
23
+ const locales = autoI18n.strategy === "prefix_except_default" ? autoI18n.locales.filter((l) => l.code !== autoI18n.defaultLocale) : autoI18n.locales;
24
+ if (!path || path.startsWith("/_")) return path;
25
+ if (locales.some((l) => path.startsWith(`/${l.code}/`) || path === `/${l.code}`)) return path;
26
+ return [path, ...locales.map((l) => `/${l.code}${path}`)];
34
27
  }
35
28
  function normalizeLocales(nuxtI18nConfig) {
36
- const rawLocales = nuxtI18nConfig.locales || [];
37
- let onlyLocales = nuxtI18nConfig?.bundle?.onlyLocales || [];
38
- onlyLocales = typeof onlyLocales === "string" ? [onlyLocales] : onlyLocales;
39
- let locales = mergeOnKey(rawLocales.map((locale) => typeof locale === "string" ? { code: locale } : locale), "code");
40
- if (onlyLocales.length) {
41
- locales = locales.filter((locale) => onlyLocales.includes(locale.code));
42
- }
43
- return locales.map((locale) => {
44
- if (typeof locale.iso === "string" && !locale.language) {
45
- locale.language = locale.iso;
46
- }
47
- const _hreflang = locale.language || locale.code;
48
- const _sitemap = locale.language || locale.code;
49
- return { ...locale, _hreflang, _sitemap };
50
- });
29
+ const rawLocales = nuxtI18nConfig.locales || [];
30
+ let onlyLocales = nuxtI18nConfig?.bundle?.onlyLocales || [];
31
+ onlyLocales = typeof onlyLocales === "string" ? [onlyLocales] : onlyLocales;
32
+ let locales = mergeOnKey(rawLocales.map((locale) => typeof locale === "string" ? { code: locale } : locale), "code");
33
+ if (onlyLocales.length) locales = locales.filter((locale) => onlyLocales.includes(locale.code));
34
+ return locales.map((locale) => {
35
+ if (typeof locale.iso === "string" && !locale.language) locale.language = locale.iso;
36
+ const _hreflang = locale.language || locale.code;
37
+ const _sitemap = locale.language || locale.code;
38
+ return {
39
+ ...locale,
40
+ _hreflang,
41
+ _sitemap
42
+ };
43
+ });
51
44
  }
52
45
  function mapPathForI18nPages(path, autoI18n) {
53
- const pages = autoI18n.pages;
54
- if (!pages || !Object.keys(pages).length)
55
- return false;
56
- const withoutSlashes = path.replace(SLASH_PATTERN, "").replace("/index", "");
57
- function resolveForAllLocales(pageName, pageLocales) {
58
- return autoI18n.locales.filter((l) => {
59
- if (l.code in pageLocales && pageLocales[l.code] === false)
60
- return false;
61
- if (autoI18n.strategy === "prefix_except_default" && l.code === autoI18n.defaultLocale)
62
- return false;
63
- return true;
64
- }).map((l) => {
65
- const localePath = l.code in pageLocales && pageLocales[l.code] !== false ? pageLocales[l.code] : `/${pageName}`;
66
- return withLeadingSlash(generatePathForI18nPages({
67
- localeCode: l.code,
68
- pageLocales: localePath,
69
- nuxtI18nConfig: { strategy: autoI18n.strategy, defaultLocale: autoI18n.defaultLocale },
70
- normalisedLocales: autoI18n.locales
71
- }));
72
- });
73
- }
74
- if (withoutSlashes in pages) {
75
- const pageLocales = pages[withoutSlashes];
76
- if (pageLocales)
77
- return resolveForAllLocales(withoutSlashes, pageLocales);
78
- }
79
- for (const [pageName, pageLocales] of Object.entries(pages)) {
80
- if (!pageLocales)
81
- continue;
82
- if (autoI18n.defaultLocale in pageLocales && pageLocales[autoI18n.defaultLocale] === path)
83
- return resolveForAllLocales(pageName, pageLocales);
84
- }
85
- return false;
46
+ const pages = autoI18n.pages;
47
+ if (!pages || !Object.keys(pages).length) return false;
48
+ const withoutSlashes = path.replace(SLASH_PATTERN, "").replace("/index", "");
49
+ function resolveForAllLocales(pageName, pageLocales) {
50
+ return autoI18n.locales.filter((l) => {
51
+ if (l.code in pageLocales && pageLocales[l.code] === false) return false;
52
+ if (autoI18n.strategy === "prefix_except_default" && l.code === autoI18n.defaultLocale) return false;
53
+ return true;
54
+ }).map((l) => {
55
+ const localePath = l.code in pageLocales && pageLocales[l.code] !== false ? pageLocales[l.code] : `/${pageName}`;
56
+ return withLeadingSlash(generatePathForI18nPages({
57
+ localeCode: l.code,
58
+ pageLocales: localePath,
59
+ nuxtI18nConfig: {
60
+ strategy: autoI18n.strategy,
61
+ defaultLocale: autoI18n.defaultLocale
62
+ },
63
+ normalisedLocales: autoI18n.locales
64
+ }));
65
+ });
66
+ }
67
+ if (withoutSlashes in pages) {
68
+ const pageLocales = pages[withoutSlashes];
69
+ if (pageLocales) return resolveForAllLocales(withoutSlashes, pageLocales);
70
+ }
71
+ for (const [pageName, pageLocales] of Object.entries(pages)) {
72
+ if (!pageLocales) continue;
73
+ if (autoI18n.defaultLocale in pageLocales && pageLocales[autoI18n.defaultLocale] === path) return resolveForAllLocales(pageName, pageLocales);
74
+ }
75
+ return false;
76
+ }
77
+ /**
78
+ * Detect which i18n module is installed (@nuxtjs/i18n or nuxt-i18n-micro).
79
+ *
80
+ * Returns `false` when neither is installed.
81
+ */
82
+ function resolveI18nModule() {
83
+ const found = I18N_MODULES.find((m) => hasNuxtModule(m));
84
+ if (!found) return false;
85
+ return {
86
+ module: found,
87
+ isMicro: found === "nuxt-i18n-micro"
88
+ };
86
89
  }
87
90
  async function resolveI18nConfig(logger) {
88
- if (!hasNuxtModule("@nuxtjs/i18n"))
89
- return false;
90
- const i18nVersion = await getNuxtModuleVersion("@nuxtjs/i18n");
91
- if (!await hasNuxtModuleCompatibility("@nuxtjs/i18n", ">=8")) {
92
- logger?.warn(`You are using @nuxtjs/i18n v${i18nVersion}. For the best compatibility, please upgrade to @nuxtjs/i18n v8.0.0 or higher.`);
93
- }
94
- const nuxtI18nConfig = await getNuxtModuleOptions("@nuxtjs/i18n") || {};
95
- const normalisedLocales = normalizeLocales(nuxtI18nConfig);
96
- const usingI18nPages = Object.keys(nuxtI18nConfig.pages || {}).length;
97
- const hasI18nConfigForAlternatives = nuxtI18nConfig.differentDomains || usingI18nPages || nuxtI18nConfig.strategy !== "no_prefix" && nuxtI18nConfig.locales;
98
- if (!hasI18nConfigForAlternatives)
99
- return false;
100
- return {
101
- differentDomains: nuxtI18nConfig.differentDomains,
102
- defaultLocale: nuxtI18nConfig.defaultLocale,
103
- locales: normalisedLocales,
104
- strategy: nuxtI18nConfig.strategy,
105
- pages: nuxtI18nConfig.pages
106
- };
91
+ const i18n = resolveI18nModule();
92
+ if (!i18n) return false;
93
+ if (!i18n.isMicro) {
94
+ const i18nVersion = await getNuxtModuleVersion(i18n.module);
95
+ if (!await hasNuxtModuleCompatibility(i18n.module, ">=8")) logger?.warn(`You are using ${i18n.module} v${i18nVersion}. For the best compatibility, please upgrade to ${i18n.module} v8.0.0 or higher.`);
96
+ }
97
+ const nuxtI18nConfig = await getNuxtModuleOptions(i18n.module) || {};
98
+ const normalisedLocales = normalizeLocales(nuxtI18nConfig);
99
+ const usingI18nPages = Object.keys(nuxtI18nConfig.pages || {}).length;
100
+ if (!(nuxtI18nConfig.differentDomains || usingI18nPages || nuxtI18nConfig.strategy !== "no_prefix" && nuxtI18nConfig.locales)) return false;
101
+ return {
102
+ differentDomains: nuxtI18nConfig.differentDomains,
103
+ defaultLocale: nuxtI18nConfig.defaultLocale,
104
+ locales: normalisedLocales,
105
+ strategy: nuxtI18nConfig.strategy,
106
+ pages: nuxtI18nConfig.pages
107
+ };
107
108
  }
108
109
  function mergeOnKey(arr, key) {
109
- const map = /* @__PURE__ */ new Map();
110
- for (const item of arr) {
111
- const k = item[key];
112
- if (map.has(k)) {
113
- map.set(k, { ...map.get(k), ...item });
114
- } else {
115
- map.set(k, item);
116
- }
117
- }
118
- return [...map.values()];
110
+ const map = /* @__PURE__ */ new Map();
111
+ for (const item of arr) {
112
+ const k = item[key];
113
+ if (map.has(k)) map.set(k, {
114
+ ...map.get(k),
115
+ ...item
116
+ });
117
+ else map.set(k, item);
118
+ }
119
+ return [...map.values()];
119
120
  }
120
-
121
- export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, splitPathForI18nLocales };
121
+ //#endregion
122
+ export { generatePathForI18nPages, mapPathForI18nPages, mergeOnKey, normalizeLocales, resolveI18nConfig, resolveI18nModule, splitPathForI18nLocales };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,3 @@
1
- export { setupDevToolsUI } from './devtools.mjs';
2
- export { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset } from './kit.mjs';
3
- import '@nuxt/kit';
4
- import 'nuxt/schema';
5
- import '@nuxt/schema';
6
- import 'nitropack';
7
- import 'nitropack/types';
1
+ import { setupDevToolsUI } from "./devtools.mjs";
2
+ import { NuxtContentVersion, createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion } from "./kit.mjs";
3
+ export { type NuxtContentVersion, createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion, setupDevToolsUI };
package/dist/index.mjs CHANGED
@@ -1,7 +1,3 @@
1
- export { setupDevToolsUI } from './devtools.mjs';
2
- export { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset } from './kit.mjs';
3
- import 'node:fs';
4
- import '@nuxt/devtools-kit';
5
- import '@nuxt/kit';
6
- import 'pathe';
7
- import 'std-env';
1
+ import { setupDevToolsUI } from "./devtools.mjs";
2
+ import { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion } from "./kit.mjs";
3
+ export { createNitroPromise, createPagesPromise, detectTarget, extendTypes, getNuxtModuleOptions, isNuxtGenerate, resolveNitroPreset, resolveNuxtContentVersion, setupDevToolsUI };