-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use shell: true and explicit cwd for all package manager commands
- Loading branch information
1 parent
7d50f92
commit 675ba68
Showing
16 changed files
with
98 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "Use shell: true and explicit cwd for all package manager commands", | ||
"packageName": "beachball", | ||
"email": "elcraig@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
import execa from 'execa'; | ||
import { PackageManagerResult, packageManager } from './packageManager'; | ||
|
||
export type NpmResult = Awaited<ReturnType<typeof npm>>; | ||
// The npm wrapper for packageManager is preserved for convenience. | ||
|
||
export type NpmResult = PackageManagerResult; | ||
|
||
/** | ||
* Run an npm command. Returns the error result instead of throwing on failure. | ||
*/ | ||
export async function npm( | ||
args: string[], | ||
options: execa.Options = {} | ||
): Promise<execa.ExecaReturnValue & { success: boolean }> { | ||
try { | ||
const result = await execa('npm', args, { ...options, shell: true }); | ||
return { | ||
...result, | ||
success: !result.failed, | ||
}; | ||
} catch (e) { | ||
return { | ||
...(e as execa.ExecaError), | ||
success: false, | ||
}; | ||
} | ||
} | ||
export const npm = packageManager.bind(null, 'npm'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import execa from 'execa'; | ||
|
||
export type PackageManagerResult = execa.ExecaReturnValue & { success: boolean }; | ||
|
||
/** | ||
* Run a package manager command. Returns the error result instead of throwing on failure. | ||
* @param manager The package manager to use | ||
* @param args Package manager command and arguments | ||
* @param options cwd must be specified in options to reduce the chance of accidentally running | ||
* commands in the wrong place. If it's definitely irrelevant in this case, use undefined. | ||
*/ | ||
export async function packageManager( | ||
manager: 'npm' | 'yarn' | 'pnpm', | ||
args: string[], | ||
options: execa.Options & { cwd: string | undefined } | ||
): Promise<execa.ExecaReturnValue & { success: boolean }> { | ||
try { | ||
const result = await execa(manager, args, { | ||
...options, | ||
// This is required for Windows due to https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 | ||
shell: true, | ||
}); | ||
return { | ||
...result, | ||
success: !result.failed, | ||
}; | ||
} catch (e) { | ||
return { | ||
...(e as execa.ExecaError), | ||
success: false, | ||
}; | ||
} | ||
} |
Oops, something went wrong.