@verbaly/unplugin 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/dist/index.js CHANGED
@@ -1,9 +1,6 @@
1
- import { MessageRegistry, VIRTUAL_ID, analyze, check, formatCheckResult, generateLocaleModule, generateRuntimeModule, loadCatalogs, loadConfig, transformCode } from "@verbaly/compiler";
1
+ import { MessageRegistry, RESOLVED_VIRTUAL_ID, analyze, isTransformTarget, loadCatalogs, loadConfig, loadVirtualModule, resolveVirtualId, runBuildGate, transformCode } from "@verbaly/compiler";
2
2
  import { createUnplugin } from "unplugin";
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
  const factory = (options = {}) => {
8
5
  let cfg;
9
6
  let catalogs;
@@ -19,19 +16,16 @@ const factory = (options = {}) => {
19
16
  await ready;
20
17
  },
21
18
  resolveId(id) {
22
- if (id === VIRTUAL_ID || id.startsWith(`${VIRTUAL_ID}/`)) return "\0" + id;
23
- return null;
19
+ return resolveVirtualId(id) ?? null;
24
20
  },
25
21
  loadInclude(id) {
26
- return id.startsWith(RESOLVED);
22
+ return id.startsWith(RESOLVED_VIRTUAL_ID);
27
23
  },
28
24
  load(id) {
29
- if (id === RESOLVED) return generateRuntimeModule(cfg);
30
- if (id.startsWith(LOCALE_PREFIX)) return generateLocaleModule(catalogs[id.slice(LOCALE_PREFIX.length)] ?? {});
31
- return null;
25
+ return loadVirtualModule(id, cfg, catalogs) ?? null;
32
26
  },
33
27
  transformInclude(id) {
34
- return SOURCE_RE.test(id) && !id.includes("node_modules") && !id.startsWith("\0");
28
+ return isTransformTarget(id);
35
29
  },
36
30
  transform(code, id) {
37
31
  const analysis = analyze(code, id);
@@ -40,8 +34,7 @@ const factory = (options = {}) => {
40
34
  },
41
35
  buildEnd() {
42
36
  if (options.failOnMissing === false) return;
43
- const result = check(cfg, loadCatalogs(cfg), registry);
44
- if (!result.ok) throw new Error(`[verbaly] build blocked\n${formatCheckResult(result)}\nRun \`npx verbaly extract\` and fill the missing translations.`);
37
+ runBuildGate(cfg, registry);
45
38
  }
46
39
  };
47
40
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n MessageRegistry,\n VIRTUAL_ID,\n analyze,\n check,\n formatCheckResult,\n generateLocaleModule,\n generateRuntimeModule,\n loadCatalogs,\n loadConfig,\n transformCode,\n type Catalogs,\n type ResolvedConfig,\n type VerbalyConfig,\n} from '@verbaly/compiler';\nimport { createUnplugin, type UnpluginFactory, type UnpluginInstance } from 'unplugin';\n\nconst RESOLVED = '\\0' + VIRTUAL_ID;\nconst LOCALE_PREFIX = `${RESOLVED}/locale/`;\nconst SOURCE_RE = /\\.[cm]?[jt]sx?$/;\n\nexport interface UnpluginVerbalyOptions extends VerbalyConfig {\n failOnMissing?: boolean;\n}\n\n// build-focused: virtual modules + transform + gate.\nconst factory: UnpluginFactory<UnpluginVerbalyOptions | undefined> = (options = {}) => {\n let cfg: ResolvedConfig;\n let catalogs: Catalogs;\n const registry = new MessageRegistry();\n const ready = (async () => {\n cfg = await loadConfig(options.root ?? process.cwd(), options);\n catalogs = loadCatalogs(cfg);\n })();\n\n return {\n name: 'verbaly',\n enforce: 'pre',\n\n async buildStart() {\n await ready;\n },\n\n resolveId(id) {\n if (id === VIRTUAL_ID || id.startsWith(`${VIRTUAL_ID}/`)) return '\\0' + id;\n return null;\n },\n\n loadInclude(id) {\n return id.startsWith(RESOLVED);\n },\n\n load(id) {\n if (id === RESOLVED) return generateRuntimeModule(cfg);\n if (id.startsWith(LOCALE_PREFIX)) {\n return generateLocaleModule(catalogs[id.slice(LOCALE_PREFIX.length)] ?? {});\n }\n return null;\n },\n\n transformInclude(id) {\n return SOURCE_RE.test(id) && !id.includes('node_modules') && !id.startsWith('\\0');\n },\n\n transform(code, id) {\n const analysis = analyze(code, id);\n registry.update(id, analysis);\n return transformCode(code, id, analysis) ?? null;\n },\n\n buildEnd() {\n if (options.failOnMissing === false) return;\n const result = check(cfg, loadCatalogs(cfg), registry);\n if (!result.ok) {\n throw new Error(\n `[verbaly] build blocked\\n${formatCheckResult(result)}\\n` +\n `Run \\`npx verbaly extract\\` and fill the missing translations.`,\n );\n }\n },\n };\n};\n\nexport const verbaly: UnpluginInstance<UnpluginVerbalyOptions | undefined> =\n createUnplugin(factory);\n\nexport default verbaly;\n\nexport type { VerbalyConfig } from '@verbaly/compiler';\n"],"mappings":";;;AAiBA,MAAM,WAAW,OAAO;AACxB,MAAM,gBAAgB,GAAG,SAAS;AAClC,MAAM,YAAY;AAOlB,MAAM,WAAgE,UAAU,CAAC,MAAM;CACrF,IAAI;CACJ,IAAI;CACJ,MAAM,WAAW,IAAI,gBAAgB;CACrC,MAAM,SAAS,YAAY;EACzB,MAAM,MAAM,WAAW,QAAQ,QAAQ,QAAQ,IAAI,GAAG,OAAO;EAC7D,WAAW,aAAa,GAAG;CAC7B,EAAA,CAAG;CAEH,OAAO;EACL,MAAM;EACN,SAAS;EAET,MAAM,aAAa;GACjB,MAAM;EACR;EAEA,UAAU,IAAI;GACZ,IAAI,OAAO,cAAc,GAAG,WAAW,GAAG,WAAW,EAAE,GAAG,OAAO,OAAO;GACxE,OAAO;EACT;EAEA,YAAY,IAAI;GACd,OAAO,GAAG,WAAW,QAAQ;EAC/B;EAEA,KAAK,IAAI;GACP,IAAI,OAAO,UAAU,OAAO,sBAAsB,GAAG;GACrD,IAAI,GAAG,WAAW,aAAa,GAC7B,OAAO,qBAAqB,SAAS,GAAG,MAAM,cAAc,MAAM,MAAM,CAAC,CAAC;GAE5E,OAAO;EACT;EAEA,iBAAiB,IAAI;GACnB,OAAO,UAAU,KAAK,EAAE,KAAK,CAAC,GAAG,SAAS,cAAc,KAAK,CAAC,GAAG,WAAW,IAAI;EAClF;EAEA,UAAU,MAAM,IAAI;GAClB,MAAM,WAAW,QAAQ,MAAM,EAAE;GACjC,SAAS,OAAO,IAAI,QAAQ;GAC5B,OAAO,cAAc,MAAM,IAAI,QAAQ,KAAK;EAC9C;EAEA,WAAW;GACT,IAAI,QAAQ,kBAAkB,OAAO;GACrC,MAAM,SAAS,MAAM,KAAK,aAAa,GAAG,GAAG,QAAQ;GACrD,IAAI,CAAC,OAAO,IACV,MAAM,IAAI,MACR,4BAA4B,kBAAkB,MAAM,EAAE,iEAExD;EAEJ;CACF;AACF;AAEA,MAAa,UACX,eAAe,OAAO"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n MessageRegistry,\n RESOLVED_VIRTUAL_ID,\n analyze,\n isTransformTarget,\n loadCatalogs,\n loadConfig,\n loadVirtualModule,\n resolveVirtualId,\n runBuildGate,\n transformCode,\n type Catalogs,\n type ResolvedConfig,\n type VerbalyConfig,\n} from '@verbaly/compiler';\nimport { createUnplugin, type UnpluginFactory, type UnpluginInstance } from 'unplugin';\n\nexport interface UnpluginVerbalyOptions extends VerbalyConfig {\n failOnMissing?: boolean;\n}\n\n// build-focused: virtual modules + transform + gate.\nconst factory: UnpluginFactory<UnpluginVerbalyOptions | undefined> = (options = {}) => {\n let cfg: ResolvedConfig;\n let catalogs: Catalogs;\n const registry = new MessageRegistry();\n const ready = (async () => {\n cfg = await loadConfig(options.root ?? process.cwd(), options);\n catalogs = loadCatalogs(cfg);\n })();\n\n return {\n name: 'verbaly',\n enforce: 'pre',\n\n async buildStart() {\n await ready;\n },\n\n resolveId(id) {\n return resolveVirtualId(id) ?? null;\n },\n\n loadInclude(id) {\n return id.startsWith(RESOLVED_VIRTUAL_ID);\n },\n\n load(id) {\n return loadVirtualModule(id, cfg, catalogs) ?? null;\n },\n\n transformInclude(id) {\n return isTransformTarget(id);\n },\n\n transform(code, id) {\n const analysis = analyze(code, id);\n registry.update(id, analysis);\n return transformCode(code, id, analysis) ?? null;\n },\n\n buildEnd() {\n if (options.failOnMissing === false) return;\n runBuildGate(cfg, registry);\n },\n };\n};\n\nexport const verbaly: UnpluginInstance<UnpluginVerbalyOptions | undefined> =\n createUnplugin(factory);\n\nexport default verbaly;\n\nexport type { VerbalyConfig } from '@verbaly/compiler';\n"],"mappings":";;;AAsBA,MAAM,WAAgE,UAAU,CAAC,MAAM;CACrF,IAAI;CACJ,IAAI;CACJ,MAAM,WAAW,IAAI,gBAAgB;CACrC,MAAM,SAAS,YAAY;EACzB,MAAM,MAAM,WAAW,QAAQ,QAAQ,QAAQ,IAAI,GAAG,OAAO;EAC7D,WAAW,aAAa,GAAG;CAC7B,EAAA,CAAG;CAEH,OAAO;EACL,MAAM;EACN,SAAS;EAET,MAAM,aAAa;GACjB,MAAM;EACR;EAEA,UAAU,IAAI;GACZ,OAAO,iBAAiB,EAAE,KAAK;EACjC;EAEA,YAAY,IAAI;GACd,OAAO,GAAG,WAAW,mBAAmB;EAC1C;EAEA,KAAK,IAAI;GACP,OAAO,kBAAkB,IAAI,KAAK,QAAQ,KAAK;EACjD;EAEA,iBAAiB,IAAI;GACnB,OAAO,kBAAkB,EAAE;EAC7B;EAEA,UAAU,MAAM,IAAI;GAClB,MAAM,WAAW,QAAQ,MAAM,EAAE;GACjC,SAAS,OAAO,IAAI,QAAQ;GAC5B,OAAO,cAAc,MAAM,IAAI,QAAQ,KAAK;EAC9C;EAEA,WAAW;GACT,IAAI,QAAQ,kBAAkB,OAAO;GACrC,aAAa,KAAK,QAAQ;EAC5B;CACF;AACF;AAEA,MAAa,UACX,eAAe,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbaly/unplugin",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Verbaly for webpack, Rollup, esbuild and Rspack — extraction, virtual modules and build gate via unplugin.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -43,13 +43,13 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "unplugin": "^3.3.0",
46
- "@verbaly/compiler": "0.16.0"
46
+ "@verbaly/compiler": "0.18.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "verbaly": "^0.16.0"
49
+ "verbaly": "^0.18.0"
50
50
  },
51
51
  "devDependencies": {
52
- "verbaly": "0.16.0"
52
+ "verbaly": "0.18.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown",