mirror of
https://github.com/Microsoft/vscode
synced 2024-10-02 09:18:59 +00:00
Add Bun as package manager to npm
extension
* Auto-detect Bun by looking for `bun.lockb` lockfile * Extend `npm.packageManager` setting * Update documentation Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
This commit is contained in:
parent
55c1e8473c
commit
4645305f14
|
@ -34,7 +34,7 @@ The extension fetches data from <https://registry.npmjs.org> and <https://regist
|
||||||
|
|
||||||
- `npm.autoDetect` - Enable detecting scripts as tasks, the default is `on`.
|
- `npm.autoDetect` - Enable detecting scripts as tasks, the default is `on`.
|
||||||
- `npm.runSilent` - Run npm script with the `--silent` option, the default is `false`.
|
- `npm.runSilent` - Run npm script with the `--silent` option, the default is `false`.
|
||||||
- `npm.packageManager` - The package manager used to run the scripts: `auto`, `npm`, `yarn` or `pnpm`, the default is `auto`, which detects your package manager based on your files.
|
- `npm.packageManager` - The package manager used to run the scripts: `auto`, `npm`, `yarn`, `pnpm` or `bun`. The default is `auto`, which detects your package manager based on files in your workspace.
|
||||||
- `npm.exclude` - Glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'.
|
- `npm.exclude` - Glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'.
|
||||||
- `npm.enableScriptExplorer` - Enable an explorer view for npm scripts.
|
- `npm.enableScriptExplorer` - Enable an explorer view for npm scripts.
|
||||||
- `npm.scriptExplorerAction` - The default click action: `open` or `run`, the default is `open`.
|
- `npm.scriptExplorerAction` - The default click action: `open` or `run`, the default is `open`.
|
||||||
|
|
|
@ -237,13 +237,15 @@
|
||||||
"auto",
|
"auto",
|
||||||
"npm",
|
"npm",
|
||||||
"yarn",
|
"yarn",
|
||||||
"pnpm"
|
"pnpm",
|
||||||
|
"bun"
|
||||||
],
|
],
|
||||||
"enumDescriptions": [
|
"enumDescriptions": [
|
||||||
"%config.npm.packageManager.auto%",
|
"%config.npm.packageManager.auto%",
|
||||||
"%config.npm.packageManager.npm%",
|
"%config.npm.packageManager.npm%",
|
||||||
"%config.npm.packageManager.yarn%",
|
"%config.npm.packageManager.yarn%",
|
||||||
"%config.npm.packageManager.pnpm%"
|
"%config.npm.packageManager.pnpm%",
|
||||||
|
"%config.npm.packageManager.bun%"
|
||||||
],
|
],
|
||||||
"default": "auto",
|
"default": "auto",
|
||||||
"description": "%config.npm.packageManager%"
|
"description": "%config.npm.packageManager%"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"config.npm.packageManager.npm": "Use npm as the package manager for running scripts.",
|
"config.npm.packageManager.npm": "Use npm as the package manager for running scripts.",
|
||||||
"config.npm.packageManager.yarn": "Use yarn as the package manager for running scripts.",
|
"config.npm.packageManager.yarn": "Use yarn as the package manager for running scripts.",
|
||||||
"config.npm.packageManager.pnpm": "Use pnpm as the package manager for running scripts.",
|
"config.npm.packageManager.pnpm": "Use pnpm as the package manager for running scripts.",
|
||||||
|
"config.npm.packageManager.bun": "Use bun as the package manager for running scripts.",
|
||||||
"config.npm.packageManager.auto": "Auto-detect which package manager to use for running scripts based on lock files and installed package managers.",
|
"config.npm.packageManager.auto": "Auto-detect which package manager to use for running scripts based on lock files and installed package managers.",
|
||||||
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
|
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
|
||||||
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts when there is no top-level 'package.json' file.",
|
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts when there is no top-level 'package.json' file.",
|
||||||
|
|
|
@ -23,6 +23,14 @@ async function pathExists(filePath: string) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function isBunPreferred(pkgPath: string): Promise<PreferredProperties> {
|
||||||
|
if (await pathExists(path.join(pkgPath, 'bun.lockb'))) {
|
||||||
|
return { isPreferred: true, hasLockfile: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { isPreferred: false, hasLockfile: false };
|
||||||
|
}
|
||||||
|
|
||||||
async function isPNPMPreferred(pkgPath: string): Promise<PreferredProperties> {
|
async function isPNPMPreferred(pkgPath: string): Promise<PreferredProperties> {
|
||||||
if (await pathExists(path.join(pkgPath, 'pnpm-lock.yaml'))) {
|
if (await pathExists(path.join(pkgPath, 'pnpm-lock.yaml'))) {
|
||||||
return { isPreferred: true, hasLockfile: true };
|
return { isPreferred: true, hasLockfile: true };
|
||||||
|
@ -78,6 +86,12 @@ export async function findPreferredPM(pkgPath: string): Promise<{ name: string;
|
||||||
detectedPackageManagerProperties.push(yarnPreferred);
|
detectedPackageManagerProperties.push(yarnPreferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bunPreferred = await isBunPreferred(pkgPath);
|
||||||
|
if (bunPreferred.isPreferred) {
|
||||||
|
detectedPackageManagerNames.push('bun');
|
||||||
|
detectedPackageManagerProperties.push(bunPreferred);
|
||||||
|
}
|
||||||
|
|
||||||
const pmUsedForInstallation: { name: string } | null = await whichPM(pkgPath);
|
const pmUsedForInstallation: { name: string } | null = await whichPM(pkgPath);
|
||||||
|
|
||||||
if (pmUsedForInstallation && !detectedPackageManagerNames.includes(pmUsedForInstallation.name)) {
|
if (pmUsedForInstallation && !detectedPackageManagerNames.includes(pmUsedForInstallation.name)) {
|
||||||
|
|
Loading…
Reference in a new issue