-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
module: fix directory option in the enableCompileCache() API #59931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nodejs-github-bot
merged 3 commits into
nodejs:main
from
joyeecheung:fix-compile-cache-api
Oct 9, 2025
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| 'use strict'; | ||
|
|
||
| const { enableCompileCache, getCompileCacheDir, constants } = require('module'); | ||
|
|
||
| console.log('dir before enableCompileCache:', getCompileCacheDir()); | ||
| const options = JSON.parse(process.env.NODE_TEST_COMPILE_CACHE_OPTIONS); | ||
| console.log('options:', options); | ||
| const result = enableCompileCache(options); | ||
| switch (result.status) { | ||
| case constants.compileCacheStatus.FAILED: | ||
| console.log('Compile cache failed. ' + result.message); | ||
| break; | ||
| case constants.compileCacheStatus.ENABLED: | ||
| console.log('Compile cache enabled. ' + result.directory); | ||
| break; | ||
| case constants.compileCacheStatus.ALREADY_ENABLED: | ||
| console.log('Compile cache already enabled.'); | ||
| break; | ||
| case constants.compileCacheStatus.DISABLED: | ||
| console.log('Compile cache already disabled.'); | ||
| break; | ||
| } | ||
| console.log('dir after enableCompileCache:', getCompileCacheDir()); |
89 changes: 89 additions & 0 deletions
89
test/parallel/test-compile-cache-api-options-portable-env.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests module.enableCompileCache() with an options object still works with environment | ||
| // variable NODE_COMPILE_CACHE overrides. | ||
|
|
||
| require('../common'); | ||
| const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| const assert = require('assert'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const wrapper = fixtures.path('compile-cache-wrapper-options.js'); | ||
| tmpdir.refresh(); | ||
|
|
||
| // Create a build directory and copy the entry point file. | ||
| const buildDir = tmpdir.resolve('build'); | ||
| fs.mkdirSync(buildDir); | ||
| const entryPoint = path.join(buildDir, 'empty.js'); | ||
| fs.copyFileSync(fixtures.path('empty.js'), entryPoint); | ||
|
|
||
| // Check that the portable option can be overridden by NODE_COMPILE_CACHE_PORTABLE. | ||
| // We don't override NODE_COMPILE_CACHE because it will enable the cache before | ||
| // the wrapper is loaded. | ||
| spawnSyncAndAssert( | ||
| process.execPath, | ||
| ['-r', wrapper, entryPoint], | ||
| { | ||
| env: { | ||
| ...process.env, | ||
| NODE_DEBUG_NATIVE: 'COMPILE_CACHE', | ||
| NODE_COMPILE_CACHE_PORTABLE: '1', | ||
| NODE_TEST_COMPILE_CACHE_OPTIONS: JSON.stringify({ directory: 'build/.compile_cache' }), | ||
| }, | ||
| cwd: tmpdir.path | ||
| }, | ||
| { | ||
| stdout(output) { | ||
| console.log(output); // Logging for debugging. | ||
| assert.match(output, /dir before enableCompileCache: undefined/); | ||
| assert.match(output, /Compile cache enabled/); | ||
| assert.match(output, /dir after enableCompileCache: .*build\/\.compile_cache/); | ||
| return true; | ||
| }, | ||
| stderr(output) { | ||
| console.log(output); // Logging for debugging. | ||
| assert.match(output, /reading cache from .*build\/\.compile_cache.* for CommonJS .*empty\.js/); | ||
| assert.match(output, /empty\.js was not initialized, initializing the in-memory entry/); | ||
| assert.match(output, /writing cache for .*empty\.js.*success/); | ||
| return true; | ||
| } | ||
| }); | ||
|
|
||
| assert(fs.existsSync(tmpdir.resolve('build/.compile_cache'))); | ||
|
|
||
| const movedDir = buildDir + '_moved'; | ||
| fs.renameSync(buildDir, movedDir); | ||
| const movedEntryPoint = path.join(movedDir, 'empty.js'); | ||
|
|
||
| // When portable is undefined, it should use the env var NODE_COMPILE_CACHE_PORTABLE. | ||
| spawnSyncAndAssert( | ||
| process.execPath, | ||
| ['-r', wrapper, movedEntryPoint], | ||
| { | ||
| env: { | ||
| ...process.env, | ||
| NODE_DEBUG_NATIVE: 'COMPILE_CACHE', | ||
| NODE_COMPILE_CACHE_PORTABLE: '1', | ||
| NODE_TEST_COMPILE_CACHE_OPTIONS: JSON.stringify({ directory: 'build_moved/.compile_cache' }), | ||
| }, | ||
| cwd: tmpdir.path | ||
| }, | ||
| { | ||
| stdout(output) { | ||
| console.log(output); // Logging for debugging. | ||
| assert.match(output, /dir before enableCompileCache: undefined/); | ||
| assert.match(output, /Compile cache enabled/); | ||
| assert.match(output, /dir after enableCompileCache: .*build_moved\/\.compile_cache/); | ||
| return true; | ||
| }, | ||
| stderr(output) { | ||
| console.log(output); // Logging for debugging. | ||
| assert.match(output, /reading cache from .*build_moved\/\.compile_cache.* for CommonJS .*empty\.js/); | ||
| assert.match(output, /cache for .*empty\.js was accepted, keeping the in-memory entry/); | ||
| assert.match(output, /.*skip .*empty\.js because cache was the same/); | ||
| return true; | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.