@verbaly/vite 0.69.1 → 0.70.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
@@ -36,7 +36,7 @@ import { t, setLocale } from 'virtual:verbaly';
36
36
  - **Live extraction** with debounced catalog writes + HMR, from `.js/.ts/.jsx/.tsx` and `.svelte`/`.vue` files (script and markup). Every write starts from the files on disk, so a checkout or an `extract` run in another terminal is never undone with an older text, and a catalog saved half-typed is reported in one line while the server keeps running. The terminal says what `next dev` says, once each: a hand edit of a text your code owns, a key with two texts, a `t` under another name, a translation older than its source.
37
37
  - **Typed keys**: the types go to `src/verbaly.d.ts` (the root when there is no `src/`), the folder the Vite and SvelteKit templates' `tsconfig` includes, so `tsc -b` sees them with nothing to configure. `npx verbaly typegen` writes them on a fresh clone.
38
38
  - **Per-locale code-splitting**: `setLocale` lazy-loads only what's used.
39
- - **Build gate**: missing translations stop the build (same as `verbaly check`); `failOnMissing: false` opts out.
39
+ - **Build report**: every `vite build` says what `verbaly check` would fail on (broken translations first, then missing ones and keys no catalog has) and goes on, since a text never stops a deploy; `verbaly check` is the gate for CI. `failOnMissing: true` stops the build instead.
40
40
  - **Files outside `include`**: when the dev server or the build starts, it names once every file outside your `include` that writes a `` t`…` ``, since that text is never extracted and shows in the source language.
41
41
 
42
42
  📖 Docs: **https://verbaly-web.vercel.app/docs/frameworks/vite**
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, createDevReporter, createSourceFilter, extractProject, formatCliError, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, outdatedTranslations, reportOutsideInclude, resolveVirtualId, runBuildGate, syncCatalogs, syncProject, transformSource, writeDts } from "@verbaly/compiler";
1
+ import { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, createDevReporter, createSourceFilter, extractProject, formatCliError, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, outdatedTranslations, reportOutsideInclude, resolveVirtualId, runBuildGate, syncCatalogs, syncProject, transformSource, writeDts } from "@verbaly/compiler";
2
2
  import { readFileSync } from "node:fs";
3
3
  //#region src/index.ts
4
4
  function safeRead(file) {
@@ -8,6 +8,9 @@ function safeRead(file) {
8
8
  return;
9
9
  }
10
10
  }
