From 134cb2e47ebacbae7d276ac5fc925df27482ed08 Mon Sep 17 00:00:00 2001 From: guybedford Date: Fri, 12 Jun 2015 19:42:09 +0200 Subject: [PATCH] extension & wildcard adjustments --- lib/package.js | 33 +++++++++++++++++---------------- test/test.js | 6 +++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lib/package.js b/lib/package.js index 5dd7608e..3d590aca 100644 --- a/lib/package.js +++ b/lib/package.js @@ -23,7 +23,8 @@ * paths: { * // map any internal or external require of 'jquery/vendor/another' to 'another/index.js' * 'vendor/another': 'another/index.js', - * 'test': 'lib/test.js' + * // test -> lib/test.js (defaultExtension) + * 'test': 'lib/test', * } * } * } @@ -39,8 +40,9 @@ * - main is the only property where a leading "./" can be added optionally * - paths and defaultExtension are applied to the main * - defaultExtension adds the extension only if no other extension is present - * - defaultExtension applies after paths only if not a path match - * - defaultJSExtensions applies only when defaultExtension is not set + * - defaultExtension applies after paths + * - defaultJSExtensions applies after paths when defaultExtension is not set + * - paths do not support wildcards * - if a meta value is available for a module, paths and defaultExtension are skipped * - like global map, package map also applies to subpaths (sizzle/x, ./vendor/another/sub) * @@ -126,26 +128,25 @@ normalized += '/' + (pkg.main.substr(0, 2) == './' ? pkg.main.substr(2) : pkg.main); } - var defaultExtension; - if (pkg.defaultExtension && normalized.split('/').pop().indexOf('.') == -1) - defaultExtension = '.' + pkg.defaultExtension; - // apply paths checking without defaultExtension, then as defaultExtension exact match if (pkg.paths) { var subPath = normalized.substr(pkgName.length + 1); - var mapped = applyPaths(pkg.paths, subPath) || defaultExtension && pkg.paths[subPath + defaultExtension]; + var mapped = pkg.paths[subPath]; if (mapped) normalized = pkgName + '/' + mapped; } - // apply default extension if not in meta and not the package itself - if (defaultExtension) { - if (normalized.split('/').pop().indexOf('.') == -1) - normalized += defaultExtension; - } - // apply defaultJSExtensions if defaultExtension not set - else if (defaultJSExtension) { - normalized += '.js'; + // if we have meta for this package, don't do defaultExtensions + if (!pkg.meta || !pkg.meta[normalized.substr(pkgName.length + 1)]) { + // apply defaultExtension + if (pkg.defaultExtension) { + if (normalized.split('/').pop().indexOf('.') == -1) + normalized += '.' + pkg.defaultExtension; + } + // apply defaultJSExtensions if defaultExtension not set + else if (defaultJSExtension) { + normalized += '.js'; + } } } // add back defaultJSExtension if not a package diff --git a/test/test.js b/test/test.js index f1fa7d9f..a32b7340 100644 --- a/test/test.js +++ b/test/test.js @@ -844,7 +844,7 @@ asyncTest('Package configuration CommonJS config example', function() { 'json': 'json.json', 'dir/': 'dir/index.js', 'dir2': 'dir2/index.json', - 'dir/*': '*.ts' + //'dir/': './' } } } @@ -855,13 +855,13 @@ asyncTest('Package configuration CommonJS config example', function() { System['import']('tests/testpkg/json'), System['import']('tests/testpkg/dir/'), System['import']('tests/testpkg/dir2'), - System['import']('tests/testpkg/dir/test') + //System['import']('tests/testpkg/dir/test') ]).then(function(m) { ok(m[0].prop == 'value'); ok(m[1].prop == 'value'); ok(m[2] == 'dirindex'); ok(m[3].json == 'index'); - ok(m[4] == 'ts'); + //ok(m[4] == 'ts'); start(); }, err); });