diff --git a/src/parseUtils.js b/src/parseUtils.js index 5169c00f..48b7ceeb 100644 --- a/src/parseUtils.js +++ b/src/parseUtils.js @@ -7,8 +7,12 @@ module.exports = { parseBundle }; -function parseBundle(bundlePath) { - const content = fs.readFileSync(bundlePath, 'utf8'); +const defaultBundleHost = { + getFileContent: path => fs.readFileSync(path, 'utf8') +}; + +function parseBundle(bundlePath, bundleHost = defaultBundleHost) { + const content = bundleHost.getFileContent(bundlePath); const ast = acorn.parse(content, { sourceType: 'script', // I believe in a bright future of ECMAScript! diff --git a/test/parseUtils.js b/test/parseUtils.js index f863e689..970dbfbe 100644 --- a/test/parseUtils.js +++ b/test/parseUtils.js @@ -30,4 +30,16 @@ describe('parseBundle', function () { expect(bundle.src).to.equal(fs.readFileSync(bundleFile, 'utf8')); expect(bundle.modules).to.deep.equal({}); }); + + it('should allow a custom bundle host to override file system operations', function () { + let getBundleContentArg; + const bundle = parseBundle('arg', { + getFileContent: bundlePath => { + getBundleContentArg = bundlePath; + return 'webpackJsonp([0],[(t,e,r)=>{}])'; + } + }); + expect(getBundleContentArg).to.equal('arg'); + expect(bundle.modules).to.deep.equal({0: '(t,e,r)=>{}'}); + }); });