bun-polyfills: fix test loader error printing

This commit is contained in:
jhmaster2000
2023-10-13 20:42:27 -03:00
parent f9af6d3411
commit 89d8939a45
2 changed files with 12 additions and 7 deletions

View File

@@ -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",

View File

@@ -1,9 +1,10 @@
// @ts-check
/// <reference types="typings-esm-loader" />
/// <reference types="bun-types" />
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;
}