-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathnpm-tag.ts
58 lines (51 loc) · 1.35 KB
/
npm-tag.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
56
57
58
import { getPackages } from "@manypkg/get-packages";
import { PackageJSON } from "@changesets/types";
import spawn from "spawndamnit";
import pLimit from "p-limit";
let npmLimit = pLimit(40);
function getCorrectRegistry() {
let registry =
process.env.npm_config_registry === "https://registry.yarnpkg.com"
? undefined
: process.env.npm_config_registry;
return registry;
}
async function tagApackage(
packageJson: PackageJSON,
tag: string,
otpCode?: string
) {
// Due to a super annoying issue in yarn, we have to manually override this env variable
// See: https://github.com/yarnpkg/yarn/issues/2935#issuecomment-355292633
const envOverride = {
npm_config_registry: getCorrectRegistry(),
};
let flags = [];
if (otpCode) {
flags.push("--otp", otpCode);
}
return await spawn(
"npm",
[
"dist-tag",
"add",
`${packageJson.name}@${packageJson.version}`,
tag,
...flags,
],
{
stdio: "inherit",
env: Object.assign({}, process.env, envOverride),
}
);
}
export async function npmTagAll([tag, _, otp]: string[]) {
let { packages } = await getPackages(process.cwd());
await Promise.all(
packages
.filter(({ packageJson }) => packageJson.private !== true)
.map(({ packageJson }) =>
npmLimit(() => tagApackage(packageJson, tag, otp))
)
);
}