Merge pull request #15557 from atom/as-use-electron-node-to-verify-snapshot-script

Use the Node version bundled in Electron to verify snapshot script
This commit is contained in:
Damien Guard
2017-09-06 10:11:12 -07:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -3,7 +3,6 @@ const fs = require('fs')
const path = require('path')
const electronLink = require('electron-link')
const CONFIG = require('../config')
const vm = require('vm')
module.exports = function (packagedAppPath) {
const snapshotScriptPath = path.join(CONFIG.buildOutputPath, 'startup.js')
@@ -76,7 +75,20 @@ module.exports = function (packagedAppPath) {
process.stdout.write('\n')
console.log('Verifying if snapshot can be executed via `mksnapshot`')
vm.runInNewContext(snapshotScript, undefined, {filename: snapshotScriptPath, displayErrors: true})
const verifySnapshotScriptPath = path.join(CONFIG.repositoryRootPath, 'script', 'verify-snapshot-script')
let nodeBundledInElectronPath
if (process.platform === 'darwin') {
nodeBundledInElectronPath = path.join(packagedAppPath, 'Contents', 'MacOS', 'Atom')
} else if (process.platform === 'win32') {
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom.exe')
} else {
nodeBundledInElectronPath = path.join(packagedAppPath, 'atom')
}
childProcess.execFileSync(
nodeBundledInElectronPath,
[verifySnapshotScriptPath, snapshotScriptPath],
{env: Object.assign({}, process.env, {ELECTRON_RUN_AS_NODE: 1})}
)
const generatedStartupBlobPath = path.join(CONFIG.buildOutputPath, 'snapshot_blob.bin')
console.log(`Generating startup blob at "${generatedStartupBlobPath}"`)

6
script/verify-snapshot-script Executable file
View File

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