You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
add api to detect whether source-maps are enabled #46304
#39085 added process.setSourceMapsEnabled to 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.getSourceMapsEnabled that returns whether the source-maps are enabled.
What alternatives have you considered?
Add a getter + setter named process.isSourceMapsEnabled that works like process.getSourceMapsEnabled and process.setSourceMapsEnabled.
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?
Vite exports a function that rewrites Error::stack to make the stack trace point to the original source file using source maps. When source maps are enabled on Node.js, Error::stack contains a stack trace that already points to the original source file. If the Error::stack already 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 workimport{load,rewriteStacktrace}from'vite'constmod=awaitload('./foo.js')try{mod.error()}catch(e){console.log(e.stack)// this stack trace points to the transformed filerewriteStacktrace(e)// rewrite the stack traceconsole.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-maps is set.
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.sourceMapsEnabled getter either; maybe that's even better.
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.
Activity
bnoordhuis commentedon 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?
sapphi-red commentedon Jan 24, 2023
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.
bnoordhuis commentedon Jan 24, 2023
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.sapphi-red commentedon Jan 24, 2023
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.bnoordhuis commentedon Jan 25, 2023
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.github-actions commentedon Jul 25, 2023
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.
lib: add api to detect whether source-maps are enabled
lib: add api to detect whether source-maps are enabled
lib: add api to detect whether source-maps are enabled
lib: add api to detect whether source-maps are enabled
lib: add api to detect whether source-maps are enabled
lib: add api to detect whether source-maps are enabled