-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
module: add a read-only mode to the compile cache #65302
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
Open
codebytere
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
codebytere:compile-cache-read-only
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+189
−26
Open
Changes from all commits
Commits
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
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
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,65 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests module.enableCompileCache({ directory, readOnly: true }): existing | ||
| // entries are read, nothing is written, and a missing directory is not created. | ||
|
|
||
| const common = require('../common'); | ||
| const { spawnSyncAndAssert } = require('../common/child_process'); | ||
| const assert = require('assert'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const tmpdir = require('../common/tmpdir'); | ||
| const fixtures = require('../common/fixtures'); | ||
|
|
||
| tmpdir.refresh(); | ||
| const wrapper = fixtures.path('compile-cache-wrapper-options.js'); | ||
| const target = path.join(tmpdir.path, 'target.js'); | ||
| fs.writeFileSync(target, 'module.exports = 1;'); | ||
| const other = path.join(tmpdir.path, 'other.js'); | ||
| fs.writeFileSync(other, 'module.exports = 2;'); | ||
| const directory = path.join(tmpdir.path, 'cache'); | ||
| const list = () => fs.readdirSync(directory, { recursive: true }).sort(); | ||
| const run = (options, extraEnv, requires, check) => spawnSyncAndAssert( | ||
| process.execPath, | ||
| [...requires.flatMap((r) => ['-r', r]), target], | ||
| { | ||
| env: { | ||
| ...process.env, | ||
| NODE_DEBUG_NATIVE: 'COMPILE_CACHE', | ||
| NODE_TEST_COMPILE_CACHE_OPTIONS: JSON.stringify(options), | ||
| ...extraEnv, | ||
| }, | ||
| }, | ||
| check); | ||
|
|
||
| // Read-only against a directory that does not exist: enabling fails and | ||
| // nothing is created. | ||
| run({ directory, readOnly: true }, {}, [wrapper], { | ||
| stderr: /read-only cache directory .*\.\.\.not found/, | ||
| }); | ||
| assert(!fs.existsSync(directory)); | ||
|
|
||
| // A normal run generates the cache for target.js. | ||
| run({ directory }, {}, [wrapper], { | ||
| stderr: /writing cache for .*target\.js.*success/, | ||
| }); | ||
| const generated = list(); | ||
| assert.notStrictEqual(generated.length, 0); | ||
|
|
||
| // Read-only against it: target.js's entry is accepted, other.js is compiled | ||
| // but not written, and persistence is skipped. | ||
| run({ directory, readOnly: true }, {}, [wrapper, other], { | ||
| stderr: common.mustCall((output) => { | ||
| assert.match(output, /cache for .*target\.js was accepted/); | ||
| assert.match(output, /read-only, skipping persistence/); | ||
| assert.doesNotMatch(output, /writing cache for/); | ||
| return true; | ||
| }), | ||
| }); | ||
| assert.deepStrictEqual(list(), generated); | ||
|
|
||
| // The environment variable form. | ||
| run({ directory }, { NODE_COMPILE_CACHE_READONLY: '1' }, [wrapper, other], { | ||
| stderr: /read-only, skipping persistence/, | ||
| }); | ||
| assert.deepStrictEqual(list(), generated); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this emit a warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think so, for consistency: none of the other
FAILEDpaths here (can't create the directory, not writable) warn either. throughmodule.enableCompileCache()the caller gets{ status, message }back and can decide what to do with it, and forNODE_COMPILE_CACHEthe existing behavior is an inherited env var never adds output to a program that didn't ask for the cache;NODE_DEBUG_NATIVE=COMPILE_CACHEprints it. happy to add one if you feel strongly, but i'd rather do it for all theFAILEDcases at once in a follow-up than special-case read-only.