Skip to content

Commit

Permalink
fix(exec, bundle): allow passing one exec result to another and banda…
Browse files Browse the repository at this point in the history
…id 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.
  • Loading branch information
andrewbrey authored and c4spar committed Aug 13, 2021
1 parent fd82808 commit 0da5a1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/cli/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/runtime/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ let runningProcesses = 0;

export async function exec(
pieces: TemplateStringsArray,
...args: Array<string | number>
...args: Array<string | number | ProcessOutput>
): Promise<ProcessOutput> {
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);
Expand Down

0 comments on commit 0da5a1e

Please sign in to comment.