Merge pull request #1734 from atom/forked-original-fs
Make "original-fs" available in forked scripts
This commit is contained in:
Коммит
097d4d9870
|
@ -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.
|
||||
source = process.binding 'natives'
|
||||
source.originalFs = source.fs
|
||||
source.fs = """
|
||||
source['original-fs'] = source.fs
|
||||
source['fs'] = """
|
||||
var src = '(function (exports, require, module, __filename, __dirname) { ' +
|
||||
process.binding('natives').originalFs +
|
||||
process.binding('natives')['original-fs'] +
|
||||
' });';
|
||||
var vm = require('vm');
|
||||
var fn = vm.runInThisContext(src, { filename: 'fs.js' });
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
'atom/common/api/lib/crash-reporter.coffee',
|
||||
'atom/common/api/lib/id-weak-map.coffee',
|
||||
'atom/common/api/lib/native-image.coffee',
|
||||
'atom/common/api/lib/original-fs.coffee',
|
||||
'atom/common/api/lib/shell.coffee',
|
||||
'atom/common/lib/init.coffee',
|
||||
'atom/renderer/lib/chrome-api.coffee',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
assert = require 'assert'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
assert = require 'assert'
|
||||
child_process = require 'child_process'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
|
||||
describe 'asar package', ->
|
||||
fixtures = path.join __dirname, 'fixtures'
|
||||
|
@ -443,6 +444,13 @@ describe 'asar package', ->
|
|||
stats = originalFs.statSync file
|
||||
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', ->
|
||||
gfs = require 'graceful-fs'
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
process.on('message', function (msg) {
|
||||
process.send(typeof require('original-fs'));
|
||||
});
|
Загрузка…
Ссылка в новой задаче