diff --git a/packages/suite-desktop-core/package.json b/packages/suite-desktop-core/package.json index 6f6c55367d7a..f2e76897473b 100644 --- a/packages/suite-desktop-core/package.json +++ b/packages/suite-desktop-core/package.json @@ -7,9 +7,9 @@ "homepage": "https://trezor.io/", "main": "src/app.ts", "scripts": { - "build:scripts": "yarn g:rimraf ./lib && yarn g:tsc --build tsconfig.scripts.json && find ./lib -name '*.js' -exec bash -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;", + "build:scripts": "yarn g:rimraf ./lib && yarn g:tsc --build scripts/tsconfig.json && node scripts/rename-js-to-mjs.cjs", "build:core": "yarn g:rimraf dist && TS_NODE_PROJECT=\"tsconfig.json\" yarn webpack --config ./webpack/core.webpack.config.ts", - "type-check": "yarn g:tsc --build tsconfig.json", + "type-check": "yarn g:tsc --build tsconfig.json && yarn g:tsc --build scripts/tsconfig.json", "test:unit": "yarn g:jest", "test:e2e:desktop": "yarn xvfb-maybe -- playwright test --config=./e2e/playwright.config.ts --project=desktop", "test:e2e:web": "yarn xvfb-maybe -- playwright test --config=./e2e/playwright.config.ts --project=web", @@ -54,7 +54,7 @@ }, "devDependencies": { "@currents/playwright": "^1.13.4", - "@electron/fuses": "^1.8.0", + "@electron/fuses": "^2.0.0", "@electron/notarize": "3.0.2", "@octokit/rest": "^21.1.1", "@playwright/browser-chromium": "^1.52.0", diff --git a/packages/suite-desktop-core/scripts/rename-js-to-mjs.cjs b/packages/suite-desktop-core/scripts/rename-js-to-mjs.cjs new file mode 100644 index 000000000000..7b3c2c9b9483 --- /dev/null +++ b/packages/suite-desktop-core/scripts/rename-js-to-mjs.cjs @@ -0,0 +1,21 @@ +/** + * Electron-builder hooks in /scripts/*.ts are compiled to /lib/*.js + * They are built as ESM, as required by some of the libs, but the whole module is still CJS. + * Electron-builder needs to know that the hooks are ESM, so we rename the extension. + * This is an interim solution while electron-main is still built as CJS. + * TODO #14482 Delete this, update the filenames in electron-builder-config.js + */ + +const fs = require('fs'); +const path = require('path'); + +const libDir = path.join(__dirname, '../lib'); + +fs.readdirSync(libDir).forEach(file => { + if (file.endsWith('.js')) { + const oldPath = path.join(libDir, file); + const newPath = path.join(libDir, file.replace(/\.js$/, '.mjs')); + fs.renameSync(oldPath, newPath); + } +}); +console.log(`Renamed electron-builder hooks .js files to .mjs`); diff --git a/packages/suite-desktop-core/scripts/tsconfig.json b/packages/suite-desktop-core/scripts/tsconfig.json new file mode 100644 index 000000000000..27a1aba3f5cf --- /dev/null +++ b/packages/suite-desktop-core/scripts/tsconfig.json @@ -0,0 +1,12 @@ +{ + "extends": "../../../tsconfig.lib.json", + "compilerOptions": { + "module": "ESNext", + "moduleResolution": "bundler", + "declaration": false, + "sourceMap": false, + "declarationMap": false, + "outDir": "../lib" + }, + "include": ["."] +} diff --git a/packages/suite-desktop-core/tsconfig.json b/packages/suite-desktop-core/tsconfig.json index 12c7d4331f31..3c2f6ba89e41 100644 --- a/packages/suite-desktop-core/tsconfig.json +++ b/packages/suite-desktop-core/tsconfig.json @@ -5,12 +5,7 @@ "moduleResolution": "node", "outDir": "libDev" }, - "include": [ - "src", - "e2e", - "scripts", - "**/*.json" - ], + "include": ["src", "e2e", "**/*.json"], "references": [ { "path": "../../suite-common/message-system" diff --git a/packages/suite-desktop-core/tsconfig.scripts.json b/packages/suite-desktop-core/tsconfig.scripts.json deleted file mode 100644 index 21c6c16b782b..000000000000 --- a/packages/suite-desktop-core/tsconfig.scripts.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.lib.json", - "compilerOptions": { - "module": "ESNext", - "declaration": false, - "sourceMap": false, - "declarationMap": false, - "outDir": "lib" - }, - "include": ["./scripts"], - "references": [ - { - "path": "../eslint" - } - ] -} diff --git a/yarn.lock b/yarn.lock index f56a48aeff00..9cd0d12cb34d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2189,6 +2189,15 @@ __metadata: languageName: node linkType: hard +"@electron/fuses@npm:^2.0.0": + version: 2.0.0 + resolution: "@electron/fuses@npm:2.0.0" + bin: + electron-fuses: dist/bin.js + checksum: 10/12af9e5164a9870f353368cebd8b451b82ca0abd82bc62b2a3745c51dd3692a761e8e107c2f35cf85aa0781bbbda3afafac8b77c4f8692b6dc820d9a455297a7 + languageName: node + linkType: hard + "@electron/get@npm:^2.0.0": version: 2.0.2 resolution: "@electron/get@npm:2.0.2" @@ -12701,7 +12710,7 @@ __metadata: resolution: "@trezor/suite-desktop-core@workspace:packages/suite-desktop-core" dependencies: "@currents/playwright": "npm:^1.13.4" - "@electron/fuses": "npm:^1.8.0" + "@electron/fuses": "npm:^2.0.0" "@electron/notarize": "npm:3.0.2" "@octokit/rest": "npm:^21.1.1" "@playwright/browser-chromium": "npm:^1.52.0"