@verbaly/vite 0.75.0 → 0.77.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 +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.js +4 -5
- package/package.json +9 -5
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ export default { sourceLocale: 'en', locales: ['en', 'es', 'pt'] };
|
|
|
40
40
|
import { t, setLocale } from 'virtual:verbaly';
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
- **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.
|
|
43
|
+
- **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. To keep the dev server from writing your translation files, pass `liveExtraction: false`: new texts still render from memory, as in a build, and `npx verbaly extract` writes them when you choose.
|
|
44
44
|
- **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.
|
|
45
45
|
- **Per-locale code-splitting**: `setLocale` lazy-loads only what's used.
|
|
46
46
|
- **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.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { PluginOptions, VerbalyConfig } from "@verbaly/compiler";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
|
-
//#region src/index.d.ts
|
|
4
3
|
export type ViteVerbalyOptions = PluginOptions;
|
|
5
4
|
export default function verbaly(options?: ViteVerbalyOptions): Plugin;
|
|
6
|
-
|
|
7
|
-
export type { VerbalyConfig };
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
|
5
|
+
export type { VerbalyConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
+
// src/index.ts
|
|
4
4
|
function safeRead(file) {
|
|
5
5
|
try {
|
|
6
6
|
return readFileSync(file, "utf8");
|
|
@@ -64,9 +64,11 @@ function verbaly(options = {}) {
|
|
|
64
64
|
registry,
|
|
65
65
|
catalogs: loadCatalogs(cfg),
|
|
66
66
|
confirm: true,
|
|
67
|
-
write: "changed"
|
|
67
|
+
write: "changed",
|
|
68
|
+
dryRun: options.liveExtraction === false
|
|
68
69
|
});
|
|
69
70
|
catalogs = result.catalogs;
|
|
71
|
+
if (options.liveExtraction === false) flushDts();
|
|
70
72
|
for (const [locale, serialized] of Object.entries(result.written)) selfWrites.set(locale, serialized);
|
|
71
73
|
report(result, catalogEdit);
|
|
72
74
|
invalidateVirtual();
|
|
@@ -157,7 +159,4 @@ function verbaly(options = {}) {
|
|
|
157
159
|
}
|
|
158
160
|
};
|
|
159
161
|
}
|
|
160
|
-
//#endregion
|
|
161
162
|
export { verbaly as default };
|
|
162
|
-
|
|
163
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"description": "Zero-config Vite plugin for Verbaly: extraction, codegen and HMR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"bugs": {
|
|
19
19
|
"url": "https://github.com/AronSoto/verbaly/issues"
|
|
20
20
|
},
|
|
21
|
+
"funding": {
|
|
22
|
+
"type": "github",
|
|
23
|
+
"url": "https://github.com/sponsors/AronSoto"
|
|
24
|
+
},
|
|
21
25
|
"type": "module",
|
|
22
26
|
"types": "./dist/index.d.ts",
|
|
23
27
|
"exports": {
|
|
@@ -38,15 +42,15 @@
|
|
|
38
42
|
"access": "public"
|
|
39
43
|
},
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@verbaly/compiler": "0.
|
|
45
|
+
"@verbaly/compiler": "0.77.0"
|
|
42
46
|
},
|
|
43
47
|
"peerDependencies": {
|
|
44
|
-
"verbaly": "^0.
|
|
48
|
+
"verbaly": "^0.77.0",
|
|
45
49
|
"vite": "^7.0.0 || ^8.0.0"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
|
-
"verbaly": "^0.
|
|
49
|
-
"vite": "^8.3.
|
|
52
|
+
"verbaly": "^0.77.0",
|
|
53
|
+
"vite": "^8.3.5"
|
|
50
54
|
},
|
|
51
55
|
"scripts": {
|
|
52
56
|
"build": "tsdown",
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 // a build's scan: each file it read unchanged reaches transform already parsed\n let scan: MessageRegistry | undefined;\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 const lock: Finding[] = [];\n for (const finding of result.findings) {\n if (finding.kind === 'collision' || finding.kind === 'renamed') code.push(finding);\n else if (finding.kind === 'lock') lock.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 reporter.report('lock', lock);\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, { plugin: true });\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, { plugin: true });\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 an older state file: 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 scan = await extractProject(cfg, { keepSource: true });\n syncCatalogs(cfg, catalogs, scan);\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, scan);\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 scan = undefined;\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;CAEJ,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,WAAsB,CAAC;EAC7B,MAAM,OAAkB,CAAC;EACzB,MAAM,OAAkB,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