@intutic/proxy 1.6.3 → 1.7.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/bin/proxy.js +42 -3
- package/package.json +1 -1
package/bin/proxy.js
CHANGED
|
@@ -57,9 +57,28 @@ function cacheDir() {
|
|
|
57
57
|
return path.join(home, '.intutic', 'bin');
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Name the cached binary after the version that produced it.
|
|
62
|
+
*
|
|
63
|
+
* The cache used to be a single unversioned `intutic-proxy`, and nothing ever
|
|
64
|
+
* checked what was in it — `findExistingBinary` returned the first path that
|
|
65
|
+
* existed and `main` only downloaded when there was none. So upgrading the npm
|
|
66
|
+
* package did not upgrade the binary: anyone who ran `intutic connect` or
|
|
67
|
+
* `npx @intutic/proxy` before this kept executing whatever they first
|
|
68
|
+
* downloaded, indefinitely. Combined with the release tag having been pinned to
|
|
69
|
+
* a literal 1.6.0, that meant users stuck on a proxy that still required Valkey
|
|
70
|
+
* no matter how many times they upgraded.
|
|
71
|
+
*
|
|
72
|
+
* Versioning the filename makes a stale cache unrepresentable: a new version
|
|
73
|
+
* looks for a name that does not exist yet, so it downloads.
|
|
74
|
+
*/
|
|
75
|
+
function cachedBinaryName() {
|
|
76
|
+
return isWindows ? `intutic-proxy-${version}.exe` : `intutic-proxy-${version}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
60
79
|
/**
|
|
61
80
|
* Search order matches `intutic connect`: a locally built binary wins (so repo
|
|
62
|
-
* development never hits the network), then the
|
|
81
|
+
* development never hits the network), then the version-specific global cache.
|
|
63
82
|
*/
|
|
64
83
|
function findExistingBinary() {
|
|
65
84
|
const cache = cacheDir();
|
|
@@ -67,11 +86,30 @@ function findExistingBinary() {
|
|
|
67
86
|
path.join(__dirname, binaryName),
|
|
68
87
|
path.resolve(__dirname, '..', 'target', 'release', binaryName),
|
|
69
88
|
path.resolve(__dirname, '..', '..', '..', 'target', 'release', binaryName),
|
|
70
|
-
...(cache ? [path.join(cache,
|
|
89
|
+
...(cache ? [path.join(cache, cachedBinaryName())] : []),
|
|
71
90
|
];
|
|
72
91
|
return candidates.find((p) => fs.existsSync(p)) ?? null;
|
|
73
92
|
}
|
|
74
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Remove the pre-1.7.1 unversioned cache entry if present. Its version is
|
|
96
|
+
* unknowable, so it cannot be trusted or reused — and leaving it behind means
|
|
97
|
+
* every upgraded user carries a dead 39MB file forever.
|
|
98
|
+
*/
|
|
99
|
+
function pruneLegacyCache() {
|
|
100
|
+
const cache = cacheDir();
|
|
101
|
+
if (!cache) return;
|
|
102
|
+
const legacy = path.join(cache, binaryName);
|
|
103
|
+
try {
|
|
104
|
+
if (fs.existsSync(legacy)) {
|
|
105
|
+
fs.unlinkSync(legacy);
|
|
106
|
+
process.stderr.write('intutic-proxy: removed unversioned cached binary from a previous release\n');
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
// Best effort. A stale file we cannot delete is not a reason to fail.
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
75
113
|
async function downloadBinary(destPath) {
|
|
76
114
|
const assetName = resolveAssetName();
|
|
77
115
|
if (!assetName) {
|
|
@@ -108,6 +146,7 @@ async function downloadBinary(destPath) {
|
|
|
108
146
|
}
|
|
109
147
|
|
|
110
148
|
async function main() {
|
|
149
|
+
pruneLegacyCache();
|
|
111
150
|
let binaryPath = findExistingBinary();
|
|
112
151
|
|
|
113
152
|
if (!binaryPath) {
|
|
@@ -121,7 +160,7 @@ async function main() {
|
|
|
121
160
|
process.exit(1);
|
|
122
161
|
}
|
|
123
162
|
try {
|
|
124
|
-
binaryPath = await downloadBinary(path.join(cache,
|
|
163
|
+
binaryPath = await downloadBinary(path.join(cache, cachedBinaryName()));
|
|
125
164
|
} catch (err) {
|
|
126
165
|
process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
127
166
|
process.exit(1);
|