@juit/check-updates 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/check-updates.js CHANGED
@@ -1,283 +1,186 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
2
 
8
- // dist/npmrc.cjs
9
- var require_npmrc = __commonJS({
10
- "dist/npmrc.cjs"(exports2, module2) {
11
- "use strict";
12
- var __create2 = Object.create;
13
- var __defProp2 = Object.defineProperty;
14
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
15
- var __getOwnPropNames3 = Object.getOwnPropertyNames;
16
- var __getProtoOf2 = Object.getPrototypeOf;
17
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
18
- var __export = (target, all) => {
19
- for (var name in all)
20
- __defProp2(target, name, { get: all[name], enumerable: true });
21
- };
22
- var __copyProps2 = (to, from, except, desc) => {
23
- if (from && typeof from === "object" || typeof from === "function") {
24
- for (let key of __getOwnPropNames3(from))
25
- if (!__hasOwnProp2.call(to, key) && key !== except)
26
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
3
+ // dist/main.mjs
4
+ import * as yargs from "yargs";
5
+
6
+ // dist/updater.mjs
7
+ import { readFile as readFile2, writeFile } from "node:fs/promises";
8
+ import glob from "glob";
9
+ import semver from "semver";
10
+ import fetch from "npm-registry-fetch";
11
+
12
+ // dist/npmrc.mjs
13
+ import fs from "node:fs/promises";
14
+ import path from "node:path";
15
+ import { parse } from "ini";
16
+ function replaceEnvironmentVariable(token) {
17
+ return token.replace(/^\$\{?([^}]*)\}?$/, (_match, ...vars) => {
18
+ return process.env[vars[0]] || "";
19
+ });
20
+ }
21
+ async function readFile(filename) {
22
+ try {
23
+ const data = await fs.readFile(filename, "utf8");
24
+ const npmrc = parse(data);
25
+ for (const key in npmrc) {
26
+ if (typeof npmrc[key] === "string") {
27
+ npmrc[key] = replaceEnvironmentVariable(npmrc[key]);
27
28
  }
28
- return to;
29
- };
30
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
31
- // If the importer is in node compatibility mode or this is not an ESM
32
- // file that has been converted to a CommonJS file using a Babel-
33
- // compatible transform (i.e. "__esModule" has not been set), then set
34
- // "default" to the CommonJS "module.exports" for node compatibility.
35
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
36
- mod
37
- ));
38
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
39
- var npmrc_exports = {};
40
- __export(npmrc_exports, {
41
- readNpmRc: () => readNpmRc
29
+ }
30
+ return npmrc;
31
+ } catch (error) {
32
+ if (error.code === "ENOENT")
33
+ return {};
34
+ throw error;
35
+ }
36
+ }
37
+ async function readNpmRc(packageJsonFile) {
38
+ const local = readFile(path.resolve(packageJsonFile, "..", ".npmrc"));
39
+ const user = readFile(
40
+ process.env.NPM_CONFIG_USERCONFIG ? process.env.NPM_CONFIG_USERCONFIG : process.env.HOME ? path.resolve(process.env.HOME, ".npmrc") : ""
41
+ );
42
+ const global = readFile(
43
+ process.env.NPM_CONFIG_GLOBALCONFIG ? process.env.NPM_CONFIG_GLOBALCONFIG : "/etc/npmrc"
44
+ );
45
+ return Object.assign({}, ...await Promise.all([global, user, local]));
46
+ }
47
+
48
+ // dist/updater.mjs
49
+ var cache = {};
50
+ var [K, R, G, Y, B] = [0, 31, 32, 33, 34].map((x) => `\x1B[${x}m`);
51
+ async function processPackages(patterns, options) {
52
+ const { bump: bump2, quick: quick2, strict: strict2, debug: debug2, dryrun: dryrun2 } = options;
53
+ function $debug(...args2) {
54
+ if (debug2 && args2)
55
+ console.log(`${R}[DEBUG]${K}`, ...args2);
56
+ }
57
+ function getVersions(name, npmrc) {
58
+ if (name in cache) {
59
+ $debug(`Returning cached versions for ${Y}${name}${K}`);
60
+ return cache[name];
61
+ }
62
+ $debug(`Retrieving versions for package ${Y}${name}${K}`);
63
+ const range = new semver.Range(">=0.0.0", { includePrerelease: false });
64
+ return cache[name] = fetch.json(name, Object.assign({}, npmrc, { spec: name })).then((data) => {
65
+ return Object.entries(data.versions).filter(([, info]) => !info.deprecated).map(([version]) => version).filter((version) => range.test(version)).sort(semver.rcompare);
42
66
  });
43
- module2.exports = __toCommonJS(npmrc_exports);
44
- var import_promises = __toESM2(require("node:fs/promises"));
45
- var import_node_path = __toESM2(require("node:path"));
46
- var import_ini = require("ini");
47
- function replaceEnvironmentVariable(token) {
48
- return token.replace(/^\$\{?([^}]*)\}?$/, (_match, ...vars) => {
49
- return process.env[vars[0]] || "";
50
- });
67
+ }
68
+ async function updateDependency(name, rangeString, npmrc) {
69
+ const match = /^\s*([~^])\s*(\d+(\.\d+(\.\d+)?)?)\s*$/.exec(rangeString);
70
+ if (!match) {
71
+ $debug(`Not processing range ${G}${rangeString}${K} for ${Y}${name}${K}`);
72
+ return rangeString;
51
73
  }
52
- async function readFile(filename) {
53
- try {
54
- const data = await import_promises.default.readFile(filename, "utf8");
55
- const npmrc = (0, import_ini.parse)(data);
56
- for (const key in npmrc) {
57
- if (typeof npmrc[key] === "string") {
58
- npmrc[key] = replaceEnvironmentVariable(npmrc[key]);
59
- }
60
- }
61
- return npmrc;
62
- } catch (error) {
63
- if (error.code === "ENOENT")
64
- return {};
65
- throw error;
66
- }
74
+ const [, specifier = "", version = ""] = match;
75
+ if (!strict2) {
76
+ const r = rangeString;
77
+ rangeString = `>=${version}`;
78
+ if (specifier === "~")
79
+ rangeString += ` <${semver.inc(version, "major")}`;
80
+ $debug(`Extending version for ${Y}${name}${K} from ${G}${r}${K} to ${G}${rangeString}${K}`);
67
81
  }
68
- async function readNpmRc(packageJsonFile) {
69
- const local = readFile(import_node_path.default.resolve(packageJsonFile, "..", ".npmrc"));
70
- const user = readFile(
71
- process.env.NPM_CONFIG_USERCONFIG ? process.env.NPM_CONFIG_USERCONFIG : process.env.HOME ? import_node_path.default.resolve(process.env.HOME, ".npmrc") : ""
72
- );
73
- const global = readFile(
74
- process.env.NPM_CONFIG_GLOBALCONFIG ? process.env.NPM_CONFIG_GLOBALCONFIG : "/etc/npmrc"
75
- );
76
- return Object.assign({}, ...await Promise.all([global, user, local]));
82
+ const range = new semver.Range(rangeString);
83
+ const versions = await getVersions(name, npmrc);
84
+ for (const v of versions) {
85
+ if (range.test(v))
86
+ return `${specifier}${v}`;
77
87
  }
88
+ return `${specifier}${version}`;
78
89
  }
79
- });
80
-
81
- // dist/updater.cjs
82
- var require_updater = __commonJS({
83
- "dist/updater.cjs"(exports2, module2) {
84
- "use strict";
85
- var __create2 = Object.create;
86
- var __defProp2 = Object.defineProperty;
87
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
88
- var __getOwnPropNames3 = Object.getOwnPropertyNames;
89
- var __getProtoOf2 = Object.getPrototypeOf;
90
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
91
- var __export = (target, all) => {
92
- for (var name in all)
93
- __defProp2(target, name, { get: all[name], enumerable: true });
94
- };
95
- var __copyProps2 = (to, from, except, desc) => {
96
- if (from && typeof from === "object" || typeof from === "function") {
97
- for (let key of __getOwnPropNames3(from))
98
- if (!__hasOwnProp2.call(to, key) && key !== except)
99
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
100
- }
101
- return to;
102
- };
103
- var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(
104
- // If the importer is in node compatibility mode or this is not an ESM
105
- // file that has been converted to a CommonJS file using a Babel-
106
- // compatible transform (i.e. "__esModule" has not been set), then set
107
- // "default" to the CommonJS "module.exports" for node compatibility.
108
- isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", { value: mod, enumerable: true }) : target,
109
- mod
110
- ));
111
- var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
112
- var updater_exports = {};
113
- __export(updater_exports, {
114
- processPackages: () => processPackages
115
- });
116
- module2.exports = __toCommonJS(updater_exports);
117
- var import_promises = __toESM2(require("node:fs/promises"));
118
- var import_glob = __toESM2(require("glob"));
119
- var import_semver = __toESM2(require("semver"));
120
- var import_npm_registry_fetch = __toESM2(require("npm-registry-fetch"));
121
- var import_npmrc = require_npmrc();
122
- var cache = {};
123
- var { readFile, writeFile } = import_promises.default;
124
- var [K, R, G, Y, B] = [0, 31, 32, 33, 34].map((x) => `\x1B[${x}m`);
125
- async function processPackages(patterns, options) {
126
- const { bump, quick, strict, debug, dryrun } = options;
127
- function $debug(...args) {
128
- if (debug && args)
129
- console.log(`${R}[DEBUG]${K}`, ...args);
130
- }
131
- function getVersions(name, npmrc) {
132
- if (name in cache) {
133
- $debug(`Returning cached versions for ${Y}${name}${K}`);
134
- return cache[name];
135
- }
136
- $debug(`Retrieving versions for package ${Y}${name}${K}`);
137
- const range = new import_semver.default.Range(">=0.0.0", { includePrerelease: false });
138
- return cache[name] = import_npm_registry_fetch.default.json(name, Object.assign({}, npmrc, { spec: name })).then((data) => {
139
- return Object.entries(data.versions).filter(([, info]) => !info.deprecated).map(([version]) => version).filter((version) => range.test(version)).sort(import_semver.default.rcompare);
140
- });
141
- }
142
- async function updateDependency(name, rangeString, npmrc) {
143
- const match = /^\s*([~^])\s*(\d+(\.\d+(\.\d+)?)?)\s*$/.exec(rangeString);
144
- if (!match) {
145
- $debug(`Not processing range ${G}${rangeString}${K} for ${Y}${name}${K}`);
146
- return rangeString;
147
- }
148
- const [, specifier, version] = match;
149
- if (!strict) {
150
- const r = rangeString;
151
- rangeString = `>=${version}`;
152
- if (specifier === "~")
153
- rangeString += ` <${import_semver.default.inc(version, "major")}`;
154
- $debug(`Extending version for ${Y}${name}${K} from ${G}${r}${K} to ${G}${rangeString}${K}`);
155
- }
156
- const range = new import_semver.default.Range(rangeString);
157
- const versions = await getVersions(name, npmrc);
158
- for (const v of versions) {
159
- if (range.test(v))
160
- return `${specifier}${v}`;
161
- }
162
- return `${specifier}${version}`;
163
- }
164
- async function processPackage(file) {
165
- process.stdout.write(`Processing ${G}${file}${K} `);
166
- const data = JSON.parse(await readFile(file, "utf8"));
167
- if (data.name) {
168
- process.stdout.write(`[${Y}${data.name}`);
169
- if (data.version)
170
- process.stdout.write(` ${data.version}`);
171
- process.stdout.write(`${K}] `);
172
- }
173
- if (debug)
174
- process.stdout.write("\n");
175
- const npmrc = await (0, import_npmrc.readNpmRc)(file);
176
- const changes2 = [];
177
- let mainDependencyChanges = 0;
178
- for (const type in data) {
179
- if (!type.match(/[dD]ependencies$/))
180
- continue;
181
- if (type.match(/bundled?Dependencies/))
182
- continue;
183
- const kind = type.length > 12 ? ` [${type.slice(0, -12)}]` : "";
184
- const dependencies = {};
185
- const promises = Object.keys(data[type] || {}).sort().map(async (name) => {
186
- const from = data[type][name];
187
- const to = await updateDependency(name, from, npmrc);
188
- if (!debug)
189
- process.stdout.write(".");
190
- if (from !== to) {
191
- changes2.push({ name, from, to, kind });
192
- if (type === "dependencies")
193
- mainDependencyChanges++;
194
- }
195
- dependencies[name] = to;
196
- });
197
- await Promise.all(promises);
198
- if (Object.keys(dependencies).length) {
199
- data[type] = dependencies;
200
- } else {
201
- delete data[type];
202
- }
203
- }
204
- if (debug)
205
- process.stdout.write("Updated with");
206
- if (!changes2.length) {
207
- console.log(` ${R}no changes${K}`);
208
- return 0;
209
- }
210
- changes2.sort(({ name: a }, { name: b }) => a < b ? -1 : a > b ? 1 : 0);
211
- console.log(` ${R}${changes2.length} changes${K}`);
212
- let lname = 0;
213
- let lfrom = 0;
214
- let lto = 0;
215
- for (const { name, from, to } of changes2) {
216
- lname = lname > name.length ? lname : name.length;
217
- lfrom = lfrom > from.length ? lfrom : from.length;
218
- lto = lto > to.length ? lto : to.length;
219
- }
220
- for (const { name, from, to, kind } of changes2) {
221
- console.log(` * ${Y}${name.padEnd(lname)}${K} : ${G}${from.padStart(lfrom)}${K} -> ${G}${to.padEnd(lto)} ${B}${kind}${K}`);
222
- }
223
- if (quick && mainDependencyChanges === 0) {
224
- console.log(`No changes to main dependencies, ${Y}ignoring ${changes2.length} other changes${K}`);
225
- return 0;
226
- }
227
- if (bump) {
228
- const bumped = import_semver.default.inc(data.version, bump);
229
- console.log(` - Bumping version ${Y}${data.version}${K} -> ${G}${bumped}${K}`);
230
- data.version = bumped;
231
- }
232
- if (dryrun) {
233
- console.log(`Dry run, not writing ${G}${file}${K}`);
234
- return 0;
235
- } else {
236
- await writeFile(file, JSON.stringify(data, null, 2) + "\n");
237
- return changes2.length;
90
+ async function processPackage(file) {
91
+ process.stdout.write(`Processing ${G}${file}${K} `);
92
+ const data = JSON.parse(await readFile2(file, "utf8"));
93
+ if (data.name) {
94
+ process.stdout.write(`[${Y}${data.name}`);
95
+ if (data.version)
96
+ process.stdout.write(` ${data.version}`);
97
+ process.stdout.write(`${K}] `);
98
+ }
99
+ if (debug2)
100
+ process.stdout.write("\n");
101
+ const npmrc = await readNpmRc(file);
102
+ const changes2 = [];
103
+ let mainDependencyChanges = 0;
104
+ for (const type in data) {
105
+ if (!type.match(/[dD]ependencies$/))
106
+ continue;
107
+ if (type.match(/bundled?Dependencies/))
108
+ continue;
109
+ const kind = type.length > 12 ? ` [${type.slice(0, -12)}]` : "";
110
+ const dependencies = {};
111
+ const promises = Object.keys(data[type] || {}).sort().map(async (name) => {
112
+ const from = data[type][name];
113
+ const to = await updateDependency(name, from, npmrc);
114
+ if (!debug2)
115
+ process.stdout.write(".");
116
+ if (from !== to) {
117
+ changes2.push({ name, from, to, kind });
118
+ if (type === "dependencies")
119
+ mainDependencyChanges++;
238
120
  }
121
+ dependencies[name] = to;
122
+ });
123
+ await Promise.all(promises);
124
+ if (Object.keys(dependencies).length) {
125
+ data[type] = Object.entries(dependencies).sort(([a], [b]) => a.localeCompare(b)).reduce((deps, [name, version]) => {
126
+ deps[name] = version;
127
+ return deps;
128
+ }, {});
129
+ } else {
130
+ delete data[type];
239
131
  }
240
- const files = await (0, import_glob.default)(patterns);
241
- let changes = 0;
242
- let newline = false;
243
- for (const file of files) {
244
- if (newline)
245
- console.log();
246
- const packageChanges = await processPackage(file);
247
- newline = !!packageChanges;
248
- changes += packageChanges;
249
- }
250
- return changes;
132
+ }
133
+ if (debug2)
134
+ process.stdout.write("Updated with");
135
+ if (!changes2.length) {
136
+ console.log(` ${R}no changes${K}`);
137
+ return 0;
138
+ }
139
+ changes2.sort(({ name: a }, { name: b }) => a < b ? -1 : a > b ? 1 : 0);
140
+ console.log(` ${R}${changes2.length} changes${K}`);
141
+ let lname = 0;
142
+ let lfrom = 0;
143
+ let lto = 0;
144
+ for (const { name, from, to } of changes2) {
145
+ lname = lname > name.length ? lname : name.length;
146
+ lfrom = lfrom > from.length ? lfrom : from.length;
147
+ lto = lto > to.length ? lto : to.length;
148
+ }
149
+ for (const { name, from, to, kind } of changes2) {
150
+ console.log(` * ${Y}${name.padEnd(lname)}${K} : ${G}${from.padStart(lfrom)}${K} -> ${G}${to.padEnd(lto)} ${B}${kind}${K}`);
151
+ }
152
+ if (quick2 && mainDependencyChanges === 0) {
153
+ console.log(`No changes to main dependencies, ${Y}ignoring ${changes2.length} other changes${K}`);
154
+ return 0;
155
+ }
156
+ if (bump2) {
157
+ const bumped = semver.inc(data.version, bump2);
158
+ console.log(` - Bumping version ${Y}${data.version}${K} -> ${G}${bumped}${K}`);
159
+ data.version = bumped;
160
+ }
161
+ if (dryrun2) {
162
+ console.log(`Dry run, not writing ${G}${file}${K}`);
163
+ return 0;
164
+ } else {
165
+ await writeFile(file, JSON.stringify(data, null, 2) + "\n");
166
+ return changes2.length;
251
167
  }
252
168
  }
253
- });
254
-
255
- // dist/main.cjs
256
- var __create = Object.create;
257
- var __defProp = Object.defineProperty;
258
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
259
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
260
- var __getProtoOf = Object.getPrototypeOf;
261
- var __hasOwnProp = Object.prototype.hasOwnProperty;
262
- var __copyProps = (to, from, except, desc) => {
263
- if (from && typeof from === "object" || typeof from === "function") {
264
- for (let key of __getOwnPropNames2(from))
265
- if (!__hasOwnProp.call(to, key) && key !== except)
266
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
169
+ const files2 = await glob(patterns);
170
+ let changes = 0;
171
+ let newline = false;
172
+ for (const file of files2) {
173
+ if (newline)
174
+ console.log();
175
+ const packageChanges = await processPackage(file);
176
+ newline = !!packageChanges;
177
+ changes += packageChanges;
267
178
  }
268
- return to;
269
- };
270
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
271
- // If the importer is in node compatibility mode or this is not an ESM
272
- // file that has been converted to a CommonJS file using a Babel-
273
- // compatible transform (i.e. "__esModule" has not been set), then set
274
- // "default" to the CommonJS "module.exports" for node compatibility.
275
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
276
- mod
277
- ));
278
- var yargs = __toESM(require("yargs"));
279
- var import_updater = require_updater();
280
- var parsed = yargs.usage("$0 [--options ...] [package.json ...]").help("h").alias("h", "help").alias("v", "version").option("s", {
179
+ return changes;
180
+ }
181
+
182
+ // dist/main.mjs
183
+ var parsed = await yargs.default(process.argv.slice(2)).usage("$0 [--options ...] [package.json ...]").help("h").alias("h", "help").alias("v", "version").option("s", {
281
184
  alias: "strict",
282
185
  type: "boolean",
283
186
  description: [
@@ -301,7 +204,7 @@ var parsed = yargs.usage("$0 [--options ...] [package.json ...]").help("h").alia
301
204
  description: "Exit with 0 (zero) in case of no updates"
302
205
  }).options("b", {
303
206
  alias: "bump",
304
- coerce: (bump) => bump == true ? "patch" : bump,
207
+ coerce: (bump2) => bump2 == true ? "patch" : bump2,
305
208
  choices: ["major", "minor", "patch"],
306
209
  description: "Bump the version of the package file on changes"
307
210
  }).options("x", {
@@ -312,14 +215,14 @@ var parsed = yargs.usage("$0 [--options ...] [package.json ...]").help("h").alia
312
215
  "Multiple files (or globs) can be specified on the command line.\n",
313
216
  'When no files are specified, the default is to process the "package.json" file in the current directory'
314
217
  ].join("\n")).strictOptions().argv;
315
- Promise.resolve(parsed).then(({ b: bump, s: strict, q: quick, n: noerr, d: debug, x: dryrun, _: args = [] }) => {
316
- const files = args.map((arg) => arg.toString());
317
- if (!files.length)
318
- files.push("package.json");
319
- (0, import_updater.processPackages)(files, { strict, quick, debug, dryrun, bump }).then((changes) => {
320
- process.exit(changes ? 0 : noerr ? 0 : -1);
321
- }).catch((error) => {
322
- console.error(error);
323
- process.exit(1);
324
- });
325
- }).catch((error) => console.log(error));
218
+ var { b: bump, s: strict, q: quick, n: noerr, d: debug, x: dryrun, _: args = [] } = parsed;
219
+ var files = args.map((arg) => arg.toString());
220
+ if (!files.length)
221
+ files.push("package.json");
222
+ try {
223
+ const changes = await processPackages(files, { strict, quick, debug, dryrun, bump });
224
+ process.exit(changes ? 0 : noerr ? 0 : -1);
225
+ } catch (error) {
226
+ console.error(error);
227
+ process.exit(1);
228
+ }
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@juit/check-updates",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
+ "type": "module",
4
5
  "description": "Small and fast utility to update package dependencies",
5
6
  "author": "Team Juit <developers@juit.com>",
6
7
  "license": "Apache-2.0",
@@ -16,19 +17,19 @@
16
17
  "transpile": "plug transpile"
17
18
  },
18
19
  "dependencies": {
19
- "glob": "^9.2.1",
20
- "ini": "^3.0.1",
20
+ "glob": "^9.3.2",
21
+ "ini": "^4.0.0",
21
22
  "npm-registry-fetch": "^14.0.3",
22
23
  "semver": "^7.3.8",
23
24
  "yargs": "^17.7.1"
24
25
  },
25
26
  "devDependencies": {
26
- "@plugjs/build": "^0.2.4",
27
+ "@plugjs/build": "^0.3.0",
27
28
  "@types/glob": "^8.1.0",
28
29
  "@types/ini": "^1.3.31",
29
30
  "@types/npm-registry-fetch": "^8.0.4",
30
31
  "@types/semver": "^7.3.13",
31
- "@types/yargs": "^17.0.22"
32
+ "@types/yargs": "^17.0.23"
32
33
  },
33
34
  "repository": {
34
35
  "type": "git",
package/src/main.ts CHANGED
@@ -11,7 +11,7 @@ type ReleaseType = 'major' | 'minor' | 'patch'
11
11
  * ========================================================================== */
12
12
 
13
13
  /* Parse command line arguments */
14
- const parsed = yargs
14
+ const parsed = await yargs.default(process.argv.slice(2))
15
15
  .usage('$0 [--options ...] [package.json ...]')
16
16
  .help('h').alias('h', 'help').alias('v', 'version')
17
17
  .option('s', {
@@ -58,18 +58,18 @@ const parsed = yargs
58
58
  .strictOptions()
59
59
  .argv
60
60
 
61
- Promise.resolve(parsed).then(({ b: bump, s: strict, q: quick, n: noerr, d: debug, x: dryrun, _: args = [] }) => {
62
- /* Normalize arguments and default to package.json in the current directory */
63
- const files = args.map((arg) => arg.toString())
64
- if (! files.length) files.push('package.json')
61
+ /* Expand parsed arguments */
62
+ const { b: bump, s: strict, q: quick, n: noerr, d: debug, x: dryrun, _: args = [] } = parsed
65
63
 
66
- /* Process packages, one by one */
67
- processPackages(files, { strict, quick, debug, dryrun, bump })
68
- .then((changes) => {
69
- process.exit(changes ? 0 : noerr ? 0 : -1)
70
- })
71
- .catch((error) => {
72
- console.error(error)
73
- process.exit(1)
74
- })
75
- }).catch((error) => console.log(error))
64
+ /* Normalize arguments and default to package.json in the current directory */
65
+ const files = args.map((arg) => arg.toString())
66
+ if (! files.length) files.push('package.json')
67
+
68
+ /* Process packages, one by one */
69
+ try {
70
+ const changes = await processPackages(files, { strict, quick, debug, dryrun, bump })
71
+ process.exit(changes ? 0 : noerr ? 0 : -1)
72
+ } catch (error) {
73
+ console.error(error)
74
+ process.exit(1)
75
+ }
package/src/updater.ts CHANGED
@@ -1,4 +1,4 @@
1
- import fs from 'node:fs/promises'
1
+ import { readFile, writeFile } from 'node:fs/promises'
2
2
 
3
3
  import glob from 'glob'
4
4
  import semver from 'semver'
@@ -26,9 +26,6 @@ interface Change {
26
26
  /* Our packages cache version */
27
27
  const cache: Record<string, Promise<string[]>> = {}
28
28
 
29
- /* Destructuring from "fs.promises" */
30
- const { readFile, writeFile } = fs
31
-
32
29
  /* Colors */
33
30
  const [ K, R, G, Y, B ] = [ 0, 31, 32, 33, 34 ].map((x) => `\u001b[${x}m`)
34
31
 
@@ -57,7 +54,7 @@ export async function processPackages(
57
54
  function getVersions(name: string, npmrc: Record<string, any>): Promise<string[]> {
58
55
  if (name in cache) {
59
56
  $debug(`Returning cached versions for ${Y}${name}${K}`)
60
- return cache[name]
57
+ return cache[name] as Promise<string[]>
61
58
  }
62
59
 
63
60
  $debug(`Retrieving versions for package ${Y}${name}${K}`)
@@ -84,7 +81,7 @@ export async function processPackages(
84
81
  return rangeString
85
82
  }
86
83
 
87
- const [ , specifier, version ] = match
84
+ const [ , specifier = '', version = '' ] = match
88
85
 
89
86
  if (! strict) {
90
87
  const r = rangeString
@@ -142,7 +139,12 @@ export async function processPackages(
142
139
  await Promise.all(promises)
143
140
 
144
141
  if (Object.keys(dependencies).length) {
145
- data[type] = dependencies
142
+ data[type] = Object.entries(dependencies)
143
+ .sort(([ a ], [ b ]) => a.localeCompare(b))
144
+ .reduce((deps, [ name, version ]) => {
145
+ deps[name] = version
146
+ return deps
147
+ }, {} as Record<string, string>)
146
148
  } else {
147
149
  delete data[type]
148
150
  }