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

Commit

Permalink
handle canonicalization of plugin extensions against defaultJSExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 26, 2015
1 parent a8d3500 commit 6347cfe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ function getCanonicalName(loader, normalized) {
}
}

// add defaultJSExtension for reverse-pathing process to work out
// due to the fact that plugins remove defaultJSExtensions to begin with
var defaultJSExtension = false;
if (plugin && loader.defaultJSExtensions && normalized.substr(normalized.length - 3, 3) != '.js') {
normalized += '.js';
defaultJSExtension = true;
}

// now just reverse apply paths rules to get canonical name
var pathMatch;

Expand Down Expand Up @@ -116,6 +124,9 @@ function getCanonicalName(loader, normalized) {
}

if (plugin) {
if (defaultJSExtension && pathMatch.substr(pathMatch.length - 3, 3) == '.js')
pathMatch = pathMatch.substr(0, pathMatch.length - 3);

if (loader.pluginFirst) {
pathMatch = getCanonicalName(loader, plugin) + '!' + pathMatch;
}
Expand Down
6 changes: 6 additions & 0 deletions test/canonicals.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ suite('Canonical Names', function() {
test('Wildcard extensions', function() {
assert.equal(builder.getCanonicalName(baseURL + 'test/dummy/file.jade'), 'file.jade');
});

test('Wildcard extensions with a plugin', function() {
builder.loader.defaultJSExtensions = true;
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');
});
});

0 comments on commit 6347cfe

Please sign in to comment.