From 97a437e7ea98686cc6b453f79678fc0cb85226b5 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sun, 23 Aug 2026 10:14:37 +0200 Subject: [PATCH] module: add a read-only mode to the compile cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A compile cache generated ahead of time and shipped inside an application package should only ever be read: the package may be immutable or covered by an integrity check, and a cache directory that appears at run time would be a surprise. Add readOnly to module.enableCompileCache() and NODE_COMPILE_CACHE_READONLY=1: existing entries are loaded as before, nothing is serialized or persisted, flushCompileCache() is a no-op, and the cache directory is used as found rather than created, so enabling against a missing directory fails instead of making one. Signed-off-by: Shelley Vohr PR-URL: https://github.com/nodejs/node/pull/65302 Reviewed-By: James M Snell Reviewed-By: René --- doc/api/cli.md | 9 +++ doc/api/module.md | 18 +++++ doc/node.1 | 4 ++ lib/internal/modules/helpers.js | 15 ++-- src/compile_cache.cc | 70 ++++++++++++++----- src/compile_cache.h | 19 ++++- src/env.cc | 10 ++- src/node_modules.cc | 5 +- .../test-compile-cache-api-readonly.js | 65 +++++++++++++++++ 9 files changed, 189 insertions(+), 26 deletions(-) create mode 100644 test/parallel/test-compile-cache-api-readonly.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 40a61c90ac2..4b2113fae2a 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -3708,6 +3708,15 @@ When set to 1, the [module compile cache][] can be reused across different direc locations as long as the module layout relative to the cache directory remains the same, and by any user (the cache subdirectory is not suffixed with the creating user's uid). +### `NODE_COMPILE_CACHE_READONLY=1` + + + +When set to 1, the [module compile cache][] only reads existing entries from +its directory: nothing is written to it and it is not created if missing. + ### `NODE_DEBUG=module[,…]`