Skip to content

add api to detect whether source-maps are enabled #46304

Description

@sapphi-red

What is the problem this feature will solve?

#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.

Activity

  1. bnoordhuis commented on Jan 22, 2023

    @bnoordhuis
    Member

    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?

  2. sapphi-red commented on Jan 24, 2023

    @sapphi-red
    ContributorAuthor

    Thanks for the response!

    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 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
    }
  3. bnoordhuis commented on Jan 24, 2023

    @bnoordhuis
    Member

    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.

  4. sapphi-red commented on Jan 24, 2023

    @sapphi-red
    ContributorAuthor

    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.

  5. bnoordhuis commented on Jan 25, 2023

    @bnoordhuis
    Member

    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.

  6. github-actions commented on Jul 25, 2023

    @github-actions
    Contributor

    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.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 25, 2023
  8. moved this from Awaiting Triage to Done in Node.js feature requestson Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions