@verbaly/vite 0.25.0 → 0.27.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/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, resolveVirtualId, runBuildGate, syncCatalogs, transformSource, writeCatalog, writeDts } from "@verbaly/compiler";
|
|
1
|
+
import { LOCALE_MODULE_PREFIX, MessageRegistry, RESOLVED_VIRTUAL_ID, createSourceFilter, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, resolveVirtualId, runBuildGate, syncCatalogs, transformSource, writeCatalog, writeDts } from "@verbaly/compiler";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
function safeRead(file) {
|
|
@@ -14,6 +14,7 @@ function verbaly(options = {}) {
|
|
|
14
14
|
let isBuild = false;
|
|
15
15
|
let server;
|
|
16
16
|
let writeTimer;
|
|
17
|
+
let included;
|
|
17
18
|
const registry = new MessageRegistry();
|
|
18
19
|
const selfWrites = /* @__PURE__ */ new Map();
|
|
19
20
|
function invalidateVirtual() {
|
|
@@ -25,13 +26,17 @@ function verbaly(options = {}) {
|
|
|
25
26
|
}
|
|
26
27
|
server.ws.send({ type: "full-reload" });
|
|
27
28
|
}
|
|
29
|
+
function flushDts() {
|
|
30
|
+
if (cfg.dts === false) return;
|
|
31
|
+
writeDts(cfg, catalogs[cfg.sourceLocale] ?? {}, cfg.dts);
|
|
32
|
+
}
|
|
28
33
|
function flushCatalogs() {
|
|
29
34
|
syncCatalogs(cfg, catalogs, registry);
|
|
30
35
|
for (const locale of cfg.locales) {
|
|
31
36
|
const serialized = writeCatalog(cfg, locale, catalogs[locale] ?? {});
|
|
32
37
|
selfWrites.set(locale, serialized);
|
|
33
38
|
}
|
|
34
|
-
|
|
39
|
+
flushDts();
|
|
35
40
|
invalidateVirtual();
|
|
36
41
|
}
|
|
37
42
|
function scheduleFlush() {
|
|
@@ -50,7 +55,8 @@ function verbaly(options = {}) {
|
|
|
50
55
|
isBuild = viteConfig.command === "build";
|
|
51
56
|
cfg = await loadConfig(options.root ?? viteConfig.root, options);
|
|
52
57
|
catalogs = loadCatalogs(cfg);
|
|
53
|
-
|
|
58
|
+
included = createSourceFilter(cfg);
|
|
59
|
+
if (!isBuild) flushDts();
|
|
54
60
|
},
|
|
55
61
|
configureServer(devServer) {
|
|
56
62
|
server = devServer;
|
|
@@ -68,7 +74,7 @@ function verbaly(options = {}) {
|
|
|
68
74
|
devServer.watcher.on("change", onCatalogFile);
|
|
69
75
|
devServer.watcher.on("add", onCatalogFile);
|
|
70
76
|
devServer.watcher.on("unlink", (file) => {
|
|
71
|
-
if (isTransformTarget(file)) {
|
|
77
|
+
if (isTransformTarget(file) && included(file)) {
|
|
72
78
|
registry.remove(file);
|
|
73
79
|
scheduleFlush();
|
|
74
80
|
}
|
|
@@ -81,7 +87,7 @@ function verbaly(options = {}) {
|
|
|
81
87
|
return loadVirtualModule(id, cfg, catalogs);
|
|
82
88
|
},
|
|
83
89
|
transform(code, id) {
|
|
84
|
-
if (!isTransformTarget(id)) return void 0;
|
|
90
|
+
if (!isTransformTarget(id) || !included(id)) return void 0;
|
|
85
91
|
const { analysis, result } = transformSource(code, id, registry);
|
|
86
92
|
if (!isBuild && analysis.tagged.length > 0) {
|
|
87
93
|
const source = catalogs[cfg.sourceLocale] ??= {};
|
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 isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n resolveVirtualId,\n runBuildGate,\n syncCatalogs,\n transformSource,\n writeCatalog,\n writeDts,\n type Catalogs,\n type PluginOptions,\n type ResolvedConfig,\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 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
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n LOCALE_MODULE_PREFIX,\n MessageRegistry,\n RESOLVED_VIRTUAL_ID,\n createSourceFilter,\n isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n resolveVirtualId,\n runBuildGate,\n syncCatalogs,\n transformSource,\n writeCatalog,\n writeDts,\n type Catalogs,\n type PluginOptions,\n type ResolvedConfig,\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 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 carries the option merged from file config and inline overrides\n // (@verbaly/astro fills its override in astro:config:done, before Vite resolves config)\n function flushDts(): void {\n if (cfg.dts === false) return;\n writeDts(cfg, catalogs[cfg.sourceLocale] ?? {}, cfg.dts);\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 flushDts();\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 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 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 void reloadFromDisk();\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 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 { analysis, result } = transformSource(code, id, registry);\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 result ?? undefined;\n },\n\n buildEnd() {\n if (!isBuild) return;\n runBuildGate(cfg, registry, options.failOnMissing);\n },\n };\n}\n"],"mappings":";;;AAsBA,SAAS,SAAS,MAAkC;CAClD,IAAI;EACF,OAAO,aAAa,MAAM,MAAM;CAClC,QAAQ;EACN;CACF;AACF;AAKA,SAAwB,QAAQ,UAA8B,CAAC,GAAW;CACxE,IAAI;CACJ,IAAI;CACJ,IAAI,UAAU;CACd,IAAI;CACJ,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,OAA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B,IAAI,SAAS,IAAI,MAAM,UAAU;IACnC;IACA,eAAoB;GACtB;GACA,UAAU,QAAQ,GAAG,UAAU,aAAa;GAC5C,UAAU,QAAQ,GAAG,OAAO,aAAa;GACzC,UAAU,QAAQ,GAAG,WAAW,SAAS;IACvC,IAAI,kBAAkB,IAAI,KAAK,SAAS,IAAI,GAAG;KAC7C,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,KAAK,CAAC,SAAS,EAAE,GAAG,OAAO,KAAA;GACpD,MAAM,EAAE,UAAU,WAAW,gBAAgB,MAAM,IAAI,QAAQ;GAE/D,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,UAAU,KAAA;EACnB;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.
|
|
3
|
+
"version": "0.27.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.27.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vite": "^7.0.0 || ^8.0.0",
|
|
45
|
-
"verbaly": "^0.
|
|
45
|
+
"verbaly": "^0.27.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"vite": "^8.1.5",
|
|
49
|
-
"verbaly": "0.
|
|
49
|
+
"verbaly": "0.27.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsdown",
|