Skip to content

Commit

Permalink
support file protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
watilde committed Jul 24, 2017
1 parent a1d80c5 commit 8d1e48c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/install/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const nm = require('../utils/nm')
const bin = require('./bin')
const git = require('./installer/git')
const local = require('./installer/local')
const registry = require('./installer/registry')

const installer = (dep, deps, base, resolve, reject) => {
Expand All @@ -21,6 +22,9 @@ const installer = (dep, deps, base, resolve, reject) => {
case 'git':
fetch = git(pkg, target)
break
case 'local':
fetch = local(pkg, target)
break
case 'registry':
default:
fetch = registry(pkg, target)
Expand Down
5 changes: 5 additions & 0 deletions lib/install/installer/local.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const fs = require('fs-extra')

module.exports = (pkg, cwd) => {
return fs.copy(pkg.url, cwd)
}
24 changes: 22 additions & 2 deletions lib/install/resolver/fetchers/local.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
module.exports = () => {
const { readFile } = require('fs')
const { URL } = require('url')
const { normalize, resolve, join } = require('path')

module.exports = (name, spec, result) => {
spec = spec.replace('file:', '')
if (spec[0] === '~') {
spec = join(process.env.HOME, spec.slice(1))
}
spec = resolve(spec)
pkgJSON = spec.indexOf('package.json') !== -1
? spec
: join(spec, 'package.json')
return new Promise((resolve, reject) => {
reject(new Error('this type is not supported yet'))
try {
const pkg = require(pkgJSON)
resolve({
type: 'local',
version: pkg.version,
dependencies: pkg.dependencies,
url: spec
})
} catch (e) { reject (e) }
})
}

0 comments on commit 8d1e48c

Please sign in to comment.