Skip to content

Commit

Permalink
fix: fix parallel install from local directory (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Apr 21, 2022
1 parent 6adde64 commit 08b5f88
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/download/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const debug = require('debug')('npminstall:download:local');
const cp = require('mz/child_process');
const rimraf = require('mz-modules/rimraf');
const fse = require('fs-extra');
const fs = require('mz/fs');
const path = require('path');
const chalk = require('chalk');
Expand Down Expand Up @@ -31,14 +32,18 @@ module.exports = async (pkg, options) => {
async function localFolder(filepath, pkg, options) {
debug(`install ${pkg.name}@${pkg.rawSpec} from local folder ${filepath}`);
try {
// everytime copy to a different directory to avoid parallel install
const tmpDir = path.join(options.storeDir, '.tmp', uuid());
await utils.mkdirp(tmpDir);
await fse.copy(filepath, tmpDir);
// use npm pack to ensure npmignore/gitignore/package.files work fine
const res = await cp.exec('npm pack', { cwd: filepath });
const res = await cp.exec('npm pack', { cwd: tmpDir });
if (res && res[0]) {
const tarball = path.join(filepath, res[0].trim());
const tarball = path.join(tmpDir, res[0].trim());
try {
return await localTarball(tarball, pkg, options);
} finally {
await rimraf(tarball);
await rimraf(tmpDir);
}
}
} catch (err) {
Expand Down

0 comments on commit 08b5f88

Please sign in to comment.