@wuchale/vite-plugin 0.16.1 → 0.16.3
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 -19
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ type HotUpdateCtx = {
|
|
|
15
15
|
declare class Wuchale {
|
|
16
16
|
#private;
|
|
17
17
|
name: string;
|
|
18
|
-
constructor(configPath?: string);
|
|
18
|
+
constructor(configPath?: string, hmrDelayThreshold?: number);
|
|
19
19
|
configResolved: (config: {
|
|
20
20
|
env: {
|
|
21
21
|
DEV?: boolean;
|
|
@@ -33,5 +33,5 @@ declare class Wuchale {
|
|
|
33
33
|
}>;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export declare const wuchale: (configPath?: string) => Wuchale;
|
|
36
|
+
export declare const wuchale: (configPath?: string, hmrDelayThreshold?: number) => Wuchale;
|
|
37
37
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// $$ cd ../.. && npm run test
|
|
2
|
-
import { relative, resolve } from
|
|
3
|
-
import {
|
|
4
|
-
import { getConfig as getConfig, Logger, AdapterHandler } from "wuchale";
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { AdapterHandler, getConfig, Logger, normalizeSep } from 'wuchale';
|
|
5
4
|
const pluginName = 'wuchale';
|
|
6
5
|
const confUpdateName = 'confUpdate.json';
|
|
7
6
|
class Wuchale {
|
|
@@ -17,9 +16,12 @@ class Wuchale {
|
|
|
17
16
|
#mode;
|
|
18
17
|
#configPath;
|
|
19
18
|
#hmrVersion = -1;
|
|
19
|
+
#hmrDelayThreshold;
|
|
20
20
|
#lastSourceTriggeredPOWrite = 0;
|
|
21
|
-
constructor(configPath) {
|
|
21
|
+
constructor(configPath, hmrDelayThreshold = 1000) {
|
|
22
22
|
this.#configPath = configPath;
|
|
23
|
+
// threshold to consider po file change is manual edit instead of a sideeffect of editing code
|
|
24
|
+
this.#hmrDelayThreshold = hmrDelayThreshold;
|
|
23
25
|
}
|
|
24
26
|
#init = async () => {
|
|
25
27
|
this.#config = await getConfig(this.#configPath);
|
|
@@ -42,15 +44,11 @@ class Wuchale {
|
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
for (const locale of this.#config.locales) {
|
|
45
|
-
this.#singleCompiledCatalogs.add(resolve(handler.getCompiledFilePath(locale, null)));
|
|
47
|
+
this.#singleCompiledCatalogs.add(normalizeSep(resolve(handler.getCompiledFilePath(locale, null))));
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
for (const path of Object.values(handler.loaderPath)) {
|
|
49
|
-
|
|
50
|
-
if (platform === 'win32') {
|
|
51
|
-
// seems vite does this for the importer field in the resolveId hook
|
|
52
|
-
loaderPath = loaderPath.replaceAll('\\', '/');
|
|
53
|
-
}
|
|
51
|
+
const loaderPath = normalizeSep(resolve(path));
|
|
54
52
|
if (adaptersByLoaderPath.has(loaderPath)) {
|
|
55
53
|
const otherKey = adaptersByLoaderPath.get(loaderPath)?.key;
|
|
56
54
|
if (otherKey === key) {
|
|
@@ -60,12 +58,12 @@ class Wuchale {
|
|
|
60
58
|
throw new Error([
|
|
61
59
|
'While catalogs can be shared, the same loader cannot be used by multiple adapters',
|
|
62
60
|
`Conflicting: ${key} and ${otherKey}`,
|
|
63
|
-
'Specify a different loaderPath for one of them.'
|
|
61
|
+
'Specify a different loaderPath for one of them.',
|
|
64
62
|
].join('\n'));
|
|
65
63
|
}
|
|
66
64
|
adaptersByLoaderPath.set(loaderPath, handler);
|
|
67
65
|
}
|
|
68
|
-
for (const fname of
|
|
66
|
+
for (const fname of handler.catalogPathsToLocales.keys()) {
|
|
69
67
|
const handlers = this.#adaptersByCatalogPath.get(fname);
|
|
70
68
|
if (handlers) {
|
|
71
69
|
handlers.push(handler);
|
|
@@ -74,7 +72,7 @@ class Wuchale {
|
|
|
74
72
|
this.#adaptersByCatalogPath.set(fname, [handler]);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
|
-
this.#adaptersByConfUpdate.set(resolve(adapter.localesDir, confUpdateName), handler);
|
|
75
|
+
this.#adaptersByConfUpdate.set(normalizeSep(resolve(adapter.localesDir, confUpdateName)), handler);
|
|
78
76
|
}
|
|
79
77
|
};
|
|
80
78
|
configResolved = async (config) => {
|
|
@@ -108,8 +106,8 @@ class Wuchale {
|
|
|
108
106
|
// for granular as well
|
|
109
107
|
for (const adapter of this.#granularLoadAdapters) {
|
|
110
108
|
for (const loc of this.#config.locales) {
|
|
111
|
-
for (const id
|
|
112
|
-
if (resolve(adapter.getCompiledFilePath(loc, id)) === ctx.file) {
|
|
109
|
+
for (const id of adapter.granularStateByID.keys()) {
|
|
110
|
+
if (normalizeSep(resolve(adapter.getCompiledFilePath(loc, id))) === ctx.file) {
|
|
113
111
|
return [];
|
|
114
112
|
}
|
|
115
113
|
}
|
|
@@ -119,15 +117,15 @@ class Wuchale {
|
|
|
119
117
|
return;
|
|
120
118
|
}
|
|
121
119
|
// catalog changed
|
|
122
|
-
const sourceTriggered = performance.now() - this.#lastSourceTriggeredPOWrite <
|
|
120
|
+
const sourceTriggered = performance.now() - this.#lastSourceTriggeredPOWrite < this.#hmrDelayThreshold;
|
|
123
121
|
const invalidatedModules = new Set();
|
|
124
122
|
for (const adapter of adapters) {
|
|
125
|
-
const loc = adapter.catalogPathsToLocales
|
|
123
|
+
const loc = adapter.catalogPathsToLocales.get(ctx.file);
|
|
126
124
|
if (!sourceTriggered) {
|
|
127
125
|
await adapter.loadCatalogNCompile(loc, this.#hmrVersion);
|
|
128
126
|
}
|
|
129
127
|
for (const loadID of adapter.getLoadIDs()) {
|
|
130
|
-
const fileID = resolve(adapter.getCompiledFilePath(loc, loadID));
|
|
128
|
+
const fileID = normalizeSep(resolve(adapter.getCompiledFilePath(loc, loadID)));
|
|
131
129
|
for (const module of ctx.server.moduleGraph.getModulesByFile(fileID) ?? []) {
|
|
132
130
|
ctx.server.moduleGraph.invalidateModule(module, invalidatedModules, ctx.timestamp, false);
|
|
133
131
|
}
|
|
@@ -160,4 +158,4 @@ class Wuchale {
|
|
|
160
158
|
};
|
|
161
159
|
transform = { order: 'pre', handler: this.#transformHandler };
|
|
162
160
|
}
|
|
163
|
-
export const wuchale = (configPath) => new Wuchale(configPath);
|
|
161
|
+
export const wuchale = (configPath, hmrDelayThreshold = 1000) => new Wuchale(configPath, hmrDelayThreshold);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wuchale/vite-plugin",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.3",
|
|
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.19.
|
|
43
|
+
"wuchale": "^0.19.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "^5.9.3"
|