1
1
import fs = require( "fs" ) ;
2
2
import path = require( "path" ) ;
3
- import crypto = require( "crypto" ) ;
4
3
import cp = require( "child_process" ) ;
5
4
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
+
6
22
const args = process . argv . slice ( 2 ) ;
7
23
8
24
const doBuildSnapshot = process . env . TYPESCRIPT_BUILD_SNAPSHOT === "true" ;
9
25
10
26
function checksumFile ( path : string ) {
27
+ const crypto = require ( "crypto" ) as typeof import ( "crypto" ) ;
11
28
// Benchmarking shows that sha1 is the fastest hash.
12
29
// It is theoretically insecure, but we're just using it to detect file mismatches.
13
30
// TODO(jakebailey): If sha1 is ever removed, this will fail; we should try catch
@@ -18,10 +35,8 @@ function checksumFile(path: string) {
18
35
return hash . digest ( "hex" ) ;
19
36
}
20
37
21
- const exe = path . join ( __dirname , "tscReal.js" ) ;
22
38
const exeHash = checksumFile ( exe ) ;
23
39
const blobName = `${ exe } .${ process . version } .${ exeHash } .blob` ;
24
- // const blobName = `${exe}.${process.version}.blob`;
25
40
26
41
if ( doBuildSnapshot ) {
27
42
// Build and atomic rename.
0 commit comments