diff --git a/packages/rstack/bin/rs.js b/packages/rstack/bin/rs.js index a29c927f..2dd9fc9f 100755 --- a/packages/rstack/bin/rs.js +++ b/packages/rstack/bin/rs.js @@ -1,12 +1,17 @@ #!/usr/bin/env node import nodeModule from 'node:module'; -// enable on-disk code caching of all modules loaded by Node.js +// enable on-disk code caching and share its directory with child workers // requires Nodejs >= 22.8.0 -const { enableCompileCache } = nodeModule; +const { enableCompileCache, constants } = nodeModule; if (enableCompileCache) { try { - enableCompileCache(); + const { directory, status } = enableCompileCache(); + // ALREADY_ENABLED returns the active version-specific cache directory. + // Passing it to workers would append another version directory. + if (directory && status === constants.compileCacheStatus.ENABLED) { + process.env.NODE_COMPILE_CACHE = directory; + } } catch { // ignore errors }