Skip to content

Commit

Permalink
Grab expose field specified after last colon, handling Windows
Browse files Browse the repository at this point in the history
Take care of the colon used as drive specifier under Windows.
Add corresponding test case to test/args.js
  • Loading branch information
ElNounch committed Mar 26, 2015
1 parent 931a1ea commit e420a32
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bin/args.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
})
});

0 comments on commit e420a32

Please sign in to comment.