Skip to content

Commit 3988ca2

Browse files
authored
Merge pull request atom#15557 from atom/as-use-electron-node-to-verify-snapshot-script
Use the Node version bundled in Electron to verify snapshot script
2 parents a3e82a5 + 8c8d6f7 commit 3988ca2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

script/lib/generate-startup-snapshot.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const fs = require('fs')
33
const path = require('path')
44
const electronLink = require('electron-link')
55
const CONFIG = require('../config')
6-
const vm = require('vm')
76

87
module.exports = function (packagedAppPath) {
98
const snapshotScriptPath = path.join(CONFIG.buildOutputPath, 'startup.js')
@@ -76,7 +75,20 @@ module.exports = function (packagedAppPath) {
7675
process.stdout.write('\n')
7776

7877
console.log('Verifying if snapshot can be executed via `mksnapshot`')
79-
vm.runInNewContext(snapshotScript, undefined, {filename: snapshotScriptPath, displayErrors: true})
78+
const verifySnapshotScriptPath = path.join(CONFIG.repositoryRootPath, 'script', 'verify-snapshot-script')
79+
let nodeBundledInElectronPath
80+
if (process.platform === 'darwin') {
81+
nodeBundledInElectronPath = path.join(packagedAppPath, 'Contents', 'MacOS', 'Atom')
82+
} else if (process.platform === 'win32') {
83+
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom.exe')
84+
} else {
85+
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom')
86+
}
87+
childProcess.execFileSync(
88+
nodeBundledInElectronPath,
89+
[verifySnapshotScriptPath, snapshotScriptPath],
90+
{env: Object.assign({}, process.env, {ELECTRON_RUN_AS_NODE: 1})}
91+
)
8092

8193
const generatedStartupBlobPath = path.join(CONFIG.buildOutputPath, 'snapshot_blob.bin')
8294
console.log(`Generating startup blob at "${generatedStartupBlobPath}"`)

script/verify-snapshot-script

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs')
3+
const vm = require('vm')
4+
const snapshotScriptPath = process.argv[2]
5+
const snapshotScript = fs.readFileSync(snapshotScriptPath, 'utf8')
6+
vm.runInNewContext(snapshotScript, undefined, {filename: snapshotScriptPath, displayErrors: true})

0 commit comments

Comments
 (0)