Merge pull request #7479 from bpasero/process-no-asar

Introduce ELECTRON_NO_ASAR
This commit is contained in:
Kevin Sawicki 2016-10-12 13:48:03 -07:00 committed by GitHub
commit fefc7c23f9
4 changed files with 66 additions and 1 deletions

View file

@ -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: geocoding requests. To enable geocoding requests, visit this page:
https://console.developers.google.com/apis/api/geolocation/overview 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 ## Development Variables
The following environment variables are intended primarily for development and The following environment variables are intended primarily for development and

View file

@ -10,6 +10,16 @@
// Cache asar archive objects. // Cache asar archive objects.
const cachedArchives = {} 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) { const getOrCreateArchive = function (p) {
let archive = cachedArchives[p] let archive = cachedArchives[p]
if (archive != null) { if (archive != null) {
@ -34,7 +44,7 @@
// Separate asar package's path from full path. // Separate asar package's path from full path.
const splitPath = function (p) { const splitPath = function (p) {
// shortcut to disable asar. // shortcut to disable asar.
if (process.noAsar) { if (isAsarDisabled()) {
return [false] return [false]
} }

View file

@ -753,6 +753,41 @@ describe('asar package', function () {
assert.equal(process.noAsar, false) 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 () { describe('asar protocol', function () {

15
spec/fixtures/module/no-asar.js vendored Normal file
View file

@ -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))
}