pax_global_header 0000666 0000000 0000000 00000000064 14017272677 0014527 g ustar 00root root 0000000 0000000 52 comment=fee3d0924d14dea5d3a1c42303c457a4b1971f7f
exorcist-2.0.0/ 0000775 0000000 0000000 00000000000 14017272677 0013366 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/.github/ 0000775 0000000 0000000 00000000000 14017272677 0014726 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14017272677 0016763 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/.github/workflows/test.yml 0000664 0000000 0000000 00000000623 14017272677 0020466 0 ustar 00root root 0000000 0000000 name: Test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: install and test
run: |
npm install
npm test
exorcist-2.0.0/.gitignore 0000664 0000000 0000000 00000000131 14017272677 0015351 0 ustar 00root root 0000000 0000000 lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
npm-debug.log
node_modules
exorcist-2.0.0/LICENSE 0000664 0000000 0000000 00000002066 14017272677 0014377 0 ustar 00root root 0000000 0000000 Copyright 2014 Thorsten Lorenz.
All rights reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
exorcist-2.0.0/README.md 0000664 0000000 0000000 00000014661 14017272677 0014655 0 ustar 00root root 0000000 0000000 # exorcist [](http://travis-ci.org/thlorenz/exorcist)
Externalizes the source map found inside a stream to an external `.map` file or stream.
Works with both JavaScript and CSS input streams.
```js
var browserify = require('browserify')
, path = require('path')
, fs = require('fs')
, exorcist = require('exorcist')
, mapfile = path.join(__dirname, 'bundle.js.map')
// from a file, to a file, and send source map to its own file
browserify({debug: true})
.require(require.resolve('./main'), { entry: true })
.bundle()
.pipe(exorcist(mapfile))
.pipe(fs.createWriteStream(path.join(__dirname, 'bundle.js'), 'utf8'))
// from a stream, to a stream, and send source map to a stream
browserify([readableSourceStream], browserifyOptions)
.bundle()
.pipe(exorcist(targetSourceMapStream, '/url/path/to/replace/source/comment/with/bundle.js'))
.pipe(writableTargetStream)
```
### command line example
```
browserify main.js --debug | exorcist bundle.js.map > bundle.js
```
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
- [Usage](#usage)
- [Installation](#installation)
- [API](#api)
- [Integration with other tools](#integration-with-other-tools)
- [License](#license)
## Usage
```
exorcist map_file [options]
Externalizes the source map of the file streamed in.
The source map is written as JSON to map_file, and the original file is streamed out with its
sourceMappingURL set to the path of map_file (or to the value of the --url option).
OPTIONS:
--base -b Base path for calculating relative source paths.
(default: use absolute paths)
--root -r Root URL for loading relative source paths.
Set as sourceRoot in the source map.
(default: '')
--url -u Full URL to source map.
Set as sourceMappingURL in the output stream.
(default: map_file)
--error-on-missing -e Abort with error if no map is found in the stream.
(default: warn but still pipe through source)
EXAMPLE:
Bundle main.js with browserify into bundle.js and externalize the map to bundle.js.map.
browserify main.js --debug | exorcist bundle.js.map > bundle.js
```
## Installation
npm install exorcist
## API
-
exorcist(input, url, root, base, errorOnMissing) → {TransformStream}
-
Externalizes the source map of the file streamed in.
The source map is written as JSON to file, and the original file is streamed out with its
sourceMappingURL set to the path of file (or to the value of url).
Events (in addition to stream events)
missing-map emitted if no map was found in the stream and errorOnMissing is falsey
(the src is still piped through in this case, but no map file is written)
Parameters:
| Name |
Type |
Argument |
Description |
input |
String / Object
|
|
full path to the map file to which to write the extracted source map or a writable stream |
url |
String
|
<optional>
|
full URL to the map file, set as sourceMappingURL in the streaming output (default: file) |
root |
String
|
<optional>
|
root URL for loading relative source paths, set as sourceRoot in the source map (default: '') |
base |
String
|
<optional>
|
base path for calculating relative source paths (default: use absolute paths) |
errorOnMissing |
Boolean
|
<optional>
|
when truthy, causes 'error' to be emitted instead of 'missing-map' if no map was found in the stream (default: falsey) |
- Source:
Returns:
transform stream into which to pipe the code containing the source map
-
Type
-
TransformStream
*generated with [docme](https://github.com/thlorenz/docme)*
## Integration with other tools
- [using exorcist with gulp](https://github.com/thlorenz/exorcist/wiki/Recipes#gulp)
## License
MIT
exorcist-2.0.0/bin/ 0000775 0000000 0000000 00000000000 14017272677 0014136 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/bin/exorcist.js 0000664 0000000 0000000 00000002235 14017272677 0016336 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
'use strict';
var minimist = require('minimist')
, fs = require('fs')
, path = require('path')
, exorcist = require('../')
;
function onerror(err) {
console.error(err.toString());
process.exit(err.errno || 1);
}
function usage() {
var usageFile = path.join(__dirname, 'usage.txt');
fs.createReadStream(usageFile).pipe(process.stdout);
return;
}
(function damnYouEsprima() {
var argv = minimist(process.argv.slice(2)
, { boolean: [ 'h', 'help', 'e', 'error-on-missing' ]
, string: [ 'url', 'u', 'root', 'r', 'base', 'b' ]
});
if (argv.h || argv.help) return usage();
var mapfile = argv._.shift();
if (!mapfile) {
console.error('Missing map file');
return usage();
}
var url = argv.url || argv.u
, root = argv.root || argv.r
, base = argv.base || argv.b
, errorOnMissing = argv.errorOnMissing || argv.e || argv['error-on-missing'];
mapfile = path.resolve(mapfile);
process.stdin
.pipe(exorcist(mapfile, url, root, base, errorOnMissing))
.on('error', onerror)
.on('missing-map', console.error.bind(console))
.pipe(process.stdout);
})()
exorcist-2.0.0/bin/usage.txt 0000664 0000000 0000000 00000002067 14017272677 0016010 0 ustar 00root root 0000000 0000000 usage: exorcist map_file [options]
Externalizes the source map of the file streamed in.
The source map is written as JSON to map_file, and the original file is streamed out with its
sourceMappingURL set to the path of map_file (or to the value of the --url option).
OPTIONS:
--base -b Base path for calculating relative source paths.
(default: use absolute paths)
--root -r Root URL for loading relative source paths.
Set as sourceRoot in the source map.
(default: '')
--url -u Full URL to source map.
Set as sourceMappingURL in the output stream.
(default: map_file)
--error-on-missing -e Abort with error if no map is found in the stream.
(default: warn but still pipe through source)
EXAMPLE:
Bundle main.js with browserify into bundle.js and externalize the map to bundle.js.map.
browserify main.js --debug | exorcist bundle.js.map > bundle.js
exorcist-2.0.0/example/ 0000775 0000000 0000000 00000000000 14017272677 0015021 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/example/bar.js 0000664 0000000 0000000 00000000130 14017272677 0016115 0 ustar 00root root 0000000 0000000 'use strict';
var go = module.exports = function () {
return 'hey, I am bar';
};
exorcist-2.0.0/example/build.js 0000664 0000000 0000000 00000000736 14017272677 0016464 0 ustar 00root root 0000000 0000000 'use strict';
var browserify = require('browserify')
, path = require('path')
, fs = require('fs')
, exorcist = require('../')
, mapfile = path.join(__dirname, 'bundle.js.map')
browserify()
.require(require.resolve('./main'), { entry: true })
.bundle({ debug: true })
.on('end', function () {
console.log('all done, open index.html')
})
.pipe(exorcist(mapfile))
.pipe(fs.createWriteStream(path.join(__dirname, 'bundle.js'), 'utf8'))
exorcist-2.0.0/example/build.sh 0000664 0000000 0000000 00000000203 14017272677 0016447 0 ustar 00root root 0000000 0000000 #!/usr/bin/env sh
rm -f bundle.*
../node_modules/.bin/browserify main.js -d | node ../bin/exorcist.js bundle.js.map > bundle.js
exorcist-2.0.0/example/foo.js 0000664 0000000 0000000 00000000157 14017272677 0016145 0 ustar 00root root 0000000 0000000 'use strict';
var bar = require('./bar');
var go = module.exports = function () {
console.log(bar());
};
exorcist-2.0.0/example/index.html 0000664 0000000 0000000 00000000364 14017272677 0017021 0 ustar 00root root 0000000 0000000
Exorcist Example
Open dev tools, look for output printed to console and investigate sources tab
exorcist-2.0.0/example/main.js 0000664 0000000 0000000 00000000063 14017272677 0016302 0 ustar 00root root 0000000 0000000 'use strict';
var foo = require('./foo');
foo();
exorcist-2.0.0/index.js 0000664 0000000 0000000 00000006273 14017272677 0015043 0 ustar 00root root 0000000 0000000 'use strict';
var mold = require('mold-source-map')
, path = require('path')
, fs = require('fs')
, mkdirp = require('mkdirp')
, isStream = require('is-stream')
, fs = require('fs');
function separate(src, url, root, base) {
src.sourceRoot(root || src.sourcemap.getProperty('sourceRoot') || '');
if (base) {
src.mapSources(mold.mapPathRelativeTo(base));
}
var json = src.toJSON(2);
var comment = '';
var commentRx = /^\s*\/(\/|\*)[@#]\s+sourceMappingURL/mg;
var commentMatch = commentRx.exec(src.source);
var commentBlock = (commentMatch && commentMatch[1] === '*');
if (commentBlock) {
comment = '/*# sourceMappingURL=' + url + ' */';
} else {
comment = '//# sourceMappingURL=' + url;
}
return { json: json, comment: comment }
}
var go = module.exports =
/**
*
* Externalizes the source map of the file streamed in.
*
* The source map is written as JSON to `file`, and the original file is streamed out with its
* `sourceMappingURL` set to the path of `file` (or to the value of `url`).
*
* #### Events (in addition to stream events)
*
* - `missing-map` emitted if no map was found in the stream and errorOnMissing is falsey
* (the src is still piped through in this case, but no map file is written)
*
* @name exorcist
* @function
* @param {String|Object} input file path or writable stream where the source map will be written
* @param {String=} url full URL to the map file, set as `sourceMappingURL` in the streaming output (default: file)
* @param {String=} root root URL for loading relative source paths, set as `sourceRoot` in the source map (default: '')
* @param {String=} base base path for calculating relative source paths (default: use absolute paths)
* @param {Boolean=} errorOnMissing when truthy, causes 'error' to be emitted instead of 'missing-map' if no map was found in the stream (default: falsey)
* @return {TransformStream} transform stream into which to pipe the code containing the source map
*/
function exorcist(input, url, root, base, errorOnMissing) {
var missingMapMsg = "The code that you piped into exorcist contains no source map!";
var stream = mold.transform(function(src, write) {
if (!src.sourcemap) {
if (errorOnMissing) return stream.emit('error', new Error(missingMapMsg));
stream.emit(
'missing-map'
, missingMapMsg + '\n'
+ 'Therefore it was piped through as is and no external map file generated.'
);
return write(src.source);
}
if (isStream(input) && isStream.writable(stream)) {
return stream.emit('error', new Error('Must provide a writable stream'));
}
if (isStream(input) && typeof url !== 'string') {
return stream.emit('error', new Error('map file URL is required when using stream output'));
}
url = url || path.basename(input)
var separated = separate(src, url, root, base);
if (isStream(input)) {
return input.end(separated.json, 'utf8', done);
}
mkdirp(path.dirname(input))
.then(() => fs.writeFile(input, separated.json, 'utf8', done))
.catch(done);
function done(err) {
if (err) return stream.emit('error', err);
write(separated.comment);
}
});
return stream;
}
exorcist-2.0.0/package.json 0000664 0000000 0000000 00000001764 14017272677 0015664 0 ustar 00root root 0000000 0000000 {
"name": "exorcist",
"version": "2.0.0",
"description": "Externalizes the source map found inside a stream to an external `.js.map` file",
"bin": {
"exorcist": "bin/exorcist.js"
},
"main": "index.js",
"scripts": {
"test": "tap test/*.js"
},
"repository": {
"type": "git",
"url": "git://github.com/thlorenz/exorcist.git"
},
"homepage": "https://github.com/thlorenz/exorcist",
"dependencies": {
"is-stream": "^2.0.0",
"minimist": "^1.2.5",
"mkdirp": "^1.0.4",
"mold-source-map": "^0.4.0"
},
"devDependencies": {
"browserify": "^17.0.0",
"nave": "^3.2.2",
"proxyquire": "^2.1.3",
"tap": "^14.11.0",
"through2": "~4.0.2"
},
"keywords": [
"source-map",
"source",
"map",
"external",
"mapfile",
"browserify",
"browserify-tool"
],
"author": {
"name": "Thorsten Lorenz",
"email": "thlorenz@gmx.de",
"url": "http://thlorenz.com"
},
"license": "MIT",
"engine": {
"node": ">=14"
}
}
exorcist-2.0.0/test/ 0000775 0000000 0000000 00000000000 14017272677 0014345 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/test/exorcist.js 0000664 0000000 0000000 00000025314 14017272677 0016550 0 ustar 00root root 0000000 0000000 'use strict';
/*jshint asi: true */
var test = require('tap').test
var fs = require('fs');
var through = require('through2');
var proxyquire = require('proxyquire');
var exorcist = require('../')
var fixtures = __dirname + '/fixtures';
var scriptMapfile = fixtures + '/bundle.js.map';
var styleMapfile = fixtures + '/to.css.map';
// This base path is baken into the source maps in the fixtures.
var base = '/Users/thlorenz/dev/projects/exorcist';
function cleanup() {
if (fs.existsSync(scriptMapfile)) fs.unlinkSync(scriptMapfile);
if (fs.existsSync(styleMapfile)) fs.unlinkSync(styleMapfile);
}
test('\nwhen piping a bundle generated with browserify through exorcist without adjusting properties', function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(scriptMapfile))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
lines.pop(); // Trailing newline
t.equal(lines.length, 25, 'pipes entire bundle including prelude, sources and source map url')
t.equal(lines.pop(), '//# sourceMappingURL=bundle.js.map', 'last line as source map url pointing to .js.map file')
var map = JSON.parse(fs.readFileSync(scriptMapfile, 'utf8'));
t.equal(map.file, 'generated.js', 'leaves file name unchanged')
t.equal(map.sources.length, 4, 'maps 4 source files')
t.equal(map.sources[0].indexOf(base), 0, 'uses absolute source paths')
t.equal(map.sourcesContent.length, 4, 'includes 4 source contents')
t.equal(map.mappings.length, 106, 'maintains mappings')
t.equal(map.sourceRoot, '', 'if source root missing, use empty string')
cb();
t.end()
}
})
test('\nwhen piping a bundle generated with browserify through exorcist and adjusting url', function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(scriptMapfile, 'http://my.awseome.site/bundle.js.map'))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
lines.pop(); // Trailing newline
t.equal(lines.length, 25, 'pipes entire bundle including prelude, sources and source map url')
t.equal(lines.pop(), '//# sourceMappingURL=http://my.awseome.site/bundle.js.map', 'last line as source map url pointing to .js.map file at url set to supplied url')
var map = JSON.parse(fs.readFileSync(scriptMapfile, 'utf8'));
t.equal(map.file, 'generated.js', 'leaves file name unchanged')
t.equal(map.sources.length, 4, 'maps 4 source files')
t.equal(map.sourcesContent.length, 4, 'includes 4 source contents')
t.equal(map.mappings.length, 106, 'maintains mappings')
t.equal(map.sourceRoot, '', 'if source root missing, use empty string')
cb();
t.end()
}
})
test('\nwhen piping a bundle generated with browserify through exorcist and adjusting root and url', function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(scriptMapfile, 'http://my.awseome.site/bundle.js.map', 'http://my.awesome.site/src'))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
lines.pop(); // Trailing newline
t.equal(lines.length, 25, 'pipes entire bundle including prelude, sources and source map url')
t.equal(lines.pop(), '//# sourceMappingURL=http://my.awseome.site/bundle.js.map', 'last line as source map url pointing to .js.map file at url set to supplied url')
var map = JSON.parse(fs.readFileSync(scriptMapfile, 'utf8'));
t.equal(map.file, 'generated.js', 'leaves file name unchanged')
t.equal(map.sources.length, 4, 'maps 4 source files')
t.equal(map.sourcesContent.length, 4, 'includes 4 source contents')
t.equal(map.mappings.length, 106, 'maintains mappings')
t.equal(map.sourceRoot, 'http://my.awesome.site/src', 'adapts source root')
cb();
t.end()
}
})
test('\nwhen piping a bundle generated with browserify through exorcist and adjusting root, url, and base', function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(scriptMapfile, 'http://my.awseome.site/bundle.js.map', 'http://my.awesome.site/src', base))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
lines.pop(); // Trailing newline
t.equal(lines.length, 25, 'pipes entire bundle including prelude, sources and source map url')
t.equal(lines.pop(), '//# sourceMappingURL=http://my.awseome.site/bundle.js.map', 'last line as source map url pointing to .js.map file at url set to supplied url')
var map = JSON.parse(fs.readFileSync(scriptMapfile, 'utf8'));
t.equal(map.file, 'generated.js', 'leaves file name unchanged')
t.equal(map.sources.length, 4, 'maps 4 source files')
t.equal(map.sources[0].indexOf(base), -1, 'uses relative source paths')
t.equal(map.sourcesContent.length, 4, 'includes 4 source contents')
t.equal(map.mappings.length, 106, 'maintains mappings')
t.equal(map.sourceRoot, 'http://my.awesome.site/src', 'adapts source root')
cb();
t.end()
}
})
test('\nwhen piping a bundle generated with browserify to a map file in a directory that does not exist', function (t) {
t.on('end', cleanup);
var badPathScriptMapfile = fixtures + '/noexists/bundle.js.map';
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(badPathScriptMapfile))
.on('error', t.end)
.on('end', function () {
var map = JSON.parse(fs.readFileSync(badPathScriptMapfile, 'utf8'));
t.ok(map);
fs.unlinkSync(badPathScriptMapfile);
t.end();
})
})
test('\nwhen piping a bundle generated with browserify and the write fails', function (t) {
t.on('end', cleanup);
var expectedErr = new Error('File write failed')
var ex = proxyquire('../', {
fs: {
writeFile: function (file, content, enc, callback) {
callback(expectedErr)
}
}
})
fs.createReadStream(fixtures + '/bundle.js')
.pipe(ex(scriptMapfile))
.on('error', function (err) {
t.equal(err, expectedErr)
t.end();
})
})
test('\nwhen piping a bundle generated with browserify thats missing a map through exorcist and errorOnMissing is truthy' , function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/bundle.nomap.js')
.pipe(exorcist(scriptMapfile, undefined, undefined, undefined, true))
.on('error', onerror);
function onerror(err) {
t.type(err, 'Error');
t.end();
}
})
test('\nwhen piping a bundle generated with browserify thats missing a map through exorcist and errorOnMissing is falsey' , function (t) {
t.on('end', cleanup);
var data = ''
var missingMapEmitted = false;
fs.createReadStream(fixtures + '/bundle.nomap.js')
.pipe(exorcist(scriptMapfile))
.on('missing-map', function () { missingMapEmitted = true })
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
t.equal(lines.length, 25, 'pipes entire bundle including prelude')
t.ok(missingMapEmitted, 'emits missing-map event')
cb();
t.end()
}
})
test('\nwhen performing a stylish exorcism', function (t) {
t.on('end', cleanup);
var data = ''
fs.createReadStream(fixtures + '/to.css')
.pipe(exorcist(styleMapfile))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
t.equal(lines.length, 22, 'pipes entire style including prelude, sources and source map url')
t.equal(lines.pop(), '/*# sourceMappingURL=to.css.map */', 'last line as source map url pointing to .css.map file')
var map = JSON.parse(fs.readFileSync(styleMapfile, 'utf8'));
t.equal(map.file, 'to.css', 'leaves file name unchanged')
t.equal(map.sources.length, 2, 'maps 4 source files')
t.equal(map.sourcesContent.length, 2, 'includes 4 source contents')
t.equal(map.mappings.length, 214, 'maintains mappings')
t.equal(map.sourceRoot, '', 'if source root missing, use empty string')
cb();
t.end();
}
})
test('\nwhen piping a bundle generated with browserify with preexisting source root', function(t) {
t.on('end', cleanup);
fs.createReadStream(fixtures + '/bundle.withroot.js')
.pipe(exorcist(scriptMapfile))
.pipe(through(onread, onflush));
function onread(_, __, cb) { cb(); }
function onflush(cb) {
var map = JSON.parse(fs.readFileSync(scriptMapfile, 'utf8'));
t.equal(map.sourceRoot, base, 'leaves source root value in place')
cb();
t.end();
}
});
test('\nwhen piping a bundle generated with browserify through exorcist without adjusting properties and sending source map to stream', function (t) {
t.on('end', cleanup);
var data = ''
var map = ''
fs.createReadStream(fixtures + '/bundle.js')
.pipe(exorcist(through(onreadMap, onflushMap), 'bundle.js.map'))
.pipe(through(onread, onflush));
function onread(d, _, cb) { data += d; cb(); }
function onflush(cb) {
var lines = data.split('\n')
lines.pop(); // Trailing newline
t.equal(lines.length, 25, 'pipes entire bundle including prelude, sources and source map url')
t.equal(lines.pop(), '//# sourceMappingURL=bundle.js.map', 'last line as source map url pointing to .js.map file')
cb();
t.end()
}
function onreadMap(d, _, cb) { map += d; cb(); }
function onflushMap(cb) {
map = JSON.parse(map);
t.equal(map.file, 'generated.js', 'leaves file name unchanged')
t.equal(map.sources.length, 4, 'maps 4 source files')
t.equal(map.sources[0].indexOf(base), 0, 'uses absolute source paths')
t.equal(map.sourcesContent.length, 4, 'includes 4 source contents')
t.equal(map.mappings.length, 106, 'maintains mappings')
t.equal(map.sourceRoot, '', 'leaves source root an empty string')
cb();
}
})
test('\nwhen piping a browserify bundle thru exorcist sending source map to a stream with missing required url', function (t) {
t.on('end', cleanup);
var exorcistStream =
exorcist(through(onread)) // this is missing the URL as second argument
.on('error', function (err) {
t.ok(/map file URL is required/.test(err.message));
t.end();
})
.on('end', function () {
t.fail('should have emitted an error about missing url');
});
fs.createReadStream(fixtures + '/bundle.js').pipe(exorcistStream);
function onread(d, _, cb) { cb(); }
})
exorcist-2.0.0/test/fixtures/ 0000775 0000000 0000000 00000000000 14017272677 0016216 5 ustar 00root root 0000000 0000000 exorcist-2.0.0/test/fixtures/bundle.js 0000664 0000000 0000000 00000004562 14017272677 0020034 0 ustar 00root root 0000000 0000000 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o