-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathversions.ts
More file actions
68 lines (62 loc) · 1.49 KB
/
versions.ts
File metadata and controls
68 lines (62 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2018-2025 the Deno authors. MIT license.
interface WasmCrate {
name: string;
getDependencyVersion(name: string): string | undefined;
}
export const versions = {
"wasm-bindgen": "0.2.108",
"wasm-bindgen-futures": "0.4.58",
"js-sys": "0.3.85",
"web-sys": "0.3.85",
} as const;
export function verifyVersions(crate: WasmCrate) {
verifyVersion(crate, "wasm-bindgen", versions["wasm-bindgen"]);
verifyVersionAllowNone(
crate,
"wasm-bindgen-futures",
versions["wasm-bindgen-futures"],
);
verifyVersionAllowNone(crate, "js-sys", versions["js-sys"]);
verifyVersionAllowNone(crate, "web-sys", versions["web-sys"]);
}
function verifyVersionAllowNone(
crate: WasmCrate,
name: string,
expectedVersion: string,
) {
const actualVersion = crate.getDependencyVersion(name);
if (actualVersion != null) {
verifyVersionInner(
crate,
name,
actualVersion,
expectedVersion,
);
}
}
function verifyVersion(
crate: WasmCrate,
name: string,
expectedVersion: string,
) {
verifyVersionInner(
crate,
name,
crate.getDependencyVersion(name),
expectedVersion,
);
}
function verifyVersionInner(
crate: WasmCrate,
name: string,
actualVersion: string | undefined,
expectedVersion: string,
) {
if (actualVersion !== expectedVersion) {
throw new Error(
`The crate '${crate.name}' must have a dependency on ${name} ` +
`${expectedVersion} (found ` +
`${actualVersion ?? "<NOT FOUND>"}).`,
);
}
}