Skip to content

Commit 94bb856

Browse files
committed
Detect non-v8 snapshotable systems
1 parent 944b399 commit 94bb856

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/tscSnapshot/tsc.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import fs = require("fs");
22
import path = require("path");
3-
import crypto = require("crypto");
43
import cp = require("child_process");
54

5+
let v8: typeof import("v8") | undefined;
6+
try {
7+
if (!process.versions.bun) {
8+
v8 = require("v8");
9+
}
10+
}
11+
catch {
12+
// do nothing
13+
}
14+
15+
const exe = path.join(__dirname, "tscReal.js");
16+
17+
if (!(v8 as any)?.startupSnapshot) {
18+
require(exe);
19+
throw new Error("unreachable");
20+
}
21+
622
const args = process.argv.slice(2);
723

824
const doBuildSnapshot = process.env.TYPESCRIPT_BUILD_SNAPSHOT === "true";
925

1026
function checksumFile(path: string) {
27+
const crypto = require("crypto") as typeof import("crypto");
1128
// Benchmarking shows that sha1 is the fastest hash.
1229
// It is theoretically insecure, but we're just using it to detect file mismatches.
1330
// TODO(jakebailey): If sha1 is ever removed, this will fail; we should try catch
@@ -18,10 +35,8 @@ function checksumFile(path: string) {
1835
return hash.digest("hex");
1936
}
2037

21-
const exe = path.join(__dirname, "tscReal.js");
2238
const exeHash = checksumFile(exe);
2339
const blobName = `${exe}.${process.version}.${exeHash}.blob`;
24-
// const blobName = `${exe}.${process.version}.blob`;
2540

2641
if (doBuildSnapshot) {
2742
// Build and atomic rename.

0 commit comments

Comments
 (0)