Repository navigation
add api to detect whether source-maps are enabled #46304
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Jan 22, 2023 I read through the linked vite pull request but it wasn't clear to me why you need to know whether source maps are enabled. Can you explain? What's the use case?
Thanks for the response!
Vite exports a function that rewrites
Error::stackto make the stack trace point to the original source file using source maps. When source maps are enabled on Node.js,Error::stackcontains a stack trace that already points to the original source file. If theError::stackalready points to the original source file, that function should be no-op.Because Vite nor the script using Vite knows whether the stack trace points to the original source file or the transformed file, we cannot make that function no-op.
// this is a pseudocode and won't work import { load, rewriteStacktrace } from 'vite' const mod = await load('./foo.js') try { mod.error() } catch (e) { console.log(e.stack) // this stack trace points to the transformed file rewriteStacktrace(e) // rewrite the stack trace console.log(e.stack) // this stack trace points to the original source file }
Right, that makes sense.
getSourceMapsEnabled()already exists internally but would it work for you? It enables, as a side effect, source maps on first call when--enable-source-mapsis set.getSourceMapsEnabled()would work for me.I know I should avoid using internal things, but is there any way to access the internal
getSourceMapsEnabled()? If it's possible, I can support older versions.It's not exposed in any way (I think) but pull request welcome. I wouldn't object to a side-effect-free
process.sourceMapsEnabledgetter either; maybe that's even better.Reacted by 翠There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jul 25, 2023 - added a commit that references this issue
on Aug 15, 2023 - added a commit that references this issue
on Aug 17, 2023 - added a commit that references this issue
on Sep 10, 2023 - added a commit that references this issue
on Nov 15, 2023 - added 2 commits that reference this issue
on Apr 25, 2024
What is the problem this feature will solve?
#39085 added
process.setSourceMapsEnabledto enable source-maps programmatically. This is helpful for tools like Vite, thank you for implementing. 💚But as this was implemented we now cannot know whether source-maps are enabled. I guess it was possible by
process.execArgv.includes('--enable-source-maps')previously.What is the feature you are proposing to solve the problem?
Add
process.getSourceMapsEnabledthat returns whether the source-maps are enabled.What alternatives have you considered?
Add a getter + setter named
process.isSourceMapsEnabledthat works likeprocess.getSourceMapsEnabledandprocess.setSourceMapsEnabled.