@badisi/latest-version 6.1.9 → 7.0.0

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,8 +72,11 @@ 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
- res.setTimeout(0);
77
80
  res.removeAllListeners();
78
81
  try {
79
82
  const pkgMetadata = JSON.parse(rawData);
@@ -108,9 +111,9 @@ var getCacheDir = (name = "@badisi/latest-version") => {
108
111
  case "darwin":
109
112
  return (0, import_path.join)(homeDir, "Library", "Caches", name);
110
113
  case "win32":
111
- return (0, import_path.join)(process.env.LOCALAPPDATA || (0, import_path.join)(homeDir, "AppData", "Local"), name, "Cache");
114
+ return (0, import_path.join)(process.env.LOCALAPPDATA ?? (0, import_path.join)(homeDir, "AppData", "Local"), name, "Cache");
112
115
  default:
113
- return (0, import_path.join)(process.env.XDG_CACHE_HOME || (0, import_path.join)(homeDir, ".cache"), name);
116
+ return (0, import_path.join)(process.env.XDG_CACHE_HOME ?? (0, import_path.join)(homeDir, ".cache"), name);
114
117
  }
115
118
  };
116
119
  var saveMetadataToCache = (pkg) => {
@@ -148,10 +151,10 @@ var getRegistryVersions = async (pkgName, tagOrRange, options) => {
148
151
  latest: pkgMetadata?.distTags?.latest,
149
152
  next: pkgMetadata?.distTags?.next
150
153
  };
151
- if (tagOrRange && pkgMetadata?.distTags && pkgMetadata?.distTags[tagOrRange]) {
154
+ if (tagOrRange && pkgMetadata?.distTags?.[tagOrRange]) {
152
155
  versions.wanted = pkgMetadata.distTags[tagOrRange];
153
156
  } else if (tagOrRange && pkgMetadata?.versions?.length) {
154
- versions.wanted = (0, import_max_satisfying.default)(pkgMetadata.versions, tagOrRange) || void 0;
157
+ versions.wanted = (0, import_max_satisfying.default)(pkgMetadata.versions, tagOrRange) ?? void 0;
155
158
  }
156
159
  return versions;
157
160
  };
@@ -205,7 +208,7 @@ var getInfo = async (pkg, options) => {
205
208
  const globalYarn = pkgInfo.globalYarn && pkgInfo.wanted ? (0, import_gt.default)(pkgInfo.wanted, pkgInfo.globalYarn) ? pkgInfo.wanted : false : false;
206
209
  pkgInfo.updatesAvailable = local || globalNpm || globalYarn ? { local, globalNpm, globalYarn } : false;
207
210
  } catch (err) {
208
- pkgInfo.error = err?.message || err;
211
+ pkgInfo.error = err?.message ?? err;
209
212
  }
210
213
  return pkgInfo;
211
214
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badisi/latest-version",
3
- "version": "6.1.9",
3
+ "version": "7.0.0",
4
4
  "description": "Get latest versions of packages",
5
5
  "homepage": "https://github.com/badisi/latest-version",
6
6
  "license": "MIT",
@@ -41,13 +41,13 @@
41
41
  "module"
42
42
  ],
43
43
  "engines": {
44
- "node": ">= 15"
44
+ "node": ">= 18"
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
  }