@@ -80,37 +80,48 @@ declare module "module" {
8080 */
8181 directory ?: string ;
8282 }
83+ interface EnableCompileCacheOptions {
84+ /**
85+ * Optional. Directory to store the compile cache. If not specified, the directory specified by
86+ * the [`NODE_COMPILE_CACHE=dir`](https://nodejs.org/docs/latest-v24.x/api/cli.html#node_compile_cachedir)
87+ * environment variable will be used if it's set, or `path.join(os.tmpdir(), 'node-compile-cache')` otherwise.
88+ * @since v24.12.0
89+ */
90+ directory ?: string | undefined ;
91+ /**
92+ * Optional. If `true`, enables portable compile cache so that the cache can be reused even if the project directory
93+ * is moved. This is a best-effort feature. If not specified, it will depend on whether the environment variable
94+ * [NODE_COMPILE_CACHE_PORTABLE=1](https://nodejs.org/docs/latest-v24.x/api/cli.html#node_compile_cache_portable1) is set.
95+ * @since v24.12.0
96+ */
97+ portable ?: boolean | undefined ;
98+ }
8399 /**
84100 * Enable [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
85101 * in the current Node.js instance.
86102 *
87- * If `cacheDir` is not specified, Node.js will either use the directory specified by the
88- * `NODE_COMPILE_CACHE=dir` environment variable if it's set, or use
89- * `path.join(os.tmpdir(), 'node-compile-cache')` otherwise. For general use cases, it's
90- * recommended to call `module.enableCompileCache()` without specifying the `cacheDir`,
91- * so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
103+ * For general use cases, it's recommended to call `module.enableCompileCache()` without specifying the
104+ * `options.directory`, so that the directory can be overridden by the `NODE_COMPILE_CACHE` environment
92105 * variable when necessary.
93106 *
94- * Since compile cache is supposed to be a quiet optimization that is not required for the
95- * application to be functional, this method is designed to not throw any exception when the
96- * compile cache cannot be enabled. Instead, it will return an object containing an error
97- * message in the `message` field to aid debugging.
98- * If compile cache is enabled successfully, the `directory` field in the returned object
99- * contains the path to the directory where the compile cache is stored. The `status`
100- * field in the returned object would be one of the `module.constants.compileCacheStatus`
101- * values to indicate the result of the attempt to enable the
107+ * Since compile cache is supposed to be a optimization that is not mission critical, this method is
108+ * designed to not throw any exception when the compile cache cannot be enabled. Instead, it will return
109+ * an object containing an error message in the `message` field to aid debugging. If compile cache is
110+ * enabled successfully, the `directory` field in the returned object contains the path to the directory
111+ * where the compile cache is stored. The `status` field in the returned object would be one of the
112+ * `module.constants.compileCacheStatus` values to indicate the result of the attempt to enable the
102113 * [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache).
103114 *
104115 * This method only affects the current Node.js instance. To enable it in child worker threads,
105116 * either call this method in child worker threads too, or set the
106117 * `process.env.NODE_COMPILE_CACHE` value to compile cache directory so the behavior can
107118 * be inherited into the child workers. The directory can be obtained either from the
108- * `directory` field returned by this method, or with {@link getCompileCacheDir}.
119+ * `directory` field returned by this method, or with {@link getCompileCacheDir `module.getCompileCacheDir()` }.
109120 * @since v22.8.0
110- * @param cacheDir Optional path to specify the directory where the compile cache
121+ * @param options Optional. If a string is passed, it is considered to be `options.directory`.
111122 * will be stored/retrieved.
112123 */
113- function enableCompileCache ( cacheDir ?: string ) : EnableCompileCacheResult ;
124+ function enableCompileCache ( options ?: string | EnableCompileCacheOptions ) : EnableCompileCacheResult ;
114125 /**
115126 * Flush the [module compile cache](https://nodejs.org/docs/latest-v24.x/api/module.html#module-compile-cache)
116127 * accumulated from modules already loaded
0 commit comments