From c8babc7b5c82915a6c5bbb95e063ecbd2b0cb844 Mon Sep 17 00:00:00 2001 From: Cosmo Myzrail Gorynych Date: Thu, 16 May 2024 15:56:04 +0300 Subject: [PATCH 1/5] chore(bld): Replace rcedit with resedit --- package-lock.json | 111 +++++++++++++--------------------------------- package.json | 2 +- src/bld.js | 51 ++++++++++++--------- 3 files changed, 60 insertions(+), 104 deletions(-) diff --git a/package-lock.json b/package-lock.json index ca8c801c1..3bc875d4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "glob": "^10.3.15", "node-gyp": "^10.1.0", "plist": "^3.1.0", - "rcedit": "^4.0.1", + "resedit": "^2.0.2", "semver": "^7.6.2", "tar": "^7.1.0", "yargs": "^17.7.2", @@ -684,27 +684,6 @@ "node": ">=v12.0.0" } }, - "node_modules/@malept/cross-spawn-promise": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz", - "integrity": "sha512-RTBGWL5FWQcg9orDOCcp4LvItNzUPcyEU9bwaeJX0rJ1IQxzucC48Y0/sQLp/g6t99IQgAlGIaesJS+gTn7tVQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/malept" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/subscription/pkg/npm-.malept-cross-spawn-promise?utm_medium=referral&utm_source=npm_fund" - } - ], - "dependencies": { - "cross-spawn": "^7.0.1" - }, - "engines": { - "node": ">= 10" - } - }, "node_modules/@napi-rs/wasm-runtime": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.1.1.tgz", @@ -2007,29 +1986,6 @@ "node": ">= 8" } }, - "node_modules/cross-spawn-windows-exe": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/cross-spawn-windows-exe/-/cross-spawn-windows-exe-1.2.0.tgz", - "integrity": "sha512-mkLtJJcYbDCxEG7Js6eUnUNndWjyUZwJ3H7bErmmtOYU/Zb99DyUkpamuIZE0b3bhmJyZ7D90uS6f+CGxRRjOw==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/malept" - }, - { - "type": "tidelift", - "url": "https://tidelift.com/subscription/pkg/npm-cross-spawn-windows-exe?utm_medium=referral&utm_source=npm_fund" - } - ], - "dependencies": { - "@malept/cross-spawn-promise": "^1.1.0", - "is-wsl": "^2.2.0", - "which": "^2.0.2" - }, - "engines": { - "node": ">= 10" - } - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3043,20 +2999,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/is-docker": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", - "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", - "bin": { - "is-docker": "cli.js" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3134,17 +3076,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-wsl": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", - "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", - "dependencies": { - "is-docker": "^2.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -4092,6 +4023,19 @@ "node": "*" } }, + "node_modules/pe-library": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pe-library/-/pe-library-1.0.1.tgz", + "integrity": "sha512-nh39Mo1eGWmZS7y+mK/dQIqg7S1lp38DpRxkyoHf0ZcUs/HDc+yyTjuOtTvSMZHmfSLuSQaX945u05Y2Q6UWZg==", + "engines": { + "node": ">=14", + "npm": ">=7" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jet2jet" + } + }, "node_modules/pend": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", @@ -4267,17 +4211,6 @@ } ] }, - "node_modules/rcedit": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/rcedit/-/rcedit-4.0.1.tgz", - "integrity": "sha512-bZdaQi34krFWhrDn+O53ccBDw0MkAT2Vhu75SqhtvhQu4OPyFM4RoVheyYiVQYdjhUi6EJMVWQ0tR6bCIYVkUg==", - "dependencies": { - "cross-spawn-windows-exe": "^1.1.0" - }, - "engines": { - "node": ">= 14.0.0" - } - }, "node_modules/react-is": { "version": "18.3.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", @@ -4320,6 +4253,22 @@ "lodash": "^4.17.21" } }, + "node_modules/resedit": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/resedit/-/resedit-2.0.2.tgz", + "integrity": "sha512-UKTnq602iVe+W5SyRAQx/WdWMnlDiONfXBLFg/ur4QE4EQQ8eP7Jgm5mNXdK12kKawk1vvXPja2iXKqZiGDW6Q==", + "dependencies": { + "pe-library": "^1.0.1" + }, + "engines": { + "node": ">=14", + "npm": ">=7" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jet2jet" + } + }, "node_modules/resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", diff --git a/package.json b/package.json index ea0531a3e..8fd0f5849 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "glob": "^10.3.15", "node-gyp": "^10.1.0", "plist": "^3.1.0", - "rcedit": "^4.0.1", + "resedit": "^2.0.2", "semver": "^7.6.2", "tar": "^7.1.0", "yargs": "^17.7.2", diff --git a/src/bld.js b/src/bld.js index f828773ed..578b3b67b 100644 --- a/src/bld.js +++ b/src/bld.js @@ -5,7 +5,9 @@ import fsm from "node:fs/promises"; import process from "node:process"; import compressing from "compressing"; -import rcedit from "rcedit"; +import * as resedit from "resedit"; +// pe-library is a direct dependency of resedit +import * as peLibrary from 'pe-library'; import plist from "plist"; import util from "./util.js" @@ -103,7 +105,7 @@ import util from "./util.js" * * @async * @function - * @param {BuildOptions} options - Build options + * @param {BuildOptions} options - Build options * @return {Promise} */ async function bld({ @@ -311,28 +313,33 @@ const setWinConfig = async ({ app, outDir }) => { } }); - const rcEditOptions = { - "file-version": app.version, - "product-version": app.version, - "version-string": versionString, - }; - + const outDirAppExe = path.resolve(outDir, `${app.name}.exe`); + await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe); + const exe = peLibrary.NtExecutable.from(await fsm.readFile(outDirAppExe)); + const res = peLibrary.NtExecutableResource.from(exe); if (app.icon) { - rcEditOptions.icon = app.icon; - } - - try { - const outDirAppExe = path.resolve(outDir, `${app.name}.exe`); - await fsm.rename(path.resolve(outDir, "nw.exe"), outDirAppExe); - await rcedit(outDirAppExe, rcEditOptions); - } catch (error) { - if (process.platform !== "win32") { - console.warn( - "Ensure WINE is installed or build your application on Windows platform", - ); - } - throw error; + const iconBuffer = await fsm.readFile(path.resolve(app.icon)); + const iconFile = resedit.Data.IconFile.from(iconBuffer); + resedit.Resource.IconGroupEntry.replaceIconsForResource( + res.entries, + // This is the name of the icon group nw.js uses that gets shown in file exlorers + 'IDR_MAINFRAME', + // 1033 means "English (United States)" + 1033, + iconFile.icons.map(i => i.data) + ); } + const [vi] = resedit.Resource.VersionInfo.fromEntries(res.entries); + const [major, minor, patch] = app.version.split("."); + vi.setFileVersion(major, minor, patch, 0, 1033); + vi.setStringValues({ + lang: 1033, + codepage: 1200 + }, versionString); + vi.outputToResourceEntries(res.entries); + res.outputResource(exe); + const outBuffer = Buffer.from(exe.generate()); + await fsm.writeFile(outDirAppExe, outBuffer); }; const setOsxConfig = async ({ outDir, app }) => { From c42923ce4266e7880fa16f2a3e4ca971bac86a75 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 22 May 2024 22:02:05 +0530 Subject: [PATCH 2/5] Update src/bld.js Co-authored-by: The Jared Wilcurt --- src/bld.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bld.js b/src/bld.js index 578b3b67b..29a274d4e 100644 --- a/src/bld.js +++ b/src/bld.js @@ -320,6 +320,8 @@ const setWinConfig = async ({ app, outDir }) => { if (app.icon) { const iconBuffer = await fsm.readFile(path.resolve(app.icon)); const iconFile = resedit.Data.IconFile.from(iconBuffer); + // English (United States) + const EN_US = 1033; resedit.Resource.IconGroupEntry.replaceIconsForResource( res.entries, // This is the name of the icon group nw.js uses that gets shown in file exlorers From 1a1e371010156e1b946989082f3e970e5f065139 Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 22 May 2024 22:02:18 +0530 Subject: [PATCH 3/5] Update src/bld.js Co-authored-by: The Jared Wilcurt --- src/bld.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bld.js b/src/bld.js index 29a274d4e..2d045de89 100644 --- a/src/bld.js +++ b/src/bld.js @@ -326,8 +326,7 @@ const setWinConfig = async ({ app, outDir }) => { res.entries, // This is the name of the icon group nw.js uses that gets shown in file exlorers 'IDR_MAINFRAME', - // 1033 means "English (United States)" - 1033, + EN_US, iconFile.icons.map(i => i.data) ); } From 638228501e995415ed07fad1ee0e4e1872a3eb5a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 22 May 2024 22:02:26 +0530 Subject: [PATCH 4/5] Update src/bld.js Co-authored-by: The Jared Wilcurt --- src/bld.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld.js b/src/bld.js index 2d045de89..81fb18410 100644 --- a/src/bld.js +++ b/src/bld.js @@ -332,7 +332,7 @@ const setWinConfig = async ({ app, outDir }) => { } const [vi] = resedit.Resource.VersionInfo.fromEntries(res.entries); const [major, minor, patch] = app.version.split("."); - vi.setFileVersion(major, minor, patch, 0, 1033); + vi.setFileVersion(major, minor, patch, 0, EN_US); vi.setStringValues({ lang: 1033, codepage: 1200 From a2f7cc6c52a6f06e51f525bb99a65f06c5941a9d Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Wed, 22 May 2024 22:02:42 +0530 Subject: [PATCH 5/5] Update src/bld.js Co-authored-by: The Jared Wilcurt --- src/bld.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld.js b/src/bld.js index 81fb18410..767c6fb65 100644 --- a/src/bld.js +++ b/src/bld.js @@ -334,7 +334,7 @@ const setWinConfig = async ({ app, outDir }) => { const [major, minor, patch] = app.version.split("."); vi.setFileVersion(major, minor, patch, 0, EN_US); vi.setStringValues({ - lang: 1033, + lang: EN_US, codepage: 1200 }, versionString); vi.outputToResourceEntries(res.entries);