From af9dec7bf426b6f745d9289d0835e4d1b0ed7889 Mon Sep 17 00:00:00 2001 From: sqwishy Date: Thu, 14 Jul 2022 12:30:31 -0700 Subject: [PATCH] deno script args spread to array (#203) smol issue where a deno script with parameters named `main` or `run` will try to assign over imported main or the run function. This uses the spread syntax to unpack the arguments and arrange them in an array in argument order. Instead of making assignments to the scope. --- backend/src/worker.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/worker.rs b/backend/src/worker.rs index 39db3248e6..85b1511c7e 100644 --- a/backend/src/worker.rs +++ b/backend/src/worker.rs @@ -604,10 +604,13 @@ print(res_json) let wrapper_content: String = format!( r#" import {{ main }} from "./inner.ts"; -const {{{spread}}} = JSON.parse(await Deno.readTextFile("args.json")) + +const args = await Deno.readTextFile("args.json") + .then(JSON.parse) + .then(({{ {spread} }}) => [ {spread} ]) async function run() {{ - let res: any = await main({spread}); + let res: any = await main(...args); if (res == undefined) {{ res = {{}} }}