@dev.fast/diffr 0.1.10 → 0.1.12
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/README.md +9 -24
- package/dist/binary.d.ts +2 -0
- package/dist/binary.js +13 -0
- package/dist/contract.d.ts +8 -14
- package/dist/contract.js +5 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +9 -8
- package/src/binary.ts +13 -0
- package/src/contract.ts +15 -23
- package/src/index.ts +1 -0
- package/bin/fetch.mjs +0 -93
- package/pins.json +0 -20
package/README.md
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
# @dev.fast/diffr
|
|
2
2
|
|
|
3
|
-
TypeScript types
|
|
4
|
-
The package version matches the diffr release.
|
|
3
|
+
TypeScript types and zod validators for diffr's NDJSON protocol, plus the diffr
|
|
4
|
+
executable. The package version matches the diffr release.
|
|
5
5
|
|
|
6
6
|
```ts
|
|
7
7
|
import { decodeStructuralDiffEvent } from "@dev.fast/diffr";
|
|
8
8
|
const event = decodeStructuralDiffEvent(line);
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Supports macOS arm64, macOS x64, Linux arm64, Linux x64, and Windows x64 (`diffr.exe`). `--check` verifies an existing install without
|
|
16
|
-
network access. Downloads warn on network failure unless `--required`; invalid
|
|
17
|
-
hashes or archives always fail.
|
|
18
|
-
|
|
19
|
-
`--full` fetches the full edition, which adds the parsers lean builds omit (Apex,
|
|
20
|
-
Fortran, F#, Haskell, Julia, OCaml, QML, Verilog, VHDL). It requires full-edition
|
|
21
|
-
pins, which start with the next release.
|
|
11
|
+
`diffrBinaryPath()` returns the executable from the `@dev.fast/diffr-<platform>-<arch>`
|
|
12
|
+
optional dependency npm installed for this machine, or `undefined` when there is none
|
|
13
|
+
(musl Linux, Windows arm64, or `--omit=optional`). Platforms: macOS arm64 and x64,
|
|
14
|
+
glibc Linux arm64 and x64, Windows x64.
|
|
22
15
|
|
|
23
16
|
## Wire changes
|
|
24
17
|
|
|
@@ -26,20 +19,12 @@ Keep these files in sync:
|
|
|
26
19
|
|
|
27
20
|
| Files (from repo root) | Check |
|
|
28
21
|
|---|---|
|
|
29
|
-
| `src/protocol/mod.rs`, `src/pairing.rs`, `diffr-ts/src/contract.ts` | Contract tests against the binary; Rust version check |
|
|
22
|
+
| `crates/diffr-core/src/protocol/mod.rs`, `crates/diffr-core/src/pairing.rs`, `diffr-ts/src/contract.ts` | Contract tests against the binary; Rust version check |
|
|
30
23
|
| `docs/streaming.md` | Review against the wire format |
|
|
31
24
|
| `tui/packages/hunk/src/diffr/wire.ts` (v3 only) | TUI fixture tests |
|
|
32
25
|
| Review's `packages/review-protocol/package.json` and `packages/review/package.json` | Exact package version pins |
|
|
33
26
|
|
|
34
27
|
## Release
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
older pins continue to use the combined archives:
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
bun install --frozen-lockfile
|
|
42
|
-
npm run pin
|
|
43
|
-
bun run typecheck && bun test
|
|
44
|
-
npm publish --access public
|
|
45
|
-
```
|
|
29
|
+
Bump `diffr-ts/package.json` with `Cargo.toml`. The release workflow publishes the
|
|
30
|
+
platform packages and this package from the tag, using npm trusted publishing.
|
package/dist/binary.d.ts
ADDED
package/dist/binary.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
/** The diffr executable from the installed platform package, if npm installed one for this machine. */
|
|
3
|
+
export function diffrBinaryPath() {
|
|
4
|
+
const name = process.platform === "win32" ? "diffr.exe" : "diffr";
|
|
5
|
+
try {
|
|
6
|
+
// Resolve from this package's own directory, which also holds when a bundler inlines it.
|
|
7
|
+
const self = createRequire(import.meta.url).resolve("@dev.fast/diffr/package.json");
|
|
8
|
+
return createRequire(self).resolve(`@dev.fast/diffr-${process.platform}-${process.arch}/${name}`);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mirrors src/protocol/mod.rs and src/pairing.rs. See ../README.md for sync checks.
|
|
2
|
+
* Mirrors crates/diffr-core/src/protocol/mod.rs and crates/diffr-core/src/pairing.rs. See ../README.md for sync checks.
|
|
3
3
|
* Import only zod: Review embeds this file in generated source.
|
|
4
4
|
* Defaults are omitted, not null. Lines are zero-based, columns are UTF-8 bytes,
|
|
5
5
|
* and ranges are half-open.
|
|
@@ -16,9 +16,7 @@ export type StructuralPairing<T> = {
|
|
|
16
16
|
rhs: T;
|
|
17
17
|
lhs?: never;
|
|
18
18
|
};
|
|
19
|
-
export declare const STRUCTURAL_DIFF_WIRE_VERSION =
|
|
20
|
-
/** Base stream version without --stream-annotations. */
|
|
21
|
-
export declare const STRUCTURAL_DIFF_BASE_WIRE_VERSION = 3;
|
|
19
|
+
export declare const STRUCTURAL_DIFF_WIRE_VERSION = 3;
|
|
22
20
|
export type StructuralDiffEvent = {
|
|
23
21
|
type: "start";
|
|
24
22
|
version: number;
|
|
@@ -28,16 +26,7 @@ export type StructuralDiffEvent = {
|
|
|
28
26
|
} | ({
|
|
29
27
|
type: "file";
|
|
30
28
|
file: StructuralPairing<StructuralFileRef>;
|
|
31
|
-
visibility?: StructuralVisibility;
|
|
32
29
|
} & StructuralOutcome) | {
|
|
33
|
-
type: "annotations";
|
|
34
|
-
file: StructuralPairing<StructuralFileRef>;
|
|
35
|
-
annotations: {
|
|
36
|
-
region_id: number;
|
|
37
|
-
label: string;
|
|
38
|
-
}[];
|
|
39
|
-
error?: StructuralProblem;
|
|
40
|
-
} | {
|
|
41
30
|
type: "complete";
|
|
42
31
|
succeeded: number;
|
|
43
32
|
failed: number;
|
|
@@ -109,7 +98,8 @@ export declare const StructuralDiffSchema: z.ZodType<StructuralDiff>;
|
|
|
109
98
|
export type StructuralSource = {
|
|
110
99
|
text: string;
|
|
111
100
|
syntax?: StructuralSyntaxSpan[];
|
|
112
|
-
|
|
101
|
+
/** The whole file, as one fold. Both sides' roots share a fold_state_id; its visibility is the file's. */
|
|
102
|
+
root: StructuralRegion;
|
|
113
103
|
};
|
|
114
104
|
export declare const StructuralSourceSchema: z.ZodType<StructuralSource>;
|
|
115
105
|
export type StructuralBinaryRef = {
|
|
@@ -138,6 +128,10 @@ export type StructuralNode = {
|
|
|
138
128
|
} | {
|
|
139
129
|
kind: "fold";
|
|
140
130
|
children: StructuralRegion[];
|
|
131
|
+
/** Where the fold's content starts. Collapsed rows sit at this column. */
|
|
132
|
+
indent: StructuralPos;
|
|
133
|
+
/** From the opener to the closer, before rounding to lines. Absent without an opener. */
|
|
134
|
+
syntax?: StructuralSourceRange;
|
|
141
135
|
};
|
|
142
136
|
export declare const StructuralNodeSchema: z.ZodType<StructuralNode>;
|
|
143
137
|
export type StructuralSpan = {
|
package/dist/contract.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mirrors src/protocol/mod.rs and src/pairing.rs. See ../README.md for sync checks.
|
|
2
|
+
* Mirrors crates/diffr-core/src/protocol/mod.rs and crates/diffr-core/src/pairing.rs. See ../README.md for sync checks.
|
|
3
3
|
* Import only zod: Review embeds this file in generated source.
|
|
4
4
|
* Defaults are omitted, not null. Lines are zero-based, columns are UTF-8 bytes,
|
|
5
5
|
* and ranges are half-open.
|
|
@@ -13,9 +13,7 @@ function structuralPairingSchema(value) {
|
|
|
13
13
|
]);
|
|
14
14
|
}
|
|
15
15
|
const structuralU32 = z.number().int().min(0).max(0xffff_ffff);
|
|
16
|
-
export const STRUCTURAL_DIFF_WIRE_VERSION =
|
|
17
|
-
/** Base stream version without --stream-annotations. */
|
|
18
|
-
export const STRUCTURAL_DIFF_BASE_WIRE_VERSION = 3;
|
|
16
|
+
export const STRUCTURAL_DIFF_WIRE_VERSION = 3;
|
|
19
17
|
export const StructuralDiffEventSchema = z.lazy(() => z.union([
|
|
20
18
|
z.object({
|
|
21
19
|
type: z.literal("start"),
|
|
@@ -28,15 +26,8 @@ export const StructuralDiffEventSchema = z.lazy(() => z.union([
|
|
|
28
26
|
.object({
|
|
29
27
|
type: z.literal("file"),
|
|
30
28
|
file: structuralPairingSchema(StructuralFileRefSchema),
|
|
31
|
-
visibility: StructuralVisibilitySchema.optional(),
|
|
32
29
|
})
|
|
33
30
|
.and(StructuralOutcomeSchema),
|
|
34
|
-
z.object({
|
|
35
|
-
type: z.literal("annotations"),
|
|
36
|
-
file: structuralPairingSchema(StructuralFileRefSchema),
|
|
37
|
-
annotations: z.array(z.object({ region_id: structuralU32, label: z.string() })),
|
|
38
|
-
error: StructuralProblemSchema.optional(),
|
|
39
|
-
}),
|
|
40
31
|
z.object({
|
|
41
32
|
type: z.literal("complete"),
|
|
42
33
|
succeeded: structuralU32,
|
|
@@ -100,7 +91,7 @@ export const StructuralDiffSchema = z.lazy(() => z.union([
|
|
|
100
91
|
export const StructuralSourceSchema = z.lazy(() => z.object({
|
|
101
92
|
text: z.string(),
|
|
102
93
|
syntax: z.array(StructuralSyntaxSpanSchema).optional(),
|
|
103
|
-
|
|
94
|
+
root: StructuralRegionSchema,
|
|
104
95
|
}));
|
|
105
96
|
export const StructuralBinaryRefSchema = z.lazy(() => z.object({ size: z.number().int().nonnegative() }));
|
|
106
97
|
export const StructuralSyntaxSpanSchema = z.lazy(() => z.object({
|
|
@@ -127,6 +118,8 @@ export const StructuralNodeSchema = z.lazy(() => z.union([
|
|
|
127
118
|
z.object({
|
|
128
119
|
kind: z.literal("fold"),
|
|
129
120
|
children: z.array(StructuralRegionSchema),
|
|
121
|
+
indent: StructuralPosSchema,
|
|
122
|
+
syntax: StructuralSourceRangeSchema.optional(),
|
|
130
123
|
}),
|
|
131
124
|
]));
|
|
132
125
|
export const StructuralSpanSchema = z.lazy(() => z.object({
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev.fast/diffr",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "diffr's NDJSON wire contract, validators, and
|
|
3
|
+
"version": "0.1.12",
|
|
4
|
+
"description": "diffr's NDJSON wire contract, validators, and the diffr binary for this platform",
|
|
5
5
|
"repository": "https://github.com/devdotfast/diffr",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -14,23 +14,17 @@
|
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./src/*": "./src/*"
|
|
16
16
|
},
|
|
17
|
-
"bin": {
|
|
18
|
-
"diffr-fetch": "bin/fetch.mjs"
|
|
19
|
-
},
|
|
20
17
|
"files": [
|
|
21
18
|
"dist",
|
|
22
19
|
"src",
|
|
23
20
|
"!src/*.test.ts",
|
|
24
21
|
"!src/test-binary.ts",
|
|
25
|
-
"bin",
|
|
26
|
-
"pins.json",
|
|
27
22
|
"README.md"
|
|
28
23
|
],
|
|
29
24
|
"scripts": {
|
|
30
25
|
"build": "tsc -p tsconfig.build.json",
|
|
31
26
|
"typecheck": "tsc --noEmit",
|
|
32
27
|
"test": "bun test",
|
|
33
|
-
"pin": "node scripts/pin.mjs",
|
|
34
28
|
"prepack": "npm run build"
|
|
35
29
|
},
|
|
36
30
|
"peerDependencies": {
|
|
@@ -43,5 +37,12 @@
|
|
|
43
37
|
},
|
|
44
38
|
"engines": {
|
|
45
39
|
"node": ">=20"
|
|
40
|
+
},
|
|
41
|
+
"optionalDependencies": {
|
|
42
|
+
"@dev.fast/diffr-darwin-arm64": "0.1.12",
|
|
43
|
+
"@dev.fast/diffr-darwin-x64": "0.1.12",
|
|
44
|
+
"@dev.fast/diffr-linux-x64": "0.1.12",
|
|
45
|
+
"@dev.fast/diffr-linux-arm64": "0.1.12",
|
|
46
|
+
"@dev.fast/diffr-win32-x64": "0.1.12"
|
|
46
47
|
}
|
|
47
48
|
}
|
package/src/binary.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
/** The diffr executable from the installed platform package, if npm installed one for this machine. */
|
|
4
|
+
export function diffrBinaryPath(): string | undefined {
|
|
5
|
+
const name = process.platform === "win32" ? "diffr.exe" : "diffr";
|
|
6
|
+
try {
|
|
7
|
+
// Resolve from this package's own directory, which also holds when a bundler inlines it.
|
|
8
|
+
const self = createRequire(import.meta.url).resolve("@dev.fast/diffr/package.json");
|
|
9
|
+
return createRequire(self).resolve(`@dev.fast/diffr-${process.platform}-${process.arch}/${name}`);
|
|
10
|
+
} catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/contract.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Mirrors src/protocol/mod.rs and src/pairing.rs. See ../README.md for sync checks.
|
|
2
|
+
* Mirrors crates/diffr-core/src/protocol/mod.rs and crates/diffr-core/src/pairing.rs. See ../README.md for sync checks.
|
|
3
3
|
* Import only zod: Review embeds this file in generated source.
|
|
4
4
|
* Defaults are omitted, not null. Lines are zero-based, columns are UTF-8 bytes,
|
|
5
5
|
* and ranges are half-open.
|
|
@@ -24,9 +24,7 @@ function structuralPairingSchema<T>(
|
|
|
24
24
|
|
|
25
25
|
const structuralU32 = z.number().int().min(0).max(0xffff_ffff);
|
|
26
26
|
|
|
27
|
-
export const STRUCTURAL_DIFF_WIRE_VERSION =
|
|
28
|
-
/** Base stream version without --stream-annotations. */
|
|
29
|
-
export const STRUCTURAL_DIFF_BASE_WIRE_VERSION = 3;
|
|
27
|
+
export const STRUCTURAL_DIFF_WIRE_VERSION = 3;
|
|
30
28
|
|
|
31
29
|
export type StructuralDiffEvent =
|
|
32
30
|
| {
|
|
@@ -39,14 +37,7 @@ export type StructuralDiffEvent =
|
|
|
39
37
|
| ({
|
|
40
38
|
type: "file";
|
|
41
39
|
file: StructuralPairing<StructuralFileRef>;
|
|
42
|
-
visibility?: StructuralVisibility;
|
|
43
40
|
} & StructuralOutcome)
|
|
44
|
-
| {
|
|
45
|
-
type: "annotations";
|
|
46
|
-
file: StructuralPairing<StructuralFileRef>;
|
|
47
|
-
annotations: { region_id: number; label: string }[];
|
|
48
|
-
error?: StructuralProblem;
|
|
49
|
-
}
|
|
50
41
|
| {
|
|
51
42
|
type: "complete";
|
|
52
43
|
succeeded: number;
|
|
@@ -68,17 +59,8 @@ export const StructuralDiffEventSchema: z.ZodType<StructuralDiffEvent> = z.lazy(
|
|
|
68
59
|
.object({
|
|
69
60
|
type: z.literal("file"),
|
|
70
61
|
file: structuralPairingSchema(StructuralFileRefSchema),
|
|
71
|
-
visibility: StructuralVisibilitySchema.optional(),
|
|
72
62
|
})
|
|
73
63
|
.and(StructuralOutcomeSchema),
|
|
74
|
-
z.object({
|
|
75
|
-
type: z.literal("annotations"),
|
|
76
|
-
file: structuralPairingSchema(StructuralFileRefSchema),
|
|
77
|
-
annotations: z.array(
|
|
78
|
-
z.object({ region_id: structuralU32, label: z.string() }),
|
|
79
|
-
),
|
|
80
|
-
error: StructuralProblemSchema.optional(),
|
|
81
|
-
}),
|
|
82
64
|
z.object({
|
|
83
65
|
type: z.literal("complete"),
|
|
84
66
|
succeeded: structuralU32,
|
|
@@ -233,14 +215,15 @@ export const StructuralDiffSchema: z.ZodType<StructuralDiff> = z.lazy(() =>
|
|
|
233
215
|
export type StructuralSource = {
|
|
234
216
|
text: string;
|
|
235
217
|
syntax?: StructuralSyntaxSpan[];
|
|
236
|
-
|
|
218
|
+
/** The whole file, as one fold. Both sides' roots share a fold_state_id; its visibility is the file's. */
|
|
219
|
+
root: StructuralRegion;
|
|
237
220
|
};
|
|
238
221
|
|
|
239
222
|
export const StructuralSourceSchema: z.ZodType<StructuralSource> = z.lazy(() =>
|
|
240
223
|
z.object({
|
|
241
224
|
text: z.string(),
|
|
242
225
|
syntax: z.array(StructuralSyntaxSpanSchema).optional(),
|
|
243
|
-
|
|
226
|
+
root: StructuralRegionSchema,
|
|
244
227
|
}),
|
|
245
228
|
);
|
|
246
229
|
|
|
@@ -290,7 +273,14 @@ export const StructuralRegionSchema: z.ZodType<StructuralRegion> = z.lazy(() =>
|
|
|
290
273
|
|
|
291
274
|
export type StructuralNode =
|
|
292
275
|
| { kind: "leaf"; alignment_id: number; changed?: StructuralSpan[] }
|
|
293
|
-
| {
|
|
276
|
+
| {
|
|
277
|
+
kind: "fold";
|
|
278
|
+
children: StructuralRegion[];
|
|
279
|
+
/** Where the fold's content starts. Collapsed rows sit at this column. */
|
|
280
|
+
indent: StructuralPos;
|
|
281
|
+
/** From the opener to the closer, before rounding to lines. Absent without an opener. */
|
|
282
|
+
syntax?: StructuralSourceRange;
|
|
283
|
+
};
|
|
294
284
|
|
|
295
285
|
export const StructuralNodeSchema: z.ZodType<StructuralNode> = z.lazy(() =>
|
|
296
286
|
z.union([
|
|
@@ -302,6 +292,8 @@ export const StructuralNodeSchema: z.ZodType<StructuralNode> = z.lazy(() =>
|
|
|
302
292
|
z.object({
|
|
303
293
|
kind: z.literal("fold"),
|
|
304
294
|
children: z.array(StructuralRegionSchema),
|
|
295
|
+
indent: StructuralPosSchema,
|
|
296
|
+
syntax: StructuralSourceRangeSchema.optional(),
|
|
305
297
|
}),
|
|
306
298
|
]),
|
|
307
299
|
);
|
package/src/index.ts
CHANGED
package/bin/fetch.mjs
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
import { spawnSync } from "node:child_process";
|
|
4
|
-
import { chmodSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { dirname, join, resolve } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { parseArgs } from "node:util";
|
|
8
|
-
|
|
9
|
-
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
-
const targets = { "darwin-arm64": "aarch64-apple-darwin", "darwin-x64": "x86_64-apple-darwin", "linux-x64": "x86_64-unknown-linux-gnu", "linux-arm64": "aarch64-unknown-linux-gnu", "win32-x64": "x86_64-pc-windows-msvc" };
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
await main();
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.error(`diffr-fetch: ${error.message}`);
|
|
16
|
-
process.exitCode = 1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
const { values } = parseArgs({ options: {
|
|
21
|
-
into: { type: "string" },
|
|
22
|
-
full: { type: "boolean", default: false },
|
|
23
|
-
check: { type: "boolean" },
|
|
24
|
-
required: { type: "boolean" },
|
|
25
|
-
pins: { type: "string", default: join(root, "pins.json") },
|
|
26
|
-
} });
|
|
27
|
-
if (!values.into) throw new Error("--into <dir> is required");
|
|
28
|
-
const into = resolve(values.into);
|
|
29
|
-
const { version } = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
30
|
-
const pins = JSON.parse(readFileSync(values.pins, "utf8"));
|
|
31
|
-
if (pins.version !== version) throw new Error(`pins.json is for ${pins.version}, package is ${version}; run \`npm run pin\``);
|
|
32
|
-
const target = targets[`${process.platform}-${process.arch}`];
|
|
33
|
-
if (!target) throw new Error(`no diffr release for ${process.platform}-${process.arch}`);
|
|
34
|
-
const pin = values.full ? pins.full : pins;
|
|
35
|
-
if (!pin) throw new Error(`pins.json has no full edition for ${version}`);
|
|
36
|
-
const expected = pin.sha256?.[target];
|
|
37
|
-
if (typeof expected !== "string" || !/^[a-f0-9]{64}$/.test(expected)) {
|
|
38
|
-
throw new Error(`pins.json has no valid sha256 for ${target}`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const name = process.platform === "win32" ? "diffr.exe" : "diffr";
|
|
42
|
-
const binary = join(into, name);
|
|
43
|
-
const stampPath = join(into, "diffr.stamp.json");
|
|
44
|
-
let installed = false;
|
|
45
|
-
try {
|
|
46
|
-
const stamp = JSON.parse(readFileSync(stampPath, "utf8"));
|
|
47
|
-
const stat = lstatSync(binary);
|
|
48
|
-
installed = stat.isFile() && (process.platform === "win32" || (stat.mode & 0o111) !== 0) && stamp.version === version && stamp.target === target
|
|
49
|
-
&& Boolean(stamp.full) === values.full;
|
|
50
|
-
} catch { /* Missing or damaged installations are fetched again. */ }
|
|
51
|
-
if (installed) {
|
|
52
|
-
console.log(`diffr ${version} (${target}) already at ${binary}`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (values.check) throw new Error(`${binary} is missing or not diffr ${version} (${target})`);
|
|
56
|
-
|
|
57
|
-
const artifact = values.full ? "diffr-cli-full" : pins.artifact ?? "diffr";
|
|
58
|
-
if (!["diffr", "diffr-cli", "diffr-cli-full"].includes(artifact)) throw new Error(`unknown pinned artifact: ${artifact}`);
|
|
59
|
-
const asset = `${artifact}-${version}-${target}.tar.gz`;
|
|
60
|
-
const url = `https://github.com/devdotfast/diffr/releases/download/${version}/${asset}`;
|
|
61
|
-
let bytes;
|
|
62
|
-
try {
|
|
63
|
-
const response = await fetch(url, { redirect: "follow", signal: AbortSignal.timeout(120_000) });
|
|
64
|
-
if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`);
|
|
65
|
-
bytes = Buffer.from(await response.arrayBuffer());
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (values.required) throw new Error(`could not download ${url}: ${error.message}`);
|
|
68
|
-
console.warn(`diffr-fetch: could not download ${url}: ${error.message}; continuing without a bundled diffr`);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const actual = createHash("sha256").update(bytes).digest("hex");
|
|
72
|
-
if (actual !== expected) throw new Error(`${asset} sha256 ${actual} does not match pinned ${expected}`);
|
|
73
|
-
|
|
74
|
-
mkdirSync(into, { recursive: true });
|
|
75
|
-
const staging = mkdtempSync(join(into, ".diffr-"));
|
|
76
|
-
try {
|
|
77
|
-
writeFileSync(join(staging, "archive.tar.gz"), bytes);
|
|
78
|
-
// Relative paths: GNU tar on Windows reads "C:" in an archive path as a remote host.
|
|
79
|
-
const tar = spawnSync("tar", ["-xzf", "archive.tar.gz", name], { cwd: staging, encoding: "utf8" });
|
|
80
|
-
const extracted = join(staging, name);
|
|
81
|
-
if (tar.status !== 0 || !lstatSync(extracted).isFile()) {
|
|
82
|
-
throw new Error(`${asset} does not contain a regular ${name} file at its root`);
|
|
83
|
-
}
|
|
84
|
-
chmodSync(extracted, 0o755);
|
|
85
|
-
const stamp = join(staging, "stamp.json");
|
|
86
|
-
writeFileSync(stamp, `${JSON.stringify({ version, target, ...(values.full && { full: true }) }, null, 2)}\n`);
|
|
87
|
-
renameSync(extracted, binary);
|
|
88
|
-
renameSync(stamp, stampPath);
|
|
89
|
-
} finally {
|
|
90
|
-
rmSync(staging, { recursive: true, force: true });
|
|
91
|
-
}
|
|
92
|
-
console.log(`diffr ${version} (${target}) installed at ${binary}`);
|
|
93
|
-
}
|
package/pins.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.1.10",
|
|
3
|
-
"artifact": "diffr-cli",
|
|
4
|
-
"sha256": {
|
|
5
|
-
"aarch64-apple-darwin": "2f67b7f4c096445047c618687a35eff40fd3a637683a738a59c40f702d97dd72",
|
|
6
|
-
"x86_64-apple-darwin": "674b719f45944ac387e58f21529e2a52a15c72d9cb28906e5e8ce7b28773c4da",
|
|
7
|
-
"x86_64-unknown-linux-gnu": "190c506b238d95f15a552b3983cd3351a5eb385f2057b5a08c90d87a2b466075",
|
|
8
|
-
"aarch64-unknown-linux-gnu": "91abbca8f38cb3de355cbc8a47086686c7e0f88961d6e2012fbefcdee1979607",
|
|
9
|
-
"x86_64-pc-windows-msvc": "0e129b2cf5c86af44643861da42656fc266f2e1f94ab501f0a2b34dc6efff1b7"
|
|
10
|
-
},
|
|
11
|
-
"full": {
|
|
12
|
-
"sha256": {
|
|
13
|
-
"aarch64-apple-darwin": "6675ba404990be3e7b7f8e26b113b7f083e609e88c7eae366e3367a4e32364d5",
|
|
14
|
-
"x86_64-apple-darwin": "c9188df81078fe6bb3fbae2b44e7c1fff9b37cbe66c7cd9c11091c3d151e4dcf",
|
|
15
|
-
"x86_64-unknown-linux-gnu": "a56aa73980850ecdfdce201253d37d06a38ef30cdb0507d61bc973e944f4174a",
|
|
16
|
-
"aarch64-unknown-linux-gnu": "d6788ac5e17e986ce2f2ebc6069dc27bcb127847f38632a7cfecf434820e3f81",
|
|
17
|
-
"x86_64-pc-windows-msvc": "d10f2fbb55df4a42e3305c531ffd1e615bca494b8161d4817ed946239063b67b"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|