Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/npm install #254

Merged
merged 6 commits into from
Mar 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: test
  • Loading branch information
buqiyuan committed Mar 7, 2023
commit f42d78e2b877b1faf6ea06bcb2cf754c6dc34930
40 changes: 24 additions & 16 deletions src/platform/node/extension-manager/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Action = 'uninstall' | 'install' | 'update';
* Install npm packages in case of missing Node Environment
* ! npm version should be 6.14.8, otherwise npm function can't be used
* */
const npmCli = require('npm');
// const npmCli = require('npm');

/**
* Fix the $PATH on macOS and Linux when run from a GUI app
Expand Down Expand Up @@ -126,22 +126,30 @@ export class ModuleHandler extends CoreHandler {
}
}
private executeByAppNpm(command: string, modules: any[], resolve, reject) {
// https://www.npmjs.com/package/bin-links
npmCli.load({ 'bin-links': false, verbose: true, prefix: this.baseDir }, loaderr => {
const moduleList = modules.map(({ name, version }) => (version ? `${name}@${version}` : name));
let executeCommand = ['update', 'install', 'uninstall'];
if (!executeCommand.includes(command)) {
return;
const moduleList = modules.map(({ name, version }) => (version ? `${name}@${version}` : name));
let executeCommand = ['update', 'install', 'uninstall'];
if (!executeCommand.includes(command)) {
return;
}

const npmPath = require.resolve(`npm/bin/npm${process.platform === 'win32' ? '.cmd' : ''}`).replace('app.asar', 'app.asar.unpacked');

const npm = spawn(npmPath, [command, '--prefix', this.baseDir, '--registry', this.registry, ...moduleList], {
shell: process.platform === 'win32'
});
npm.stdout.setEncoding('utf8');
npm.stdout.on('data', async data => {
console.log('data', data);
});
npm.stdout.on('error', err => {
console.log(`npm ${command} error`, err);
if (err) {
return reject(err);
}
npmCli.commands[command](moduleList, (err, data) => {
// console.log('command', command);
process.chdir(this.baseDir);
if (err) {
return reject(err);
}
this.operatePackage(data, moduleList, command as Action);
return resolve({ code: 0, data });
});
});
npm.stdout.on('end', () => {
process.chdir(this.baseDir);
return resolve({ code: 0, data: true });
});
}
private setRegistry() {
Expand Down