@verbaly/vite 0.16.0 → 0.18.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 +5 -2
- package/dist/index.js +8 -13
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ import { t, setLocale } from 'virtual:verbaly';
|
|
|
35
35
|
|
|
36
36
|
- **Live extraction** with debounced catalog writes + HMR.
|
|
37
37
|
- **Per-locale code-splitting** — `setLocale` lazy-loads only what's used.
|
|
38
|
-
- **Build gate** — missing translations stop the build (same as `verbaly check`).
|
|
38
|
+
- **Build gate** — missing translations stop the build (same as `verbaly check`); `failOnMissing: false` opts out.
|
|
39
39
|
|
|
40
40
|
📖 Docs & live playground: **https://verbaly-web.vercel.app**
|
|
41
41
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { VerbalyConfig, VerbalyConfig as VerbalyConfig$1 } from "@verbaly/compiler";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
//#region src/index.d.ts
|
|
4
|
-
|
|
4
|
+
interface ViteVerbalyOptions extends VerbalyConfig$1 {
|
|
5
|
+
failOnMissing?: boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function verbaly(options?: ViteVerbalyOptions): Plugin;
|
|
5
8
|
//#endregion
|
|
6
|
-
export { type VerbalyConfig, verbaly as default };
|
|
9
|
+
export { type VerbalyConfig, ViteVerbalyOptions, verbaly as default };
|
|
7
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { MessageRegistry,
|
|
1
|
+
import { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, SOURCE_FILE_RE, analyze, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, resolveVirtualId, runBuildGate, syncCatalogs, transformCode, writeCatalog, writeDts } from "@verbaly/compiler";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
//#region src/index.ts
|
|
4
|
-
const RESOLVED = "\0" + VIRTUAL_ID;
|
|
5
|
-
const LOCALE_PREFIX = `${RESOLVED}/locale/`;
|
|
6
|
-
const SOURCE_RE = /\.[cm]?[jt]sx?$/;
|
|
7
4
|
function safeRead(file) {
|
|
8
5
|
try {
|
|
9
6
|
return readFileSync(file, "utf8");
|
|
@@ -21,7 +18,7 @@ function verbaly(options = {}) {
|
|
|
21
18
|
const selfWrites = /* @__PURE__ */ new Map();
|
|
22
19
|
function invalidateVirtual() {
|
|
23
20
|
if (!server) return;
|
|
24
|
-
const ids = [
|
|
21
|
+
const ids = [RESOLVED_VIRTUAL_ID, ...cfg.locales.map((locale) => LOCALE_MODULE_PREFIX + locale)];
|
|
25
22
|
for (const id of ids) {
|
|
26
23
|
const mod = server.moduleGraph.getModuleById(id);
|
|
27
24
|
if (mod) server.moduleGraph.invalidateModule(mod);
|
|
@@ -73,21 +70,20 @@ function verbaly(options = {}) {
|
|
|
73
70
|
devServer.watcher.on("change", (file) => onCatalogFile(file, localeOf(file)));
|
|
74
71
|
devServer.watcher.on("add", (file) => onCatalogFile(file, localeOf(file)));
|
|
75
72
|
devServer.watcher.on("unlink", (file) => {
|
|
76
|
-
if (
|
|
73
|
+
if (SOURCE_FILE_RE.test(file) && !file.includes("node_modules")) {
|
|
77
74
|
registry.remove(file);
|
|
78
75
|
scheduleFlush();
|
|
79
76
|
}
|
|
80
77
|
});
|
|
81
78
|
},
|
|
82
79
|
resolveId(id) {
|
|
83
|
-
|
|
80
|
+
return resolveVirtualId(id);
|
|
84
81
|
},
|
|
85
82
|
load(id) {
|
|
86
|
-
|
|
87
|
-
if (id.startsWith(LOCALE_PREFIX)) return generateLocaleModule(catalogs[id.slice(LOCALE_PREFIX.length)] ?? {});
|
|
83
|
+
return loadVirtualModule(id, cfg, catalogs);
|
|
88
84
|
},
|
|
89
85
|
transform(code, id) {
|
|
90
|
-
if (!
|
|
86
|
+
if (!isTransformTarget(id)) return void 0;
|
|
91
87
|
const analysis = analyze(code, id);
|
|
92
88
|
registry.update(id, analysis);
|
|
93
89
|
if (!isBuild && analysis.tagged.length > 0) {
|
|
@@ -102,9 +98,8 @@ function verbaly(options = {}) {
|
|
|
102
98
|
return transformCode(code, id, analysis) ?? void 0;
|
|
103
99
|
},
|
|
104
100
|
buildEnd() {
|
|
105
|
-
if (!isBuild) return;
|
|
106
|
-
|
|
107
|
-
if (!result.ok) throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\nRun \`npx verbaly extract\` and fill the missing translations.`);
|
|
101
|
+
if (!isBuild || options.failOnMissing === false) return;
|
|
102
|
+
runBuildGate(cfg, registry);
|
|
108
103
|
}
|
|
109
104
|
};
|
|
110
105
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n MessageRegistry,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n LOCALE_MODULE_PREFIX,\n MessageRegistry,\n RESOLVED_VIRTUAL_ID,\n SOURCE_FILE_RE,\n analyze,\n isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n resolveVirtualId,\n runBuildGate,\n syncCatalogs,\n transformCode,\n writeCatalog,\n writeDts,\n type Catalogs,\n type ResolvedConfig,\n type VerbalyConfig,\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';\n\nexport interface ViteVerbalyOptions extends VerbalyConfig {\n // opt out of the build gate (parity with @verbaly/unplugin)\n failOnMissing?: boolean;\n}\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 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 function flushCatalogs(): void {\n syncCatalogs(cfg, catalogs, registry);\n for (const locale of cfg.locales) {\n const serialized = writeCatalog(cfg, locale, catalogs[locale] ?? {});\n selfWrites.set(locale, serialized);\n }\n writeDts(cfg, new Map(Object.entries(catalogs[cfg.sourceLocale] ?? {})));\n invalidateVirtual();\n }\n\n function scheduleFlush(): void {\n clearTimeout(writeTimer);\n writeTimer = setTimeout(flushCatalogs, 50);\n }\n\n async function reloadFromDisk(): Promise<void> {\n cfg = await loadConfig(cfg.root, options);\n catalogs = loadCatalogs(cfg);\n invalidateVirtual();\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 if (!isBuild) {\n writeDts(cfg, new Map(Object.entries(catalogs[cfg.sourceLocale] ?? {})));\n }\n },\n\n configureServer(devServer) {\n server = devServer;\n devServer.watcher.add(cfg.dir);\n const onCatalogFile = (file: string, locale?: string): void => {\n if (!file.startsWith(cfg.dir) || !file.endsWith('.json')) return;\n if (locale) {\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 }\n void reloadFromDisk();\n };\n const localeOf = (file: string): string | undefined =>\n file.split(/[\\\\/]/).pop()?.slice(0, -5);\n devServer.watcher.on('change', (file) => onCatalogFile(file, localeOf(file)));\n devServer.watcher.on('add', (file) => onCatalogFile(file, localeOf(file)));\n devServer.watcher.on('unlink', (file) => {\n if (SOURCE_FILE_RE.test(file) && !file.includes('node_modules')) {\n registry.remove(file);\n scheduleFlush();\n }\n });\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)) return undefined;\n const analysis = analyze(code, id);\n registry.update(id, analysis);\n\n if (!isBuild && analysis.tagged.length > 0) {\n const source = (catalogs[cfg.sourceLocale] ??= {});\n let changed = false;\n for (const msg of analysis.tagged) {\n if (source[msg.key] !== msg.message) {\n source[msg.key] = msg.message;\n changed = true;\n }\n }\n if (changed) scheduleFlush();\n }\n\n return transformCode(code, id, analysis) ?? undefined;\n },\n\n buildEnd() {\n if (!isBuild || options.failOnMissing === false) return;\n runBuildGate(cfg, registry);\n },\n };\n}\n"],"mappings":";;;AAuBA,SAAS,SAAS,MAAkC;CAClD,IAAI;EACF,OAAO,aAAa,MAAM,MAAM;CAClC,QAAQ;EACN;CACF;AACF;AASA,SAAwB,QAAQ,UAA8B,CAAC,GAAW;CACxE,IAAI;CACJ,IAAI;CACJ,IAAI,UAAU;CACd,IAAI;CACJ,IAAI;CACJ,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;CAEA,SA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S,cAAc,MAAM,SAAS,IAAI,CAAC,CAAC;GAC5E,UAAU,QAAQ,GAAG,QAAQ,SAAS,cAAc,MAAM,SAAS,IAAI,CAAC,CAAC;GACzE,UAAU,QAAQ,GAAG,WAAW,SAAS;IACvC,IAAI,eAAe,KAAK,IAAI,KAAK,CAAC,KAAK,SAAS,cAAc,GAAG;KAC/D,SAAS,OAAO,IAAI;KACpB,cAAc;IAChB;GACF,CAAC;EACH;EAEA,UAAU,IAAI;GACZ,OAAO,iBAAiB,EAAE;EAC5B;EAEA,KAAK,IAAI;GACP,OAAO,kBAAkB,IAAI,KAAK,QAAQ;EAC5C;EAEA,UAAU,MAAM,IAAI;GAClB,IAAI,CAAC,kBAAkB,EAAE,GAAG,OAAO,KAAA;GACnC,MAAM,WAAW,QAAQ,MAAM,EAAE;GACjC,SAAS,OAAO,IAAI,QAAQ;GAE5B,IAAI,CAAC,WAAW,SAAS,OAAO,SAAS,GAAG;IAC1C,MAAM,SAAU,SAAS,IAAI,kBAAkB,CAAC;IAChD,IAAI,UAAU;IACd,KAAK,MAAM,OAAO,SAAS,QACzB,IAAI,OAAO,IAAI,SAAS,IAAI,SAAS;KACnC,OAAO,IAAI,OAAO,IAAI;KACtB,UAAU;IACZ;IAEF,IAAI,SAAS,cAAc;GAC7B;GAEA,OAAO,cAAc,MAAM,IAAI,QAAQ,KAAK,KAAA;EAC9C;EAEA,WAAW;GACT,IAAI,CAAC,WAAW,QAAQ,kBAAkB,OAAO;GACjD,aAAa,KAAK,QAAQ;EAC5B;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Zero-config Vite plugin for Verbaly — extraction, codegen and HMR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@verbaly/compiler": "0.
|
|
41
|
+
"@verbaly/compiler": "0.18.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vite": "^7.0.0 || ^8.0.0",
|
|
45
|
-
"verbaly": "^0.
|
|
45
|
+
"verbaly": "^0.18.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"vite": "^8.1.
|
|
49
|
-
"verbaly": "0.
|
|
48
|
+
"vite": "^8.1.4",
|
|
49
|
+
"verbaly": "0.18.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsdown",
|