Skip to content

Source Map V3 Support in Node.js #40

@bcoe

Description

@bcoe

There's an open PR to start caching source-maps when scripts are loaded in Node.js; It piggybacks off the NODE_V8_COVERAGE implementation, and is an attempt to solve problems presented by tools like ts-node which dynamically insert source-maps at runtime.

I've been scratching my head and trying to think of what a more generic solution looks like for the community...

Is the additional functionality added to NODE_V8_COVERAGE too much of a hack?

This would allow upstream tooling to start working for tools like esm, ts-node, ts-mocha, without any additional work, e.g., hooking into require.extensions, application exit events, but, is it adding something into Node.js we'll regret?

Is it useful for Node.js to maintain and expose a cache of loaded source-maps

An alternative would be the folks override require.extensions and eventually loader-hooks for ESM, and detect source-maps themselves in userland ... this is how things work today.

If we do maintain a cache, what should an API for interacting with it look like?

I was picturing something like this:

const {fetchSourceMap} = require('source_map');
const sm1 = fetchSourceMap(require.resolve('./my-script'));

Should Node.js rewrite stack traces, taking into account source-maps?

Today there's a popular tool node-source-map-support that does this, if Node.js was now maintaining a cache of source-maps, should we make this a first-class-citizen of Node.

Alternatively, we could try to upstream this behavior into V8, but this might be a fairly long-term project.

Should Node.js also provide an API for applying with source-maps?

If Node.js were to apply source-maps to stack-traces, we would already need to ship something like source-map for parsing and applying the maps, should this API be exposed?

What's the MVP functionality that would be useful to folks in the community?

tldr; I've looped in a few folks who work on Source Map adjacent projects, and would love to know people's opinions ... what's an MVP that would make people's lives easier?

CC: @evanw, @LinusU, @cpojer, @SimenB, @joyeecheung, @boneskull, @iansu, @jdalton.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions