Skip to content

Commit 142b803

Browse files
committed
fix: restored default value of scripts.mainScripts
feat: add leadingPackageManager setting that allows you specify pm that will be used by default with extremely sane default fix: add output piping for pnpm commands fix: it seems commands (incluing pnpm) are now cancellable!
1 parent 36aad08 commit 142b803

File tree

8 files changed

+152
-25
lines changed

8 files changed

+152
-25
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
"execa": "^5.1.1",
172172
"filesize": "^8.0.7",
173173
"find-up": "^6.2.0",
174+
"fkill": "^8.0.0",
174175
"fs-extra": "^10.0.0",
175176
"globby": "^11.1.0",
176177
"got": "^11.8.3",

pnpm-lock.yaml

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands-core/getPmFolders.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { posix } from 'path'
22
import vscode from 'vscode'
33
import yamlJs from 'yamljs'
4-
import { SupportedPackageManagersNames } from '../core/packageManager'
4+
import { SupportedPackageManagersName } from '../core/packageManager'
55
import { readDirPackageJson } from './packageJson'
66
import { fsExists } from './util'
77
import { getPrefferedPackageManager } from './packageManager'
@@ -22,7 +22,7 @@ export const getPmFolders = async () => {
2222
return undefined
2323
}
2424

25-
const monorepoProviders: Record<SupportedPackageManagersNames, (cwd: vscode.Uri) => Promise<{ patterns: string[] } | void>> = {
25+
const monorepoProviders: Record<SupportedPackageManagersName, (cwd: vscode.Uri) => Promise<{ patterns: string[] } | void>> = {
2626
npm: getYarnWorkspaces,
2727
yarn: getYarnWorkspaces,
2828
async pnpm(cwd) {

src/commands-core/packageManager.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import vscode from 'vscode'
22
import execa from 'execa'
3-
import { GracefulCommandError } from 'vscode-framework'
4-
import { pnpmCommand, supportedPackageManagers, SupportedPackageManagersNames } from '../core/packageManager'
3+
import { getExtensionSetting, GracefulCommandError } from 'vscode-framework'
4+
import { pnpmCommand, supportedPackageManagers, SupportedPackageManagersName } from '../core/packageManager'
55
import { firstExists } from './util'
66

7-
export const getPrefferedPackageManager = async (cwd: vscode.Uri): Promise<SupportedPackageManagersNames> => {
7+
export const getPrefferedPackageManager = async (cwd: vscode.Uri): Promise<SupportedPackageManagersName> => {
88
let preffereddFromNpm = vscode.workspace.getConfiguration('npm').get<string>('packageManager')
99
if (preffereddFromNpm === 'auto') preffereddFromNpm = undefined
1010
// TODO move it to bottom and always use workspace client
@@ -15,19 +15,30 @@ export const getPrefferedPackageManager = async (cwd: vscode.Uri): Promise<Suppo
1515
uri: vscode.Uri.joinPath(cwd, detectFile),
1616
})),
1717
)
18-
// TODO why npm
19-
return name ?? 'npm'
18+
const leadingPackageManager = getExtensionSetting('leadingPackageManager')
19+
if (name) return name
20+
if (leadingPackageManager !== null) return leadingPackageManager
21+
let pm: SupportedPackageManagersName = 'npm' // will be used last
22+
// TODO check also version
23+
24+
for (const pmToCheck of ['pnpm', 'yarn'] as SupportedPackageManagersName[])
25+
if (await getPmVersion(pmToCheck)) {
26+
pm = pmToCheck
27+
break
28+
}
29+
30+
return pm
2031
}
2132

