Skip to content

src: add an option to make compile cache path relative - #58797

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Aditi-1400:compile-cache
Sep 12, 2025
Merged

src: add an option to make compile cache path relative#58797
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
Aditi-1400:compile-cache

Conversation

@Aditi-1400

@Aditi-1400Aditi-1400 commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

Adds an option (NODE_COMPILE_CACHE_RELATIVE_PATH) for the built-in compile cache to encode the hashes with relative file paths. On enabling the option,
the source directory along with cache directory can be bundled and moved, and the cache continues to work.

When enabled, paths encoded in hash are relative to compile cache directory.

Fixes: #58755
Refs: #52696

Thanks @joyeecheung for all the help :)

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jun 23, 2025
@codecov

codecovBot commented Jun 23, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.07595% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.89%. Comparing base (9bcc5a8) to head (b879f6b).
⚠️ Report is 319 commits behind head on main.

Files with missing linesPatch %Lines
src/compile_cache.cc81.48%1 Missing and 4 partials ⚠️
src/path.cc73.68%2 Missing and 3 partials ⚠️
src/env.cc87.50%0 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #58797 +/- ##
==========================================
+ Coverage 89.37% 89.89% +0.52% 
==========================================
Files 654 667 +13 Lines 192554 196670 +4116 Branches 37434 38617 +1183 ==========================================
+ Hits 172086 176794 +4708 + Misses 12995 12331 -664 - Partials 7473 7545 +72 
Files with missing linesCoverage Δ
lib/internal/modules/helpers.js98.29% <100.00%> (+0.92%)⬆️
src/compile_cache.h100.00% <ø> (ø)
src/env.h98.14% <ø> (ø)
src/node_modules.cc77.06% <100.00%> (-0.25%)⬇️
src/env.cc80.83% <87.50%> (-0.05%)⬇️
src/compile_cache.cc80.78% <81.48%> (-0.01%)⬇️
src/path.cc72.81% <73.68%> (+3.76%)⬆️

... and 195 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joyeecheungjoyeecheung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some integration to module.enableCompileCache() as well? I think having it in options bag when the first argument is an object might work well enough. The path can be options.path in that case.

Comment threaddoc/api/cli.md Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadtest/parallel/test-compile-cache-relative-path.js
@joyeecheungjoyeecheung mentioned this pull request Jul 3, 2025
13 tasks
@mcollinamcollina added the semver-minor PRs that contain new features and should be released in the next minor version. label Jul 4, 2025
Comment threaddoc/api/module.md Outdated
Comment threaddoc/api/module.md Outdated
Comment threaddoc/api/module.md Outdated
Comment threaddoc/node.1 Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
@Aditi-1400
Aditi-1400force-pushed the compile-cache branch 2 times, most recently from 5abcfc9 to de78d1aCompareAugust 1, 2025 13:15
Comment threaddoc/api/module.md Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threaddoc/api/module.md Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.cc Outdated
Comment threadsrc/compile_cache.h Outdated
Comment threadtest/parallel/test-compile-cache-portable.js Outdated

@jasnelljasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file:// URL handling in this is incorrect. Either support for file:// URLs here at all should be dropped or they should be correctly handled.

jasnell

This comment was marked as duplicate.

@Aditi-1400
Aditi-1400force-pushed the compile-cache branch 4 times, most recently from ddd3bcd to d03bf27CompareAugust 11, 2025 16:30
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 11, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 11, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Aditi-1400Aditi-1400 added the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 12, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 12, 2025
@nodejs-github-bot
nodejs-github-bot merged commit 94422e8 into nodejs:mainSep 12, 2025
73 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 94422e8

targos pushed a commit that referenced this pull request Sep 12, 2025
Adds an option (NODE_COMPILE_CACHE_PORTABLE) for
the built-in compile cache to encode the hashes with
relative file paths. On enabling the option,
the source directory along with cache directory can be
bundled and moved, and the cache continues to work.
When enabled, paths encoded in hash are relative to
compile cache directory.
PR-URL: #58797Fixes: #58755
Refs: #52696
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@joyeecheungjoyeecheung added dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v25.x labels Sep 18, 2025
* - `portable`: If `portable` is true, the cache directory will be considered relative. Defaults to false.
* If cache path is undefined, it defaults to the NODE_MODULE_CACHE environment variable.
* If `NODE_MODULE_CACHE` isn't set, it defaults to `path.join(os.tmpdir(), 'node-compile-cache')`.
* @param {string | { path?: string, portable?: boolean } | undefined} options

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed an issue with the new options - it should be directory instead of path to align with the return value. Marking the PR with dont-land labels to fix it before it gets released.

@targostargos mentioned this pull request Sep 24, 2025
9 tasks
@targostargos removed dont-land-on-v24.x PRs that should not land on the v24.x-staging branch and should not be released in v24.x. dont-land-on-v25.x labels Oct 10, 2025
@targos

