(file: string)
| 48 | } |
| 49 | |
| 50 | const compile = (file: string): string => { |
| 51 | const { mtimeMs, size } = Fs.statSync(file) |
| 52 | const cached = cache === undefined ? undefined : Path.join( |
| 53 | cache, |
| 54 | Crypto.createHash("sha1") |
| 55 | .update(`${version}\0${file}\0${mtimeMs}\0${size}`) |
| 56 | .digest("hex") + ".js" |
| 57 | ) |
| 58 | if (cached !== undefined) { |
| 59 | try { |
| 60 | return Fs.readFileSync(cached, "utf8") |
| 61 | } catch { |
| 62 | // A missing or unreadable cache entry falls back to compilation. |
| 63 | } |
| 64 | } |
| 65 | const code = compilerOf()(Fs.readFileSync(file, "utf8"), file) |
| 66 | if (cached !== undefined) { |
| 67 | // Rename atomically so other workers never read a partial file. |
| 68 | Fs.mkdirSync(cache!, { recursive: true }) |
| 69 | const temp = `${cached}.${process.pid}.${Math.random()}` |
| 70 | Fs.writeFileSync(temp, code) |
| 71 | Fs.renameSync(temp, cached) |
| 72 | } |
| 73 | return code |
| 74 | } |
| 75 | |
| 76 | const variants = [`.${platform}.js`, ".native.js"] |
| 77 | const relative = [...variants, ".js", "", "/index.js"] |
no test coverage detected