From 2a6dcde0b4557e9553d98809a9944acbddbeb578 Mon Sep 17 00:00:00 2001 From: Benjamin Coe Date: Fri, 20 Sep 2019 11:43:02 -0700 Subject: [PATCH] process: initial SourceMap support via NODE_V8_COVERAGE --- doc/api/cli.md | 62 +++++-- lib/internal/bootstrap/pre_execution.js | 2 + lib/internal/modules/cjs/loader.js | 7 +- lib/internal/modules/esm/translators.js | 2 + lib/internal/source_map.js | 152 ++++++++++++++++++ node.gyp | 1 + src/env.h | 1 + src/inspector_profiler.cc | 60 +++++++ src/inspector_profiler.h | 8 +- test/fixtures/source-map/basic.js | 7 + .../fixtures/source-map/disk-relative-path.js | 2 + test/fixtures/source-map/disk.js | 27 ++++ test/fixtures/source-map/disk.map | 20 +++ test/fixtures/source-map/esm-basic.mjs | 4 + test/fixtures/source-map/esm-dep.mjs | 4 + test/fixtures/source-map/exit-1.js | 8 + test/fixtures/source-map/inline-base64.js | 2 + test/fixtures/source-map/sigint.js | 8 + test/parallel/test-bootstrap-modules.js | 1 + test/parallel/test-source-map.js | 132 +++++++++++++++ 20 files changed, 497 insertions(+), 13 deletions(-) create mode 100644 lib/internal/source_map.js create mode 100644 test/fixtures/source-map/basic.js create mode 100644 test/fixtures/source-map/disk-relative-path.js create mode 100644 test/fixtures/source-map/disk.js create mode 100644 test/fixtures/source-map/disk.map create mode 100644 test/fixtures/source-map/esm-basic.mjs create mode 100644 test/fixtures/source-map/esm-dep.mjs create mode 100644 test/fixtures/source-map/exit-1.js create mode 100644 test/fixtures/source-map/inline-base64.js create mode 100644 test/fixtures/source-map/sigint.js create mode 100644 test/parallel/test-source-map.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 31e554024285ff..8a1ca4893a8b69 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1110,9 +1110,19 @@ variable is strongly discouraged. ### `NODE_V8_COVERAGE=dir` -When set, Node.js will begin outputting [V8 JavaScript code coverage][] to the -directory provided as an argument. Coverage is output as an array of -[ScriptCoverage][] objects: +When set, Node.js will begin outputting [V8 JavaScript code coverage][] and +[Source Map][] data to the directory provided as an argument (coverage +information is written as JSON to files with a `coverage` prefix). + +`NODE_V8_COVERAGE` will automatically propagate to subprocesses, making it +easier to instrument applications that call the `child_process.spawn()` family +of functions. `NODE_V8_COVERAGE` can be set to an empty string, to prevent +propagation. + +#### Coverage Output + +Coverage is output as an array of [ScriptCoverage][] objects on the top-level +key `result`: ```json { @@ -1126,13 +1136,46 @@ directory provided as an argument. Coverage is output as an array of } ``` -`NODE_V8_COVERAGE` will automatically propagate to subprocesses, making it -easier to instrument applications that call the `child_process.spawn()` family -of functions. `NODE_V8_COVERAGE` can be set to an empty string, to prevent -propagation. +#### Source Map Cache + +> Stability: 1 - Experimental + +If found, Source Map data is appended to the top-level key `source-map-cache` +on the JSON coverage object. + +`source-map-cache` is an object with keys representing the files source maps +were extracted from, and the values include the raw source-map URL +(in the key `url`) and the parsed Source Map V3 information (in the key `data`). -At this time coverage is only collected in the main thread and will not be -output for code executed by worker threads. +```json +{ + "result": [ + { + "scriptId": "68", + "url": "file:///absolute/path/to/source.js", + "functions": [] + } + ], + "source-map-cache": { + "file:///absolute/path/to/source.js": { + "url": "./path-to-map.json", + "data": { + "version": 3, + "sources": [ + "file:///absolute/path/to/original.js" + ], + "names": [ + "Foo", + "console", + "info" + ], + "mappings": "MAAMA,IACJC,YAAaC", + "sourceRoot": "./" + } + } + } +} +``` ### `OPENSSL_CONF=file`