@badisi/latest-version 6.1.8 → 6.1.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.
package/cli.js CHANGED
@@ -196,7 +196,7 @@ var checkVersions = async (packages, skipMissing, options = { useCache: true })
196
196
  spinner.start();
197
197
  let latestVersionPackages = await (0, import_index.default)(packages, options);
198
198
  if (skipMissing) {
199
- latestVersionPackages = latestVersionPackages.filter((pkg) => pkg.local || pkg.globalNpm || pkg.globalYarn);
199
+ latestVersionPackages = latestVersionPackages.filter((pkg) => pkg.local ?? pkg.globalNpm ?? pkg.globalYarn);
200
200
  }
201
201
  spinner.stop();
202
202
  displayTable(latestVersionPackages);
package/index.d.ts CHANGED
@@ -102,7 +102,7 @@ interface LatestVersionOptions {
102
102
  */
103
103
  readonly requestOptions?: RequestOptions;
104
104
  }
105
- type LatestVersion = {
105
+ interface LatestVersion {
106
106
  /**
107
107
  * Get latest versions of packages from of a package json like object.
108
108
  *
@@ -139,9 +139,9 @@ type LatestVersion = {
139
139
  * @returns {Promise<LatestVersionPackage[]>}
140
140
  */
141
141
  (items: Package[], options?: LatestVersionOptions): Promise<LatestVersionPackage[]>;
142
- };
142
+ }
143
143
  type PackageRange = `${'@' | ''}${string}@${string}`;
144
- type Package = string | PackageRange;
144
+ type Package = PackageRange | string;
145
145
  type PackageJsonDependencies = Record<string, string>;
146
146
  type PackageJson = Record<string, any> & ({
147
147
  dependencies: PackageJsonDependencies;
package/index.js CHANGED
@@ -51,7 +51,7 @@ var downloadMetadata = (pkgName, options) => {
51
51
  return new Promise((resolve, reject) => {
52
52
  const i = pkgName.indexOf("/");
53
53
  const pkgScope = i !== -1 ? pkgName.slice(0, i) : "";
54
- const registryUrl = options?.registryUrl || (0, import_registry_url.default)(pkgScope);
54
+ const registryUrl = options?.registryUrl ?? (0, import_registry_url.default)(pkgScope);
55
55
  const pkgUrl = new import_url.URL(encodeURIComponent(pkgName).replace(/^%40/, "@"), registryUrl);
56
56
  let requestOptions = {
57
57
  headers: { accept: "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*" },
@@ -72,6 +72,10 @@ var downloadMetadata = (pkgName, options) => {
72
72
  let rawData = "";
73
73
  res.setEncoding("utf8");
74
74
  res.on("data", (chunk) => rawData += chunk);
75
+ res.once("error", (err) => {
76
+ res.removeAllListeners();
77
+ return reject(`Request error (${err.message}): ${pkgUrl}`);
78
+ });
75
79
  res.once("end", () => {
76
80
  res.setTimeout(0);
77
81
  res.removeAllListeners();
@@ -108,9 +112,9 @@ var getCacheDir = (name = "@badisi/latest-version") => {
108
112
  case "darwin":
109
113
  return (0, import_path.join)(homeDir, "Library", "Caches", name);
110
114
  case "win32":
111
- return (0, import_path.join)(process.env.LOCALAPPDATA || (0, import_path.join)(homeDir, "AppData", "Local"), name, "Cache");
115
+ return (0, import_path.join)(process.env.LOCALAPPDATA ?? (0, import_path.join)(homeDir, "AppData", "Local"), name, "Cache");
112
116
  default:
113
- return (0, import_path.join)(process.env.XDG_CACHE_HOME || (0, import_path.join)(homeDir, ".cache"), name);
117
+ return (0, import_path.join)(process.env.XDG_CACHE_HOME ?? (0, import_path.join)(homeDir, ".cache"), name);
114
118
  }
115
119
  };
116
120
  var saveMetadataToCache = (pkg) => {
@@ -148,10 +152,10 @@ var getRegistryVersions = async (pkgName, tagOrRange, options) => {
148
152
  latest: pkgMetadata?.distTags?.latest,
149
153
  next: pkgMetadata?.distTags?.next
150
154
  };
151
- if (tagOrRange && pkgMetadata?.distTags && pkgMetadata?.distTags[tagOrRange]) {
155
+ if (tagOrRange && pkgMetadata?.distTags?.[tagOrRange]) {
152
156
  versions.wanted = pkgMetadata.distTags[tagOrRange];
153
157
  } else if (tagOrRange && pkgMetadata?.versions?.length) {
154
- versions.wanted = (0, import_max_satisfying.default)(pkgMetadata.versions, tagOrRange) || void 0;
158
+ versions.wanted = (0, import_max_satisfying.default)(pkgMetadata.versions, tagOrRange) ?? void 0;
155
159
  }
156
160
  return versions;
157
161
  };
@@ -205,7 +209,7 @@ var getInfo = async (pkg, options) => {
205
209
  const globalYarn = pkgInfo.globalYarn && pkgInfo.wanted ? (0, import_gt.default)(pkgInfo.wanted, pkgInfo.globalYarn) ? pkgInfo.wanted : false : false;
206
210
  pkgInfo.updatesAvailable = local || globalNpm || globalYarn ? { local, globalNpm, globalYarn } : false;
207
211
  } catch (err) {
208
- pkgInfo.error = err?.message || err;
212
+ pkgInfo.error = err?.message ?? err;
209
213
  }
210
214
  return pkgInfo;
211
215
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badisi/latest-version",
3
- "version": "6.1.8",
3
+ "version": "6.1.10",
4
4
  "description": "Get latest versions of packages",
5
5
  "homepage": "https://github.com/badisi/latest-version",
6
6
  "license": "MIT",
@@ -44,10 +44,10 @@
44
44
  "node": ">= 15"
45
45
  },
46
46
  "dependencies": {
47
- "global-dirs": "^3.0.1",
48
47
  "@colors/colors": "^1.6.0",
48
+ "global-dirs": "^3.0.1",
49
+ "ora": "5.4.1",
49
50
  "registry-auth-token": "^5.0.2",
50
- "semver": "^7.5.4",
51
- "ora": "5.4.1"
51
+ "semver": "^7.5.4"
52
52
  }
53
53
  }