@wuchale/vite-plugin 0.15.4 → 0.15.6
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 +2 -2
- package/dist/index.js +17 -9
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -14,14 +14,14 @@ type HotUpdateCtx = {
|
|
|
14
14
|
declare class Wuchale {
|
|
15
15
|
#private;
|
|
16
16
|
name: string;
|
|
17
|
-
constructor(configPath
|
|
17
|
+
constructor(configPath?: string);
|
|
18
18
|
configResolved: (config: {
|
|
19
19
|
env: {
|
|
20
20
|
DEV?: boolean;
|
|
21
21
|
};
|
|
22
22
|
root: string;
|
|
23
23
|
}) => Promise<void>;
|
|
24
|
-
handleHotUpdate: (ctx: HotUpdateCtx) => Promise<
|
|
24
|
+
handleHotUpdate: (ctx: HotUpdateCtx) => Promise<never[] | undefined>;
|
|
25
25
|
transform: {
|
|
26
26
|
order: "pre";
|
|
27
27
|
handler: (code: string, id: string, options?: {
|
package/dist/index.js
CHANGED
|
@@ -14,13 +14,14 @@ class Wuchale {
|
|
|
14
14
|
#singleCompiledCatalogs = new Set();
|
|
15
15
|
#locales = [];
|
|
16
16
|
#log;
|
|
17
|
+
#mode;
|
|
17
18
|
#configPath;
|
|
18
19
|
#hmrVersion = -1;
|
|
19
20
|
#lastSourceTriggeredPOWrite = 0;
|
|
20
21
|
constructor(configPath) {
|
|
21
22
|
this.#configPath = configPath;
|
|
22
23
|
}
|
|
23
|
-
#init = async (
|
|
24
|
+
#init = async () => {
|
|
24
25
|
this.#config = await getConfig(this.#configPath);
|
|
25
26
|
this.#log = new Logger(this.#config.logLevel);
|
|
26
27
|
this.#locales = [this.#config.sourceLocale, ...this.#config.otherLocales];
|
|
@@ -29,7 +30,7 @@ class Wuchale {
|
|
|
29
30
|
}
|
|
30
31
|
const sharedState = {};
|
|
31
32
|
for (const [key, adapter] of Object.entries(this.#config.adapters)) {
|
|
32
|
-
const handler = new AdapterHandler(adapter, key, this.#config, mode, this.#projectRoot, this.#log);
|
|
33
|
+
const handler = new AdapterHandler(adapter, key, this.#config, this.#mode, this.#projectRoot, this.#log);
|
|
33
34
|
await handler.init(sharedState);
|
|
34
35
|
handler.onBeforeWritePO = () => {
|
|
35
36
|
this.#lastSourceTriggeredPOWrite = performance.now();
|
|
@@ -70,25 +71,31 @@ class Wuchale {
|
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
configResolved = async (config) => {
|
|
73
|
-
let mode;
|
|
74
74
|
if (config.env.DEV) {
|
|
75
|
-
mode = 'dev';
|
|
75
|
+
this.#mode = 'dev';
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
|
-
mode = 'build';
|
|
78
|
+
this.#mode = 'build';
|
|
79
79
|
}
|
|
80
80
|
this.#projectRoot = config.root;
|
|
81
|
-
await this.#init(
|
|
81
|
+
await this.#init();
|
|
82
82
|
};
|
|
83
83
|
handleHotUpdate = async (ctx) => {
|
|
84
|
+
if (!this.#config.hmr) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// This is mainly to make sure that PO catalog changes result in a page reload with new catalogs
|
|
84
88
|
if (!(ctx.file in this.#adaptersByCatalogPath)) {
|
|
89
|
+
// prevent reloading whole app because of a change in compiled catalog
|
|
90
|
+
// triggered by extraction from single file, hmr handled by embedding patch
|
|
85
91
|
if (this.#singleCompiledCatalogs.has(ctx.file)) {
|
|
86
92
|
return [];
|
|
87
93
|
}
|
|
94
|
+
// for granular as well
|
|
88
95
|
for (const adapter of this.#granularLoadAdapters) {
|
|
89
96
|
for (const loc of this.#locales) {
|
|
90
97
|
for (const id in adapter.granularStateByID) {
|
|
91
|
-
if (resolve(adapter.getCompiledFilePath(loc, id)) ===
|
|
98
|
+
if (resolve(adapter.getCompiledFilePath(loc, id)) === ctx.file) {
|
|
92
99
|
return [];
|
|
93
100
|
}
|
|
94
101
|
}
|
|
@@ -97,12 +104,13 @@ class Wuchale {
|
|
|
97
104
|
this.#hmrVersion++;
|
|
98
105
|
return;
|
|
99
106
|
}
|
|
107
|
+
// catalog changed
|
|
100
108
|
const sourceTriggered = performance.now() - this.#lastSourceTriggeredPOWrite < 1000; // long enough threshold
|
|
101
109
|
const invalidatedModules = new Set();
|
|
102
110
|
for (const adapter of this.#adaptersByCatalogPath[ctx.file]) {
|
|
103
111
|
const loc = adapter.catalogPathsToLocales[ctx.file];
|
|
104
112
|
if (!sourceTriggered) {
|
|
105
|
-
await adapter.loadCatalogNCompile(loc);
|
|
113
|
+
await adapter.loadCatalogNCompile(loc, this.#hmrVersion);
|
|
106
114
|
}
|
|
107
115
|
for (const loadID of adapter.getLoadIDs()) {
|
|
108
116
|
const fileID = resolve(adapter.getCompiledFilePath(loc, loadID));
|
|
@@ -117,7 +125,7 @@ class Wuchale {
|
|
|
117
125
|
}
|
|
118
126
|
};
|
|
119
127
|
#transformHandler = async (code, id, options) => {
|
|
120
|
-
if (!this.#config.hmr) {
|
|
128
|
+
if (this.#mode === 'dev' && !this.#config.hmr) {
|
|
121
129
|
return {};
|
|
122
130
|
}
|
|
123
131
|
const filename = relative(this.#projectRoot, id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/vite-plugin",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.6",
|
|
4
4
|
"description": "Protobuf-like i18n from plain code: Vite plugin",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "tsc --watch",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"author": "K1DV5",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"wuchale": "^0.18.
|
|
43
|
+
"wuchale": "^0.18.9"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.9.3"
|