From b911c35eb2dbffb26928af396981cf63f3c7f2ab Mon Sep 17 00:00:00 2001 From: zkochan Date: Mon, 24 Apr 2017 17:36:00 +0300 Subject: [PATCH] fix: rewrite packages added by other package managers Close #710 --- src/safeIsInnerLink.ts | 6 +++++- test/cli.ts | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/safeIsInnerLink.ts b/src/safeIsInnerLink.ts index 52b19e4c96..bc15dfd830 100644 --- a/src/safeIsInnerLink.ts +++ b/src/safeIsInnerLink.ts @@ -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 } } diff --git a/test/cli.ts b/test/cli.ts index 9378a6d51c..90fabc7802 100644 --- a/test/cli.ts +++ b/test/cli.ts @@ -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)