Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
production condition, trailing paths slash
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 17, 2016
1 parent d3b97d2 commit 48733d5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compilers/cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ exports.compile = function(load, opts, loader) {
for (var g in load.metadata.globals) {
globals[g] = normalize && load.depMap[load.metadata.globals[g]] || load.metadata.globals[g];
}
transformer = new CJSRegisterTransformer(!opts.anonymous && load.name, deps, load.path, opts.minify, globals, opts.systemGlobal);
transformer = new CJSRegisterTransformer(!opts.anonymous && load.name, deps, load.path, opts.production, globals, opts.systemGlobal);
tree = transformer.transformAny(tree);

var output = compiler.write(tree, load.path);
Expand Down
8 changes: 6 additions & 2 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ function processTraceOpts(options, defaults) {
// conditional tracing options
browser: undefined,
node: undefined,
production: true,
traceAllConditionals: true,
conditions: {},
traceConditionsOnly: false,
Expand Down Expand Up @@ -364,6 +365,9 @@ function processTraceOpts(options, defaults) {
opts.conditions['~@system-env|browser'] = opts.browser === true ? opts.node : !opts.browser;
opts.conditions['@system-env|node'] = opts.node;
opts.conditions['~@system-env|node'] = opts.node === true ? opts.browser : !opts.node;

opts.conditions['@system-env|production'] = opts.production;
opts.conditions['~@system-env|production'] = !opts.production;
}

return opts;
Expand Down Expand Up @@ -422,9 +426,9 @@ function processCompileOpts(options, defaults) {
// conditionalResolutions: {},
// can add a special object here that matches condition predicates to direct module names to use for sfx

// this shouldn't strictly be a compile option,
// this shouldn't strictly be a compile option (its a trace option)
// but the cjs compiler needs it to do NODE_ENV optimization
minify: false,
production: true,

// use rollup optimizations
rollup: true
Expand Down
12 changes: 7 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ function getCanonicalNamePlain(loader, normalized, isPlugin) {

var curPath = normalizePath(loader, p, isPlugin);

if (normalized === curPath) {
// always stop on first exact match
pathMatch = p;
break;
}
// always stop on first exact match
if (normalized === curPath)
return p;

// support trailing / in paths rules
else if (normalized.substr(0, curPath.length - 1) == curPath.substr(0, curPath.length - 1) && (normalized.length < curPath.length || normalized[curPath.length - 1] == curPath[curPath.length - 1]) && curPath[curPath.length - 1] == '/')
return p.substr(0, p.length - 1) + (normalized.length > curPath.length ? '/' + normalized.substr(curPath.length) : '');
}

// then wildcard matches
Expand Down
12 changes: 12 additions & 0 deletions test/canonicals.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ suite('Canonical Names', function() {
assert.equal(builder.getCanonicalName('cjs'), 'cjs');
assert.equal(builder.getCanonicalName(baseURL + 'test/dummy/file.jade!' + baseURL + 'test/fixtures/test-tree/jade.js'), 'file.jade!jade');
});

test('Trailing / canonical', function() {
builder.loader.defaultJSExtensions = false;
builder.config({
paths: {
'trailing/': 'src/'
}
});
assert.equal(builder.getCanonicalName(baseURL + 'src/asdf'), 'trailing/asdf');
assert.equal(builder.getCanonicalName(baseURL + 'src/'), 'trailing/');
assert.equal(builder.getCanonicalName(baseURL + 'src'), 'trailing');
})
});

0 comments on commit 48733d5

Please sign in to comment.