MCPcopy Create free account
hub / github.com/Effect-TS/effect / compile

Function compile

packages/ui/native/src/node/internal/vitest.ts:50–74  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

48}
49
50const 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
76const variants = [`.${platform}.js`, ".native.js"]
77const relative = [...variants, ".js", "", "/index.js"]

Callers 1

loadFunction · 0.70

Calls 4

compilerOfFunction · 0.85
updateMethod · 0.65
joinMethod · 0.45
digestMethod · 0.45

Tested by

no test coverage detected