Copy link
Copy Markdown
Member

#59896 (comment)

Should land with #59931

aduh95 pushed a commit that referenced this pull request Oct 31, 2025
Adds an option (NODE_COMPILE_CACHE_PORTABLE) for
the built-in compile cache to encode the hashes with
relative file paths. On enabling the option,
the source directory along with cache directory can be
bundled and moved, and the cache continues to work.
When enabled, paths encoded in hash are relative to
compile cache directory.
PR-URL: #58797Fixes: #58755
Refs: #52696
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot added a commit that referenced this pull request Nov 7, 2025
Notable changes:
http:
* (SEMVER-MINOR) add optimizeEmptyRequests server option (Rafael Gonzaga) #59778
src:
* (SEMVER-MINOR) add watch config namespace (Marco Ippolito) #60178
* (SEMVER-MINOR) add an option to make compile cache portable (Aditi) #58797
v8:
* (SEMVER-MINOR) add cpu profile (theanarkh) #59807
PR-URL: #60615
targos pushed a commit that referenced this pull request Nov 18, 2025
Adds an option (NODE_COMPILE_CACHE_PORTABLE) for
the built-in compile cache to encode the hashes with
relative file paths. On enabling the option,
the source directory along with cache directory can be
bundled and moved, and the cache continues to work.
When enabled, paths encoded in hash are relative to
compile cache directory.
PR-URL: #58797Fixes: #58755
Refs: #52696
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
nodejs-github-bot added a commit that referenced this pull request Dec 9, 2025
Notable changes:
http:
* (SEMVER-MINOR) add optimizeEmptyRequests server option (Rafael Gonzaga) #59778
lib:
* (SEMVER-MINOR) add options to util.deprecate (Rafael Gonzaga) #59982
module:
* (SEMVER-MINOR) mark type stripping as stable (Marco Ippolito) #60600
node-api:
* (SEMVER-MINOR) add napi_create_object_with_properties (Miguel Marcondes Filho) #59953
sqlite:
* (SEMVER-MINOR) allow setting defensive flag (Bart Louwers) #60217
src:
* (SEMVER-MINOR) add watch config namespace (Marco Ippolito) #60178
* (SEMVER-MINOR) add an option to make compile cache portable (Aditi) #58797
src,permission:
* (SEMVER-MINOR) add --allow-inspector ability (Rafael Gonzaga) #59711
v8:
* (SEMVER-MINOR) add cpu profile (theanarkh) #59807
PR-URL: #61001
targos pushed a commit that referenced this pull request Dec 9, 2025
Notable changes:
http:
* (SEMVER-MINOR) add optimizeEmptyRequests server option (Rafael Gonzaga) #59778
lib:
* (SEMVER-MINOR) add options to util.deprecate (Rafael Gonzaga) #59982
module:
* (SEMVER-MINOR) mark type stripping as stable (Marco Ippolito) #60600
node-api:
* (SEMVER-MINOR) add napi_create_object_with_properties (Miguel Marcondes Filho) #59953
sqlite:
* (SEMVER-MINOR) allow setting defensive flag (Bart Louwers) #60217
src:
* (SEMVER-MINOR) add watch config namespace (Marco Ippolito) #60178
* (SEMVER-MINOR) add an option to make compile cache portable (Aditi) #58797
src,permission:
* (SEMVER-MINOR) add --allow-inspector ability (Rafael Gonzaga) #59711
v8:
* (SEMVER-MINOR) add cpu profile (theanarkh) #59807
PR-URL: #61001
targos pushed a commit that referenced this pull request Dec 10, 2025
Notable changes:
http:
* (SEMVER-MINOR) add optimizeEmptyRequests server option (Rafael Gonzaga) #59778
lib:
* (SEMVER-MINOR) add options to util.deprecate (Rafael Gonzaga) #59982
module:
* (SEMVER-MINOR) mark type stripping as stable (Marco Ippolito) #60600
node-api:
* (SEMVER-MINOR) add napi_create_object_with_properties (Miguel Marcondes Filho) #59953
sqlite:
* (SEMVER-MINOR) allow setting defensive flag (Bart Louwers) #60217
src:
* (SEMVER-MINOR) add watch config namespace (Marco Ippolito) #60178
* (SEMVER-MINOR) add an option to make compile cache portable (Aditi) #58797
src,permission:
* (SEMVER-MINOR) add --allow-inspector ability (Rafael Gonzaga) #59711
v8:
* (SEMVER-MINOR) add cpu profile (theanarkh) #59807
PR-URL: #61001
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support relative compile cache

6 participants

@Aditi-1400@nodejs-github-bot@jasnell@joyeecheung@targos@mcollina