Skip to content

Commit

Permalink
refactor(runtime): delete some cli apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jul 26, 2022
1 parent 1642e0f commit 41f4ba8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
14 changes: 4 additions & 10 deletions packages/runtime/src/cli/eval.ts
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 3 additions & 4 deletions packages/runtime/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
})
16 changes: 11 additions & 5 deletions packages/runtime/tests/repl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -51,7 +59,6 @@ test('preload web standard APIs', async () => {
'Date',
'Error',
'EvalError',
'FinalizationRegistry',
'Float32Array',
'Float64Array',
'Function',
Expand Down Expand Up @@ -85,7 +92,6 @@ test('preload web standard APIs', async () => {
'Uint8Array',
'Uint8ClampedArray',
'WeakMap',
'WeakRef',
'WeakSet',
'WebAssembly',
'addEventListener',
Expand Down

0 comments on commit 41f4ba8

Please sign in to comment.