comze 0.3.0 → 0.3.1
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/dist/cli.mjs +35 -51
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -7555,7 +7555,6 @@ function formatNewVersion(originalConstraint, newVersion) {
|
|
|
7555
7555
|
import fs from "node:fs/promises";
|
|
7556
7556
|
import path from "node:path";
|
|
7557
7557
|
import os from "node:os";
|
|
7558
|
-
var CACHE_TTL = 30 * 60 * 1000;
|
|
7559
7558
|
function getCacheDir() {
|
|
7560
7559
|
const home = os.homedir();
|
|
7561
7560
|
const platform = os.platform();
|
|
@@ -7571,81 +7570,59 @@ function getCacheDir() {
|
|
|
7571
7570
|
}
|
|
7572
7571
|
return path.join(process.env.XDG_CACHE_HOME || path.join(home, ".cache"), "comze");
|
|
7573
7572
|
}
|
|
7574
|
-
async function
|
|
7573
|
+
async function getCacheEntry(key) {
|
|
7575
7574
|
try {
|
|
7576
7575
|
const cacheDir = getCacheDir();
|
|
7577
7576
|
const filePath = path.join(cacheDir, `${key}.json`);
|
|
7578
7577
|
const content = await fs.readFile(filePath, "utf-8");
|
|
7579
7578
|
const data = JSON.parse(content);
|
|
7580
|
-
|
|
7581
|
-
fs.unlink(filePath).catch(() => {});
|
|
7582
|
-
return null;
|
|
7583
|
-
}
|
|
7584
|
-
return data.value;
|
|
7579
|
+
return data;
|
|
7585
7580
|
} catch {
|
|
7586
7581
|
return null;
|
|
7587
7582
|
}
|
|
7588
7583
|
}
|
|
7589
|
-
async function setCache(key, value) {
|
|
7584
|
+
async function setCache(key, value, meta = {}) {
|
|
7590
7585
|
try {
|
|
7591
7586
|
const cacheDir = getCacheDir();
|
|
7592
7587
|
await fs.mkdir(cacheDir, { recursive: true });
|
|
7593
7588
|
const filePath = path.join(cacheDir, `${key}.json`);
|
|
7594
7589
|
const data = {
|
|
7595
7590
|
timestamp: Date.now(),
|
|
7596
|
-
value
|
|
7591
|
+
value,
|
|
7592
|
+
lastModified: meta.lastModified,
|
|
7593
|
+
etag: meta.etag
|
|
7597
7594
|
};
|
|
7598
7595
|
await fs.writeFile(filePath, JSON.stringify(data), "utf-8");
|
|
7599
7596
|
} catch {}
|
|
7600
7597
|
}
|
|
7598
|
+
async function touchCache(key) {
|
|
7599
|
+
try {
|
|
7600
|
+
const entry = await getCacheEntry(key);
|
|
7601
|
+
if (entry) {
|
|
7602
|
+
await setCache(key, entry.value, { lastModified: entry.lastModified, etag: entry.etag });
|
|
7603
|
+
}
|
|
7604
|
+
} catch {}
|
|
7605
|
+
}
|
|
7601
7606
|
|
|
7602
7607
|
// src/fetcher.ts
|
|
7603
7608
|
var PACKAGIST_API = "https://repo.packagist.org/p2";
|
|
7604
|
-
var PACKAGIST_PACKAGE_API = "https://packagist.org/packages";
|
|
7605
|
-
async function fetchDeprecatedInfo(packageName, noCache = false) {
|
|
7606
|
-
const cacheKey = `${packageName.replace("/", "_")}_deprecated`;
|
|
7607
|
-
if (!noCache) {
|
|
7608
|
-
const cached = await getCache(cacheKey);
|
|
7609
|
-
if (cached)
|
|
7610
|
-
return cached;
|
|
7611
|
-
}
|
|
7612
|
-
try {
|
|
7613
|
-
const url = `${PACKAGIST_PACKAGE_API}/${packageName}.json`;
|
|
7614
|
-
const response = await fetch(url);
|
|
7615
|
-
if (!response.ok)
|
|
7616
|
-
return {};
|
|
7617
|
-
const data = await response.json();
|
|
7618
|
-
const abandoned = data.package?.abandoned;
|
|
7619
|
-
if (!abandoned) {
|
|
7620
|
-
const result2 = {};
|
|
7621
|
-
if (!noCache)
|
|
7622
|
-
await setCache(cacheKey, result2);
|
|
7623
|
-
return result2;
|
|
7624
|
-
}
|
|
7625
|
-
if (typeof abandoned === "string") {
|
|
7626
|
-
const result2 = { deprecated: true, replacement: abandoned };
|
|
7627
|
-
if (!noCache)
|
|
7628
|
-
await setCache(cacheKey, result2);
|
|
7629
|
-
return result2;
|
|
7630
|
-
}
|
|
7631
|
-
const result = { deprecated: true };
|
|
7632
|
-
if (!noCache)
|
|
7633
|
-
await setCache(cacheKey, result);
|
|
7634
|
-
return result;
|
|
7635
|
-
} catch {
|
|
7636
|
-
return {};
|
|
7637
|
-
}
|
|
7638
|
-
}
|
|
7639
7609
|
async function fetchPackage(packageName, minStability = "stable", preferStable = true, currentVersion, allowMajor = true, noCache = false) {
|
|
7640
7610
|
const cacheKey = packageName.replace("/", "_");
|
|
7611
|
+
let cachedEntry = null;
|
|
7612
|
+
const headers = {};
|
|
7641
7613
|
if (!noCache) {
|
|
7642
|
-
|
|
7643
|
-
if (
|
|
7644
|
-
|
|
7614
|
+
cachedEntry = await getCacheEntry(cacheKey);
|
|
7615
|
+
if (cachedEntry?.lastModified) {
|
|
7616
|
+
headers["If-Modified-Since"] = cachedEntry.lastModified;
|
|
7617
|
+
}
|
|
7645
7618
|
}
|
|
7646
7619
|
try {
|
|
7647
7620
|
const url = `${PACKAGIST_API}/${packageName}.json`;
|
|
7648
|
-
const response = await fetch(url);
|
|
7621
|
+
const response = await fetch(url, { headers });
|
|
7622
|
+
if (response.status === 304 && cachedEntry) {
|
|
7623
|
+
await touchCache(cacheKey);
|
|
7624
|
+
return cachedEntry.value;
|
|
7625
|
+
}
|
|
7649
7626
|
if (!response.ok)
|
|
7650
7627
|
return null;
|
|
7651
7628
|
const data = await response.json();
|
|
@@ -7699,7 +7676,13 @@ async function fetchPackage(packageName, minStability = "stable", preferStable =
|
|
|
7699
7676
|
}
|
|
7700
7677
|
}
|
|
7701
7678
|
}
|
|
7702
|
-
const deprecatedInfo =
|
|
7679
|
+
const deprecatedInfo = {};
|
|
7680
|
+
if (typeof selectedVersion.abandoned === "string") {
|
|
7681
|
+
deprecatedInfo.deprecated = true;
|
|
7682
|
+
deprecatedInfo.replacement = selectedVersion.abandoned;
|
|
7683
|
+
} else if (selectedVersion.abandoned) {
|
|
7684
|
+
deprecatedInfo.deprecated = true;
|
|
7685
|
+
}
|
|
7703
7686
|
const result = {
|
|
7704
7687
|
latestVersion: selectedVersion.version,
|
|
7705
7688
|
releaseTime: selectedVersion.time,
|
|
@@ -7709,7 +7692,8 @@ async function fetchPackage(packageName, minStability = "stable", preferStable =
|
|
|
7709
7692
|
replacement: deprecatedInfo.replacement
|
|
7710
7693
|
};
|
|
7711
7694
|
if (!noCache) {
|
|
7712
|
-
|
|
7695
|
+
const lastModified = response.headers.get("Last-Modified") || undefined;
|
|
7696
|
+
await setCache(cacheKey, result, { lastModified });
|
|
7713
7697
|
}
|
|
7714
7698
|
return result;
|
|
7715
7699
|
} catch {
|
|
@@ -8073,7 +8057,7 @@ async function selectPackages(packages) {
|
|
|
8073
8057
|
// package.json
|
|
8074
8058
|
var package_default = {
|
|
8075
8059
|
name: "comze",
|
|
8076
|
-
version: "0.3.
|
|
8060
|
+
version: "0.3.1",
|
|
8077
8061
|
description: "A taze-like CLI for updating composer.json dependencies",
|
|
8078
8062
|
author: "qoqn",
|
|
8079
8063
|
license: "MIT",
|