Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Support file protocol #121

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
4 changes: 4 additions & 0 deletions analyze-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ function parseTag(value) {
};
}

if (uri.protocol === 'file:') {
return null;
}

// support github
var parts = value.split('/');
if (parts.length === 2) {
Expand Down
3 changes: 2 additions & 1 deletion sync/force-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function isCorrect(filePath, dep, opts, cb) {
var resolvedUri = url.parse(dep.resolved);

if (resolvedUri.protocol === 'http:' ||
resolvedUri.protocol === 'https:'
resolvedUri.protocol === 'https:' ||
resolvedUri.protocol === 'file:'
) {
return isCorrectVersion(filePath, dep, cb);
} else if (resolvedUri.protocol === 'git:' ||
Expand Down
62 changes: 62 additions & 0 deletions test/npm-shrinkwrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ function gitSSHModuleFixture(name, version, opts) {
return module;
}

function fileModuleFixture(name, version, path, opts) {
opts = opts || {};

var module = {
'package.json': JSON.stringify({
name: name,
_id: name + '@' + version,
_from: path,
_resolved: 'file:' + path,
version: version,
dependencies: opts.dependencies ?
opts.dependencies : undefined
})
};

/*jshint camelcase: false*/
if (opts.node_modules) {
module.node_modules = opts.node_modules;
}

return module;
}

test('npmShrinkwrap is a function', function (assert) {
assert.strictEqual(typeof npmShrinkwrap, 'function');
assert.end();
Expand Down Expand Up @@ -149,6 +172,45 @@ test('create shrinkwrap for git dep', fixtures(__dirname, {
});
}));

test('create shrinkwrap for file dep', fixtures(__dirname, {
'proj': Object.assign(moduleFixture('proj', '0.1.0', {
dependencies: {
bar: 'file:file-deps/bar'
},
'node_modules': {
'bar': fileModuleFixture('bar', '2.0.0', 'file-deps/bar')
}
}), {
'file-deps': {
'bar': moduleFixture('bar', '2.0.0')
}
})
}, function (assert) {
npmShrinkwrap(PROJ, function (err) {
assert.ifError(err);

var shrinkwrap = path.join(PROJ, 'npm-shrinkwrap.json');
fs.readFile(shrinkwrap, 'utf8', function (err, file) {
assert.ifError(err);
assert.notEqual(file, '');

var json = JSON.parse(file);

assert.equal(json.name, 'proj');
assert.equal(json.version, '0.1.0');
assert.deepEqual(json.dependencies, {
bar: {
version: '2.0.0',
resolved: 'file:file-deps/bar'
}
});

assert.end();
});
});
}));


test('create shrinkwrap for git+ssh dep', fixtures(__dirname, {
'proj': moduleFixture('proj', '0.1.0', {
dependencies: {
Expand Down