From 41f4ba8e33b1b8a3181c5bebe6f203509fd0b9d1 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 26 Jul 2022 20:23:12 +0200 Subject: [PATCH] refactor(runtime): delete some cli apis --- packages/runtime/src/cli/eval.ts | 14 ++++---------- packages/runtime/src/cli/index.ts | 7 +++---- packages/runtime/tests/repl.test.ts | 16 +++++++++++----- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/runtime/src/cli/eval.ts b/packages/runtime/src/cli/eval.ts index 6da89d43b..0d474f487 100644 --- a/packages/runtime/src/cli/eval.ts +++ b/packages/runtime/src/cli/eval.ts @@ -1,14 +1,8 @@ import { format } from './logger' import { EdgeRuntime } from '../edge-runtime' -export const inlineEval = async (scripts: string[]) => { - const results = [] - - for (const script of scripts) { - const runtime = new EdgeRuntime() - const result = await runtime.evaluate(script) - results.push(format(result)) - } - - return results +export const inlineEval = async (script: string) => { + const runtime = new EdgeRuntime() + const result = await runtime.evaluate(script) + return result } diff --git a/packages/runtime/src/cli/index.ts b/packages/runtime/src/cli/index.ts index e4707f061..f79561ca4 100644 --- a/packages/runtime/src/cli/index.ts +++ b/packages/runtime/src/cli/index.ts @@ -27,8 +27,7 @@ const { _: input, ...flags } = mri(process.argv.slice(2), { async function main() { if (flags.eval) { const { inlineEval } = await import('./eval') - const results = await inlineEval(input) - results.forEach((result) => console.log(result)) + console.log(await inlineEval(input[0])) return } @@ -74,7 +73,7 @@ async function main() { logger(`Waiting incoming requests at ${logger.quotes(server.url)}`) } -main().catch((err: unknown) => { - console.error(err) +main().catch((error: any) => { + if (!(error instanceof Error)) error = new Error(error) process.exit(1) }) diff --git a/packages/runtime/tests/repl.test.ts b/packages/runtime/tests/repl.test.ts index 4fe88cf63..a86d1fa10 100644 --- a/packages/runtime/tests/repl.test.ts +++ b/packages/runtime/tests/repl.test.ts @@ -36,10 +36,18 @@ test('preload web standard APIs', async () => { expect(code).toBe(0) const output: string[] = JSON.parse(stdout) - const normalized = output.filter((api) => !api.startsWith('__')).sort() - expect(normalized).toStrictEqual([ - 'AggregateError', + const replApis = output + // exclude private props + .filter((api) => !api.startsWith('__')) + // exclude v8 props + .filter( + (api) => + !['URLPattern', 'WeakRef', 'FinalizationRegistry', 'AggregateError'].includes(api) + ) + .sort() + + expect(replApis).toStrictEqual([ 'Array', 'ArrayBuffer', 'Atomics', @@ -51,7 +59,6 @@ test('preload web standard APIs', async () => { 'Date', 'Error', 'EvalError', - 'FinalizationRegistry', 'Float32Array', 'Float64Array', 'Function', @@ -85,7 +92,6 @@ test('preload web standard APIs', async () => { 'Uint8Array', 'Uint8ClampedArray', 'WeakMap', - 'WeakRef', 'WeakSet', 'WebAssembly', 'addEventListener',