fix: fix util import statement (#45104)

Co-authored-by: IsmailTlemcani <ismail.tlemcani@gmail.com>
This commit is contained in:
Ismail Tlemcani
2022-02-24 17:16:47 +01:00
committed by GitHub
parent 3f22ab9d5a
commit 2846df2b66
5 changed files with 12 additions and 6 deletions

View File

@ -229,7 +229,7 @@ exports.onCreateWebpackConfig = ({ stage, actions }) => {
path: require.resolve('path-browserify'),
assert: require.resolve('assert'),
crypto: require.resolve('crypto-browserify'),
util: false,
util: require.resolve('util/util'),
buffer: require.resolve('buffer'),
stream: require.resolve('stream-browserify'),
process: require.resolve('process/browser')

View File

@ -124,6 +124,7 @@
"stream-browserify": "3.0.0",
"tone": "14.7.77",
"typescript": "4.5.5",
"util": "^0.12.4",
"uuid": "8.3.2",
"validator": "13.7.0"
},

View File

@ -25,6 +25,7 @@ const __utils = (() => {
const oldLog = ctx.console.log.bind(ctx.console);
function proxyLog(...args: string[]) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
logs.push(args.map(arg => __format(arg)).join(' '));
if (logs.join('\n').length > MAX_LOGS_SIZE) {
flushLogs();

View File

@ -1,4 +1,4 @@
import { inspect } from 'util';
import { inspect } from 'util/util';
export function format(x) {
// we're trying to mimic console.log, so we avoid wrapping strings in quotes:
@ -10,6 +10,10 @@ export function format(x) {
x.entries(),
([k, v]) => `${k} => ${v}`
).join(', ')}})`;
} else if (typeof x === 'bigint') {
return x.toString() + 'n';
} else if (typeof x === 'symbol') {
return x.toString();
}
return inspect(x);
}

View File

@ -35,17 +35,17 @@ describe('format', () => {
const primitives = [
'str',
57,
BigInt(10),
true,
false,
null,
// eslint-disable-next-line no-undefined
undefined,
Symbol('Sym')
undefined
];
expect(format(primitives)).toBe(
`[ 'str', 57, 10n, true, false, null, undefined, Symbol(Sym) ]`
`[ 'str', 57, true, false, null, undefined ]`
);
expect(format(BigInt(10))).toBe(`10n`);
expect(format(Symbol('Sym'))).toBe(`Symbol(Sym)`);
});
it(`outputs NaN as 'NaN'`, () => {
expect(format(NaN)).toBe('NaN');