diff --git a/electron-builder.js b/electron-builder.ts similarity index 86% rename from electron-builder.js rename to electron-builder.ts index 39b6b7a..b564b49 100644 --- a/electron-builder.js +++ b/electron-builder.ts @@ -1,10 +1,8 @@ -const os = require("os"); -const fs = require("fs"); -const path = require("path"); -const Arch = require("electron-builder").Arch; -const { flipFuses, FuseVersion, FuseV1Options } = require("@electron/fuses"); - -// Typescript conversion blocked on https://github.com/electron-userland/electron-builder/issues/7775 +import * as os from "os"; +import * as fs from "fs"; +import * as path from "path"; +import { Arch, Configuration as BaseConfiguration, AfterPackContext } from "electron-builder"; +import { flipFuses, FuseVersion, FuseV1Options } from "@electron/fuses"; /** * This script has different outputs depending on your os platform. @@ -26,24 +24,47 @@ const { flipFuses, FuseVersion, FuseV1Options } = require("@electron/fuses"); const NIGHTLY_APP_ID = "im.riot.nightly"; const NIGHTLY_DEB_NAME = "element-nightly"; -const pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); +interface Pkg { + name: string; + productName: string; + description: string; + version: string; +} + +type Writable = NonNullable< + T extends Function ? T : T extends object ? { -readonly [K in keyof T]: Writable } : T +>; + +const pkg: Pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); + +interface Configuration extends BaseConfiguration { + extraMetadata: Partial> & Omit; + linux: { + desktop: Record; + } & BaseConfiguration["linux"]; + win: BaseConfiguration["win"]; + mac: BaseConfiguration["mac"]; + deb: { + fpm: string[]; + } & BaseConfiguration["deb"]; +} /** * @type {import('electron-builder').Configuration} * @see https://www.electron.build/configuration/configuration */ -const config = { +const config: Writable = { appId: "im.riot.app", asarUnpack: "**/*.node", - afterPack: async (context) => { + afterPack: async (context: AfterPackContext) => { if (context.electronPlatformName !== "darwin" || context.arch === Arch.universal) { // Burn in electron fuses for proactive security hardening. // On macOS, we only do this for the universal package, as the constituent arm64 and amd64 packages are embedded within. - const ext = { + const ext = (>{ darwin: ".app", win32: ".exe", linux: "", - }[context.electronPlatformName]; + })[context.electronPlatformName]; let executableName = context.packager.appInfo.productFilename; if (context.electronPlatformName === "linux") { @@ -212,4 +233,4 @@ if (os.platform() === "linux") { } } -exports.default = config; +export default config; diff --git a/knip.ts b/knip.ts index eb0d22a..5366ede 100644 --- a/knip.ts +++ b/knip.ts @@ -1,7 +1,7 @@ import { KnipConfig } from "knip"; export default { - entry: ["src/electron-main.ts", "src/preload.ts", "electron-builder.js", ".eslintrc-*.js", "scripts/**", "hak/**"], + entry: ["src/electron-main.ts", "src/preload.ts", "electron-builder.ts", ".eslintrc-*.js", "scripts/**", "hak/**"], project: ["**/*.{js,ts}"], ignoreDependencies: [ // Brought in via hak scripts @@ -9,6 +9,7 @@ export default { "matrix-seshat", // Needed by `electron-builder` "electron-builder-squirrel-windows", + "@types/yargs", // Required for `action-validator` "@action-validator/*", ], diff --git a/package.json b/package.json index 10a2b89..aa84c86 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@types/pacote": "^11.1.1", "@types/tar": "^6.1.3", "@types/uuid": "^9.0.2", + "@types/yargs": "^17.0.32", "@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/parser": "^7.0.0", "app-builder-lib": "24.13.3", @@ -123,6 +124,7 @@ "keytar": "^7.9.0" }, "resolutions": { - "@types/node": "18.19.28" + "@types/node": "18.19.28", + "config-file-ts": "0.2.8-rc1" } } diff --git a/scripts/hak/hakEnv.ts b/scripts/hak/hakEnv.ts index 724d419..e8f4d41 100644 --- a/scripts/hak/hakEnv.ts +++ b/scripts/hak/hakEnv.ts @@ -17,17 +17,17 @@ limitations under the License. import path from "path"; import os from "os"; import nodePreGypVersioning from "node-pre-gyp/lib/util/versioning"; -import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"; +import { getElectronVersionFromInstalled } from "app-builder-lib/out/electron/electronVersion"; import { Arch, Target, TARGETS, getHost, isHostId, TargetId } from "./target"; async function getRuntime(projectRoot: string): Promise { - const electronVersion = await getElectronVersion(projectRoot); + const electronVersion = await getElectronVersionFromInstalled(projectRoot); return electronVersion ? "electron" : "node-webkit"; } async function getRuntimeVersion(projectRoot: string): Promise { - const electronVersion = await getElectronVersion(projectRoot); + const electronVersion = await getElectronVersionFromInstalled(projectRoot); if (electronVersion) { return electronVersion; } else { diff --git a/yarn.lock b/yarn.lock index 822f56a..017b17e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1924,6 +1924,18 @@ resolved "https://registry.yarnpkg.com/@types/verror/-/verror-1.10.9.tgz#420c32adb9a2dd50b3db4c8f96501e05a0e72941" integrity sha512-MLx9Z+9lGzwEuW16ubGeNkpBDE84RpB/NyGgg6z2BTpWzKkGU451cAY3UkUzZEp72RHF585oJ3V8JVNqIplcAQ== +"@types/yargs-parser@*": + version "21.0.3" + resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15" + integrity sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ== + +"@types/yargs@^17.0.32": + version "17.0.32" + resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.32.tgz#030774723a2f7faafebf645f4e5a48371dca6229" + integrity sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog== + dependencies: + "@types/yargs-parser" "*" + "@types/yauzl@^2.9.1": version "2.10.3" resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.10.3.tgz#e9b2808b4f109504a03cda958259876f61017999" @@ -2829,13 +2841,13 @@ conf@^10.2.0: pkg-up "^3.1.0" semver "^7.3.5" -config-file-ts@^0.2.4: - version "0.2.4" - resolved "https://registry.yarnpkg.com/config-file-ts/-/config-file-ts-0.2.4.tgz#6c0741fbe118a7cf786c65f139030f0448a2cc99" - integrity sha512-cKSW0BfrSaAUnxpgvpXPLaaW/umg4bqg4k3GO1JqlRfpx+d5W0GDXznCMkWotJQek5Mmz1MJVChQnz3IVaeMZQ== +config-file-ts@0.2.8-rc1, config-file-ts@^0.2.4: + version "0.2.8-rc1" + resolved "https://registry.yarnpkg.com/config-file-ts/-/config-file-ts-0.2.8-rc1.tgz#fb7fc6ccb2e313f69dbeb78f1db0b00038049de0" + integrity sha512-GtNECbVI82bT4RiDIzBSVuTKoSHufnU7Ce7/42bkWZJZFLjmDF2WBpVsvRkhKCfKBnTBb3qZrBwPpFBU/Myvhg== dependencies: - glob "^7.1.6" - typescript "^4.0.2" + glob "^10.3.12" + typescript "^5.4.3" console-control-strings@^1.0.0, console-control-strings@~1.1.0: version "1.1.0" @@ -3892,7 +3904,7 @@ glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob@^10.0.0, glob@^10.2.2, glob@^10.3.10, glob@^10.3.7: +glob@^10.0.0, glob@^10.2.2, glob@^10.3.10, glob@^10.3.12, glob@^10.3.7: version "10.3.12" resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.12.tgz#3a65c363c2e9998d220338e88a5f6ac97302960b" integrity sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg== @@ -6614,10 +6626,10 @@ typescript@5.4.3: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== -typescript@^4.0.2: - version "4.9.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" - integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== +typescript@^5.4.3: + version "5.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.4.tgz#eb2471e7b0a5f1377523700a21669dce30c2d952" + integrity sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw== unbox-primitive@^1.0.2: version "1.0.2"