From 89d8939a45461a8205feb03f4e074a3ce195b6c0 Mon Sep 17 00:00:00 2001 From: jhmaster2000 <32803471+jhmaster2000@users.noreply.github.com> Date: Fri, 13 Oct 2023 20:42:27 -0300 Subject: [PATCH] bun-polyfills: fix test loader error printing --- packages/bun-polyfills/package.json | 3 ++- packages/bun-polyfills/tools/bun_test_loader.mjs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/bun-polyfills/package.json b/packages/bun-polyfills/package.json index 7fdae98323..eae5b2a16e 100644 --- a/packages/bun-polyfills/package.json +++ b/packages/bun-polyfills/package.json @@ -15,7 +15,8 @@ "typescript": "^5.2.2" }, "scripts": { - "node": "tsx --enable-source-maps --import ./dist/src/repl.js", + "node": "tsx --no-warnings --enable-source-maps --import ./dist/src/repl.js", + "test": "node --no-warnings --loader ./tools/bun_test_loader.mjs", "clean": "rm -rf dist", "preprocess": "bun tools/updateversions.ts", "build": "bun run clean && bun run preprocess && bunx tsc && bunx copyfiles \"./lib/**/*.wasm\" dist", diff --git a/packages/bun-polyfills/tools/bun_test_loader.mjs b/packages/bun-polyfills/tools/bun_test_loader.mjs index b4076da33b..2466157ce7 100644 --- a/packages/bun-polyfills/tools/bun_test_loader.mjs +++ b/packages/bun-polyfills/tools/bun_test_loader.mjs @@ -1,9 +1,10 @@ // @ts-check /// /// -import { fileURLToPath, pathToFileURL } from 'url'; -import path from 'path'; -import fs from 'fs'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import path from 'node:path'; +import util from 'node:util'; +import fs from 'node:fs'; import $ from 'chalk'; import bunwasm from 'bun-wasm'; import { TransformResponseStatus } from 'bun-wasm/schema'; @@ -104,16 +105,19 @@ function formatBuildErrors(buildErrors) { const loc = err.data.location; const str = `${$.redBright('error')}${$.gray(':')} ${$.bold(err.data.text)}\n` + (loc - ? `${highlightErrorChar(loc.line_text, loc.offset)}\n` + + ? `${highlightErrorChar(loc.line_text, loc.column)}\n` + $.redBright.bold('^'.padStart(loc.column)) + '\n' + `${$.bold(loc.file)}${$.gray(':')}${$.yellowBright(loc.line)}${$.gray(':')}${$.yellowBright(loc.column)} ${$.gray(loc.offset)}` : '' ); - return { __proto__: Error.prototype, stack: str }; + const newerr = new Error(str); + newerr.name = 'BuildError'; + newerr.stack = str; + return newerr; }); const aggregate = new AggregateError(formatted, `Input code has ${formatted.length} error${formatted.length === 1 ? '' : 's'}`); Error.captureStackTrace(aggregate, NO_STACK); - aggregate.name = 'BuildError'; + aggregate.name = 'BuildFailed'; return aggregate; }