hunk.code_window:       tempy: 0.5.0
         write-json-file: 4.0.0
     packages/parse-cli-args:
       dependencies:
         '@pnpm/find-workspace-dir': 'link:../find-workspace-dir'
         didyoumean2: 4.0.0
         nopt: 4.0.3
       devDependencies:
         '@pnpm/parse-cli-args': 'link:'
         '@types/nopt': 3.0.29
       specifiers:
  
hunk.labels: keep keep keep keep keep replace keep keep keep keep keep
hunk.after_edit:       didyoumean2: 4.1.0
  
hunk.file_path: pnpm-lock.yaml
hunk.type: replace
file: import fs = require('fs')
  import path = require('path')
  import proxyquire = require('proxyquire')
  import sinon = require('sinon')
  import test = require('tape')
  
  const fsMock = {} as any // tslint:disable-line
  const makeDirMock = sinon.spy()
  const createImportPackage = proxyquire('@pnpm/package-store/lib/storeController/createImportPackage', {
    '../fs/importIndexedDir': proxyquire('@pnpm/package-store/lib/fs/importIndexedDir', {
      'make-dir': makeDirMock,
      'mz/fs': fsMock,
      'path-temp': (dir: string) => path.join(dir, '_tmp'),
      'rename-overwrite': sinon.spy(),
    }),
    'make-dir': makeDirMock,
    'mz/fs': fsMock,
  }).default
  
  test('packageImportMethod=auto: clone files by default', async (t) => {
    const importPackage = createImportPackage('auto')
    fsMock.copyFile = sinon.spy()
    fsMock.rename = sinon.spy()
    await importPackage('project/package', {
      filesMap: {
        'index.js': 'hash2',
        'package.json': 'hash1',
      },
      force: false,
      fromStore: false,
    })
    t.ok(fsMock.copyFile.calledWith(path.join('hash1'), path.join('project', '_tmp', 'package.json'), fs.constants.COPYFILE_FICLONE_FORCE))
    t.ok(fsMock.copyFile.calledWith(path.join('hash2'), path.join('project', '_tmp', 'index.js'), fs.constants.COPYFILE_FICLONE_FORCE))
    t.end()
  })
  
  test('packageImportMethod=auto: link files if cloning fails', async (t) => {
    const importPackage = createImportPackage('auto')
    fsMock.copyFile = () => { throw new Error('This file system does not support cloning') }
    fsMock.link = sinon.spy()
    fsMock.rename = sinon.spy()
    await importPackage('project/package', {
      filesMap: {
        'index.js': 'hash2',
        'package.json': 'hash1',
      },
      force: false,
      fromStore: false,
    })
    t.ok(fsMock.link.calledWith(path.join('hash1'), path.join('project', '_tmp', 'package.json')))
    t.ok(fsMock.link.calledWith(path.join('hash2'), path.join('project', '_tmp', 'index.js')))
    t.end()
  })
  