11
+ const VIRTUAL_ID_FILTER = new RegExp(`^${RESOLVED_VIRTUAL_ID.slice(1)}(?:/|$)`);
12
+ const RESOLVED_ID_FILTER = new RegExp(`^${RESOLVED_VIRTUAL_ID}(?:/|$)`);
13
+ const ANY_RESOLVED_ID = new RegExp(`^${RESOLVED_VIRTUAL_ID.charAt(0)}`);
11
14
  function verbaly(options = {}) {
12
15
  let cfg;
13
16
  let catalogs;
@@ -109,26 +112,38 @@ function verbaly(options = {}) {
109
112
  if (!isBuild) return;
110
113
  syncCatalogs(cfg, catalogs, await extractProject(cfg));
111
114
  },
112
- resolveId(id) {
113
- return resolveVirtualId(id);
115
+ resolveId: {
116
+ filter: { id: VIRTUAL_ID_FILTER },
117
+ handler(id) {
118
+ return resolveVirtualId(id);
119
+ }
114
120
  },
115
- load(id) {
116
- return loadVirtualModule(id, cfg, catalogs);
121
+ load: {
122
+ filter: { id: RESOLVED_ID_FILTER },
123
+ handler(id) {
124
+ return loadVirtualModule(id, cfg, catalogs);
125
+ }
117
126
  },
118
- transform(code, id) {
119
- if (!isTransformTarget(id) || !included(id)) return void 0;
120
- const { messages, result } = transformSource(code, id, registry);
121
- const found = Object.entries(messages);
122
- if (!isBuild && found.length > 0) {
123
- const source = catalogs[cfg.sourceLocale] ??= {};
124
- let changed = false;
125
- for (const [key, message] of found) if (source[key] !== message) {
126
- source[key] = message;
127
- changed = true;
127
+ transform: {
128
+ filter: { id: {
129
+ include: SOURCE_FILE_RE,
130
+ exclude: [/node_modules/, ANY_RESOLVED_ID]
131
+ } },
132
+ handler(code, id) {
133
+ if (!isTransformTarget(id) || !included(id)) return void 0;
134
+ const { messages, result } = transformSource(code, id, registry);
135
+ const found = Object.entries(messages);
136
+ if (!isBuild && found.length > 0) {
137
+ const source = catalogs[cfg.sourceLocale] ??= {};
138
+ let changed = false;
139
+ for (const [key, message] of found) if (source[key] !== message) {
140
+ source[key] = message;
141
+ changed = true;
142
+ }
143
+ if (changed) scheduleFlush();
128
144
  }
129
- if (changed) scheduleFlush();
145
+ return result ?? void 0;
130
146
  }
131
- return result ?? void 0;
132
147
  },
133
148
  buildEnd() {
134
149
  if (!isBuild) return;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n LOCALE_MODULE_PREFIX,\n MessageRegistry,\n RESOLVED_VIRTUAL_ID,\n createDevReporter,\n createSourceFilter,\n extractProject,\n formatCliError,\n reportOutsideInclude,\n isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n outdatedTranslations,\n resolveVirtualId,\n runBuildGate,\n syncCatalogs,\n syncProject,\n transformSource,\n writeDts,\n type Catalogs,\n type DevReporter,\n type Finding,\n type PluginOptions,\n type ResolvedConfig,\n type SyncProjectResult,\n} from '@verbaly/compiler';\nimport { readFileSync } from 'node:fs';\nimport type { Plugin, ViteDevServer } from 'vite';\n\nfunction safeRead(file: string): string | undefined {\n try {\n return readFileSync(file, 'utf8');\n } catch {\n return undefined;\n }\n}\n\nexport type { VerbalyConfig } from '@verbaly/compiler';\nexport type ViteVerbalyOptions = PluginOptions;\n\nexport default function verbaly(options: ViteVerbalyOptions = {}): Plugin {\n let cfg: ResolvedConfig;\n let catalogs: Catalogs;\n let isBuild = false;\n let server: ViteDevServer | undefined;\n let writeTimer: ReturnType<typeof setTimeout> | undefined;\n let included: (id: string) => boolean;\n let reporter: DevReporter | undefined;\n let stateBroken = false;\n // one write-back at a time: a save and a catalog edit landing together must not interleave\n let writing: Promise<void> = Promise.resolve();\n const registry = new MessageRegistry();\n const selfWrites = new Map<string, string>();\n\n function invalidateVirtual(): void {\n if (!server) return;\n const ids = [\n RESOLVED_VIRTUAL_ID,\n ...cfg.locales.map((locale) => LOCALE_MODULE_PREFIX + locale),\n ];\n for (const id of ids) {\n const mod = server.moduleGraph.getModuleById(id);\n if (mod) server.moduleGraph.invalidateModule(mod);\n }\n server.ws.send({ type: 'full-reload' });\n }\n\n // cfg.dts is the merged option: @verbaly/astro fills its override before Vite resolves config\n function flushDts(): void {\n writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});\n }\n\n // what the dev server says, through the same reporter and wording as next dev\n function report(result: SyncProjectResult, catalogEdit: boolean): void {\n reporter ??= createDevReporter(cfg.root);\n const replaced: Finding[] = [];\n const code: Finding[] = [];\n for (const finding of result.findings) {\n if (finding.kind === 'collision' || finding.kind === 'renamed') code.push(finding);\n // a change to the catalog that the code undid was a person's edit; one to the code is not\n else if (finding.kind === 'replaced' && catalogEdit)\n replaced.push({ ...finding, edited: true });\n }\n reporter.report('replaced', replaced);\n reporter.report('code', code);\n const outdated = result.state\n ? outdatedTranslations(cfg, result.catalogs, result.state.fingerprints)\n : [];\n reporter.report(\n 'outdated',\n outdated.map((entry): Finding => ({ kind: 'outdated', ...entry })),\n );\n if (result.stateProblem && !stateBroken) {\n console.warn(`[verbaly] ${result.stateProblem}, so drafts are not tracked`);\n }\n stateBroken = Boolean(result.stateProblem);\n }\n\n // every write in dev starts from the disk, and re-reads the files behind each text that changes\n async function writeBack(catalogEdit: boolean): Promise<void> {\n if (catalogEdit) cfg = await loadConfig(cfg.root, options);\n const result = await syncProject(cfg, {\n registry,\n catalogs: loadCatalogs(cfg),\n confirm: true,\n write: 'changed',\n });\n catalogs = result.catalogs;\n for (const [locale, serialized] of Object.entries(result.written)) {\n selfWrites.set(locale, serialized);\n }\n report(result, catalogEdit);\n invalidateVirtual();\n }\n\n function queueWriteBack(catalogEdit: boolean): void {\n // a catalog saved half-typed is broken JSON for a moment, and that must never end the server\n writing = writing\n .then(() => writeBack(catalogEdit))\n .catch((error: unknown) => console.warn(formatCliError(error)));\n }\n\n function scheduleFlush(): void {\n clearTimeout(writeTimer);\n writeTimer = setTimeout(() => queueWriteBack(false), 50);\n }\n\n return {\n name: 'verbaly',\n enforce: 'pre',\n\n async configResolved(viteConfig) {\n isBuild = viteConfig.command === 'build';\n cfg = await loadConfig(options.root ?? viteConfig.root, options);\n catalogs = loadCatalogs(cfg);\n included = createSourceFilter(cfg);\n if (!isBuild) {\n flushDts();\n }\n },\n\n configureServer(devServer) {\n server = devServer;\n devServer.watcher.add(cfg.dir);\n const onCatalogFile = (file: string): void => {\n if (!file.startsWith(cfg.dir) || !file.endsWith('.json')) return;\n const locale = file.split(/[\\\\/]/).pop()!.slice(0, -5);\n // a dotfile there is the state sidecar: it changes no message, so no tab has to reload\n if (locale.startsWith('.')) return;\n const expected = selfWrites.get(locale);\n if (expected !== undefined) {\n selfWrites.delete(locale);\n // content compare: a stale entry must not swallow an external edit\n if (safeRead(file) === expected) return;\n }\n queueWriteBack(true);\n };\n devServer.watcher.on('change', onCatalogFile);\n devServer.watcher.on('add', onCatalogFile);\n devServer.watcher.on('unlink', (file) => {\n if (isTransformTarget(file) && included(file)) {\n registry.remove(file);\n scheduleFlush();\n }\n });\n },\n\n // the code's text ships, as in dev: the whole scan runs before any module is emitted\n async buildStart() {\n // dev and build alike: a file outside include writes a t`…` that no build translates\n await reportOutsideInclude(cfg);\n if (!isBuild) return;\n syncCatalogs(cfg, catalogs, await extractProject(cfg));\n },\n\n resolveId(id) {\n return resolveVirtualId(id);\n },\n\n load(id) {\n return loadVirtualModule(id, cfg, catalogs);\n },\n\n transform(code, id) {\n if (!isTransformTarget(id) || !included(id)) return undefined;\n const { messages, result } = transformSource(code, id, registry);\n\n const found = Object.entries(messages);\n if (!isBuild && found.length > 0) {\n const source = (catalogs[cfg.sourceLocale] ??= {});\n let changed = false;\n for (const [key, message] of found) {\n if (source[key] !== message) {\n source[key] = message;\n changed = true;\n }\n }\n if (changed) scheduleFlush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,aAAa,KAAK,UAAU,QAAQ,aAAa;EACnD;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n LOCALE_MODULE_PREFIX,\n MessageRegistry,\n RESOLVED_VIRTUAL_ID,\n createDevReporter,\n createSourceFilter,\n extractProject,\n formatCliError,\n reportOutsideInclude,\n isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n outdatedTranslations,\n resolveVirtualId,\n runBuildGate,\n SOURCE_FILE_RE,\n syncCatalogs,\n syncProject,\n transformSource,\n writeDts,\n type Catalogs,\n type DevReporter,\n type Finding,\n type PluginOptions,\n type ResolvedConfig,\n type SyncProjectResult,\n} from '@verbaly/compiler';\nimport { readFileSync } from 'node:fs';\nimport type { Plugin, ViteDevServer } from 'vite';\n\nfunction safeRead(file: string): string | undefined {\n try {\n return readFileSync(file, 'utf8');\n } catch {\n return undefined;\n }\n}\n\nexport type { VerbalyConfig } from '@verbaly/compiler';\nexport type ViteVerbalyOptions = PluginOptions;\n\n// built from the constant, so the NUL that marks a resolved virtual id never sits in the source\nconst VIRTUAL_ID_FILTER = new RegExp(`^${RESOLVED_VIRTUAL_ID.slice(1)}(?:/|$)`);\nconst RESOLVED_ID_FILTER = new RegExp(`^${RESOLVED_VIRTUAL_ID}(?:/|$)`);\nconst ANY_RESOLVED_ID = new RegExp(`^${RESOLVED_VIRTUAL_ID.charAt(0)}`);\n\nexport default function verbaly(options: ViteVerbalyOptions = {}): Plugin {\n let cfg: ResolvedConfig;\n let catalogs: Catalogs;\n let isBuild = false;\n let server: ViteDevServer | undefined;\n let writeTimer: ReturnType<typeof setTimeout> | undefined;\n let included: (id: string) => boolean;\n let reporter: DevReporter | undefined;\n let stateBroken = false;\n // one write-back at a time: a save and a catalog edit landing together must not interleave\n let writing: Promise<void> = Promise.resolve();\n const registry = new MessageRegistry();\n const selfWrites = new Map<string, string>();\n\n function invalidateVirtual(): void {\n if (!server) return;\n const ids = [\n RESOLVED_VIRTUAL_ID,\n ...cfg.locales.map((locale) => LOCALE_MODULE_PREFIX + locale),\n ];\n for (const id of ids) {\n const mod = server.moduleGraph.getModuleById(id);\n if (mod) server.moduleGraph.invalidateModule(mod);\n }\n server.ws.send({ type: 'full-reload' });\n }\n\n // cfg.dts is the merged option: @verbaly/astro fills its override before Vite resolves config\n function flushDts(): void {\n writeDts(cfg, catalogs[cfg.sourceLocale] ?? {});\n }\n\n // what the dev server says, through the same reporter and wording as next dev\n function report(result: SyncProjectResult, catalogEdit: boolean): void {\n reporter ??= createDevReporter(cfg.root);\n const replaced: Finding[] = [];\n const code: Finding[] = [];\n for (const finding of result.findings) {\n if (finding.kind === 'collision' || finding.kind === 'renamed') code.push(finding);\n // a change to the catalog that the code undid was a person's edit; one to the code is not\n else if (finding.kind === 'replaced' && catalogEdit)\n replaced.push({ ...finding, edited: true });\n }\n reporter.report('replaced', replaced);\n reporter.report('code', code);\n const outdated = result.state\n ? outdatedTranslations(cfg, result.catalogs, result.state.fingerprints)\n : [];\n reporter.report(\n 'outdated',\n outdated.map((entry): Finding => ({ kind: 'outdated', ...entry })),\n );\n if (result.stateProblem && !stateBroken) {\n console.warn(`[verbaly] ${result.stateProblem}, so drafts are not tracked`);\n }\n stateBroken = Boolean(result.stateProblem);\n }\n\n // every write in dev starts from the disk, and re-reads the files behind each text that changes\n async function writeBack(catalogEdit: boolean): Promise<void> {\n if (catalogEdit) cfg = await loadConfig(cfg.root, options);\n const result = await syncProject(cfg, {\n registry,\n catalogs: loadCatalogs(cfg),\n confirm: true,\n write: 'changed',\n });\n catalogs = result.catalogs;\n for (const [locale, serialized] of Object.entries(result.written)) {\n selfWrites.set(locale, serialized);\n }\n report(result, catalogEdit);\n invalidateVirtual();\n }\n\n function queueWriteBack(catalogEdit: boolean): void {\n // a catalog saved half-typed is broken JSON for a moment, and that must never end the server\n writing = writing\n .then(() => writeBack(catalogEdit))\n .catch((error: unknown) => console.warn(formatCliError(error)));\n }\n\n function scheduleFlush(): void {\n clearTimeout(writeTimer);\n writeTimer = setTimeout(() => queueWriteBack(false), 50);\n }\n\n return {\n name: 'verbaly',\n enforce: 'pre',\n\n async configResolved(viteConfig) {\n isBuild = viteConfig.command === 'build';\n cfg = await loadConfig(options.root ?? viteConfig.root, options);\n catalogs = loadCatalogs(cfg);\n included = createSourceFilter(cfg);\n if (!isBuild) {\n flushDts();\n }\n },\n\n configureServer(devServer) {\n server = devServer;\n devServer.watcher.add(cfg.dir);\n const onCatalogFile = (file: string): void => {\n if (!file.startsWith(cfg.dir) || !file.endsWith('.json')) return;\n const locale = file.split(/[\\\\/]/).pop()!.slice(0, -5);\n // a dotfile there is the state sidecar: it changes no message, so no tab has to reload\n if (locale.startsWith('.')) return;\n const expected = selfWrites.get(locale);\n if (expected !== undefined) {\n selfWrites.delete(locale);\n // content compare: a stale entry must not swallow an external edit\n if (safeRead(file) === expected) return;\n }\n queueWriteBack(true);\n };\n devServer.watcher.on('change', onCatalogFile);\n devServer.watcher.on('add', onCatalogFile);\n devServer.watcher.on('unlink', (file) => {\n if (isTransformTarget(file) && included(file)) {\n registry.remove(file);\n scheduleFlush();\n }\n });\n },\n\n // the code's text ships, as in dev: the whole scan runs before any module is emitted\n async buildStart() {\n // dev and build alike: a file outside include writes a t`…` that no build translates\n await reportOutsideInclude(cfg);\n if (!isBuild) return;\n syncCatalogs(cfg, catalogs, await extractProject(cfg));\n },\n\n // filtered: without them Vite 8 hands every module to JS, which tripled a real app's build\n resolveId: {\n filter: { id: VIRTUAL_ID_FILTER },\n handler(id) {\n return resolveVirtualId(id);\n },\n },\n\n load: {\n filter: { id: RESOLVED_ID_FILTER },\n handler(id) {\n return loadVirtualModule(id, cfg, catalogs);\n },\n },\n\n transform: {\n filter: { id: { include: SOURCE_FILE_RE, exclude: [/node_modules/, ANY_RESOLVED_ID] } },\n handler(code, id) {\n if (!isTransformTarget(id) || !included(id)) return undefined;\n const { messages, result } = transformSource(code, id, registry);\n\n const found = Object.entries(messages);\n if (!isBuild && found.length > 0) {\n const source = (catalogs[cfg.sourceLocale] ??= {});\n let changed = false;\n for (const [key, message] of found) {\n if (source[key] !== message) {\n source[key] = message;\n changed = true;\n }\n }\n if (changed) scheduleFlush();\n }\n\n return result ?? undefined;\n },\n },\n\n buildEnd() {\n if (!isBuild) return;\n runBuildGate(cfg, registry, options.failOnMissing);\n },\n };\n}\n"],"mappings":";;;AA+BA,SAAS,SAAS,MAAkC;CAClD,IAAI;EACF,OAAO,aAAa,MAAM,MAAM;CAClC,QAAQ;EACN;CACF;AACF;AAMA,MAAM,oBAAoB,IAAI,OAAO,IAAI,oBAAoB,MAAM,CAAC,EAAE,QAAQ;AAC9E,MAAM,qBAAqB,IAAI,OAAO,IAAI,oBAAoB,QAAQ;AACtE,MAAM,kBAAkB,IAAI,OAAO,IAAI,oBAAoB,OAAO,CAAC,GAAG;AAEtE,SAAwB,QAAQ,UAA8B,CAAC,GAAW;CACxE,IAAI;CACJ,IAAI;CACJ,IAAI,UAAU;CACd,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,cAAc;CAElB,IAAI,UAAyB,QAAQ,QAAQ;CAC7C,MAAM,WAAW,IAAI,gBAAgB;CACrC,MAAM,6BAAa,IAAI,IAAoB;CAE3C,SAAS,oBAA0B;EACjC,IAAI,CAAC,QAAQ;EACb,MAAM,MAAM,CACV,qBACA,GAAG,IAAI,QAAQ,KAAK,WAAW,uBAAuB,MAAM,CAC9D;EACA,KAAK,MAAM,MAAM,KAAK;GACpB,MAAM,MAAM,OAAO,YAAY,cAAc,EAAE;GAC/C,IAAI,KAAK,OAAO,YAAY,iBAAiB,GAAG;EAClD;EACA,OAAO,GAAG,KAAK,EAAE,MAAM,cAAc,CAAC;CACxC;CAGA,SAAS,WAAiB;EACxB,SAAS,KAAK,SAAS,IAAI,iBAAiB,CAAC,CAAC;CAChD;CAGA,SAAS,OAAO,QAA2B,aAA4B;EACrE,aAAa,kBAAkB,IAAI,IAAI;EACvC,MAAM,WA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Ae;GAAE,EAAE;GACtF,QAAQ,MAAM,IAAI;IAChB,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,SAAS,EAAE,GAAG,OAAO,KAAA;IACpD,MAAM,EAAE,UAAU,WAAW,gBAAgB,MAAM,IAAI,QAAQ;IAE/D,MAAM,QAAQ,OAAO,QAAQ,QAAQ;IACrC,IAAI,CAAC,WAAW,MAAM,SAAS,GAAG;KAChC,MAAM,SAAU,SAAS,IAAI,kBAAkB,CAAC;KAChD,IAAI,UAAU;KACd,KAAK,MAAM,CAAC,KAAK,YAAY,OAC3B,IAAI,OAAO,SAAS,SAAS;MAC3B,OAAO,OAAO;MACd,UAAU;KACZ;KAEF,IAAI,SAAS,cAAc;IAC7B;IAEA,OAAO,UAAU,KAAA;GACnB;EACF;EAEA,WAAW;GACT,IAAI,CAAC,SAAS;GACd,aAAa,KAAK,UAAU,QAAQ,aAAa;EACnD;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/vite",
3
- "version": "0.69.1",
3
+ "version": "0.70.0",
4
4
  "description": "Zero-config Vite plugin for Verbaly: extraction, codegen and HMR.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -38,14 +38,14 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@verbaly/compiler": "0.69.1"
41
+ "@verbaly/compiler": "0.70.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "verbaly": "^0.69.1",
44
+ "verbaly": "^0.70.0",
45
45
  "vite": "^7.0.0 || ^8.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "verbaly": "^0.69.1",
48
+ "verbaly": "^0.70.0",
49
49
  "vite": "^8.3.3"
50
50
  },
51
51
  "scripts": {