Skip to content

Commit fc0678b

Browse files
authored
perf(fmt): share compile cache with workers (#213)
1 parent 43905a6 commit fc0678b

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

packages/rstack/bin/rs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/usr/bin/env node
22
import nodeModule from 'node:module';
33

4-
// enable on-disk code caching of all modules loaded by Node.js
4+
// enable on-disk code caching and share its directory with child workers
55
// requires Nodejs >= 22.8.0
6-
const { enableCompileCache } = nodeModule;
6+
const { enableCompileCache, constants } = nodeModule;
77
if (enableCompileCache) {
88
try {
9-
enableCompileCache();
9+
const { directory, status } = enableCompileCache();
10+
// ALREADY_ENABLED returns the active version-specific cache directory.
11+
// Passing it to workers would append another version directory.
12+
if (directory && status === constants.compileCacheStatus.ENABLED) {
13+
process.env.NODE_COMPILE_CACHE = directory;
14+
}
1015
} catch {
1116
// ignore errors
1217
}

0 commit comments

Comments
 (0)