From abfdfc78ad516cb11579a342cda9196a127bd942 Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Tue, 16 Jun 2020 21:34:29 +0200 Subject: [PATCH 1/3] Switch to native Node.js source map support --- package.json | 2 - packages/alfa-test/package.json | 3 +- packages/alfa-test/src/format.ts | 18 ++++--- packages/alfa-test/src/stack.ts | 69 ++++++++++++++++++++++++ packages/alfa-test/tsconfig.json | 1 + scripts/common/tester.js | 27 +++++----- yarn.lock | 91 +++----------------------------- 7 files changed, 104 insertions(+), 107 deletions(-) create mode 100644 packages/alfa-test/src/stack.ts diff --git a/package.json b/package.json index bbf3abb842..bf94788c10 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,9 @@ "devDependencies": { "@types/node": "^12.12.24", "axios": "^0.19.0", - "execa": "^4.0.0", "lerna": "^3.19.0", "minimist": "^1.2.0", "prettier": "2.0.1", - "source-map-support": "^0.5.16", "typescript": "^3.7.4" } } diff --git a/packages/alfa-test/package.json b/packages/alfa-test/package.json index fccf64339b..b503412617 100644 --- a/packages/alfa-test/package.json +++ b/packages/alfa-test/package.json @@ -19,8 +19,7 @@ ], "dependencies": { "@siteimprove/alfa-highlight": "^0.2.0", - "@types/node": "^13.1.6", - "error-stack-parser": "^2.0.2" + "@types/node": "^13.1.6" }, "publishConfig": { "access": "public", diff --git a/packages/alfa-test/src/format.ts b/packages/alfa-test/src/format.ts index 350cb741f7..ec4b788a0a 100644 --- a/packages/alfa-test/src/format.ts +++ b/packages/alfa-test/src/format.ts @@ -3,18 +3,24 @@ import * as assert from "assert"; import * as path from "path"; -import * as stack from "error-stack-parser"; - import { mark } from "@siteimprove/alfa-highlight"; +import { stack } from "./stack"; + /** * @internal */ export function format(name: string, error: Error): string { - const [{ fileName, lineNumber, columnNumber }] = stack.parse(error); + const [callsite] = stack(error); - const filePath = - fileName === undefined ? "unknown" : path.relative(process.cwd(), fileName); + const [file, line, column] = + callsite.type === "native" + ? ["native", -1, -1] + : [ + path.relative(process.cwd(), callsite.file), + callsite.line, + callsite.column, + ]; let message: string; @@ -41,7 +47,7 @@ export function format(name: string, error: Error): string { } const output = ` -${mark.underline(`${filePath}(${lineNumber},${columnNumber}):`)} ${mark.bold( +${mark.underline(`${file}(${line},${column}):`)} ${mark.bold( name.trim().replace(/\s+/g, " ") )} ${message} diff --git a/packages/alfa-test/src/stack.ts b/packages/alfa-test/src/stack.ts new file mode 100644 index 0000000000..31de6274c0 --- /dev/null +++ b/packages/alfa-test/src/stack.ts @@ -0,0 +1,69 @@ +/** + * @internal + */ +export function* stack(error: Error): Iterable { + const frames = error + .stack!.split("\n") + .slice(1) + .map((frame) => frame.trim()); + + for (let i = 0, n = frames.length; i < n; i++) { + const frame = frames[i]; + + // If the frame doesn't contain a location reference, skip the frame. + if (!/(\d+:\d+)/.test(frame)) { + continue; + } + + // If the next frame contains a source mapping for the current frame as + // indicated by an arrow, skip the frame. + if (i + 1 < n && frames[i + 1].startsWith("->")) { + continue; + } + + // Sanitize the frame and split it on colons. This will group the frame into + // 3 separate parts: The file, the line, and the column. + const parts = frame + .replace("(", "") + .replace(")", "") + .replace("->", "") + .split(":") + .map((part) => part.trim()); + + // The part containing the file may contain other things as well that we + // need to remove so we grab everything from the last space character and + // cut off the rest. + parts[0] = parts[0].substring(parts[0].lastIndexOf(" ") + 1); + + const [file, line, column] = parts; + + yield { + type: file.startsWith("internal") ? "internal" : "user", + file, + line: +line, + column: +column, + }; + } +} + +type Frame = Frame.Native | Frame.Internal | Frame.User; + +namespace Frame { + export interface Native { + type: "native"; + } + + export interface Internal { + type: "internal"; + file: string; + line: number; + column: number; + } + + export interface User { + type: "user"; + file: string; + line: number; + column: number; + } +} diff --git a/packages/alfa-test/tsconfig.json b/packages/alfa-test/tsconfig.json index a670135cd3..3a1eb83777 100644 --- a/packages/alfa-test/tsconfig.json +++ b/packages/alfa-test/tsconfig.json @@ -4,6 +4,7 @@ "files": [ "src/format.ts", "src/index.ts", + "src/stack.ts", "src/test.ts", "src/types.ts", "test/test.spec.ts" diff --git a/scripts/common/tester.js b/scripts/common/tester.js index bef02ddb7b..1c9df901d7 100644 --- a/scripts/common/tester.js +++ b/scripts/common/tester.js @@ -1,5 +1,5 @@ const os = require("os"); -const execa = require("execa"); +const child_process = require("child_process"); const { system } = require("./system"); @@ -14,17 +14,20 @@ exports.tester = { while (queue.length > 0) { const fileName = queue.shift().replace(/\.tsx?$/, ".js"); - try { - await execa.node(fileName, [], { - nodeOptions: [ - ...process.execArgv, - ...["--require", require.resolve("source-map-support/register")], - ], - stdio: "inherit", - }); - } catch { - system.exit(1); - } + const child = child_process.fork(fileName, [], { + execArgv: [...process.execArgv, "--enable-source-maps"], + stdio: "inherit", + }); + + await new Promise((resolve) => + child.on("close", (code) => { + if (code !== 0) { + system.exit(1); + } else { + resolve(); + } + }) + ); } }); }, diff --git a/yarn.lock b/yarn.lock index 0eda76bbee..ce5a7d9714 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3067,15 +3067,6 @@ cross-spawn@^6.0.0: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^7.0.0: - version "7.0.2" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.2.tgz#d0d7dcfa74e89115c7619f4f721a94e1fdb716d6" - integrity sha512-PD6G8QG3S4FK/XCGFbEQrDqO2AnMMsy0meR7lerlIOHAAbkuavGU/pOqprrlvfTNjvowivTeBsjebAL0NSoMxw== - dependencies: - path-key "^3.1.0" - shebang-command "^2.0.0" - which "^2.0.1" - crypto-random-string@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-2.0.0.tgz#ef2a7a966ec11083388369baa02ebead229b30d5" @@ -3682,13 +3673,6 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -error-stack-parser@^2.0.2: - version "2.0.6" - resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.6.tgz#5a99a707bd7a4c58a797902d48d82803ede6aad8" - integrity sha512-d51brTeqC+BHlwF0BhPtcYgF5nlzf9ZZ0ZIUQNZpc9ZB9qw5IJ2diTrBY9jlCJkTLITYPjmiX6OWCwH+fuyNgQ== - dependencies: - stackframe "^1.1.1" - es-abstract@^1.17.0-next.1, es-abstract@^1.17.2, es-abstract@^1.17.4, es-abstract@^1.17.5: version "1.17.5" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.17.5.tgz#d8c9d1d66c8981fb9200e2251d799eee92774ae9" @@ -3805,21 +3789,6 @@ execa@^1.0.0: signal-exit "^3.0.0" strip-eof "^1.0.0" -execa@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf" - integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA== - dependencies: - cross-spawn "^7.0.0" - get-stream "^5.0.0" - human-signals "^1.1.1" - is-stream "^2.0.0" - merge-stream "^2.0.0" - npm-run-path "^4.0.0" - onetime "^5.1.0" - signal-exit "^3.0.2" - strip-final-newline "^2.0.0" - executable@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/executable/-/executable-4.1.1.tgz#41532bff361d3e57af4d763b70582db18f5d133c" @@ -4320,13 +4289,6 @@ get-stream@^4.0.0, get-stream@^4.1.0: dependencies: pump "^3.0.0" -get-stream@^5.0.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9" - integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw== - dependencies: - pump "^3.0.0" - get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -4605,6 +4567,11 @@ he@1.2.0, he@^1.1.0: resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f" integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== +highlight.js@^9.18.1: + version "9.18.1" + resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.18.1.tgz#ed21aa001fe6252bb10a3d76d47573c6539fe13c" + integrity sha512-OrVKYz70LHsnCgmbXctv/bfuvntIKDz177h0Co37DQ5jamGZLVmoCVMtjMtNZY3X9DrCcKfklHPNeA0uPZhSJg== + highlight.js@~9.12.0: version "9.12.0" resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e" @@ -4684,11 +4651,6 @@ https-proxy-agent@^4.0.0: agent-base "5" debug "4" -human-signals@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3" - integrity sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== - humanize-ms@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed" @@ -6900,13 +6862,6 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" -npm-run-path@^4.0.0: - version "4.0.1" - resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea" - integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw== - dependencies: - path-key "^3.0.0" - npmlog@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" @@ -7321,11 +7276,6 @@ path-key@^2.0.0, path-key@^2.0.1: resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= -path-key@^3.0.0, path-key@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" - integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== - path-parse@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" @@ -8203,23 +8153,11 @@ shebang-command@^1.2.0: dependencies: shebang-regex "^1.0.0" -shebang-command@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-2.0.0.tgz#ccd0af4f8835fbdc265b82461aaf0c36663f34ea" - integrity sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== - dependencies: - shebang-regex "^3.0.0" - shebang-regex@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= -shebang-regex@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" - integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== - shellwords@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" @@ -8324,7 +8262,7 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" -source-map-support@^0.5.16, source-map-support@^0.5.6: +source-map-support@^0.5.6: version "0.5.18" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.18.tgz#f5f33489e270bd7f7d7e7b8debf283f3a4066960" integrity sha512-9luZr/BZ2QeU6tO2uG8N2aZpVSli4TSAOAqFOyTO51AJcD9P99c0K1h6dD6r6qo5dyT44BR5exweOaLLeldTkQ== @@ -8426,11 +8364,6 @@ stack-utils@^1.0.1: resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-1.0.2.tgz#33eba3897788558bebfc2db059dc158ec36cebb8" integrity sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA== -stackframe@^1.1.1: - version "1.1.1" - resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.1.1.tgz#ffef0a3318b1b60c3b58564989aca5660729ec71" - integrity sha512-0PlYhdKh6AfFxRyK/v+6/k+/mMfyiEBbTM5L94D0ZytQnJ166wuwoTYLHFWGbs2dpA8Rgq763KGWmN1EQEYHRQ== - static-extend@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6" @@ -8612,11 +8545,6 @@ strip-eof@^1.0.0: resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= -strip-final-newline@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" - integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== - strip-indent@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2" @@ -9314,13 +9242,6 @@ which@1.3.1, which@^1.2.9, which@^1.3.0, which@^1.3.1: dependencies: isexe "^2.0.0" -which@^2.0.1: - version "2.0.2" - resolved "https://registry.yarnpkg.com/which/-/which-2.0.2.tgz#7c6a8dd0a636a0327e10b59c9286eee93f3f51b1" - integrity sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== - dependencies: - isexe "^2.0.0" - wide-align@1.1.3, wide-align@^1.1.0: version "1.1.3" resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.3.tgz#ae074e6bdc0c14a431e804e624549c633b000457" From 6b76838e0c83f4a938026188dcf597e986eeba08 Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Tue, 16 Jun 2020 21:35:16 +0200 Subject: [PATCH 2/3] Export `stack()` --- packages/alfa-test/src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/alfa-test/src/index.ts b/packages/alfa-test/src/index.ts index 04efde9d84..81524479d4 100644 --- a/packages/alfa-test/src/index.ts +++ b/packages/alfa-test/src/index.ts @@ -1,3 +1,4 @@ export * from "./format"; +export * from "./stack"; export * from "./test"; export * from "./types"; From 09404ae7c95921e3eb293e1d71e6c787c3797892 Mon Sep 17 00:00:00 2001 From: Kasper Isager Date: Wed, 10 Feb 2021 20:37:04 +0100 Subject: [PATCH 3/3] Don't integrate against Node.js v10 --- .github/workflows/integrate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 546d01c659..beb861139b 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [10, 12, 14] + node-version: [12, 14] name: Build steps: - uses: actions/checkout@v2