Skip to content

Commit

Permalink
fix: skip pruneJSON when package.json file not exists (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 8, 2022
1 parent 69fa07a commit 2026a73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/uninstall.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

const path = require('path');
const utils = require('./utils');
const fs = require('mz/fs');
const chalk = require('chalk');
const utils = require('./utils');
const preUninstall = require('./preuninstall');
const postUninstall = require('./postuninstall');

Expand Down Expand Up @@ -42,7 +43,10 @@ async function uninstall(pkg, options) {
await utils.rimraf(pkgRoot);
await utils.rimraf(realRoot);
}
await utils.pruneJSON(path.resolve(options.targetDir, 'package.json'), pkg.name);
const pkgFile = path.resolve(options.targetDir, 'package.json');
if (await fs.exists(pkgFile)) {
await utils.pruneJSON(pkgFile, pkg.name);
}
await postUninstall(pkgInfo, realRoot, options);
options.console.log('- %s %s -> %s',
chalk.yellow(`${pkgInfo.name}@${pkgInfo.version}`),
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('test/index.test.js', () => {

const bytesPkg = await readJSON(path.join(root, 'node_modules', 'bytes', 'package.json'));
assert.equal(bytesPkg._from, 'bytes@https://github.com/visionmedia/bytes.js.git');
assert(/git\+ssh\:\/\/git@github.com\/visionmedia\/bytes\.js\.git#a66d1b578f3e6fceb518f7e6a83827f7b2f17ac1/.test(bytesPkg._resolved));
assert(/git\+ssh\:\/\/git@github.com\/visionmedia\/bytes\.js\.git#\w+/.test(bytesPkg._resolved));
});
});
});
4 changes: 2 additions & 2 deletions test/install-vscode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ describe('test/install-vscode.test.js', () => {
await coffee.fork(helper.npminstall, [ '-c', '-d' ], { cwd, env: { NPMINSTALL_TEST_LOCAL_PKG: '1' } })
.debug()
.expect('code', 0)
.expect('stdout', /download from mirrors: {/)
.expect('stdout', /All packages installed/)
.end();
const installFile = path.join(cwd, 'node_modules/vscode/bin/install');
const content = await fs.readFile(installFile, 'utf8');
assert(!content.includes('https://raw.githubusercontent.com/'));
assert(content.includes('process.env.npm_package_engines_vscode'));
});
});

0 comments on commit 2026a73

Please sign in to comment.