@verbaly/nuxt 0.74.0 → 0.76.0

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/README.md CHANGED
@@ -19,6 +19,7 @@ One line in `nuxt.config` wires everything: the Vite plugin (live extraction + t
19
19
 
20
20
  ```bash
21
21
  pnpm add verbaly @verbaly/nuxt @verbaly/vue
22
+ pnpm add -D @verbaly/compiler # the verbaly command: init, extract, check
22
23
  ```
23
24
 
24
25
  ## ⚡ Wire it up
package/dist/module.d.ts CHANGED
@@ -39,5 +39,4 @@ declare namespace verbalyModule {
39
39
  var getOptions: (inlineOptions?: Partial<VerbalyNuxtOptions>, nuxt?: NuxtLike) => Promise<VerbalyNuxtOptions>;
40
40
  }
41
41
  //#endregion
42
- export { type ViteVerbalyOptions, verbalyModule as default };
43
- //# sourceMappingURL=module.d.ts.map
42
+ export { type ViteVerbalyOptions, verbalyModule as default };
package/dist/module.js CHANGED
@@ -21,7 +21,7 @@ function verbalyModule(inlineOptions, nuxt) {
21
21
  }));
22
22
  });
23
23
  nuxt.hook("prepare:types", async ({ references }) => {
24
- const cfg = await loadConfig(nuxt.options.rootDir, vite);
24
+ const cfg = await loadConfig(nuxt.options.rootDir, vite, { plugin: true });
25
25
  if (cfg.dts === false) return;
26
26
  writeDts(cfg, loadCatalogs(cfg)[cfg.sourceLocale] ?? {});
27
27
  references.push({ path: cfg.dts });
@@ -39,5 +39,3 @@ verbalyModule.getOptions = async (inlineOptions, nuxt) => ({
39
39
  });
40
40
  //#endregion
41
41
  export { verbalyModule as default };
42
-
43
- //# sourceMappingURL=module.js.map
@@ -61,5 +61,3 @@ var plugin_default = defineNuxtPlugin(async (nuxtApp) => {
61
61
  });
62
62
  //#endregion
63
63
  export { plugin_default as default };
64
-
65
- //# sourceMappingURL=plugin.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/nuxt",
3
- "version": "0.74.0",
3
+ "version": "0.76.0",
4
4
  "description": "Nuxt integration for Verbaly: zero-config module with per-request locale negotiation and flash-free hydration.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -41,19 +41,19 @@
41
41
  "access": "public"
42
42
  },
43
43
  "dependencies": {
44
- "@verbaly/compiler": "^0.74.0",
45
- "@verbaly/vite": "^0.74.0"
44
+ "@verbaly/compiler": "^0.76.0",
45
+ "@verbaly/vite": "^0.76.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@verbaly/vue": "^0.74.0",
49
- "verbaly": "^0.74.0",
48
+ "@verbaly/vue": "^0.76.0",
49
+ "verbaly": "^0.76.0",
50
50
  "vue": "^3.4.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@nuxt/schema": "^4.6.2",
54
- "@verbaly/vue": "^0.74.0",
55
- "happy-dom": "^21.0.3",
56
- "verbaly": "^0.74.0",
54
+ "@verbaly/vue": "^0.76.0",
55
+ "happy-dom": "^21.0.4",
56
+ "verbaly": "^0.76.0",
57
57
  "vue": "^3.5.44"
58
58
  },
59
59
  "scripts": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"module.js","names":[],"sources":["../src/module.ts"],"sourcesContent":["import { loadCatalogs, loadConfig, writeDts } from '@verbaly/compiler';\nimport verbalyVite, { type ViteVerbalyOptions } from '@verbaly/vite';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nexport type { ViteVerbalyOptions } from '@verbaly/vite';\n\nexport interface VerbalyNuxtOptions extends ViteVerbalyOptions {\n cookie?: string | false;\n fallback?: string;\n}\n\n// structural subset of Nuxt: no runtime or type dependency on nuxt/@nuxt/kit\ninterface ViteConfigLike {\n plugins?: unknown[];\n}\ninterface PrepareTypesLike {\n references: Array<{ path: string } | { types: string }>;\n}\nexport interface NuxtLike {\n options: {\n rootDir: string;\n buildDir: string;\n plugins: unknown[];\n build: { transpile: unknown[] };\n runtimeConfig: { public: Record<string, unknown> };\n verbaly?: VerbalyNuxtOptions;\n };\n hook(name: 'vite:extendConfig', fn: (config: ViteConfigLike) => void): void;\n hook(name: 'prepare:types', fn: (options: PrepareTypesLike) => Promise<void>): void;\n}\n\nconst runtimeDir = join(dirname(fileURLToPath(import.meta.url)), 'runtime');\n\n// plain-function Nuxt module: configKey `verbaly`, inline options win\nfunction verbalyModule(inlineOptions: VerbalyNuxtOptions | undefined, nuxt: NuxtLike): void {\n const { cookie, fallback, ...vite } = { ...nuxt.options.verbaly, ...inlineOptions };\n\n // negotiation options ride runtimeConfig to the runtime plugin\n nuxt.options.runtimeConfig.public.verbaly = {\n ...(cookie !== undefined && { cookie }),\n ...(fallback !== undefined && { fallback }),\n };\n\n // types go to Nuxt's own slot (.nuxt/), set before the hooks fire so dev keeps it fresh\n vite.dts ??= join(nuxt.options.buildDir, 'verbaly.d.ts');\n\n // fresh plugin per Vite build (client and server must not share state), root pinned to rootDir\n nuxt.hook('vite:extendConfig', (config) => {\n (config.plugins ??= []).push(verbalyVite({ root: nuxt.options.rootDir, ...vite }));\n });\n\n // the file must exist when the reference lands in .nuxt/nuxt.d.ts or TS reports it missing\n nuxt.hook('prepare:types', async ({ references }) => {\n const cfg = await loadConfig(nuxt.options.rootDir, vite);\n if (cfg.dts === false) return;\n writeDts(cfg, loadCatalogs(cfg)[cfg.sourceLocale] ?? {});\n references.push({ path: cfg.dts });\n });\n\n nuxt.options.build.transpile.push(runtimeDir);\n // prepend: the instance must exist before app plugins and components run\n nuxt.options.plugins.unshift(join(runtimeDir, 'plugin.js'));\n}\n\nverbalyModule.meta = { name: '@verbaly/nuxt', configKey: 'verbaly' };\n\n// getOptions is the anchor Nuxt's config typing infers from: the call signature alone degrades it\nverbalyModule.getOptions = async (\n inlineOptions?: Partial<VerbalyNuxtOptions>,\n nuxt?: NuxtLike,\n): Promise<VerbalyNuxtOptions> => ({ ...nuxt?.options.verbaly, ...inlineOptions });\n\nexport default verbalyModule;\n"],"mappings":";;;;;AAgCA,MAAM,aAAa,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC,GAAG,SAAS;AAG1E,SAAS,cAAc,eAA+C,MAAsB;CAC1F,MAAM,EAAE,QAAQ,UAAU,GAAG,SAAS;EAAE,GAAG,KAAK,QAAQ;EAAS,GAAG;CAAc;CAGlF,KAAK,QAAQ,cAAc,OAAO,UAAU;EAC1C,GAAI,WAAW,KAAA,KAAa,EAAE,OAAO;EACrC,GAAI,aAAa,KAAA,KAAa,EAAE,SAAS;CAC3C;CAGA,KAAK,QAAQ,KAAK,KAAK,QAAQ,UAAU,cAAc;CAGvD,KAAK,KAAK,sBAAsB,WAAW;EACzC,CAAC,OAAO,YAAY,CAAC,EAAA,CAAG,KAAK,YAAY;GAAE,MAAM,KAAK,QAAQ;GAAS,GAAG;EAAK,CAAC,CAAC;CACnF,CAAC;CAGD,KAAK,KAAK,iBAAiB,OAAO,EAAE,iBAAiB;EACnD,MAAM,MAAM,MAAM,WAAW,KAAK,QAAQ,SAAS,IAAI;EACvD,IAAI,IAAI,QAAQ,OAAO;EACvB,SAAS,KAAK,aAAa,GAAG,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC;EACvD,WAAW,KAAK,EAAE,MAAM,IAAI,IAAI,CAAC;CACnC,CAAC;CAED,KAAK,QAAQ,MAAM,UAAU,KAAK,UAAU;CAE5C,KAAK,QAAQ,QAAQ,QAAQ,KAAK,YAAY,WAAW,CAAC;AAC5D;AAEA,cAAc,OAAO;CAAE,MAAM;CAAiB,WAAW;AAAU;AAGnE,cAAc,aAAa,OACzB,eACA,UACiC;CAAE,GAAG,MAAM,QAAQ;CAAS,GAAG;AAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","names":[],"sources":["../../src/runtime/plugin.ts"],"sourcesContent":["import { defineNuxtPlugin, useHead, useRequestURL, useRuntimeConfig, useState } from '#imports';\nimport { verbalyPlugin, type VerbalyPlugin } from '@verbaly/vue';\nimport { LOCALE_STORAGE_KEY, localeDirection, resolveRequestLocale } from 'verbaly';\nimport { createRequestInstance, locales, routing, sourceLocale } from 'virtual:verbaly';\nimport { shallowRef } from 'vue';\n\ninterface VerbalyRuntimeConfig {\n cookie?: string | false;\n fallback?: string;\n}\n\n// structural subset of NuxtApp: the real one arrives at runtime\ninterface NuxtAppLike {\n vueApp: { use(plugin: VerbalyPlugin): unknown };\n ssrContext?: { event?: { headers?: { get(name: string): string | null } } };\n}\n\n// one cookie value out of a Cookie header / document.cookie\nfunction readCookie(header: string | null | undefined, name: string): string | undefined {\n if (!header) return undefined;\n for (const part of header.split(';')) {\n const eq = part.indexOf('=');\n if (eq === -1) continue;\n if (part.slice(0, eq).trim() !== name) continue;\n const value = part.slice(eq + 1).trim();\n try {\n return decodeURIComponent(value);\n } catch {\n return value;\n }\n }\n return undefined;\n}\n\nexport default defineNuxtPlugin(async (nuxtApp: NuxtAppLike) => {\n if (!Array.isArray(locales) || locales.length === 0) {\n throw new Error(\n \"[verbaly] no `locales` in 'virtual:verbaly': declare them in verbaly.config \" +\n 'or in the module options (`verbaly: { locales: [...] }` in nuxt.config)',\n );\n }\n const runtime = useRuntimeConfig();\n const config = (runtime.public.verbaly ?? {}) as VerbalyRuntimeConfig;\n const cookieName = config.cookie === false ? false : config.cookie || LOCALE_STORAGE_KEY;\n const fallback = config.fallback ?? sourceLocale;\n // the address is the same on both sides of hydration, unlike the header and the cookie\n const url = { path: useRequestURL().pathname, routing, base: runtime.app?.baseURL };\n\n // negotiated on the server, hydrated from the payload: the client renders the same locale\n const locale = useState<string>('verbaly:locale', () => {\n const headers = nuxtApp.ssrContext?.event?.headers;\n if (headers) {\n return resolveRequestLocale({\n supported: locales,\n ...url,\n cookie: cookieName ? readCookie(headers.get('cookie'), cookieName) : undefined,\n header: headers.get('accept-language'),\n fallback,\n });\n }\n // client-only app (ssr: false): url → cookie → navigator.languages → fallback\n return resolveRequestLocale({\n supported: locales,\n ...url,\n cookie:\n cookieName && typeof document !== 'undefined'\n ? readCookie(document.cookie, cookieName)\n : undefined,\n header:\n typeof navigator !== 'undefined'\n ? (navigator.languages?.join(',') ?? navigator.language)\n : undefined,\n fallback,\n });\n });\n\n // fresh instance per request, catalog awaited BEFORE render: the no-FOUC contract\n const instance = await createRequestInstance(locale.value);\n nuxtApp.vueApp.use(verbalyPlugin(instance));\n\n // <html lang> and <html dir> follow the live locale\n const lang = shallowRef(instance.locale);\n const dir = shallowRef(localeDirection(instance.locale));\n instance.subscribe(() => {\n lang.value = instance.locale;\n dir.value = localeDirection(instance.locale);\n });\n useHead({ htmlAttrs: { lang, dir } });\n});\n"],"mappings":";;;;;;AAkBA,SAAS,WAAW,QAAmC,MAAkC;CACvF,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,KAAK,MAAM,QAAQ,OAAO,MAAM,GAAG,GAAG;EACpC,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC3B,IAAI,OAAO,IAAI;EACf,IAAI,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,MAAM,MAAM;EACvC,MAAM,QAAQ,KAAK,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK;EACtC,IAAI;GACF,OAAO,mBAAmB,KAAK;EACjC,QAAQ;GACN,OAAO;EACT;CACF;AAEF;AAEA,IAAA,iBAAe,iBAAiB,OAAO,YAAyB;CAC9D,IAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW,GAChD,MAAM,IAAI,MACR,qJAEF;CAEF,MAAM,UAAU,iBAAiB;CACjC,MAAM,SAAU,QAAQ,OAAO,WAAW,CAAC;CAC3C,MAAM,aAAa,OAAO,WAAW,QAAQ,QAAQ,OAAO,UAAU;CACtE,MAAM,WAAW,OAAO,YAAY;CAEpC,MAAM,MAAM;EAAE,MAAM,cAAc,CAAC,CAAC;EAAU;EAAS,MAAM,QAAQ,KAAK;CAAQ;CAGlF,MAAM,SAAS,SAAiB,wBAAwB;EACtD,MAAM,UAAU,QAAQ,YAAY,OAAO;EAC3C,IAAI,SACF,OAAO,qBAAqB;GAC1B,WAAW;GACX,GAAG;GACH,QAAQ,aAAa,WAAW,QAAQ,IAAI,QAAQ,GAAG,UAAU,IAAI,KAAA;GACrE,QAAQ,QAAQ,IAAI,iBAAiB;GACrC;EACF,CAAC;EAGH,OAAO,qBAAqB;GAC1B,WAAW;GACX,GAAG;GACH,QACE,cAAc,OAAO,aAAa,cAC9B,WAAW,SAAS,QAAQ,UAAU,IACtC,KAAA;GACN,QACE,OAAO,cAAc,cAChB,UAAU,WAAW,KAAK,GAAG,KAAK,UAAU,WAC7C,KAAA;GACN;EACF,CAAC;CACH,CAAC;CAGD,MAAM,WAAW,MAAM,sBAAsB,OAAO,KAAK;CACzD,QAAQ,OAAO,IAAI,cAAc,QAAQ,CAAC;CAG1C,MAAM,OAAO,WAAW,SAAS,MAAM;CACvC,MAAM,MAAM,WAAW,gBAAgB,SAAS,MAAM,CAAC;CACvD,SAAS,gBAAgB;EACvB,KAAK,QAAQ,SAAS;EACtB,IAAI,QAAQ,gBAAgB,SAAS,MAAM;CAC7C,CAAC;CACD,QAAQ,EAAE,WAAW;EAAE;EAAM;CAAI,EAAE,CAAC;AACtC,CAAC"}