From 0da5a1e28e87efce0e06a2ee4848b3d3248335c3 Mon Sep 17 00:00:00 2001 From: Andrew Brey <34140052+andrewbrey@users.noreply.github.com> Date: Thu, 12 Aug 2021 16:17:12 -0700 Subject: [PATCH] fix(exec, bundle): allow passing one exec result to another and bandaid fix the bundle command Previously only numbers and strings could be passed as exec args, but now you can pass the results of one exec call to another and in this case, only the sdtout will be used from the first result. Also "fix" an intermittent failure of the bundle command which is caused by a non-deterministic key order for the `result.files` array when source maps were emitted - by disabling source maps, we effectively ensure that the first entry is always the file we want. --- src/cli/bundle.ts | 10 ++++++++++ src/runtime/exec.ts | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cli/bundle.ts b/src/cli/bundle.ts index 39a4219..6dbb053 100644 --- a/src/cli/bundle.ts +++ b/src/cli/bundle.ts @@ -68,8 +68,18 @@ async function bundleFile( const result = await Deno.emit(file, { bundle: "module", check: true, + compilerOptions: { + sourceMap: false, // Set sourcemaps to be false so that the resultant files array only has one entry + }, ...options, }); + + // TODO - the key order of `result.files` is non-deterministic, so this might + // need to be reworked a bit to more selectively pull out the bundled file + // result that is desired. In the short term, it is reasonably well known + // that the first file will be *the only file* when sourcemaps are turned + // off in the compiler options (note that not doing this results in + // intermittently failing results on repeated calls to `dzx bundle`) return Object.values(result.files)[0] as string; } catch (err) { if (err instanceof Deno.errors.NotFound) { diff --git a/src/runtime/exec.ts b/src/runtime/exec.ts index 841eb66..eae9a98 100644 --- a/src/runtime/exec.ts +++ b/src/runtime/exec.ts @@ -6,10 +6,15 @@ let runningProcesses = 0; export async function exec( pieces: TemplateStringsArray, - ...args: Array + ...args: Array ): Promise { runningProcesses++; - const cmd = quote(pieces, ...args); + const cmd = quote( + pieces, + ...args.map(( + a, + ) => (a instanceof ProcessOutput ? a.stdout.replace(/\n$/, "") : a)), + ); if ($.verbose) { console.log($.brightBlue("$ %s"), cmd);