22-
export const getPmVersion = async (pm: SupportedPackageManagersNames) => {
33+
export const getPmVersion = async (pm: SupportedPackageManagersName) => {
2334
try {
2435
return (await execa(pm, ['--version'])).stdout
2536
} catch {
2637
return undefined
2738
}
2839
}
2940

30-
export const pmIsInstalledOrThrow = async (pm: SupportedPackageManagersNames) => {
41+
export const pmIsInstalledOrThrow = async (pm: SupportedPackageManagersName) => {
3142
const version = await getPmVersion(pm)
3243
if (!version) {
3344
if (pm === 'npm')
@@ -66,7 +77,7 @@ export const packageManagerCommand = async ({
6677
// TODO combine them
6778
// cancellationToken?: vscode.CancellationToken
6879
packages?: string[]
69-
forcePm?: SupportedPackageManagersNames
80+
forcePm?: SupportedPackageManagersName
7081
// flags?: {
7182
// global: boolean
7283
// dev: boolean
@@ -95,8 +106,9 @@ export const packageManagerCommand = async ({
95106
}
96107

97108
if (typeof flags === 'string') flags = flags.split(' ')
109+
let execCmd = command
98110
if (command === 'install') {
99-
command = supportedPackageManagers[pm].installCommand as any
111+
execCmd = supportedPackageManagers[pm].installCommand as any
100112
} else if (packages.length === 0) {
101113
void vscode.window.showWarningMessage(`No packages to ${command} provided`)
102114
return
@@ -113,14 +125,14 @@ export const packageManagerCommand = async ({
113125
case 'npm':
114126
case 'yarn':
115127
// TODO yarn --json
116-
await execa(pm, [command, ...(packages ?? []), ...flags], {
128+
await execa(pm, [execCmd, ...(packages ?? []), ...flags], {
117129
cwd: cwd.fsPath,
118130
})
119131
break
120132
case 'pnpm':
121133
await pnpmCommand({
122134
cwd: cwd.fsPath,
123-
command,
135+
command: execCmd,
124136
cancellationToken,
125137
packages,
126138
reportProgress,

src/configurationType.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
// },
66
// enforcePackageManagerUse
77
export type Configuration = {
8+
// TOOD describe difference between builtin setting
9+
/**
10+
* Your main package manager that leads your projects
11+
* Used when no lockfile is detected
12+
* By default (when null) first installed is picked: pnpm, yarn, npm
13+
* @default null
14+
* */
15+
leadingPackageManager: 'pnpm' | 'yarn' | 'npm' | null
816
/**
917
* What to do on clipboard detection for copied command to install packages
1018
* @default ask
@@ -60,6 +68,15 @@ export type Configuration = {
6068
* @default true
6169
*/
6270
'addPackages.installTypes': boolean
71+
/**
72+
* The first script will be run from this list on `start-npm-script` command.
73+
* @uniqueItems true
74+
* @default [
75+
"dev",
76+
"start",
77+
"watch"
78+
]
79+
*/
6380
'scripts.mainScripts': string[]
6481
/**
6582
* Whether to match script contents in quickpick search

src/configurationTypeCache.jsonc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
// GENERATED. DON'T EDIT MANUALLY
2-
// md5hash: 1a8290bf7111a243e1fb57982d76c654
2+
// md5hash: 556480798888bbc8df856f9dbf22165a
33
{
44
"type": "object",
55
"properties": {
6+
"leadingPackageManager": {
7+
"description": "Your main package manager that leads your projects\nUsed when no lockfile is detected\nBy default (when null) first installed is picked: pnpm, yarn, npm",
8+
"default": null,
9+
"enum": [
10+
"npm",
11+
"pnpm",
12+
"yarn"
13+
],
14+
"type": "string"
15+
},
616
"install.clipboardDetection": {
717
"description": "What to do on clipboard detection for copied command to install packages",
818
"default": "ask",
@@ -59,6 +69,13 @@
5969
"type": "boolean"
6070
},
6171
"scripts.mainScripts": {
72+
"description": "The first script will be run from this list on `start-npm-script` command.",
73+
"uniqueItems": true,
74+
"default": [
75+
"dev",
76+
"start",
77+
"watch"
78+
],
6279
"type": "array",
6380
"items": {
6481
"type": "string"
@@ -128,6 +145,7 @@
128145
"install.watchDelay",
129146
"install.watchPackageJson",
130147
"install.watchPackageLocks",
148+
"leadingPackageManager",
131149
"runBinCommand.searchLocation",
132150
"scripts.mainScripts",
133151
"scripts.matchContents",

src/core/clipboardDetection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ export const registerClipboardDetection = () => {
88
vscode.window.onDidChangeWindowState(async ({ focused }) => {
99
if (!focused) return
1010
if (getExtensionSetting('install.clipboardDetection') === 'disabled') return
11-
console.time('detect')
1211
const clipboardText = (await vscode.env.clipboard.readText()).trim()
1312
const result = getPackagesFromInstallCmd(clipboardText)
14-
console.timeEnd('detect')
1513
if (!result) return
1614

1715
// TODO

0 commit comments

Comments
 (0)