Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Source.constructSource to use versionSpec instead of parsedVersionSpec #332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/sources/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ Source.constructSource = function(registries, baseDir, outputDir, dependencyName
var LocalSource = require('./LocalSource.js').LocalSource;
var NPMRegistrySource = require('./NPMRegistrySource.js').NPMRegistrySource;

var parsedVersionSpec = semver.validRange(versionSpec, true);
var parsedUrl = url.parse(versionSpec);

if(parsedVersionSpec !== null) { // If the version is valid semver range, fetch the package from the NPM registry
return new NPMRegistrySource(baseDir, dependencyName, parsedVersionSpec, registries, stripOptionalDependencies);
} else if(parsedUrl.protocol == "github:") { // If the version is a GitHub repository, compose the corresponding Git URL and do a Git checkout
if(parsedUrl.protocol == "github:") { // If the version is a GitHub repository, compose the corresponding Git URL and do a Git checkout
return new GitSource(baseDir, dependencyName, GitSource.composeGitURL("git+https://github.com", parsedUrl));
} else if(parsedUrl.protocol == "gist:") { // If the version is a GitHub gist repository, compose the corresponding Git URL and do a Git checkout
return new GitSource(baseDir, dependencyName, GitSource.composeGitURL("git+https://gist.github.com", parsedUrl));
Expand All @@ -67,7 +64,9 @@ Source.constructSource = function(registries, baseDir, outputDir, dependencyName
return new LocalSource(baseDir, dependencyName, outputDir, parsedUrl.path);
} else if(versionSpec.substr(0, 3) == "../" || versionSpec.substr(0, 2) == "~/" || versionSpec.substr(0, 2) == "./" || versionSpec.substr(0, 1) == "/") { // If the version is a path, simply compose a Nix path
return new LocalSource(baseDir, dependencyName, outputDir, versionSpec);
} else { // In all other cases, just try the registry. Sometimes invalid semver ranges are encountered or a tag has been provided (e.g. 'latest', 'unstable')
} else {
// In all other cases (valid or invalid semver range), just try the registry.
// Sometimes invalid semver ranges are encountered or a tag has been provided (e.g. 'latest', 'unstable')
return new NPMRegistrySource(baseDir, dependencyName, versionSpec, registries, stripOptionalDependencies);
}
};
Expand Down
3 changes: 2 additions & 1 deletion tests/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"node-libcurl",
"libxmljs",
{ "bcrypt": "3.0.x" },
{ "next": "npm:@blitzjs/[email protected]" }
{ "next": "npm:@blitzjs/[email protected]" },
{ "abcd": "npm:@codingame/monaco-vscode-api@ >= 1.69.0 < 1.70.0" }
]