mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-07 23:48:05 -04:00
New config value for package-importe-method: clone close #1505 PR #2043 BREAKING CHANGE: reflink is not supported by package-import-method BREAKING CHANGE: by default, try to clone packages instead of hard linking
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
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')
|
|
}),
|
|
'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('store/package', 'project/package', {
|
|
filesResponse: {
|
|
filenames: ['package.json', 'index.js'],
|
|
fromStore: false,
|
|
},
|
|
force: false,
|
|
})
|
|
t.ok(fsMock.copyFile.calledWith(path.join('store', 'package', 'package.json'), path.join('project', '_tmp', 'package.json'), fs.constants.COPYFILE_FICLONE_FORCE))
|
|
t.ok(fsMock.copyFile.calledWith(path.join('store', 'package', 'index.js'), 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('store/package', 'project/package', {
|
|
filesResponse: {
|
|
filenames: ['package.json', 'index.js'],
|
|
fromStore: false,
|
|
},
|
|
force: false,
|
|
})
|
|
t.ok(fsMock.link.calledWith(path.join('store', 'package', 'package.json'), path.join('project', '_tmp', 'package.json')))
|
|
t.ok(fsMock.link.calledWith(path.join('store', 'package', 'index.js'), path.join('project', '_tmp', 'index.js')))
|
|
t.end()
|
|
})
|