To begin collecting source-maps, node must be run with --enable-source-maps
(or with NODE_V8_COVERAGE
set).
At which point, the new built-in module source_map
can be used to interact with the source-map cache:
// tooling has one interface into the source-map cache, URIs, any type of module that we
// wish to attach source-maps to (ESM, CJS, evals, data-urls) needs to have a methodlogy
// for setting a URI; Two different source-maps cannot be stored at the same URI.
const {cache} = require('source_map');
const sm1 = cache.sourceMapFromURI(`file://${require.resolve('./my-module')}`);
These methods return the same data-structure that is written to disk when
executing with NODE_V8_COVERAGE
:
{
"url": "data:abc123", // original source-map URL.
"data": {} // parsed source-map or null.
}
When executing with --enable-source-maps
, stack traces will be rewritten if source-maps are found corresponding
to files represented in the stack-trace.
The hope is to intitially engage folks rom the https://github.com/evanw/node-source-map-support project, to support stack-trace rewritting in Node.js. And, in the future, work with the V8 team to move more of this behavior into V8 itself.
@ljharb are you picturing an API more like this:
if the source-map is already in the cache, return the object:
if the Source Map was not yet loaded, we read the file from disk and look for a source map potentially; returning the same format.
What's your reasoning for a
Buffer
rather than returning the object, as suggested above?