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

Grab expose field specified after last colon, handling Windows #1182

Merged
1 commit merged into from
Apr 1, 2015
Merged
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
19 changes: 16 additions & 3 deletions bin/args.js
Expand Up @@ -134,16 +134,16 @@ module.exports = function (args, opts) {

[].concat(argv.require).filter(Boolean)
.forEach(function (r) {
var xs = r.split(':');
var xs = _splitOnColon(r);
b.require(xs[0], { expose: xs.length === 1 ? xs[0] : xs[1] })
})
;

// resolve any external files and add them to the bundle as externals
[].concat(argv.external).filter(Boolean)
.forEach(function (x) {
if (/:/.test(x)) {
var xs = x.split(':');
var xs = _splitOnColon(x);
if (xs.length === 2) {
add(xs[0], { expose: xs[1] });
}
else if (/\*/.test(x)) {
Expand Down Expand Up @@ -242,3 +242,16 @@ function copy (obj) {
return acc;
}, {});
}

function _splitOnColon (f) {
var pos = f.lastIndexOf(':');
if (pos == -1) {
return [f]; // No colon
} else {
if ((/[a-zA-Z]:[\\/]/.test(f)) && (pos == 1)){
return [f]; // Windows path and colon is part of drive name
} else {
return [f.substr(0, pos), f.substr(pos + 1)];
}
}
}
16 changes: 16 additions & 0 deletions test/args.js
Expand Up @@ -52,3 +52,19 @@ test('numeric module names', function(t) {
t.notOk(err);
});
});

test('entry expose', function (t) {
t.plan(3)

var b = fromArgs([
path.join(__dirname, '/entry_expose/main.js'),
'--require', path.join(__dirname, '/entry_expose/main.js') + ':x',
]);
b.bundle(function (err, src) {
t.ifError(err);
var c = { console: { log: log } };
function log (msg) { t.equal(msg, 'wow') }
vm.runInNewContext(src, c);
t.equal(c.require('x'), 555);
})
});