From 6347cfe5f4f2d49d73e66b9c3d9831e4e3243ff1 Mon Sep 17 00:00:00 2001 From: guybedford Date: Wed, 26 Aug 2015 22:57:23 +0200 Subject: [PATCH] handle canonicalization of plugin extensions against defaultJSExtensions --- lib/utils.js | 11 +++++++++++ test/canonicals.js | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 93a5594..8930918 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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; @@ -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; } diff --git a/test/canonicals.js b/test/canonicals.js index 414b584..383985e 100644 --- a/test/canonicals.js +++ b/test/canonicals.js @@ -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'); + }); }); \ No newline at end of file