@bigbinary/neeto-commons-frontend 4.13.99 → 4.13.100
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.
|
@@ -1,14 +1,112 @@
|
|
|
1
|
+
/* eslint-disable @bigbinary/neeto/use-array-methods */
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const { watch } = require("chokidar");
|
|
6
|
+
|
|
1
7
|
const {
|
|
2
8
|
generateMergedTranslations,
|
|
3
9
|
writeTranslationsToDisk,
|
|
4
10
|
} = require("../../utils/packageTranslations");
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
12
|
+
// Only watch host app translations. Package translations inside
|
|
13
|
+
// node_modules/@bigbinary are handled by the nanoDevelopment plugin
|
|
14
|
+
const getTranslationWatchPaths = () => {
|
|
15
|
+
const hostTranslationsDir = path.resolve("app/javascript/src/translations");
|
|
16
|
+
|
|
17
|
+
return fs.existsSync(hostTranslationsDir) ? [hostTranslationsDir] : [];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const rebuildTranslations = () => {
|
|
21
|
+
const mergedTranslations = generateMergedTranslations();
|
|
22
|
+
writeTranslationsToDisk(mergedTranslations);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const packageTranslationsPlugin = () => {
|
|
26
|
+
let watcher;
|
|
27
|
+
let debounceTimeout;
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: "package-translations",
|
|
31
|
+
buildStart() {
|
|
32
|
+
rebuildTranslations();
|
|
33
|
+
},
|
|
34
|
+
handleHotUpdate({ file }) {
|
|
35
|
+
// Suppress Vite's default full-reload for translation JSON files
|
|
36
|
+
// so that only our plugin controls the rebuild + reload cycle.
|
|
37
|
+
if (file.includes("translations") && file.endsWith(".json")) return [];
|
|
38
|
+
|
|
39
|
+
return undefined;
|
|
40
|
+
},
|
|
41
|
+
configureServer(server) {
|
|
42
|
+
const watchPaths = getTranslationWatchPaths();
|
|
43
|
+
if (watchPaths.length === 0) return;
|
|
44
|
+
|
|
45
|
+
server.watcher.unwatch(watchPaths);
|
|
46
|
+
server.httpServer?.on("close", () => {
|
|
47
|
+
if (!watcher) return;
|
|
48
|
+
|
|
49
|
+
watcher.close();
|
|
50
|
+
watcher = null;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const invalidateAllModules = () => {
|
|
54
|
+
const moduleGraph = server.moduleGraph;
|
|
55
|
+
|
|
56
|
+
for (const mod of moduleGraph.idToModuleMap.values()) {
|
|
57
|
+
moduleGraph.invalidateModule(mod);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const handleChange = () => {
|
|
62
|
+
clearTimeout(debounceTimeout);
|
|
63
|
+
debounceTimeout = setTimeout(() => {
|
|
64
|
+
try {
|
|
65
|
+
const mergedTranslations = generateMergedTranslations();
|
|
66
|
+
writeTranslationsToDisk(mergedTranslations);
|
|
67
|
+
|
|
68
|
+
// Invalidate all modules so the preval transform re-runs and
|
|
69
|
+
// all import URLs are regenerated with the new browserHash.
|
|
70
|
+
invalidateAllModules();
|
|
71
|
+
|
|
72
|
+
// Update the browserHash on every optimized dep and chunk entry
|
|
73
|
+
// so the ?v= param changes in import URLs, forcing the browser
|
|
74
|
+
// to bypass its immutable cache for pre-bundled deps.
|
|
75
|
+
const depsOptimizer = server.environments?.client?.depsOptimizer;
|
|
76
|
+
if (depsOptimizer?.metadata) {
|
|
77
|
+
const newHash = Date.now().toString(36);
|
|
78
|
+
const { metadata } = depsOptimizer;
|
|
79
|
+
metadata.browserHash = newHash;
|
|
80
|
+
|
|
81
|
+
for (const entry of Object.values(metadata.optimized)) {
|
|
82
|
+
entry.browserHash = newHash;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const entry of Object.values(metadata.chunks)) {
|
|
86
|
+
entry.browserHash = newHash;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
server.hot.send({ type: "full-reload" });
|
|
91
|
+
} catch (error) {
|
|
92
|
+
server.config.logger.error(
|
|
93
|
+
`[package-translations] Rebuild failed: ${error}`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}, 1000);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
watcher = watch(watchPaths, { ignoreInitial: true })
|
|
100
|
+
.on("add", handleChange)
|
|
101
|
+
.on("change", handleChange)
|
|
102
|
+
.on("unlink", handleChange)
|
|
103
|
+
.on("error", error =>
|
|
104
|
+
server.config.logger.error(
|
|
105
|
+
`[package-translations] Watcher error: ${error}`
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
};
|
|
13
111
|
|
|
14
112
|
module.exports = { packageTranslationsPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.100",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|