From 359f2b7600f70fdf7308f681a8de1d34ca0725f1 Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Thu, 21 Aug 2025 20:34:11 -0700 Subject: [PATCH] Changes --- bin/cp-snapshot.js | 13 ++++++++++--- bin/mk-snapshot.js | 16 +++++++++++++--- bin/notarize.js | 5 +++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/bin/cp-snapshot.js b/bin/cp-snapshot.js index fe30e52c..a9d437e3 100644 --- a/bin/cp-snapshot.js +++ b/bin/cp-snapshot.js @@ -1,3 +1,4 @@ + const path = require('path'); const fs = require('fs'); const fsPromises = require('fs/promises'); @@ -10,24 +11,30 @@ function copySnapshot(pathToElectron, archToCopy) { const pathToBlobV8 = path.resolve(__dirname, '..', 'cache', archToCopy, v8ContextFileName); console.log('Copying v8 snapshots from', pathToBlob, 'to', pathToElectron); + fs.mkdirSync(pathToElectron, { recursive: true }); fs.copyFileSync(pathToBlob, path.join(pathToElectron, snapshotFileName)); fs.copyFileSync(pathToBlobV8, path.join(pathToElectron, v8ContextFileName)); } function getPathToElectron() { + const electronPath = require.resolve('electron'); + switch (process.platform) { case 'darwin': return path.resolve( - __dirname, + electronPath, '..', - 'node_modules/electron/dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources' + '..', + '..', + 'dist/Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Resources' ); case 'win32': case 'linux': - return path.resolve(__dirname, '..', 'node_modules', 'electron', 'dist'); + return path.resolve(electronPath, '..', '..', '..', 'dist'); } } + function getV8ContextFileName(archToCopy) { return `snapshot_blob.bin`; } diff --git a/bin/mk-snapshot.js b/bin/mk-snapshot.js index 3829139c..03ece94e 100644 --- a/bin/mk-snapshot.js +++ b/bin/mk-snapshot.js @@ -4,6 +4,7 @@ const path = require('path'); const fs = require('fs'); const electronLink = require('electron-link'); const {mkdirp} = require('fs-extra'); +const pnp = require("pnpapi"); const excludedModules = {}; @@ -15,6 +16,12 @@ const archMap = { }; async function main() { + const npmConfigArch = process.env.npm_config_arch; + if (!npmConfigArch) { + throw new Error('env var npm_config_arch is not specified') + } + + const baseDirPath = path.resolve(__dirname, '..'); console.log('Creating a linked script..'); @@ -32,11 +39,14 @@ async function main() { // Verify if we will be able to use this in `mksnapshot` vm.runInNewContext(result.snapshotScript, undefined, {filename: snapshotScriptPath, displayErrors: true}); - const outputBlobPath = `${baseDirPath}/cache/${process.env.npm_config_arch}`; + const outputBlobPath = `${baseDirPath}/cache/${npmConfigArch}`; await mkdirp(outputBlobPath); + const baseDir = pnp.resolveToUnqualified("electron-mksnapshot", __filename); + const mksnapshotBinPath = path.resolve(baseDir, "bin", "mksnapshot" + (process.platform === "win32" ? ".exe" : "")); + if (process.platform !== 'darwin') { - const mksnapshotBinPath = `${baseDirPath}/node_modules/electron-mksnapshot/bin`; + // TODO non-darwin const matchingDirs = crossArchDirs.map((dir) => `${mksnapshotBinPath}/${dir}`).filter((dir) => fs.existsSync(dir)); for (const dir of matchingDirs) { if (fs.existsSync(`${mksnapshotBinPath}/gen/v8/embedded.S`)) { @@ -50,7 +60,7 @@ async function main() { console.log(`Generating startup blob in "${outputBlobPath}"`); const res = childProcess.execFileSync( - path.resolve(__dirname, '..', 'node_modules', 'electron-mksnapshot', 'bin', 'mksnapshot' + (process.platform === 'win32' ? '.exe' : '')), + require.resolve(`electron-mksnapshot/bin/mksnapshot${process.platform === 'win32' ? '.exe' : ''}`), [ '--startup-src=' + snapshotScriptPath, '--startup-blob=' + startupBlobPath, diff --git a/bin/notarize.js b/bin/notarize.js index d4ce1ef4..3031fcbc 100644 --- a/bin/notarize.js +++ b/bin/notarize.js @@ -1,11 +1,12 @@ -const { notarize } = require("@electron/notarize"); - exports.default = async function notarizing(context) { + const { electronPlatformName, appOutDir } = context; if (electronPlatformName !== "darwin" || !process.env.APPLE_ID || !process.env.APPLE_PASSWORD) { return; } + const { notarize } = await import('@electron/notarize'); + const appName = context.packager.appInfo.productFilename; return await notarize({ appBundleId: "com.quineglobal.hyper",