@juit/check-updates 2.0.1 → 2.0.2
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 +182 -279
- package/package.json +5 -4
- package/src/main.ts +15 -15
- package/src/updater.ts +9 -7
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/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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: (
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
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.
|
|
3
|
+
"version": "2.0.2",
|
|
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.
|
|
20
|
+
"glob": "^9.3.1",
|
|
20
21
|
"ini": "^3.0.1",
|
|
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.
|
|
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.
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
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
|
}
|