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 isRemoteUri #52

Merged
merged 3 commits into from
Nov 6, 2019
Merged
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
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const fs = require('fs-extra');
var path = require('path');

var tmp = require('tmp');
var isUrl = require('is-url');
const npa = require('npm-package-arg');
var isObject = require('isobject');
var pathIsInside = require('path-is-inside');
var requireFresh = require('import-fresh');
Expand Down Expand Up @@ -88,7 +88,7 @@ function cordovaCreate (dest, opts = {}) {
emit('log', 'Creating a new cordova project.');

// Use cordova-fetch to obtain npm or git templates
if (isRemoteUri(opts.template)) {
if (needsToBeFetched(opts.template)) {
var target = opts.template;
emit('verbose', 'Using cordova-fetch for ' + target);
return fetch(target, getSelfDestructingTempDir(), {});
Expand Down Expand Up @@ -167,6 +167,6 @@ function getSelfDestructingTempDir () {
}).name;
}

function isRemoteUri (uri) {
return isUrl(uri) || uri.includes('@') || !fs.existsSync(uri);
function needsToBeFetched (uri) {
return npa(uri).type !== 'directory';
}
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"cordova-fetch": "^2.0.0",
"fs-extra": "^8.1.0",
"import-fresh": "^3.1.0",
"is-url": "^1.2.4",
"isobject": "^4.0.0",
"npm-package-arg": "^6.1.1",
timbru31 marked this conversation as resolved.
Show resolved Hide resolved
"path-is-inside": "^1.0.2",
"tmp": "^0.1.0",
"valid-identifier": "0.0.2"
Expand Down
21 changes: 21 additions & 0 deletions spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

const fs = require('fs-extra');
const rewire = require('rewire');

var path = require('path');

Expand Down Expand Up @@ -227,3 +228,23 @@ describe('when shit happens', function () {
);
});
});

describe('cordova create needsToBeFetched', () => {
let needsToBeFetched;

beforeEach(() => {
needsToBeFetched = rewire('..').__get__('needsToBeFetched');
});

it('should recognize URLs as remote', () => {
expect(needsToBeFetched('https://example.com/pkg/foo')).toBe(true);
});

it('should recognize package@version as remote', () => {
expect(needsToBeFetched('foo@1')).toBe(true);
});

it('should not detect paths as remote only because they include an @', () => {
expect(needsToBeFetched('../foo@1')).toBe(false);
});
});