@wuchale/vite-plugin 0.14.7 → 0.15.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.d.ts CHANGED
@@ -22,8 +22,6 @@ declare class Wuchale {
22
22
  root: string;
23
23
  }) => Promise<void>;
24
24
  handleHotUpdate: (ctx: HotUpdateCtx) => Promise<any[]>;
25
- resolveId: (source: string, importer?: string) => string;
26
- load: (id: string) => string;
27
25
  transform: {
28
26
  order: "pre";
29
27
  handler: (code: string, id: string, options?: {
package/dist/index.js CHANGED
@@ -3,16 +3,16 @@ import { relative, resolve } from "node:path";
3
3
  import { platform } from "node:process";
4
4
  import { getConfig as getConfig, Logger, AdapterHandler } from "wuchale";
5
5
  const pluginName = 'wuchale';
6
- const virtualPrefix = `virtual:${pluginName}/`;
7
- const virtualResolvedPrefix = '\0';
8
6
  class Wuchale {
9
7
  name = pluginName;
10
8
  #config;
11
- #locales = [];
12
9
  #projectRoot = '';
13
10
  #adapters = {};
14
11
  #adaptersByLoaderPath = {};
15
12
  #adaptersByCatalogPath = {};
13
+ #granularLoadAdapters = [];
14
+ #singleCompiledCatalogs = new Set();
15
+ #locales = [];
16
16
  #log;
17
17
  #configPath;
18
18
  #hmrVersion = -1;
@@ -22,19 +22,27 @@ class Wuchale {
22
22
  }
23
23
  #init = async (mode) => {
24
24
  this.#config = await getConfig(this.#configPath);
25
- this.#locales = [this.#config.sourceLocale, ...this.#config.otherLocales];
26
25
  this.#log = new Logger(this.#config.logLevel);
26
+ this.#locales = [this.#config.sourceLocale, ...this.#config.otherLocales];
27
27
  if (Object.keys(this.#config.adapters).length === 0) {
28
28
  throw Error('At least one adapter is needed.');
29
29
  }
30
30
  const sharedState = {};
31
31
  for (const [key, adapter] of Object.entries(this.#config.adapters)) {
32
- const handler = new AdapterHandler(adapter, key, this.#config, mode, virtualPrefix, this.#projectRoot, this.#log);
32
+ const handler = new AdapterHandler(adapter, key, this.#config, mode, this.#projectRoot, this.#log);
33
33
  await handler.init(sharedState);
34
34
  handler.onBeforeWritePO = () => {
35
35
  this.#lastSourceTriggeredPOWrite = performance.now();
36
36
  };
37
37
  this.#adapters[key] = handler;
38
+ if (adapter.granularLoad) {
39
+ this.#granularLoadAdapters.push(handler);
40
+ }
41
+ else {
42
+ for (const locale of this.#locales) {
43
+ this.#singleCompiledCatalogs.add(resolve(handler.getCompiledFilePath(locale, null)));
44
+ }
45
+ }
38
46
  for (const path of Object.values(handler.loaderPath)) {
39
47
  let loaderPath = resolve(path);
40
48
  if (platform === 'win32') {
@@ -67,13 +75,25 @@ class Wuchale {
67
75
  mode = 'dev';
68
76
  }
69
77
  else {
70
- mode = 'prod';
78
+ mode = 'build';
71
79
  }
72
80
  this.#projectRoot = config.root;
73
81
  await this.#init(mode);
74
82
  };
75
83
  handleHotUpdate = async (ctx) => {
76
84
  if (!(ctx.file in this.#adaptersByCatalogPath)) {
85
+ if (this.#singleCompiledCatalogs.has(ctx.file)) {
86
+ return [];
87
+ }
88
+ for (const adapter of this.#granularLoadAdapters) {
89
+ for (const loc of this.#locales) {
90
+ for (const id in adapter.granularStateByID) {
91
+ if (resolve(adapter.getCompiledFilePath(loc, id)) === id) {
92
+ return [];
93
+ }
94
+ }
95
+ }
96
+ }
77
97
  this.#hmrVersion++;
78
98
  return;
79
99
  }
@@ -85,7 +105,7 @@ class Wuchale {
85
105
  await adapter.loadCatalogNCompile(loc);
86
106
  }
87
107
  for (const loadID of adapter.getLoadIDs()) {
88
- const fileID = `${virtualResolvedPrefix}${adapter.virtModEvent(loc, loadID)}`;
108
+ const fileID = resolve(adapter.getCompiledFilePath(loc, loadID));
89
109
  for (const module of ctx.server.moduleGraph.getModulesByFile(fileID) ?? []) {
90
110
  ctx.server.moduleGraph.invalidateModule(module, invalidatedModules, ctx.timestamp, false);
91
111
  }
@@ -96,46 +116,6 @@ class Wuchale {
96
116
  return [];
97
117
  }
98
118
  };
99
- resolveId = (source, importer) => {
100
- if (!source.startsWith(virtualPrefix)) {
101
- return null;
102
- }
103
- return `${virtualResolvedPrefix}${source}?importer=${importer}`;
104
- };
105
- load = (id) => {
106
- const prefix = virtualResolvedPrefix + virtualPrefix;
107
- if (!id.startsWith(prefix)) {
108
- return null;
109
- }
110
- const [path, importer] = id.slice(prefix.length).split('?importer=');
111
- const [part, ...rest] = path.split('/');
112
- if (part === 'catalog') {
113
- const [adapterKey, loadID, locale] = rest;
114
- const adapter = this.#adapters[adapterKey];
115
- if (adapter == null) {
116
- this.#log.error(`Adapter not found for key: ${adapterKey}`);
117
- return null;
118
- }
119
- return adapter.loadCatalogModule(locale, loadID, this.#hmrVersion);
120
- }
121
- if (part === 'locales') {
122
- return `export const locales = ['${this.#locales.join("', '")}']`;
123
- }
124
- if (part !== 'proxy') {
125
- this.#log.error(`Unknown virtual request: ${id}`);
126
- return null;
127
- }
128
- // loader proxy
129
- const adapter = this.#adaptersByLoaderPath[importer];
130
- if (adapter == null) {
131
- this.#log.error(`Adapter not found for filename: ${importer}`);
132
- return;
133
- }
134
- if (rest[0] === 'sync') {
135
- return adapter.getProxySync();
136
- }
137
- return adapter.getProxy();
138
- };
139
119
  #transformHandler = async (code, id, options) => {
140
120
  if (!this.#config.hmr) {
141
121
  return {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wuchale/vite-plugin",
3
- "version": "0.14.7",
3
+ "version": "0.15.0",
4
4
  "description": "Protobuf-like i18n from plain code: Vite plugin",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -40,10 +40,10 @@
40
40
  "author": "K1DV5",
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "wuchale": "^0.17.0"
43
+ "wuchale": "^0.18.0"
44
44
  },
45
45
  "devDependencies": {
46
- "typescript": "^5.8.3"
46
+ "typescript": "^5.9.3"
47
47
  },
48
48
  "type": "module"
49
49
  }