fix: rewrite packages added by other package managers

Close #710
This commit is contained in:
zkochan
2017-04-24 17:36:00 +03:00
parent 6299f84cfb
commit b911c35eb2
2 changed files with 18 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import logger from 'pnpm-logger'
import path = require('path')
import isInnerLink = require('is-inner-link')
import rimraf = require('rimraf-then')
export default async function safeIsInnerLink (modules: string, depName: string) {
try {
@@ -12,6 +13,9 @@ export default async function safeIsInnerLink (modules: string, depName: string)
return false
} catch (err) {
if (err.code === 'ENOENT') return true
throw err
logger.warn(`Removing ${depName} that was installed by a different package manager`)
await rimraf(path.join(modules, depName))
return true
}
}

View File

@@ -2,7 +2,7 @@ import path = require('path')
import tape = require('tape')
import promisifyTape from 'tape-promise'
const test = promisifyTape(tape)
import spawn = require('cross-spawn')
import execa = require('execa')
import exists = require('path-exists')
import mkdirp = require('mkdirp-promise')
import {
@@ -33,6 +33,18 @@ test('installs in the folder where the package.json file is', async function (t)
await project.isExecutable('.bin/rimraf')
})
test('rewrites node_modules created by npm', async function (t) {
const project = prepare(t)
await execa('npm', ['install', 'rimraf@2.5.1', '--save'])
await execPnpm('install')
const rimraf = project.requireModule('rimraf')
t.ok(typeof rimraf === 'function', 'rimraf() is available')
await project.isExecutable('.bin/rimraf')
})
test('update', async function (t) {
const project = prepare(t)