diff --git a/docs/api/environment-variables.md b/docs/api/environment-variables.md index aca4f31cbd22..3bd2326810f9 100644 --- a/docs/api/environment-variables.md +++ b/docs/api/environment-variables.md @@ -43,6 +43,11 @@ 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. This variable is only supported in forked child processes +and spawned child processes that set `ELECTRON_RUN_AS_NODE`. + ## 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..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) { + if (isAsarDisabled()) { return [false] } diff --git a/spec/asar-spec.js b/spec/asar-spec.js index 9b53a3ffbdf4..5399cde041f6 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 () { + const 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)) +}