Skip to content

Commit

Permalink
Merge pull request #1491 from stealjs/res-mod
Browse files Browse the repository at this point in the history
Prevent running normalization on already normalized npm names
  • Loading branch information
matthewp authored Jan 8, 2019
2 parents 0a5b510 + a8f594c commit 81b9932
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
7 changes: 7 additions & 0 deletions ext/npm-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ exports.addExtension = function addNpmExtension(System){

var hasNoParent = !parentName;
var nameIsRelative = utils.path.isRelative(name);
var nameIsNpmModule = utils.moduleName.isNpm(name);
var parentIsNpmModule = utils.moduleName.isNpm(parentName);
var identifierEndsWithSlash = utils.path.endsWithSlash(name);

// If this is an npm module name already, we don't need to re-resolve it.
if(nameIsNpmModule && parentModuleName) {
return oldNormalize.call(this, name, parentName, parentAddress,
pluginNormalize);
}

// If this is a relative module name and the parent is not an npm module
// we can skip all of this logic.
if(parentName && nameIsRelative && !parentIsNpmModule) {
Expand Down
2 changes: 1 addition & 1 deletion steal.production.js

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions test/npm/import_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,41 @@ QUnit.test("Imports git+ssh URLs that contain a hash", function(assert) {
.then(done, helpers.fail(assert, done));
});

QUnit.test("Can load a module loading an exact version of an npm module", function(assert) {
var done = assert.async();

var loader = helpers.clone()
.rootPackage({
name: "app",
main: "main.js",
version: "1.0.0",
dependencies: {
"debug": "3.0.0"
}
})
.withPackages([
{
name: "dep",
main: "main.js",
version: "1.0.0",
dependencies: {
"debug": "2.0.0"
}
}
])
.withModule("[email protected]#index", "module.exports='works';")
.withModule("[email protected]#main", "module.exports=require('[email protected]#index');")
.loader;

helpers.init(loader).then(function(){
return loader["import"]("app");
})
.then(function(mod){
assert.equal(mod, "works", "It worked!");
})
.then(done, helpers.fail(assert, done));
});

QUnit.module("Error messages and warnings");

QUnit.test("importing a package with an unsaved dependency", function(assert) {
Expand Down
24 changes: 12 additions & 12 deletions test/npm/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<title>Steal tests</title>
<link rel="stylesheet" type="text/css" href="../../../node_modules/qunitjs/qunit/qunit.css"/>
<link rel="stylesheet" type="text/css" href="../../node_modules/qunitjs/qunit/qunit.css"/>
</head>
<body>
<h1 id="qunit-header">npm extension test suite</h1>
Expand All @@ -12,23 +12,23 @@ <h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-test-area"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script>
steal = {
paths: {
"npm": "../../ext/npm.js",
"npm-convert": "../../ext/npm-convert.js",
"npm-extension": "../../ext/npm-extension.js",
"npm-load": "../../ext/npm-load.js",
"npm-crawl": "../../ext/npm-crawl.js",
"npm-utils": "../../ext/npm-utils.js",
"npm-load": "../../ext/npm-load.js",
"npm-convert": "../../ext/npm-convert.js",
"semver": "../../ext/semver.js"
"npm": "ext/npm.js",
"npm-convert": "ext/npm-convert.js",
"npm-extension": "ext/npm-extension.js",
"npm-load": "ext/npm-load.js",
"npm-crawl": "ext/npm-crawl.js",
"npm-utils": "ext/npm-utils.js",
"npm-load": "ext/npm-load.js",
"npm-convert": "ext/npm-convert.js",
"semver": "ext/semver.js"
}
};
</script>
<script src="../../../steal-with-promises.js" main="@empty" config-main="@empty"></script>
<script src="../../steal-with-promises.js" main="@empty" config-main="@empty"></script>
<script>
QUnit.config.autostart = false;

Expand Down

0 comments on commit 81b9932

Please sign in to comment.