From 656ee0d9c3e0e67daa743337448ccb98e981b155 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 4 Oct 2016 10:39:05 +0200 Subject: [PATCH 1/4] introduce ELECTRON_NO_ASAR --- docs/api/environment-variables.md | 4 ++++ lib/common/asar.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/api/environment-variables.md b/docs/api/environment-variables.md index aca4f31cbd22..a946e399e883 100644 --- a/docs/api/environment-variables.md +++ b/docs/api/environment-variables.md @@ -43,6 +43,10 @@ By default, a newly generated Google API key may not be allowed to make geocoding requests. To enable geocoding requests, visit this page: https://console.developers.google.com/apis/api/geolocation/overview +### `ELECTRON_NO_ASAR` + +Disables ASAR support. Note that this variable can only be used when forking a process to disable any ASAR support in that process. + ## Development Variables The following environment variables are intended primarily for development and diff --git a/lib/common/asar.js b/lib/common/asar.js index 230e3113daab..42510119841a 100644 --- a/lib/common/asar.js +++ b/lib/common/asar.js @@ -34,7 +34,7 @@ // Separate asar package's path from full path. const splitPath = function (p) { // shortcut to disable asar. - if (process.noAsar) { + if (process.noAsar || process.env.ELECTRON_NO_ASAR) { return [false] } From 8897a7a92671701b2aa04af82256e31a376f6112 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 7 Oct 2016 10:59:18 -0700 Subject: [PATCH 2/4] Add specs for ELECTRON_NO_ASAR env var --- spec/asar-spec.js | 35 +++++++++++++++++++++++++++++++++ spec/fixtures/module/no-asar.js | 15 ++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 spec/fixtures/module/no-asar.js diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 9b53a3ffbdf4..8b5e741be176 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -753,6 +753,41 @@ describe('asar package', function () { assert.equal(process.noAsar, false) }) }) + + describe('process.env.ELECTRON_NO_ASAR', function () { + it('disables asar support in forked processes', function (done) { + const forked = ChildProcess.fork(path.join(__dirname, 'fixtures', 'module', 'no-asar.js'), [], { + env: { + ELECTRON_NO_ASAR: true + } + }) + forked.on('message', function (stats) { + assert.equal(stats.isFile, true) + assert.equal(stats.size, 778) + done() + }) + }) + + it('disables asar support in spawned processes', function (done) { + const spawned = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'no-asar.js')], { + env: { + ELECTRON_NO_ASAR: true, + ELECTRON_RUN_AS_NODE: true + } + }) + + let output = '' + spawned.stdout.on('data', function (data) { + output += data + }) + spawned.stdout.on('close', function () { + stats = JSON.parse(output) + assert.equal(stats.isFile, true) + assert.equal(stats.size, 778) + done() + }) + }) + }) }) describe('asar protocol', function () { diff --git a/spec/fixtures/module/no-asar.js b/spec/fixtures/module/no-asar.js new file mode 100644 index 000000000000..e574e3c6511b --- /dev/null +++ b/spec/fixtures/module/no-asar.js @@ -0,0 +1,15 @@ +const fs = require('fs') +const path = require('path') + +const stats = fs.statSync(path.join(__dirname, '..', 'asar', 'a.asar')) + +const details = { + isFile: stats.isFile(), + size: stats.size +} + +if (process.send != null) { + process.send(details) +} else { + console.log(JSON.stringify(details)) +} From f553d165399007266c2d0cfea2af1c86fcb45737 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 7 Oct 2016 10:59:34 -0700 Subject: [PATCH 3/4] Only support ELECTRON_NO_ASAR in non browser/renderer processes --- lib/common/asar.js | 12 +++++++++++- spec/asar-spec.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/common/asar.js b/lib/common/asar.js index 42510119841a..0891669f801a 100644 --- a/lib/common/asar.js +++ b/lib/common/asar.js @@ -10,6 +10,16 @@ // Cache asar archive objects. const cachedArchives = {} + const isAsarDisabled = function () { + if (process.noAsar) { + return true + } + if (process.env.ELECTRON_NO_ASAR && process.type !== 'browser' && process.type !== 'renderer') { + return true + } + return false + } + const getOrCreateArchive = function (p) { let archive = cachedArchives[p] if (archive != null) { @@ -34,7 +44,7 @@ // Separate asar package's path from full path. const splitPath = function (p) { // shortcut to disable asar. - if (process.noAsar || process.env.ELECTRON_NO_ASAR) { + if (isAsarDisabled()) { return [false] } diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 8b5e741be176..5399cde041f6 100644 --- a/spec/asar-spec.js +++ b/spec/asar-spec.js @@ -781,7 +781,7 @@ describe('asar package', function () { output += data }) spawned.stdout.on('close', function () { - stats = JSON.parse(output) + const stats = JSON.parse(output) assert.equal(stats.isFile, true) assert.equal(stats.size, 778) done() From 566d76def29ebc3b73b5670c21eba6be6f366f6b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 7 Oct 2016 11:03:00 -0700 Subject: [PATCH 4/4] Mention spawning with ELECTRON_RUN_AS_NODE --- docs/api/environment-variables.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api/environment-variables.md b/docs/api/environment-variables.md index a946e399e883..3bd2326810f9 100644 --- a/docs/api/environment-variables.md +++ b/docs/api/environment-variables.md @@ -45,7 +45,8 @@ https://console.developers.google.com/apis/api/geolocation/overview ### `ELECTRON_NO_ASAR` -Disables ASAR support. Note that this variable can only be used when forking a process to disable any ASAR support in that process. +Disables ASAR support. This variable is only supported in forked child processes +and spawned child processes that set `ELECTRON_RUN_AS_NODE`. ## Development Variables