From 15d988d4417ad5ab6ae033ae1aaf8b8338027a62 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 6 Sep 2017 11:02:54 +0200 Subject: [PATCH 1/3] Use the Node version bundled in Electron to verify snapshot script Previously, we used to verify the snapshot script by running it in a new, empty context (similar to the one that `mksnapshot` creates when generating the startup blob). However, this context was being created using the Node version that `script/build` was executed with. Such version may not match the Node version shipped with Electron, and could thus cause the build script to report "false negatives" when verifying the snapshot script. For instance, running `script/build` with Node 4 would cause it to throw an error when encountering keywords like `async`/`await`, even if they're 100% supported in Electron 1.6.9. With this commit we are changing the snapshot verification code to use the Node version bundled in Electron in order to avoid the aforementioned mismatches. --- script/lib/generate-startup-snapshot.js | 15 ++++++++++++++- script/verify-snapshot-script | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 script/verify-snapshot-script diff --git a/script/lib/generate-startup-snapshot.js b/script/lib/generate-startup-snapshot.js index 471bd1201..d9a5eb408 100644 --- a/script/lib/generate-startup-snapshot.js +++ b/script/lib/generate-startup-snapshot.js @@ -76,7 +76,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}"`) diff --git a/script/verify-snapshot-script b/script/verify-snapshot-script new file mode 100755 index 000000000..7fddbb1b9 --- /dev/null +++ b/script/verify-snapshot-script @@ -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}) From 2050f58a0e1b7021accd746fcb80e87cdebdd92e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 6 Sep 2017 11:08:58 +0200 Subject: [PATCH 2/3] Don't override `process.env` variables --- script/lib/generate-startup-snapshot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/lib/generate-startup-snapshot.js b/script/lib/generate-startup-snapshot.js index d9a5eb408..49893dde3 100644 --- a/script/lib/generate-startup-snapshot.js +++ b/script/lib/generate-startup-snapshot.js @@ -88,7 +88,7 @@ module.exports = function (packagedAppPath) { childProcess.execFileSync( nodeBundledInElectronPath, [verifySnapshotScriptPath, snapshotScriptPath], - {env: Object.assign(process.env, {ELECTRON_RUN_AS_NODE: 1})} + {env: Object.assign({}, process.env, {ELECTRON_RUN_AS_NODE: 1})} ) const generatedStartupBlobPath = path.join(CONFIG.buildOutputPath, 'snapshot_blob.bin') From 8c8d6f7ce465506d34c1e3ef50f2d6e3285fee4c Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 6 Sep 2017 11:28:19 +0200 Subject: [PATCH 3/3] :fire: Delete unused require --- script/lib/generate-startup-snapshot.js | 1 - 1 file changed, 1 deletion(-) diff --git a/script/lib/generate-startup-snapshot.js b/script/lib/generate-startup-snapshot.js index 49893dde3..bb635b4c1 100644 --- a/script/lib/generate-startup-snapshot.js +++ b/script/lib/generate-startup-snapshot.js @@ -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')