Merge pull request #1734 from atom/forked-original-fs
Make "original-fs" available in forked scripts
This commit is contained in:
commit
097d4d9870
5 changed files with 17 additions and 15 deletions
|
@ -1,8 +0,0 @@
|
||||||
vm = require 'vm'
|
|
||||||
|
|
||||||
# Execute the 'fs.js' and pass the 'exports' to it.
|
|
||||||
source = '(function (exports, require, module, __filename, __dirname) { ' +
|
|
||||||
process.binding('natives').originalFs +
|
|
||||||
'\n});'
|
|
||||||
fn = vm.runInThisContext source, { filename: 'fs.js' }
|
|
||||||
fn exports, require, module
|
|
|
@ -9,10 +9,10 @@ return (process, require, asarSource) ->
|
||||||
|
|
||||||
# Make graceful-fs work with asar.
|
# Make graceful-fs work with asar.
|
||||||
source = process.binding 'natives'
|
source = process.binding 'natives'
|
||||||
source.originalFs = source.fs
|
source['original-fs'] = source.fs
|
||||||
source.fs = """
|
source['fs'] = """
|
||||||
var src = '(function (exports, require, module, __filename, __dirname) { ' +
|
var src = '(function (exports, require, module, __filename, __dirname) { ' +
|
||||||
process.binding('natives').originalFs +
|
process.binding('natives')['original-fs'] +
|
||||||
' });';
|
' });';
|
||||||
var vm = require('vm');
|
var vm = require('vm');
|
||||||
var fn = vm.runInThisContext(src, { filename: 'fs.js' });
|
var fn = vm.runInThisContext(src, { filename: 'fs.js' });
|
||||||
|
|
|
@ -35,7 +35,6 @@
|
||||||
'atom/common/api/lib/crash-reporter.coffee',
|
'atom/common/api/lib/crash-reporter.coffee',
|
||||||
'atom/common/api/lib/id-weak-map.coffee',
|
'atom/common/api/lib/id-weak-map.coffee',
|
||||||
'atom/common/api/lib/native-image.coffee',
|
'atom/common/api/lib/native-image.coffee',
|
||||||
'atom/common/api/lib/original-fs.coffee',
|
|
||||||
'atom/common/api/lib/shell.coffee',
|
'atom/common/api/lib/shell.coffee',
|
||||||
'atom/common/lib/init.coffee',
|
'atom/common/lib/init.coffee',
|
||||||
'atom/renderer/lib/chrome-api.coffee',
|
'atom/renderer/lib/chrome-api.coffee',
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
assert = require 'assert'
|
assert = require 'assert'
|
||||||
|
child_process = require 'child_process'
|
||||||
fs = require 'fs'
|
fs = require 'fs'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
|
||||||
|
@ -443,6 +444,13 @@ describe 'asar package', ->
|
||||||
stats = originalFs.statSync file
|
stats = originalFs.statSync file
|
||||||
assert stats.isFile()
|
assert stats.isFile()
|
||||||
|
|
||||||
|
it 'is available in forked scripts', (done) ->
|
||||||
|
child = child_process.fork path.join(fixtures, 'module', 'original-fs.js')
|
||||||
|
child.on 'message', (msg) ->
|
||||||
|
assert.equal msg, 'object'
|
||||||
|
done()
|
||||||
|
child.send 'message'
|
||||||
|
|
||||||
describe 'graceful-fs module', ->
|
describe 'graceful-fs module', ->
|
||||||
gfs = require 'graceful-fs'
|
gfs = require 'graceful-fs'
|
||||||
|
|
||||||
|
|
3
spec/fixtures/module/original-fs.js
vendored
Normal file
3
spec/fixtures/module/original-fs.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
process.on('message', function (msg) {
|
||||||
|
process.send(typeof require('original-fs'));
|
||||||
|
});
|
Loading…
Reference in a new issue