-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.ts
55 lines (51 loc) · 1.41 KB
/
install.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import execa from 'execa';
import { canUseNpm, canUsePnpm, canUseYarn } from './env';
export function execaWithStreamLog(
command: string,
args: string[],
options: Record<string, any>,
) {
const promise = execa(command, args, {
...options,
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
return promise;
}
export async function npmInstall(cwd: string, registryUrl?: string) {
const canUse = await canUseNpm();
if (canUse) {
const params = ['install'];
if (registryUrl) {
params.push(`--registry=${registryUrl}`);
}
return execaWithStreamLog('npm', params, {
cwd,
env: process.env,
});
}
throw new Error('please install npm first');
}
export async function yarnInstall(cwd: string, registryUrl?: string) {
const canUse = await canUseYarn();
if (canUse) {
const params = ['install'];
if (registryUrl) {
params.push(`--registry=${registryUrl}`);
}
return execaWithStreamLog('yarn', params, { cwd, env: process.env });
}
throw new Error('please install yarn first');
}
export async function pnpmInstall(cwd: string, registryUrl?: string) {
const canUse = await canUsePnpm();
if (canUse) {
const params = ['install'];
if (registryUrl) {
params.push(`--registry=${registryUrl}`);
}
return execaWithStreamLog('pnpm', params, { cwd, env: process.env });
}
throw new Error('please install pnpm first');
}