'use strict'
const resolve = require('path').resolve
const spawn = require('cross-spawn')

/**
 * Resolves a package hosted on the local filesystem
 */

module.exports = function resolveLocal (pkg) {
  const dependencyPath = resolve(pkg.root, pkg.spec)

  return new Promise((resolve, reject) => {
    const proc = spawn('npm', ['pack'], {
      cwd: dependencyPath
    })

    proc.on('error', reject)

    proc.on('close', code => {
      if (code > 0) return reject(new Error('Exit code ' + code))
      return resolve()
    })
  })
  .then(_ => {
    const localPkg = require(resolve(dependencyPath, 'package.json'))
    const tgzFilename = localPkg.name + '-' + localPkg.version + '.tgz'
    return {
      name: localPkg.name,
      fullname: localPkg.name.replace('/', '!') + [
        '@file',
        escapePkgPath(dependencyPath)
      ].join('!'),
      dist: {
        local: true,
        tarball: resolve(dependencyPath, tgzFilename)
      }
    }
  })
}

function escapePkgPath (pkgPath) {
  return pkgPath.replace(/[/\\:]/g, '!').replace(/^!/, '')
}

@@ -367,16 +367,114 @@
     %7D)%0A%0A
+    let stdout = ''%0A%0A    proc.stdout.on('data', data =%3E %7B%0A      stdout += data.toString()%0A    %7D)%0A%0A
     proc
@@ -592,16 +592,56 @@
  code))%0A
+      const tgzFilename = stdout.trim()%0A
       re
@@ -653,16 +653,27 @@
 resolve(
+tgzFilename
 )%0A    %7D)
@@ -690,9 +690,19 @@
 hen(
-_
+tgzFilename
  =%3E 
@@ -777,80 +777,8 @@
 '))%0A
-    const tgzFilename = localPkg.name + '-' + localPkg.version + '.tgz'%0A
     

fix installing local scoped pkgs