Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Readable streams can be passed to opts.fileCache #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -196,8 +196,10 @@ Deps.prototype.resolve = function (id, parent, cb) {
Deps.prototype.readFile = function (file, id, pkg) {
var self = this;
if (xhas(this.fileCache, file)) {
var c = this.fileCache[file];
if (typeof c.pipe === 'function') return c;
var tr = through();
tr.push(this.fileCache[file]);
tr.push(c);
tr.push(null);
return tr;
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -24,8 +24,9 @@
"xtend": "^4.0.0"
},
"devDependencies": {
"tap": "^1.0.0",
"browser-pack": "^5.0.0"
"browser-pack": "^5.0.0",
"from2-string": "^1.1.0",
"tap": "^1.0.0"
},
"scripts": {
"test": "tap test/*.js"
Expand Down
21 changes: 17 additions & 4 deletions test/file_cache.js
Expand Up @@ -2,20 +2,24 @@ var mdeps = require('../');
var test = require('tap').test;
var path = require('path');
var through = require('through2');
var fromString = require('from2-string');

var files = {
foo: path.join(__dirname, '/files/foo.js'),
bar: path.join(__dirname, '/files/bar.js')
bar: path.join(__dirname, '/files/bar.js'),
extra: path.join(__dirname, '/files/extra.js')
};

var sources = {
foo: 'require("./bar"); var tongs;',
bar: 'notreal tongs'
foo: 'require("./bar"); require("./extra"); var tongs;',
bar: 'notreal tongs',
extra: 'notreal tongs'
};

var fileCache = {};
fileCache[files.foo] = sources.foo;
fileCache[files.bar] = sources.bar;
fileCache[files.extra] = fromString(sources.extra);

var specialReplace = function(input) {
return input.replace(/tongs/g, 'tangs');
Expand Down Expand Up @@ -43,13 +47,22 @@ test('uses file cache', function (t) {
id: 'foo',
file: files.foo,
source: specialReplace(sources.foo),
deps: { './bar': files.bar }
deps: {
'./bar': files.bar,
'./extra': files.extra
}
},
{
id: files.bar,
file: files.bar,
source: specialReplace(sources.bar),
deps: {}
},
{
id: files.extra,
file: files.extra,
source: specialReplace(sources.extra),
deps: {}
}
].sort(cmp));
});
Expand Down