Skip to content

Commit

Permalink
feat: add option to use globally installed npm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexplischke committed Aug 1, 2024
1 parent 4e7d786 commit 75dc181
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ export default class NPM {

let p;

if (
nodeCtx.nodePath.startsWith('node') &&
nodeCtx.npmPath.startsWith('npm')
) {
p = spawn(nodeCtx.npmPath, ['install', ...pkgs], { shell: true });
if (nodeCtx.useGlobals) {
p = spawn("npm", ['install', ...pkgs], { shell: true });
} else {
p = spawn(nodeCtx.nodePath, [nodeCtx.npmPath, 'install', ...pkgs]);
}
Expand Down Expand Up @@ -74,11 +71,8 @@ export default class NPM {

let p;

if (
nodeCtx.nodePath.startsWith('node') &&
nodeCtx.npmPath.startsWith('npm')
) {
p = spawn(nodeCtx.npmPath, ['config', 'set', ...args], { shell: true });
if (nodeCtx.useGlobals) {
p = spawn("npm", ['config', 'set', ...args], { shell: true });
} else {
p = spawn(nodeCtx.nodePath, [
nodeCtx.npmPath,
Expand All @@ -102,11 +96,8 @@ export default class NPM {
): Promise<number | null> {
return new Promise((resolve) => {
let p;
if (
nodeCtx.nodePath.startsWith('node') &&
nodeCtx.npmPath.startsWith('npm')
) {
p = spawn(nodeCtx.npmPath, ['rebuild', ...args], { shell: true });
if (nodeCtx.useGlobals) {
p = spawn("npm", ['rebuild', ...args], { shell: true });
} else {
p = spawn(nodeCtx.nodePath, [nodeCtx.npmPath, 'rebuild', ...args]);
}
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export interface SuitesContainer {
export interface NodeContext {
nodePath: string;
npmPath: string;

// Ignore the specific binary paths provided and rely on the binaries
// from PATH.
useGlobals: boolean;
}

0 comments on commit 75dc181

Please sign in to comment.