Skip to content
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

lib: allow skipping source maps in node_modules #56639

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

legendecas
Copy link
Member

@legendecas legendecas commented Jan 17, 2025

Files in node_modules are not authored by the user directly and the
original sources are less relevant to the user.

Skipping source maps in node_modules improves the general
performance. Add module.setSourceMapsSupport(enabled, options) to
skip source maps in node_modules if it is needed. This moves
all source maps related API to node:module and this a step to
promote the source maps API to stable.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added 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 Jan 17, 2025
@legendecas legendecas added source maps Issues and PRs related to source map support. and removed 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 Jan 17, 2025
@legendecas legendecas force-pushed the source-maps/node_modules branch 2 times, most recently from fb1a57e to cfc1fd9 Compare January 17, 2025 11:58
@legendecas legendecas marked this pull request as ready for review January 17, 2025 12:00
doc/api/module.md Outdated Show resolved Hide resolved
lib/internal/source_map/source_map_cache.js Show resolved Hide resolved
lib/internal/source_map/source_map_cache.js Show resolved Hide resolved
@legendecas legendecas force-pushed the source-maps/node_modules branch from cfc1fd9 to 94667aa Compare January 17, 2025 12:51
Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

Considering many enable source maps via --enable-source-maps I think it also warrants something like --disable-source-maps-in-node-modules or some other flag with a better name? Otherwise end users have to preload a script that invokes the API which is a bit of a hassle. We can set it to false by default for existing releases and in the next major release, flip it to true.

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.21%. Comparing base (bf59539) to head (cf84bcb).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #56639   +/-   ##
=======================================
  Coverage   89.21%   89.21%           
=======================================
  Files         662      662           
  Lines      191934   191961   +27     
  Branches    36945    36947    +2     
=======================================
+ Hits       171227   171266   +39     
+ Misses      13543    13542    -1     
+ Partials     7164     7153   -11     
Files with missing lines Coverage Δ
lib/internal/bootstrap/node.js 99.57% <100.00%> (+<0.01%) ⬆️
lib/internal/modules/esm/module_job.js 99.25% <100.00%> (ø)
lib/internal/process/pre_execution.js 91.79% <100.00%> (+0.09%) ⬆️
lib/module.js 100.00% <100.00%> (ø)

... and 43 files with indirect coverage changes

@legendecas legendecas force-pushed the source-maps/node_modules branch from 94667aa to 593b4ff Compare January 22, 2025 11:28
@legendecas legendecas changed the title lib: skip source maps in node_modules lib: allow skipping source maps in node_modules Jan 22, 2025
Files in `node_modules` are not authored by the user directly and the
original sources are less relevant to the user.

Skipping source maps in `node_modules` improves the general
performance. Add `module.setSourceMapsSupport(enabled, options)` to
skip source maps in `node_modules` if it is needed. This moves
all source maps related API to `node:module` and this a step to
promote the source maps API to stable.
@legendecas legendecas force-pushed the source-maps/node_modules branch from 593b4ff to cf84bcb Compare January 22, 2025 11:30
@legendecas
Copy link
Member Author

legendecas commented Jan 22, 2025

Updated with --enable-source-maps and process.setSourceMapsEnabled(true) implies module.setSourceMapsSupport(true, { nodeModules: true, generatedCode: true }), reducing the impacts.

The new API module.setSourceMapsSupport will still have the options default to false.

Comment on lines +4004 to +4007
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56639
description: the `process.setSourceMapsEnabled` has been deprecated.
Copy link
Contributor

@aduh95 aduh95 Jan 22, 2025

Choose a reason for hiding this comment

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

Suggested change
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56639
description: the `process.setSourceMapsEnabled` has been deprecated.

Comment on lines +4058 to +4061
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56639
description: the `process.sourceMapsEnabled` has been deprecated.
Copy link
Contributor

@aduh95 aduh95 Jan 22, 2025

Choose a reason for hiding this comment

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

Suggested change
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56639
description: the `process.sourceMapsEnabled` has been deprecated.

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Can you please add an entry in deprecations.md?

@legendecas
Copy link
Member Author

Can you please add an entry in deprecations.md?

process.setSourceMapsEnabled and its friend APIs are experimental APIs, I think it is not necessary to add a deprecation code as per #55740?

@aduh95
Copy link
Contributor

aduh95 commented Jan 22, 2025

You're right, I miss that! In that case, we should not use the word "deprecated" and keep it as experimental in that case

-->
> Stability: 1 - Experimental
> Stability: 0 - Deprecated: Use [`module.getSourceMapsSupport()`][] instead.
Copy link
Contributor

@aduh95 aduh95 Jan 22, 2025

Choose a reason for hiding this comment

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

Suggested change
> Stability: 0 - Deprecated: Use [`module.getSourceMapsSupport()`][] instead.
> Stability: 1 - Experimental: Use [`module.getSourceMapsSupport()`][] instead.

-->
> Stability: 1 - Experimental
> Stability: 0 - Deprecated: Use [`module.setSourceMapsSupport()`][] instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
> Stability: 0 - Deprecated: Use [`module.setSourceMapsSupport()`][] instead.
> Stability: 1 - Experimental: Use [`module.setSourceMapsSupport()`][] instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
source maps Issues and PRs related to source map support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants