mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-01 16:15:24 +00:00
fix: refresh cached plugin translations when only a translation changes (Support#1411)
This commit is contained in:
1 parent
18a594a92d
commit
fbf7598399
2 files changed
+27
-4
No files matched your search
@@ -76,13 +76,18 @@ export function describePluginFrontend(
|
|||||||
if (!plugin) return none;
|
if (!plugin) return none;
|
||||||
|
|
||||||
const locales: string[] = [];
|
const locales: string[] = [];
|
||||||
|
const localeFiles: string[] = [];
|
||||||
const dir = localesDir(plugin);
|
const dir = localesDir(plugin);
|
||||||
if (dir && fileExists(path.join(dir, "en.json"))) locales.push("en");
|
if (dir && fileExists(path.join(dir, "en.json"))) {
|
||||||
|
locales.push("en");
|
||||||
|
localeFiles.push(path.join(dir, "en.json"));
|
||||||
|
}
|
||||||
if (dir) {
|
if (dir) {
|
||||||
try {
|
try {
|
||||||
for (const name of fs.readdirSync(path.join(dir, "translated"))) {
|
for (const name of fs.readdirSync(path.join(dir, "translated"))) {
|
||||||
if (/^[a-z]{2}_[A-Z]{2}\.json$/.test(name)) {
|
if (/^[a-z]{2}_[A-Z]{2}\.json$/.test(name)) {
|
||||||
locales.push(name.slice(0, -".json".length));
|
locales.push(name.slice(0, -".json".length));
|
||||||
|
localeFiles.push(path.join(dir, "translated", name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -95,8 +100,9 @@ export function describePluginFrontend(
|
|||||||
|
|
||||||
const cssFile = path.join(entry.dir, "frontend.css");
|
const cssFile = path.join(entry.dir, "frontend.css");
|
||||||
const css = fileExists(cssFile);
|
const css = fileExists(cssFile);
|
||||||
|
// Locales share the version, so a translations-only update must change it.
|
||||||
const assetVersion = contentVersion(
|
const assetVersion = contentVersion(
|
||||||
css ? [entry.file, cssFile] : [entry.file],
|
[...(css ? [entry.file, cssFile] : [entry.file]), ...localeFiles.sort()],
|
||||||
plugin.manifest.version,
|
plugin.manifest.version,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -113,8 +119,8 @@ const versionCache = new Map<string, { stamp: string; version: string }>();
|
|||||||
/**
|
/**
|
||||||
* A hash of the bundle's bytes, not its mtime: assets are cached as immutable
|
* A hash of the bundle's bytes, not its mtime: assets are cached as immutable
|
||||||
* for a year, and a rebuilt .tmxplug has a fixed mtime, so a same-size rebuild
|
* for a year, and a rebuilt .tmxplug has a fixed mtime, so a same-size rebuild
|
||||||
* would otherwise keep serving the stale copy. The CSS is hashed with the JS
|
* would otherwise keep serving the stale copy. The CSS and locales are hashed
|
||||||
* because both are served under the same version.
|
* with the JS because all of them are served under the same version.
|
||||||
*/
|
*/
|
||||||
function contentVersion(files: string[], version: string): string {
|
function contentVersion(files: string[], version: string): string {
|
||||||
// ctime, unlike mtime, cannot be set by tar, so an unpack always changes it.
|
// ctime, unlike mtime, cannot be set by tar, so an unpack always changes it.
|
||||||
|
|||||||
@@ -85,6 +85,23 @@ describe("describePluginFrontend", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("changes the version when only a translation changes", () => {
|
||||||
|
const before = describePluginFrontend(plugin).assetVersion;
|
||||||
|
const locale = path.join(
|
||||||
|
root,
|
||||||
|
"gizmo",
|
||||||
|
"locales",
|
||||||
|
"translated",
|
||||||
|
"de_DE.json",
|
||||||
|
);
|
||||||
|
fs.writeFileSync(locale, '{"hello":"Hallo"}');
|
||||||
|
try {
|
||||||
|
expect(describePluginFrontend(plugin).assetVersion).not.toBe(before);
|
||||||
|
} finally {
|
||||||
|
fs.writeFileSync(locale, "{}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("reports nothing for an unknown plugin", () => {
|
it("reports nothing for an unknown plugin", () => {
|
||||||
expect(describePluginFrontend(undefined)).toEqual({
|
expect(describePluginFrontend(undefined)).toEqual({
|
||||||
frontend: false,
|
frontend: false,
|
||||||
|
|||||||
Reference in new issue
Block a user