@wuchale/vite-plugin 0.16.0 → 0.16.2
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 +3 -3
- package/dist/index.js +12 -9
- package/package.json +1 -1
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;
|
|
@@ -26,12 +26,12 @@ declare class Wuchale {
|
|
|
26
26
|
transform: {
|
|
27
27
|
order: "pre";
|
|
28
28
|
handler: (code: string, id: string, options?: {
|
|
29
|
-
ssr?: boolean;
|
|
29
|
+
ssr?: boolean | undefined;
|
|
30
30
|
}) => Promise<{
|
|
31
31
|
code?: string;
|
|
32
32
|
map?: any;
|
|
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,7 @@
|
|
|
1
1
|
// $$ cd ../.. && npm run test
|
|
2
|
-
import { relative, resolve } from
|
|
3
|
-
import { platform } from
|
|
4
|
-
import {
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { platform } from 'node:process';
|
|
4
|
+
import { AdapterHandler, getConfig, Logger } from 'wuchale';
|
|
5
5
|
const pluginName = 'wuchale';
|
|
6
6
|
const confUpdateName = 'confUpdate.json';
|
|
7
7
|
class Wuchale {
|
|
@@ -17,9 +17,12 @@ class Wuchale {
|
|
|
17
17
|
#mode;
|
|
18
18
|
#configPath;
|
|
19
19
|
#hmrVersion = -1;
|
|
20
|
+
#hmrDelayThreshold;
|
|
20
21
|
#lastSourceTriggeredPOWrite = 0;
|
|
21
|
-
constructor(configPath) {
|
|
22
|
+
constructor(configPath, hmrDelayThreshold = 1000) {
|
|
22
23
|
this.#configPath = configPath;
|
|
24
|
+
// threshold to consider po file change is manual edit instead of a sideeffect of editing code
|
|
25
|
+
this.#hmrDelayThreshold = hmrDelayThreshold;
|
|
23
26
|
}
|
|
24
27
|
#init = async () => {
|
|
25
28
|
this.#config = await getConfig(this.#configPath);
|
|
@@ -60,12 +63,12 @@ class Wuchale {
|
|
|
60
63
|
throw new Error([
|
|
61
64
|
'While catalogs can be shared, the same loader cannot be used by multiple adapters',
|
|
62
65
|
`Conflicting: ${key} and ${otherKey}`,
|
|
63
|
-
'Specify a different loaderPath for one of them.'
|
|
66
|
+
'Specify a different loaderPath for one of them.',
|
|
64
67
|
].join('\n'));
|
|
65
68
|
}
|
|
66
69
|
adaptersByLoaderPath.set(loaderPath, handler);
|
|
67
70
|
}
|
|
68
|
-
for (const fname of
|
|
71
|
+
for (const fname of handler.catalogPathsToLocales.keys()) {
|
|
69
72
|
const handlers = this.#adaptersByCatalogPath.get(fname);
|
|
70
73
|
if (handlers) {
|
|
71
74
|
handlers.push(handler);
|
|
@@ -119,10 +122,10 @@ class Wuchale {
|
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
121
124
|
// catalog changed
|
|
122
|
-
const sourceTriggered = performance.now() - this.#lastSourceTriggeredPOWrite <
|
|
125
|
+
const sourceTriggered = performance.now() - this.#lastSourceTriggeredPOWrite < this.#hmrDelayThreshold;
|
|
123
126
|
const invalidatedModules = new Set();
|
|
124
127
|
for (const adapter of adapters) {
|
|
125
|
-
const loc = adapter.catalogPathsToLocales
|
|
128
|
+
const loc = adapter.catalogPathsToLocales.get(ctx.file);
|
|
126
129
|
if (!sourceTriggered) {
|
|
127
130
|
await adapter.loadCatalogNCompile(loc, this.#hmrVersion);
|
|
128
131
|
}
|
|
@@ -160,4 +163,4 @@ class Wuchale {
|
|
|
160
163
|
};
|
|
161
164
|
transform = { order: 'pre', handler: this.#transformHandler };
|
|
162
165
|
}
|
|
163
|
-
export const wuchale = (configPath) => new Wuchale(configPath);
|
|
166
|
+
export const wuchale = (configPath, hmrDelayThreshold = 1000) => new Wuchale(configPath, hmrDelayThreshold);
|