From 8a2a0e968a2dfa98b67701c2d446e977663cc9f9 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 18:26:00 -0400 Subject: [PATCH 01/15] Initial implementation for review --- source-map-support.js | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/source-map-support.js b/source-map-support.js index 4459386..2332d6f 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -408,6 +408,17 @@ function wrapCallSite(frame, state) { return frame; } +let kIsNodeError = undefined; +try { + // Get a deliberate ERR_INVALID_ARG_TYPE + // TODO is there a better way to reliably get an instance of NodeError? + new Buffer(); +} catch(e) { + const symbols = Object.getOwnPropertySymbols(e); + const symbol = symbols.find(s => s.toString().indexOf('kIsNodeError') >= 0); + if(symbol) kIsNodeError = symbol; +} + // This function is part of the V8 stack trace API, for more info see: // https://v8.dev/docs/stack-trace-api function prepareStackTrace(error, stack) { @@ -416,9 +427,21 @@ function prepareStackTrace(error, stack) { sourceMapCache = {}; } - var name = error.name || 'Error'; - var message = error.message || ''; - var errorString = name + ": " + message; + // node gives its own errors special treatment. Mimic that behavior + // https://github.com/nodejs/node/blob/3cbaabc4622df1b4009b9d026a1a970bdbae6e89/lib/internal/errors.js#L118-L128 + // https://github.com/nodejs/node/pull/39182 + var errorString; + if (kIsNodeError) { + if(kIsNodeError in error) { + errorString = `${error.name} [${error.code}]: ${error.message}`; + } else { + errorString = ErrorPrototypeToString(error); + } + } else { + var name = error.name || 'Error'; + var message = error.message || ''; + errorString = name + ": " + message; + } var state = { nextPosition: null, curPosition: null }; var processedStack = []; @@ -471,11 +494,10 @@ function printErrorAndExit (error) { } if (source) { - console.error(); console.error(source); } - console.error(error.stack); + console.error(error); process.exit(1); } From c581e2f1f1ec1c7ac650f7d8af2f717ca31e39dd Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:10:38 -0400 Subject: [PATCH 02/15] add gh actions ci --- .github/workflows/continuous-integration.yml | 128 +++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 .github/workflows/continuous-integration.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..21b7b59 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,128 @@ +name: Continuous Integration +on: + # branches pushed by collaborators + push: + branches: + - master + # pull request from non-collaborators + pull_request: {} + # nightly + schedule: + - cron: '0 0 * * *' +jobs: + build: + name: "Test: ${{ matrix.os }}, node ${{ matrix.node }}" + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu, windows] + node: + - 16 + - 14 + - 12 + - 10 + - 9 + - '8' + - '7' + - '6' + - '4' + - '0.12' + - '0.10' + steps: + # checkout code + - uses: actions/checkout@v2 + # install node + - name: Use Node.js ${{ matrix.os }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + # npm install with caching + - run: | + npm config set cache "$( node -p "process.cwd()" )/temp/npm-cache" + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: temp/npm-cache + key: npm-cache-${{ matrix.os }} ${{ matrix.node }}-${{ hashFiles('package-lock.json') }} + # restore-keys: npm-cache-${{ matrix.os }} ${{ matrix.node }}- + - run: npm ci + + # # install version to test against + # - name: Use Node.js ${{ matrix.node }} + # uses: actions/setup-node@v1 + # with: + # node-version: ${{ matrix.node }} + + # Run tests + - run: npm test + + # test: + # needs: build + # name: "Test: ${{ matrix.os }}, node ${{ matrix.node }}" + # runs-on: ${{ matrix.os }}-latest + # strategy: + # fail-fast: false + # matrix: + # os: [ubuntu, windows] + # node: + # - 16 + # - 14 + # - 12 + # - 10 + # - 9 + # - '8' + # - '7' + # - '6' + # - '4' + # - '0.12' + # - '0.10' + # steps: + # # checkout code + # - uses: actions/checkout@v2 + # # install node + # - name: Use Node.js ${{ matrix.node }} + # uses: actions/setup-node@v1 + # with: + # node-version: ${{ matrix.node }} + # # lint, build, test + # # Downgrade from npm 7 to 6 because 7 still seems buggy to me + # - if: ${{ matrix.downgradeNpm }} + # run: npm install -g npm@6 + # - run: | + # npm config set cache "$( node -p "process.cwd()" )/temp/npm-cache" + # - name: Cache dependencies + # uses: actions/cache@v2 + # with: + # path: temp/npm-cache + # key: npm-cache-${{ matrix.os }}-${{ hashFiles('package-lock.json') }} + # restore-keys: npm-cache-${{matrix.os }}- + # - run: npm ci --ignore-scripts + # - name: Upload npm logs + # if: ${{ failure() }} + # uses: actions/upload-artifact@v1 + # with: + # name: npm-logs + # path: temp/npm-cache/_logs + # - run: npm run build-tsc + # - name: Download package artifact + # uses: actions/download-artifact@v1 + # with: + # name: ts-node-packed.tgz + # path: tests/ + # - run: npm install typescript@${{ matrix.typescript }} --force + # - run: npm run test-cov + # - name: Upload npm logs + # if: ${{ failure() }} + # uses: actions/upload-artifact@v1 + # with: + # name: npm-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }} + # path: temp/npm-cache/_logs + # - run: npm run coverage-report + # if: ${{ always() }} + # - name: Codecov + # if: ${{ always() }} + # uses: codecov/codecov-action@v1 + # with: + # flags: ${{ matrix.os }},node_${{ matrix.nodeFlag }},typescript_${{ matrix.typescriptFlag }} From 9ea5e6b2897b0c01402a6fd92d28e101f1b67788 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:14:20 -0400 Subject: [PATCH 03/15] try to fix tests --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index ef7ad55..8635296 100644 --- a/test.js +++ b/test.js @@ -616,7 +616,7 @@ it('handleUncaughtExceptions is true with existing listener', function(done) { ]; fs.writeFileSync('.original.js', 'this is the original code'); - fs.writeFileSync('.generated.js.map', createSingleLineSourceMap()); + fs.writeFileSync('.generated.js.map', `${ createSingleLineSourceMap() }`); fs.writeFileSync('.generated.js', source.join('\n')); child_process.exec('node ./.generated', function(error, stdout, stderr) { From b3b71f9fce1908a59ba285edd0a8ff565be6185f Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:19:55 -0400 Subject: [PATCH 04/15] fix --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 8635296..68e96b8 100644 --- a/test.js +++ b/test.js @@ -113,7 +113,7 @@ function compareStackTrace(sourceMap, source, expected) { function compareStdout(done, sourceMap, source, expected) { fs.writeFileSync('.original.js', 'this is the original code'); - fs.writeFileSync('.generated.js.map', sourceMap); + fs.writeFileSync('.generated.js.map', `${ sourceMap }`); fs.writeFileSync('.generated.js', source.join('\n') + '//@ sourceMappingURL=.generated.js.map'); child_process.exec('node ./.generated', function(error, stdout, stderr) { From 0fbbb8b24635e98aa38fe8912560a60ffc29d40e Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:21:11 -0400 Subject: [PATCH 05/15] npm install to support old npm --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 21b7b59..2af48b7 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -47,7 +47,7 @@ jobs: path: temp/npm-cache key: npm-cache-${{ matrix.os }} ${{ matrix.node }}-${{ hashFiles('package-lock.json') }} # restore-keys: npm-cache-${{ matrix.os }} ${{ matrix.node }}- - - run: npm ci + - run: npm install # # install version to test against # - name: Use Node.js ${{ matrix.node }} From 4aa14556c62a6d2fd135c7bc29b2dc90b8d90500 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:23:15 -0400 Subject: [PATCH 06/15] fix --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 68e96b8..03471d6 100644 --- a/test.js +++ b/test.js @@ -86,7 +86,7 @@ function createMultiLineSourceMapWithSourcesContent() { function compareStackTrace(sourceMap, source, expected) { // Check once with a separate source map - fs.writeFileSync('.generated.js.map', sourceMap); + fs.writeFileSync('.generated.js.map', `${ sourceMap }`); fs.writeFileSync('.generated.js', 'exports.test = function() {' + source.join('\n') + '};//@ sourceMappingURL=.generated.js.map'); try { From c61afc524388950ab736cb2d175167a0bf35986a Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:25:14 -0400 Subject: [PATCH 07/15] fix --- test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.js b/test.js index 03471d6..8fb0a62 100644 --- a/test.js +++ b/test.js @@ -86,7 +86,7 @@ function createMultiLineSourceMapWithSourcesContent() { function compareStackTrace(sourceMap, source, expected) { // Check once with a separate source map - fs.writeFileSync('.generated.js.map', `${ sourceMap }`); + fs.writeFileSync('.generated.js.map', sourceMap.toString()); fs.writeFileSync('.generated.js', 'exports.test = function() {' + source.join('\n') + '};//@ sourceMappingURL=.generated.js.map'); try { @@ -113,7 +113,7 @@ function compareStackTrace(sourceMap, source, expected) { function compareStdout(done, sourceMap, source, expected) { fs.writeFileSync('.original.js', 'this is the original code'); - fs.writeFileSync('.generated.js.map', `${ sourceMap }`); + fs.writeFileSync('.generated.js.map', sourceMap.toString()); fs.writeFileSync('.generated.js', source.join('\n') + '//@ sourceMappingURL=.generated.js.map'); child_process.exec('node ./.generated', function(error, stdout, stderr) { @@ -616,7 +616,7 @@ it('handleUncaughtExceptions is true with existing listener', function(done) { ]; fs.writeFileSync('.original.js', 'this is the original code'); - fs.writeFileSync('.generated.js.map', `${ createSingleLineSourceMap() }`); + fs.writeFileSync('.generated.js.map', createSingleLineSourceMap().toString()); fs.writeFileSync('.generated.js', source.join('\n')); child_process.exec('node ./.generated', function(error, stdout, stderr) { From 98ac22f9e4113f0a3f0bef843b385e3fd6e282c0 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 19:31:06 -0400 Subject: [PATCH 08/15] disable node 0.10 tests --- .github/workflows/continuous-integration.yml | 77 +------------------- 1 file changed, 1 insertion(+), 76 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 2af48b7..54fd5d3 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -28,7 +28,7 @@ jobs: - '6' - '4' - '0.12' - - '0.10' + # - '0.10' steps: # checkout code - uses: actions/checkout@v2 @@ -49,80 +49,5 @@ jobs: # restore-keys: npm-cache-${{ matrix.os }} ${{ matrix.node }}- - run: npm install - # # install version to test against - # - name: Use Node.js ${{ matrix.node }} - # uses: actions/setup-node@v1 - # with: - # node-version: ${{ matrix.node }} - # Run tests - run: npm test - - # test: - # needs: build - # name: "Test: ${{ matrix.os }}, node ${{ matrix.node }}" - # runs-on: ${{ matrix.os }}-latest - # strategy: - # fail-fast: false - # matrix: - # os: [ubuntu, windows] - # node: - # - 16 - # - 14 - # - 12 - # - 10 - # - 9 - # - '8' - # - '7' - # - '6' - # - '4' - # - '0.12' - # - '0.10' - # steps: - # # checkout code - # - uses: actions/checkout@v2 - # # install node - # - name: Use Node.js ${{ matrix.node }} - # uses: actions/setup-node@v1 - # with: - # node-version: ${{ matrix.node }} - # # lint, build, test - # # Downgrade from npm 7 to 6 because 7 still seems buggy to me - # - if: ${{ matrix.downgradeNpm }} - # run: npm install -g npm@6 - # - run: | - # npm config set cache "$( node -p "process.cwd()" )/temp/npm-cache" - # - name: Cache dependencies - # uses: actions/cache@v2 - # with: - # path: temp/npm-cache - # key: npm-cache-${{ matrix.os }}-${{ hashFiles('package-lock.json') }} - # restore-keys: npm-cache-${{matrix.os }}- - # - run: npm ci --ignore-scripts - # - name: Upload npm logs - # if: ${{ failure() }} - # uses: actions/upload-artifact@v1 - # with: - # name: npm-logs - # path: temp/npm-cache/_logs - # - run: npm run build-tsc - # - name: Download package artifact - # uses: actions/download-artifact@v1 - # with: - # name: ts-node-packed.tgz - # path: tests/ - # - run: npm install typescript@${{ matrix.typescript }} --force - # - run: npm run test-cov - # - name: Upload npm logs - # if: ${{ failure() }} - # uses: actions/upload-artifact@v1 - # with: - # name: npm-logs-${{ matrix.os }}-node-${{ matrix.nodeFlag }}-typescript-${{ matrix.typescriptFlag }} - # path: temp/npm-cache/_logs - # - run: npm run coverage-report - # if: ${{ always() }} - # - name: Codecov - # if: ${{ always() }} - # uses: codecov/codecov-action@v1 - # with: - # flags: ${{ matrix.os }},node_${{ matrix.nodeFlag }},typescript_${{ matrix.typescriptFlag }} From b731e0261f315ff9f210766707c00c684c1ae4e9 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 20:29:24 -0400 Subject: [PATCH 09/15] fix --- source-map-support.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-map-support.js b/source-map-support.js index 2332d6f..7652f7a 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -412,7 +412,7 @@ let kIsNodeError = undefined; try { // Get a deliberate ERR_INVALID_ARG_TYPE // TODO is there a better way to reliably get an instance of NodeError? - new Buffer(); + path.resolve(123); } catch(e) { const symbols = Object.getOwnPropertySymbols(e); const symbol = symbols.find(s => s.toString().indexOf('kIsNodeError') >= 0); From db624a375bf5d15e5f6df0efdabebbaa65ad29a8 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 20:37:58 -0400 Subject: [PATCH 10/15] add missing primordial --- source-map-support.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source-map-support.js b/source-map-support.js index 7652f7a..9c17d1a 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -419,6 +419,8 @@ try { if(symbol) kIsNodeError = symbol; } +const ErrorPrototypeToString = (err) =>Error.prototype.toString.call(err); + // This function is part of the V8 stack trace API, for more info see: // https://v8.dev/docs/stack-trace-api function prepareStackTrace(error, stack) { From 794bdb062c486d401436af5b673342bcfd007d02 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 20:40:25 -0400 Subject: [PATCH 11/15] fix --- source-map-support.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-map-support.js b/source-map-support.js index 9c17d1a..51f1f30 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -408,7 +408,7 @@ function wrapCallSite(frame, state) { return frame; } -let kIsNodeError = undefined; +var kIsNodeError = undefined; try { // Get a deliberate ERR_INVALID_ARG_TYPE // TODO is there a better way to reliably get an instance of NodeError? From d799caf476111a8b01910eaeaa9d590733dccbb9 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 20:44:54 -0400 Subject: [PATCH 12/15] fix --- source-map-support.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-map-support.js b/source-map-support.js index 51f1f30..98b3d52 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -415,7 +415,7 @@ try { path.resolve(123); } catch(e) { const symbols = Object.getOwnPropertySymbols(e); - const symbol = symbols.find(s => s.toString().indexOf('kIsNodeError') >= 0); + const symbol = symbols.find(function (s) {return s.toString().indexOf('kIsNodeError') >= 0}); if(symbol) kIsNodeError = symbol; } From e2891022b9f7f154f7abb991d698b98936dabddc Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 20:55:59 -0400 Subject: [PATCH 13/15] only test against and support supported node versions --- .github/workflows/continuous-integration.yml | 8 -------- package.json | 5 ++++- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 54fd5d3..92cc7bc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -21,14 +21,6 @@ jobs: - 16 - 14 - 12 - - 10 - - 9 - - '8' - - '7' - - '6' - - '4' - - '0.12' - # - '0.10' steps: # checkout code - uses: actions/checkout@v2 diff --git a/package.json b/package.json index 96dedd5..9fab3eb 100644 --- a/package.json +++ b/package.json @@ -27,5 +27,8 @@ "bugs": { "url": "https://github.com/evanw/node-source-map-support/issues" }, - "license": "MIT" + "license": "MIT", + "engines": { + "node": ">=12" + } } From 85e79ed1f33a71af563edf3e4e13494828da5517 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 21:04:01 -0400 Subject: [PATCH 14/15] remove buffer-from --- package.json | 1 - source-map-support.js | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 9fab3eb..19322a3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "test": "mocha" }, "dependencies": { - "buffer-from": "^1.0.0", "source-map": "^0.6.0" }, "devDependencies": { diff --git a/source-map-support.js b/source-map-support.js index 4459386..d0652f9 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -12,8 +12,6 @@ try { /* nop */ } -var bufferFrom = require('buffer-from'); - /** * Requires a module which is protected against bundler minification. * @@ -171,7 +169,7 @@ retrieveMapHandlers.push(function(source) { if (reSourceMap.test(sourceMappingURL)) { // Support source map URL as a data url var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1); - sourceMapData = bufferFrom(rawData, "base64").toString(); + sourceMapData = Buffer.from(rawData, "base64").toString(); sourceMappingURL = source; } else { // Support source map URLs relative to the source URL From b52b52269a06fbc4826310645cb5aae80f81e821 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Mon, 19 Jul 2021 21:10:09 -0400 Subject: [PATCH 15/15] remove buffer-from --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 8fb0a62..797ebbd 100644 --- a/test.js +++ b/test.js @@ -6,7 +6,7 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator; var child_process = require('child_process'); var assert = require('assert'); var fs = require('fs'); -var bufferFrom = require('buffer-from'); +var bufferFrom = Buffer.from; function compareLines(actual, expected) { assert(actual.length >= expected.length, 'got ' + actual.length + ' lines but expected at least ' + expected.length + ' lines');