UNPKG

3.45 kBJavaScriptView Raw
1"use strict";
2/*-----------------------------------------------------------------------------
3| Copyright (c) Jupyter Development Team.
4| Distributed under the terms of the Modified BSD License.
5|----------------------------------------------------------------------------*/
6var __importStar = (this && this.__importStar) || function (mod) {
7 if (mod && mod.__esModule) return mod;
8 var result = {};
9 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
10 result["default"] = mod;
11 return result;
12};
13var __importDefault = (this && this.__importDefault) || function (mod) {
14 return (mod && mod.__esModule) ? mod : { "default": mod };
15};
16Object.defineProperty(exports, "__esModule", { value: true });
17const path = __importStar(require("path"));
18const utils = __importStar(require("./utils"));
19const package_json_1 = __importDefault(require("package-json"));
20const commander_1 = __importDefault(require("commander"));
21const semver_1 = __importDefault(require("semver"));
22/**
23 * Handle an individual package on the path - update the dependency.
24 */
25async function handlePackage(packagePath) {
26 const cmds = [];
27 // Read in the package.json.
28 packagePath = path.join(packagePath, 'package.json');
29 let data;
30 try {
31 data = utils.readJSONFile(packagePath);
32 }
33 catch (e) {
34 console.log('Skipping package ' + packagePath);
35 return cmds;
36 }
37 if (data.private) {
38 return cmds;
39 }
40 const pkg = data.name;
41 let npmData = await package_json_1.default(pkg, { allVersions: true });
42 let versions = Object.keys(npmData.versions).sort(semver_1.default.rcompare);
43 let tags = npmData['dist-tags'];
44 // Go through the versions. The latest prerelease is 'next', the latest
45 // non-prerelease should be 'stable'.
46 let next = semver_1.default.prerelease(versions[0]) ? versions[0] : undefined;
47 let latest = versions.find(i => !semver_1.default.prerelease(i));
48 if (latest && latest !== tags.latest) {
49 cmds.push(`npm dist-tag add ${pkg}@${latest} latest`);
50 }
51 // If next is defined, but not supposed to be, remove it. If next is supposed
52 // to be defined, but is not the same as the current next, change it.
53 if (!next && tags.next) {
54 cmds.push(`npm dist-tag rm ${pkg} next`);
55 }
56 else if (next && next !== tags.next) {
57 cmds.push(`npm dist-tag add ${pkg}@${next} next`);
58 }
59 return cmds;
60}
61exports.handlePackage = handlePackage;
62function flatten(a) {
63 return a.reduce((acc, val) => acc.concat(val), []);
64}
65commander_1.default
66 .description(`Print out commands to update npm 'latest' and 'next' dist-tags
67so that 'latest' points to the latest stable release and 'next'
68points to the latest prerelease after it.`)
69 .option('--lerna', 'Update dist-tags in all lerna packages')
70 .option('--path [path]', 'Path to package or monorepo to update')
71 .action(async (args) => {
72 let basePath = path.resolve(args.path || '.');
73 let cmds = [];
74 let paths = [];
75 if (args.lerna) {
76 paths = utils.getLernaPaths(basePath).sort();
77 cmds = await Promise.all(paths.map(handlePackage));
78 }
79 cmds.push(await handlePackage(basePath));
80 let out = flatten(cmds).join('\n');
81 if (out) {
82 console.log(out);
83 }
84});
85if (require.main === module) {
86 commander_1.default.parse(process.argv);
87}
88//# sourceMappingURL=update-dist-tag.js.map
\No newline at end of file