@badisi/latest-version 7.0.8 → 7.0.10

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.
Files changed (4) hide show
  1. package/cli.js +11 -11
  2. package/index.d.ts +0 -8
  3. package/index.js +20 -15
  4. package/package.json +2 -2
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
- (row) => columns.forEach((column) => {
103
- column.maxLength = Math.max(column.label.length, column.maxLength, row[column.attrName]?.length || 0);
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: " " + (name ?? "unknown"),
128
- location: location ?? "unknown",
127
+ name: " " + name,
128
+ location,
129
129
  installed: installed ?? "unknown",
130
130
  latest: latest ?? "unknown",
131
131
  tagOrRange: wantedTagOrRange ?? "unknown",
@@ -220,11 +220,11 @@ void (async () => {
220
220
  if (args.length) {
221
221
  args = args.map((arg) => {
222
222
  if (localPkgJson?.dependencies?.[arg]) {
223
- return `${arg}@${localPkgJson?.dependencies?.[arg]}`;
223
+ return `${arg}@${localPkgJson.dependencies?.[arg]}`;
224
224
  } else if (localPkgJson?.devDependencies?.[arg]) {
225
- return `${arg}@${localPkgJson?.devDependencies?.[arg]}`;
225
+ return `${arg}@${localPkgJson.devDependencies?.[arg]}`;
226
226
  } else if (localPkgJson?.peerDependencies?.[arg]) {
227
- return `${arg}@${localPkgJson?.peerDependencies?.[arg]}`;
227
+ return `${arg}@${localPkgJson.peerDependencies?.[arg]}`;
228
228
  }
229
229
  return arg;
230
230
  });
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
@@ -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
- return reject(`Request error (${err.message}): ${pkgUrl}`);
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
- return resolve({
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
- return reject(err);
91
+ reject(err);
92
+ return;
91
93
  }
92
94
  });
93
95
  } else {
94
96
  res.removeAllListeners();
95
97
  res.resume();
96
- return reject(`Request error (${res.statusCode}): ${pkgUrl}`);
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
- return reject(error);
105
+ reject(error);
103
106
  };
104
- request.once("timeout", () => abort(`Request timed out: ${pkgUrl}`));
105
- request.once("error", (err) => abort(err));
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?.latest,
152
- next: pkgMetadata?.distTags?.next
158
+ latest: pkgMetadata?.distTags.latest,
159
+ next: pkgMetadata?.distTags.next
153
160
  };
154
- if (tagOrRange && pkgMetadata?.distTags?.[tagOrRange]) {
161
+ if (tagOrRange && pkgMetadata?.distTags[tagOrRange]) {
155
162
  versions.wanted = pkgMetadata.distTags[tagOrRange];
156
- } else if (tagOrRange && pkgMetadata?.versions?.length) {
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 if (location === "local") {
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")];
@@ -220,9 +227,7 @@ var latestVersion = async (arg, options) => {
220
227
  pkgs.push(...arg);
221
228
  } else if (isPackageJson(arg)) {
222
229
  const addDeps = (deps) => {
223
- if (deps) {
224
- pkgs.push(...Object.keys(deps).map((key) => `${key}@${deps[key]}`));
225
- }
230
+ pkgs.push(...Object.keys(deps).map((key) => `${key}@${deps[key]}`));
226
231
  };
227
232
  addDeps(arg.dependencies);
228
233
  addDeps(arg.devDependencies);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badisi/latest-version",
3
- "version": "7.0.8",
3
+ "version": "7.0.10",
4
4
  "description": "Get latest versions of packages",
5
5
  "homepage": "https://github.com/badisi/latest-version",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@colors/colors": "^1.6.0",
48
- "global-dirs": "^4.0.0",
48
+ "global-dirs": "3.0.1",
49
49
  "ora": "^8.1.0",
50
50
  "registry-auth-token": "^5.0.2",
51
51
  "semver": "^7.6.3"