@badisi/latest-version 7.0.9 → 7.0.11
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/cli.js +15 -14
- package/index.d.ts +0 -8
- package/index.js +24 -17
- package/package.json +5 -5
package/cli.js
CHANGED
|
@@ -45,7 +45,7 @@ var colorizeDiff = (from, to) => {
|
|
|
45
45
|
return to;
|
|
46
46
|
};
|
|
47
47
|
var columnCellRenderer = (column, row) => {
|
|
48
|
-
let text = row[column.attrName]
|
|
48
|
+
let text = row[column.attrName];
|
|
49
49
|
const gap = text.length < column.maxLength ? " ".repeat(column.maxLength - text.length) : "";
|
|
50
50
|
switch (column.attrName) {
|
|
51
51
|
case "name":
|
|
@@ -98,11 +98,11 @@ var getTableColumns = (rows) => {
|
|
|
98
98
|
{ label: "Wanted", attrName: "wanted", align: "right", maxLength: 0, items: [] },
|
|
99
99
|
{ label: "Latest", attrName: "latest", align: "right", maxLength: 0, items: [] }
|
|
100
100
|
];
|
|
101
|
-
rows.forEach(
|
|
102
|
-
|
|
103
|
-
column.maxLength = Math.max(column.label.length, column.maxLength, row[column.attrName]
|
|
104
|
-
})
|
|
105
|
-
);
|
|
101
|
+
rows.forEach((row) => {
|
|
102
|
+
columns.forEach((column) => {
|
|
103
|
+
column.maxLength = Math.max(column.label.length, column.maxLength, row[column.attrName].length || 0);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
106
|
return columns;
|
|
107
107
|
};
|
|
108
108
|
var getTableRows = (updates) => {
|
|
@@ -124,8 +124,8 @@ var getTableRows = (updates) => {
|
|
|
124
124
|
return "unknown";
|
|
125
125
|
};
|
|
126
126
|
const add = (group, location, installed, wanted) => all.push({
|
|
127
|
-
name: " " +
|
|
128
|
-
location
|
|
127
|
+
name: " " + name,
|
|
128
|
+
location,
|
|
129
129
|
installed: installed ?? "unknown",
|
|
130
130
|
latest: latest ?? "unknown",
|
|
131
131
|
tagOrRange: wantedTagOrRange ?? "unknown",
|
|
@@ -160,9 +160,10 @@ var getTableRows = (updates) => {
|
|
|
160
160
|
return all;
|
|
161
161
|
}, []);
|
|
162
162
|
};
|
|
163
|
-
var displayTable = (
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
163
|
+
var displayTable = (latestVersionPackages) => {
|
|
164
|
+
const updates = latestVersionPackages.filter((pkg) => pkg.updatesAvailable);
|
|
165
|
+
if (updates.length) {
|
|
166
|
+
const rows = getTableRows(updates);
|
|
166
167
|
const hasUpdates = rows.some((row) => row.installed !== "unknown");
|
|
167
168
|
const columns = getTableColumns(rows);
|
|
168
169
|
const columnGap = 2;
|
|
@@ -220,11 +221,11 @@ void (async () => {
|
|
|
220
221
|
if (args.length) {
|
|
221
222
|
args = args.map((arg) => {
|
|
222
223
|
if (localPkgJson?.dependencies?.[arg]) {
|
|
223
|
-
return `${arg}@${localPkgJson
|
|
224
|
+
return `${arg}@${localPkgJson.dependencies?.[arg]}`;
|
|
224
225
|
} else if (localPkgJson?.devDependencies?.[arg]) {
|
|
225
|
-
return `${arg}@${localPkgJson
|
|
226
|
+
return `${arg}@${localPkgJson.devDependencies?.[arg]}`;
|
|
226
227
|
} else if (localPkgJson?.peerDependencies?.[arg]) {
|
|
227
|
-
return `${arg}@${localPkgJson
|
|
228
|
+
return `${arg}@${localPkgJson.peerDependencies?.[arg]}`;
|
|
228
229
|
}
|
|
229
230
|
return arg;
|
|
230
231
|
});
|
package/index.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ interface LatestVersionPackage extends InstalledVersions, RegistryVersions {
|
|
|
34
34
|
name: string;
|
|
35
35
|
/**
|
|
36
36
|
* The tag or version range that was provided (if provided).
|
|
37
|
-
*
|
|
38
37
|
* @default "latest"
|
|
39
38
|
*/
|
|
40
39
|
wantedTagOrRange?: string;
|
|
@@ -66,7 +65,6 @@ interface LatestVersionOptions {
|
|
|
66
65
|
* 1) a latest/next version available if a cache was found
|
|
67
66
|
* 2) no latest/next version available if no cache was found - in such case updates will be fetched in the background and a cache will
|
|
68
67
|
* be created for each provided packages and made available for the next call to the api.
|
|
69
|
-
*
|
|
70
68
|
* @default false
|
|
71
69
|
*/
|
|
72
70
|
readonly useCache?: boolean;
|
|
@@ -77,13 +75,11 @@ interface LatestVersionOptions {
|
|
|
77
75
|
* 1) The api will returned immediately (without any latest nor next version available for the provided packages)
|
|
78
76
|
* 2) New updates will be fetched in the background
|
|
79
77
|
* 3) The cache for each provided packages will be refreshed and made available for the next call to the api
|
|
80
|
-
*
|
|
81
78
|
* @default ONE_DAY
|
|
82
79
|
*/
|
|
83
80
|
readonly cacheMaxAge?: number;
|
|
84
81
|
/**
|
|
85
82
|
* A JavaScript package registry url that implements the CommonJS Package Registry specification.
|
|
86
|
-
*
|
|
87
83
|
* @default "Looks at any registry urls in the .npmrc file or fallback to the default npm registry instead"
|
|
88
84
|
* @example <caption>.npmrc</caption>
|
|
89
85
|
* registry = 'https://custom-registry.com/'
|
|
@@ -92,7 +88,6 @@ interface LatestVersionOptions {
|
|
|
92
88
|
readonly registryUrl?: string;
|
|
93
89
|
/**
|
|
94
90
|
* Set of options to be passed down to Node.js http/https request.
|
|
95
|
-
*
|
|
96
91
|
* @example <caption>Behind a proxy with self-signed certificate</caption>
|
|
97
92
|
* { ca: [ fs.readFileSync('proxy-cert.pem') ] }
|
|
98
93
|
* @example <caption>Bypassing certificate validation</caption>
|
|
@@ -103,7 +98,6 @@ interface LatestVersionOptions {
|
|
|
103
98
|
interface LatestVersion {
|
|
104
99
|
/**
|
|
105
100
|
* Get latest versions of packages from of a package json like object.
|
|
106
|
-
*
|
|
107
101
|
* @param {PackageJson} item - A package json like object (with dependencies, devDependencies and peerDependencies attributes).
|
|
108
102
|
* @example { dependencies: { 'npm': 'latest' }, devDependencies: { 'npm': '1.3.2' }, peerDependencies: { '@scope/name': '^5.0.2' } }
|
|
109
103
|
* @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
|
|
@@ -115,7 +109,6 @@ interface LatestVersion {
|
|
|
115
109
|
(item: PackageJson, options?: LatestVersionOptions): Promise<LatestVersionPackage[]>;
|
|
116
110
|
/**
|
|
117
111
|
* Get latest version of a single package.
|
|
118
|
-
*
|
|
119
112
|
* @param {Package} item - A single package object (represented by a string that should match the following format: `${'@' | ''}${string}@${string}`)
|
|
120
113
|
* @example 'npm', 'npm@1.3.2', '@scope/name@^5.0.2'
|
|
121
114
|
* @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
|
|
@@ -127,7 +120,6 @@ interface LatestVersion {
|
|
|
127
120
|
(item: Package, options?: LatestVersionOptions): Promise<LatestVersionPackage>;
|
|
128
121
|
/**
|
|
129
122
|
* Get latest versions of a collection of packages.
|
|
130
|
-
*
|
|
131
123
|
* @param {Package[]} items - A collection of package object (represented by a string that should match the following format: `${'@' | ''}${string}@${string}`)
|
|
132
124
|
* @example ['npm', 'npm@1.3.2', '@scope/name@^5.0.2']
|
|
133
125
|
* @param {LatestVersionOptions} [options] - An object optionally specifying the use of the cache, the max age of the cache, the registry url and the http or https options.
|
package/index.js
CHANGED
|
@@ -28,12 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
ONE_DAY: () => ONE_DAY,
|
|
34
|
-
default: () =>
|
|
34
|
+
default: () => index_default
|
|
35
35
|
});
|
|
36
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
var import_fs = require("fs");
|
|
38
38
|
var import_path = require("path");
|
|
39
39
|
var import_global_dirs = require("global-dirs");
|
|
@@ -74,35 +74,42 @@ var downloadMetadata = (pkgName, options) => {
|
|
|
74
74
|
res.on("data", (chunk) => rawData += chunk);
|
|
75
75
|
res.once("error", (err) => {
|
|
76
76
|
res.removeAllListeners();
|
|
77
|
-
|
|
77
|
+
reject(`Request error (${err.message}): ${pkgUrl}`);
|
|
78
78
|
});
|
|
79
79
|
res.once("end", () => {
|
|
80
80
|
res.removeAllListeners();
|
|
81
81
|
try {
|
|
82
82
|
const pkgMetadata = JSON.parse(rawData);
|
|
83
|
-
|
|
83
|
+
resolve({
|
|
84
84
|
name: pkgName,
|
|
85
85
|
lastUpdateDate: Date.now(),
|
|
86
86
|
versions: Object.keys(pkgMetadata.versions),
|
|
87
87
|
distTags: pkgMetadata["dist-tags"]
|
|
88
88
|
});
|
|
89
|
+
return;
|
|
89
90
|
} catch (err) {
|
|
90
|
-
|
|
91
|
+
reject(err);
|
|
92
|
+
return;
|
|
91
93
|
}
|
|
92
94
|
});
|
|
93
95
|
} else {
|
|
94
96
|
res.removeAllListeners();
|
|
95
97
|
res.resume();
|
|
96
|
-
|
|
98
|
+
reject(`Request error (${res.statusCode}): ${pkgUrl}`);
|
|
99
|
+
return;
|
|
97
100
|
}
|
|
98
101
|
});
|
|
99
102
|
const abort = (error) => {
|
|
100
103
|
request.removeAllListeners();
|
|
101
104
|
request.destroy();
|
|
102
|
-
|
|
105
|
+
reject(error);
|
|
103
106
|
};
|
|
104
|
-
request.once("timeout", () =>
|
|
105
|
-
|
|
107
|
+
request.once("timeout", () => {
|
|
108
|
+
abort(`Request timed out: ${pkgUrl}`);
|
|
109
|
+
});
|
|
110
|
+
request.once("error", (err) => {
|
|
111
|
+
abort(err);
|
|
112
|
+
});
|
|
106
113
|
});
|
|
107
114
|
};
|
|
108
115
|
var getCacheDir = (name = "@badisi/latest-version") => {
|
|
@@ -148,12 +155,12 @@ var getRegistryVersions = async (pkgName, tagOrRange, options) => {
|
|
|
148
155
|
pkgMetadata = await downloadMetadata(pkgName, options);
|
|
149
156
|
}
|
|
150
157
|
const versions = {
|
|
151
|
-
latest: pkgMetadata?.distTags
|
|
152
|
-
next: pkgMetadata?.distTags
|
|
158
|
+
latest: pkgMetadata?.distTags.latest,
|
|
159
|
+
next: pkgMetadata?.distTags.next
|
|
153
160
|
};
|
|
154
|
-
if (tagOrRange && pkgMetadata?.distTags
|
|
161
|
+
if (tagOrRange && pkgMetadata?.distTags[tagOrRange]) {
|
|
155
162
|
versions.wanted = pkgMetadata.distTags[tagOrRange];
|
|
156
|
-
} else if (tagOrRange && pkgMetadata?.versions
|
|
163
|
+
} else if (tagOrRange && pkgMetadata?.versions.length) {
|
|
157
164
|
versions.wanted = (0, import_max_satisfying.default)(pkgMetadata.versions, tagOrRange) ?? void 0;
|
|
158
165
|
}
|
|
159
166
|
return versions;
|
|
@@ -168,7 +175,7 @@ var getInstalledVersion = (pkgName, location = "local") => {
|
|
|
168
175
|
return void 0;
|
|
169
176
|
}
|
|
170
177
|
return require((0, import_path.join)(import_global_dirs.yarn.packages, pkgName, "package.json"))?.version;
|
|
171
|
-
} else
|
|
178
|
+
} else {
|
|
172
179
|
const { root } = (0, import_path.parse)(process.cwd());
|
|
173
180
|
let path = process.cwd();
|
|
174
181
|
const localPaths = [(0, import_path.join)(path, "node_modules")];
|
|
@@ -232,7 +239,7 @@ var latestVersion = async (arg, options) => {
|
|
|
232
239
|
const results = jobs.map((jobResult) => jobResult.value);
|
|
233
240
|
return typeof arg === "string" ? results[0] : results;
|
|
234
241
|
};
|
|
235
|
-
var
|
|
242
|
+
var index_default = latestVersion;
|
|
236
243
|
// Annotate the CommonJS export names for ESM import in node:
|
|
237
244
|
0 && (module.exports = {
|
|
238
245
|
ONE_DAY
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@badisi/latest-version",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.11",
|
|
4
4
|
"description": "Get latest versions of packages",
|
|
5
5
|
"homepage": "https://github.com/badisi/latest-version",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@colors/colors": "^1.6.0",
|
|
48
|
-
"global-dirs": "
|
|
49
|
-
"ora": "^8.
|
|
50
|
-
"registry-auth-token": "^5.0.
|
|
51
|
-
"semver": "^7.
|
|
48
|
+
"global-dirs": "3.0.1",
|
|
49
|
+
"ora": "^8.2.0",
|
|
50
|
+
"registry-auth-token": "^5.0.3",
|
|
51
|
+
"semver": "^7.7.1"
|
|
52
52
|
}
|
|
53
53
|
}
|