Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 3d7784c

Browse files
committed
Revert "fix(desktop): use plugin to clean up languages"
This reverts commit cbcc219.
1 parent 0414500 commit 3d7784c

File tree

3 files changed

+55
-27
lines changed

3 files changed

+55
-27
lines changed

apps/desktop/electron-forge/forge.config.cjs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require("path");
22
const fs = require("fs-extra");
33
const { LOCALES } = require("@triliumnext/commons");
4-
const setLanguages = require('electron-packager-languages');
54

65
const ELECTRON_FORGE_DIR = __dirname;
76

@@ -30,10 +29,6 @@ const macosSignConfiguration = process.env.APPLE_ID ? {
3029
}
3130
} : undefined;
3231

33-
const localesToKeep = LOCALES
34-
.filter(locale => !locale.contentOnly)
35-
.map(locale => locale.electronLocale);
36-
3732
module.exports = {
3833
outDir: "out",
3934
// Documentation of `packagerConfig` options: https://electron.github.io/packager/main/interfaces/Options.html
@@ -50,9 +45,6 @@ module.exports = {
5045
...(process.platform === "darwin" ? [] : extraResourcesForPlatform)
5146
],
5247
prune: false,
53-
afterCopy: [
54-
setLanguages(localesToKeep)
55-
],
5648
afterComplete: [
5749
(buildPath, _electronVersion, platform, _arch, callback) => {
5850
// Only move resources on non-macOS platforms
@@ -150,6 +142,53 @@ module.exports = {
150142
}
151143
],
152144
hooks: {
145+
// Remove unused locales from the packaged app to save some space.
146+
postPackage(_, packageResult) {
147+
const localesToKeep = LOCALES
148+
.filter(locale => !locale.contentOnly)
149+
.map(locale => locale.electronLocale.replace("_", "-"));
150+
const keptLocales = new Set();
151+
const removedLocales = [];
152+
153+
for (const outputPath of packageResult.outputPaths) {
154+
const localesDir = path.join(outputPath, 'locales');
155+
156+
if (!fs.existsSync(localesDir)) {
157+
console.log('No locales directory found. Skipping cleanup.');
158+
return;
159+
}
160+
161+
const files = fs.readdirSync(localesDir);
162+
163+
for (const file of files) {
164+
let localeName = path.basename(file, ".pak");
165+
if (localeName === "en-US" && process.platform === "win32") {
166+
// If the locale is "en-US" on Windows, we treat it as "en".
167+
// This is because the Windows version of Electron uses "en-US.pak" instead of "en.pak".
168+
localeName = "en";
169+
}
170+
171+
if (localesToKeep.includes(localeName)) {
172+
keptLocales.add(localeName);
173+
continue;
174+
}
175+
176+
const filePath = path.join(localesDir, file);
177+
fs.unlinkSync(filePath);
178+
removedLocales.push(file);
179+
}
180+
}
181+
182+
console.log(`Removed unused locale files: ${removedLocales.join(", ")}`);
183+
184+
// Ensure all locales that should be kept are actually present.
185+
for (const locale of localesToKeep) {
186+
if (!keptLocales.has(locale)) {
187+
console.error(`Locale ${locale} was not found in the packaged app.`);
188+
process.exit(1);
189+
}
190+
}
191+
},
153192
// Gather all the artifacts produced by the makers and copy them to a common upload directory.
154193
postMake(_, makeResults) {
155194
const outputDir = path.join(__dirname, "..", "upload");

apps/desktop/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
"electron-debug": "4.1.0",
1111
"electron-dl": "4.0.0",
1212
"electron-squirrel-startup": "1.0.1",
13-
"jquery-hotkeys": "0.2.2",
14-
"jquery.fancytree": "2.38.5"
13+
"jquery.fancytree": "2.38.5",
14+
"jquery-hotkeys": "0.2.2"
1515
},
1616
"devDependencies": {
17+
"@types/electron-squirrel-startup": "1.0.2",
18+
"@triliumnext/server": "workspace:*",
19+
"copy-webpack-plugin": "13.0.0",
20+
"electron": "36.4.0",
1721
"@electron-forge/cli": "7.8.1",
1822
"@electron-forge/maker-deb": "7.8.1",
1923
"@electron-forge/maker-dmg": "7.8.1",
@@ -22,11 +26,6 @@
2226
"@electron-forge/maker-squirrel": "7.8.1",
2327
"@electron-forge/maker-zip": "7.8.1",
2428
"@electron-forge/plugin-auto-unpack-natives": "7.8.1",
25-
"@triliumnext/server": "workspace:*",
26-
"@types/electron-squirrel-startup": "1.0.2",
27-
"copy-webpack-plugin": "13.0.0",
28-
"electron": "36.4.0",
29-
"electron-packager-languages": "0.6.0",
3029
"prebuild-install": "^7.1.1"
3130
},
3231
"config": {
@@ -76,7 +75,7 @@
7675
"cjs"
7776
],
7877
"thirdParty": true,
79-
"declaration": false,
78+
"declaration": false,
8079
"esbuildOptions": {
8180
"splitting": false,
8281
"loader": {

pnpm-lock.yaml

Lines changed: 1 addition & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)