Skip to content

Commit

Permalink
fix: use promise exec
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Dec 13, 2023
1 parent 86f621f commit 045ed49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
### Independent Client
```bash
$ npm i @cnpmjs/rapid --registry=https://registry.npmmirror.com
$ npm i --package-lock-only --registry=https://registry.npmmirror.com
$ rapid install
```

Expand Down
24 changes: 8 additions & 16 deletions packages/cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const { existsSync } = require('node:fs');
const os = require('node:os');
const url = require('node:url');
const crypto = require('node:crypto');
const { exec } = require('node:child_process');
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const mapWorkspaces = require('@npmcli/map-workspaces');
const fuse_t = require('./fuse_t');
const { Spin } = require('./logger');
Expand Down Expand Up @@ -607,22 +608,13 @@ exports.generatePackageLock = async cwd => {
const isExist = await fs.stat(lockPath).then(() => true).catch(() => false);
if (!isExist) {
console.log('npm install --force --package-lock-only --ignore-scripts is running');
await new Promise((resolve, reject) => {
exec('npm install --force --package-lock-only --ignore-scripts', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${stderr}`);
reject(new Error(`${error}`));
return;
}
console.log(`${stdout}`);
if (stderr) {
console.error(`${stderr}`);
}
resolve();
});
});
const { stdout, stderr } = await exec('npm install --force --package-lock-only --ignore-scripts', { cwd });
console.log(`${stdout}`);
if (stderr) {
console.warn(`${stderr}`);
}
}
} catch {
} catch (e) {
Alert.error('Error', [
'generate package-lock.json error.',
'Run `npm i --package-lock-only` to generate it.',
Expand Down

0 comments on commit 045ed49

Please sign in to comment.