forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump-js-major.ts
104 lines (95 loc) · 2.97 KB
/
bump-js-major.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* -----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
import commander from 'commander';
import semver from 'semver';
import path from 'path';
import * as utils from './utils';
/**
* Get the packages that depend on a given package, recursively.
*/
export function getDeps(
pkgName: string,
lut: { [key: string]: { [key: string]: string } }
): Set<string> {
const deps: Set<string> = new Set();
for (const name in lut) {
if ('@jupyterlab/' + pkgName in lut[name]) {
const otherName = name.replace('@jupyterlab/', '');
deps.add(otherName);
const otherDeps = getDeps(otherName, lut);
otherDeps.forEach(dep => {
deps.add(dep);
});
}
}
return deps;
}
// Specify the program signature.
commander
.description('Bump the major version of JS package(s)')
.arguments('<package> [others...]')
.option('--force', 'Force the upgrade')
.option('--dry-run', 'Show what would be executed')
.action((pkg: string, others: Array<string>, options: any) => {
others.push(pkg);
const toBump: Set<string> = new Set();
const ignoreBump: Set<string> = new Set();
const maybeBump = (pkg: string) => {
if (pkg in toBump || pkg in ignoreBump) {
return;
}
const version = utils.getJSVersion(pkg);
if (semver.minor(version) === 0 && semver.prerelease(version)) {
console.warn(`${pkg} has already been bumped`);
ignoreBump.add(pkg);
} else {
toBump.add(pkg);
}
};
others.forEach(pkg => {
maybeBump(pkg);
});
// Create a lut of dependencies
const lut: { [key: string]: { [key: string]: string } } = {};
utils.getCorePaths().forEach(corePath => {
const pkgDataPath = path.join(corePath, 'package.json');
const data = utils.readJSONFile(pkgDataPath);
lut[data.name] = data.dependencies || {};
});
// Look for dependencies of bumped packages
Array.from(toBump).forEach(val => {
const deps = getDeps(val, lut);
deps.forEach(dep => {
maybeBump(dep);
});
});
if (!toBump.size) {
console.warn('No packages found to bump!');
return;
}
const pyVersion = utils.getPythonVersion();
let preId = '';
if (pyVersion.includes('a')) {
preId = 'alpha';
} else if (pyVersion.includes('rc')) {
preId = 'rc';
} else {
throw new Error(
'Cannot bump JS packages until we switch to prerelease mode'
);
}
const pkgs = Array.from(toBump).join(',');
let cmd = `lerna version premajor --preid=${preId} --force-publish=${pkgs} --no-push`;
if (options.force) {
cmd += ' --yes';
}
if (options.dryRun) {
console.debug('Would run:');
console.debug(cmd);
return;
}
utils.run(cmd);
});
commander.parse(process.argv);