hunk.code_window:   logger.warn({ message: 'Some issue', prefix: '/home/jane/repo/pkg-5' })
     statsLogger.debug({ removed: 1, prefix: '/home/jane/repo' })
     statsLogger.debug({ added: 0, prefix: '/home/jane/repo' })
     statsLogger.debug({ removed: 0, prefix: '/home/jane/repo/pkg-5' })
     statsLogger.debug({ added: 0, prefix: '/home/jane/repo/pkg-5' })
     statsLogger.debug({ added: 2, prefix: '/home/jane/repo/dir/pkg-2' })
  
hunk.labels: keep add keep keep keep keep keep
hunk.after_edit:   logger.warn({ message: 'Some other issue', prefix: rootPrefix })
  
hunk.file_path: packages/default-reporter/test/index.ts
hunk.type: add
file: import assertProject, {isExecutable} from '@pnpm/assert-project'
  import sinon = require('sinon')
  import tape = require('tape')
  import promisifyTape from 'tape-promise'
  const test = promisifyTape(tape)
  const testOnly = promisifyTape(tape.only)
  import ncpCB = require('ncp')
  import path = require('path')
  import promisify = require('util.promisify')
  import {
    pathToLocalPkg,
    prepare,
    testDefaults,
   } from './utils'
  const ncp = promisify(ncpCB.ncp)
  import exists = require('path-exists')
  import {
    installPkgs,
    link,
    linkFromGlobal,
    linkToGlobal,
    RootLog,
  } from 'supi'
  import writeJsonFile = require('write-json-file')
  
  test('relative link', async (t: tape.Test) => {
    const project = prepare(t, {
      dependencies: {
        'hello-world-js-bin': '*',
      },
    })
  
    const linkedPkgName = 'hello-world-js-bin'
    const linkedPkgPath = path.resolve('..', linkedPkgName)
  
    await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
    await link([`../${linkedPkgName}`], path.join(process.cwd(), 'node_modules'), await testDefaults())
  
    await project.isExecutable('.bin/hello-world-js-bin')
  
    // The linked package has been installed successfully as well with bins linked
    // to node_modules/.bin
    const linkedProject = assertProject(t, linkedPkgPath)
    await linkedProject.isExecutable('.bin/cowsay')
  
    const wantedShrinkwrap = await project.loadShrinkwrap()
    t.equal(wantedShrinkwrap.dependencies['hello-world-js-bin'], 'link:../hello-world-js-bin', 'link added to wanted shrinkwrap')
    t.equal(wantedShrinkwrap.specifiers['hello-world-js-bin'], '*', 'specifier of linked dependency added to shrinkwrap.yaml')
  
    const currentShrinkwrap = await project.loadCurrentShrinkwrap()
    t.equal(currentShrinkwrap.dependencies['hello-world-js-bin'], 'link:../hello-world-js-bin', 'link added to wanted shrinkwrap')
  })
  
  test('relative link is not rewritten by install', async (t: tape.Test) => {
    const project = prepare(t)
  
    const linkedPkgName = 'hello-world-js-bin'
    const linkedPkgPath = path.resolve('..', linkedPkgName)
  
    const reporter = sinon.spy()
  
    await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
    await link([linkedPkgPath], path.join(process.cwd(), 'node_modules'), await testDefaults({reporter}))
  
    t.ok(reporter.calledWithMatch({
      added: {
        dependencyType: undefined,
        linkedFrom: linkedPkgPath,
        name: 'hello-world-js-bin',
        realName: 'hello-world-js-bin',
        version: '1.0.0',
      },
      level: 'debug',
      name: 'pnpm:root',
      prefix: process.cwd(),
    } as RootLog), 'linked root dependency logged')
  
    await installPkgs(['hello-world-js-bin'], await testDefaults())
  
    t.ok(project.requireModule('hello-world-js-bin/package.json').isLocal)
  
    const wantedShrinkwrap = await project.loadShrinkwrap()
    t.equal(wantedShrinkwrap.dependencies['hello-world-js-bin'], 'link:../hello-world-js-bin', 'link still in wanted shrinkwrap')
  
    const currentShrinkwrap = await project.loadCurrentShrinkwrap()
    t.equal(currentShrinkwrap.dependencies['hello-world-js-bin'], 'link:../hello-world-js-bin', 'link still in wanted shrinkwrap')
  })
  
  test('global link', async (t: tape.Test) => {
    const project = prepare(t)
    const projectPath = process.cwd()
  
    const linkedPkgName = 'hello-world-js-bin'
    const linkedPkgPath = path.resolve('..', linkedPkgName)
  
    await ncp(pathToLocalPkg(linkedPkgName), linkedPkgPath)
  
    process.chdir(linkedPkgPath)
    const globalPrefix = path.resolve('..', 'global')
    const globalBin = path.resolve('..', 'global', 'bin')
    await linkToGlobal(process.cwd(), await testDefaults({globalPrefix, globalBin}))
  
    await isExecutable(t, path.join(globalBin, 'hello-world-js-bin'))
  
    // bins of dependencies should not be linked, see issue https://github.com/pnpm/pnpm/issues/905
    t.notOk(await exists(path.join(globalBin, 'cowsay')), 'cowsay not linked')
    t.notOk(await exists(path.join(globalBin, 'cowthink')), 'cowthink not linked')
  
    process.chdir(projectPath)
  
    await linkFromGlobal([linkedPkgName], process.cwd(), await testDefaults({globalPrefix}))
  
    await project.isExecutable('.bin/hello-world-js-bin')
  })
  
  test('failed linking should not create empty folder', async (t: tape.Test) => {
    prepare(t)
  
    const globalPrefix = path.resolve('..', 'global')
  
    try {
      await linkFromGlobal(['does-not-exist'], process.cwd(), await testDefaults({globalPrefix}))
      t.fail('should have failed')
    } catch (err) {
      t.notOk(await exists(path.join(globalPrefix, 'node_modules', 'does-not-exist')))
    }
  })
  
  test('node_modules is pruned after linking', async (t: tape.Test) => {
    const project = prepare(t)
  
    await writeJsonFile('../is-positive/package.json', {name: 'is-positive', version: '1.0.0'})
  
    await installPkgs(['is-positive@1.0.0'], await testDefaults())
  
    t.ok(await exists('node_modules/.localhost+4873/is-positive/1.0.0/node_modules/is-positive/package.json'))
  
    await link(['../is-positive'], path.resolve('node_modules'), await testDefaults())
  
    t.notOk(await exists('node_modules/.localhost+4873/is-positive/1.0.0/node_modules/is-positive/package.json'), 'pruned')
  })
  