Merge pull request #3641 from atom/process-no-asar
Add process.noAsar to toggle asar support
This commit is contained in:
commit
a2f1390b0d
4 changed files with 52 additions and 1 deletions
|
@ -18,6 +18,7 @@ process.on 'exit', ->
|
|||
|
||||
# Separate asar package's path from full path.
|
||||
splitPath = (p) ->
|
||||
return [false] if process.noAsar # shortcut to disable asar.
|
||||
return [false] if typeof p isnt 'string'
|
||||
return [true, p, ''] if p.substr(-5) is '.asar'
|
||||
p = path.normalize p
|
||||
|
|
|
@ -31,11 +31,18 @@ process.once('loaded', function() {
|
|||
});
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
### `process.noAsar`
|
||||
|
||||
Setting this to `true` can disable the support for `asar` archives in Node's
|
||||
built-in modules.
|
||||
|
||||
## Methods
|
||||
|
||||
The `process` object has the following method:
|
||||
|
||||
### `process.hang`
|
||||
### `process.hang()`
|
||||
|
||||
Causes the main thread of the current process hang.
|
||||
|
||||
|
|
|
@ -103,6 +103,14 @@ var originalFs = require('original-fs');
|
|||
originalFs.readFileSync('/path/to/example.asar');
|
||||
```
|
||||
|
||||
You can also set `process.noAsar` to `true` to disable the support for `asar` in
|
||||
the `fs` module:
|
||||
|
||||
```javascript
|
||||
process.noAsar = true;
|
||||
fs.readFileSync('/path/to/example.asar');
|
||||
```
|
||||
|
||||
## Limitations on Node API
|
||||
|
||||
Even though we tried hard to make `asar` archives in the Node API work like
|
||||
|
|
|
@ -423,6 +423,41 @@ describe 'asar package', ->
|
|||
p = path.join fixtures, 'asar', 'unpack.asar', 'a.txt'
|
||||
assert.equal internalModuleReadFile(p).toString().trim(), 'a'
|
||||
|
||||
describe 'process.noAsar', ->
|
||||
beforeEach ->
|
||||
process.noAsar = true
|
||||
afterEach ->
|
||||
process.noAsar = false
|
||||
|
||||
it 'disables asar support in sync API', ->
|
||||
file = path.join fixtures, 'asar', 'a.asar', 'file1'
|
||||
dir = path.join fixtures, 'asar', 'a.asar', 'dir1'
|
||||
assert.throws (-> fs.readFileSync file), /ENOTDIR/
|
||||
assert.throws (-> fs.lstatSync file), /ENOTDIR/
|
||||
assert.throws (-> fs.realpathSync file), /ENOTDIR/
|
||||
assert.throws (-> fs.readdirSync dir), /ENOTDIR/
|
||||
|
||||
it 'disables asar support in async API', (done) ->
|
||||
file = path.join fixtures, 'asar', 'a.asar', 'file1'
|
||||
dir = path.join fixtures, 'asar', 'a.asar', 'dir1'
|
||||
fs.readFile file, (error) ->
|
||||
assert.equal error.code, 'ENOTDIR'
|
||||
fs.lstat file, (error) ->
|
||||
assert.equal error.code, 'ENOTDIR'
|
||||
fs.realpath file, (error) ->
|
||||
assert.equal error.code, 'ENOTDIR'
|
||||
fs.readdir dir, (error) ->
|
||||
assert.equal error.code, 'ENOTDIR'
|
||||
done()
|
||||
|
||||
it 'treats *.asar as normal file', ->
|
||||
originalFs = require 'original-fs'
|
||||
asar = path.join fixtures, 'asar', 'a.asar'
|
||||
content1 = fs.readFileSync asar
|
||||
content2 = originalFs.readFileSync asar
|
||||
assert.equal content1.compare(content2), 0
|
||||
assert.throws (-> fs.readdirSync asar), /ENOTDIR/
|
||||
|
||||
describe 'asar protocol', ->
|
||||
url = require 'url'
|
||||
|
||||
|
|
Loading…
Reference in a new issue