no-mistakes 0.31.2 → 0.31.4
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/package.json
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const { createHash, randomBytes } = require("node:crypto");
|
|
4
4
|
const { closeSync, createReadStream, existsSync, openSync, readSync } = require("node:fs");
|
|
5
|
-
const { chmod, mkdir, rename, rm } = require("node:fs/promises");
|
|
5
|
+
const { chmod, mkdir, rename, rm, writeFile } = require("node:fs/promises");
|
|
6
6
|
const { join } = require("node:path");
|
|
7
7
|
|
|
8
8
|
const { assetName, parseChecksum, releaseBaseUrl } = require("./assets");
|
|
9
9
|
const { download, fetchText } = require("./download");
|
|
10
10
|
const { platformTarget, supportedGlibc } = require("./platform");
|
|
11
|
+
const { installedVersion, versionMarkerPath } = require("./version-marker");
|
|
11
12
|
|
|
12
13
|
const PLACEHOLDER_TEXT = "Native binary placeholder.";
|
|
13
14
|
const PLACEHOLDER_READ_BYTES = 256;
|
|
@@ -48,7 +49,12 @@ async function install(binName, repository, options = {}) {
|
|
|
48
49
|
);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
if (
|
|
52
|
+
if (
|
|
53
|
+
options.checkExisting &&
|
|
54
|
+
destinationExists &&
|
|
55
|
+
!destinationIsPlaceholder &&
|
|
56
|
+
installedVersion(destination) === version
|
|
57
|
+
) {
|
|
52
58
|
return destination;
|
|
53
59
|
}
|
|
54
60
|
|
|
@@ -84,6 +90,7 @@ async function install(binName, repository, options = {}) {
|
|
|
84
90
|
await chmod(temp, 0o755);
|
|
85
91
|
}
|
|
86
92
|
await rename(temp, destination);
|
|
93
|
+
await writeFile(versionMarkerPath(destination), version);
|
|
87
94
|
return destination;
|
|
88
95
|
} catch (error) {
|
|
89
96
|
await rm(temp, { force: true });
|
|
@@ -202,8 +209,10 @@ function unsupportedPlatformMessage(
|
|
|
202
209
|
|
|
203
210
|
module.exports = {
|
|
204
211
|
install,
|
|
212
|
+
installedVersion,
|
|
205
213
|
isPlaceholder,
|
|
206
214
|
sha256,
|
|
207
215
|
unsupportedPlatformMessage,
|
|
208
216
|
validateReleaseBaseUrl,
|
|
217
|
+
versionMarkerPath,
|
|
209
218
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { readFileSync } = require("node:fs");
|
|
4
|
+
|
|
5
|
+
function versionMarkerPath(destination) {
|
|
6
|
+
return `${destination}.version`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// The destination binary alone can't tell us which version it is (the CLI's
|
|
10
|
+
// own --version requires spawning a process, and the N-API .node addon isn't
|
|
11
|
+
// executable at all), so track the installed version in a small sidecar file
|
|
12
|
+
// written right after a successful install. A missing or mismatched marker
|
|
13
|
+
// means we can't prove the existing file matches the requested version, so
|
|
14
|
+
// checkExisting must fall through to a real (re)download rather than trust
|
|
15
|
+
// stale bytes left behind by an earlier install of a different version.
|
|
16
|
+
function installedVersion(destination) {
|
|
17
|
+
try {
|
|
18
|
+
return readFileSync(versionMarkerPath(destination), "utf8").trim();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error.code === "ENOENT") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
installedVersion,
|
|
29
|
+
versionMarkerPath,
|
|
30
|
+
};
|