Skip to content

Commit

Permalink
fix(file-prefix): Handles dependencies where version is file: path (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdh authored and bahmutov committed Feb 5, 2018
1 parent add1e64 commit 45611ec
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/is-supported-version-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ var check = require('check-types');
var verify = check.verify;

var gitAt = /^git@/;
var startsWithGit = /^git:/;
var startsWithPrefix = /^(git|github|file):/;

function isGitVersion(str) {
return gitAt.test(str) || startsWithGit.test(str);
function isGitAtVersion(str) {
return gitAt.test(str);
}

function isVersionKeyword(str) {
return str === '*' || str === 'latest';
}

function isGithubPackage(str) {
return /^github:/.test(str);
function isPrefixed(str) {
return startsWithPrefix.test(str);
}

function isSupportedVersionFormat(version) {
verify.unemptyString(version, 'expected version string');

return !check.webUrl(version) &&
!check.gitUrl(version) &&
!isGitVersion(version) &&
!isGitAtVersion(version) &&
!isVersionKeyword(version) &&
!isGithubPackage(version);
!isPrefixed(version);
}

module.exports = isSupportedVersionFormat;
4 changes: 3 additions & 1 deletion src/test/supported-version.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ gt.test 'regular versions', ->
gt.test 'unsupported urls', ->
gt.ok !isSupported('http://somewhere/repo'), 'http'
gt.ok !isSupported('git@github.com:bahmutov/angular-minicolors.git'), 'git@'
gt.ok !isSupported('git://gh.com/foo/bar#30030')
gt.ok !isSupported('git://gh.com/foo/bar#30030'), 'git'
gt.ok !isSupported('github:jstrace/bars'), 'github'
gt.ok !isSupported('file:./dummy'), 'file'
5 changes: 5 additions & 0 deletions test/dummy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "dummy",
"version": "0.0.1",
"description": "Dummy module for testing 'file:' version"
}
8 changes: 8 additions & 0 deletions test/e2e.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ gt.async 'test version with github version', ->
gt.exec 'node', args.concat(relative('./package-with-github.json')), 0,
'this handles github: version string'

gt.async 'test version with local file path', ->
gt.exec 'node', args.concat(relative('./package-with-file.json')), 0,
'this handles file: version string'

gt.async 'test version with url', ->
gt.exec 'node', args.concat(relative('./package-with-url.json')), 0,
'this handles url string'

gt.async 'test non-existing file', ->
gt.exec 'node', args.concat(relative('./does-not-exist.json')), ERROR_EXIT_CODE,
'package file does not exist'
Expand Down
8 changes: 8 additions & 0 deletions test/package-with-file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-package",
"description": "One dependency has local file path",
"version": "0.0.1",
"dependencies": {
"dummy": "file:./dummy"
}
}
8 changes: 8 additions & 0 deletions test/package-with-url.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-package",
"description": "One dependency has url",
"version": "0.0.1",
"dependencies": {
"bars": "https://github.com/jstrace/bars/archive/1.2.2.tar.gz"
}
}

0 comments on commit 45611ec

Please sign in to comment.