Skip to content

Commit

Permalink
fix: bundle <url> throws file not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed May 13, 2021
1 parent fb990c5 commit 8e4b385
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/cli/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export async function preBundle(
script: string,
options?: Deno.EmitOptions,
): Promise<string> {
if (!await fs.exists(script)) {
error(`File not found: ${script}`);
}

const scriptResult = await bundleFile(script, options);

const bundleContent =
Expand All @@ -64,12 +60,21 @@ async function bundleFile(
file: string,
options: Deno.EmitOptions = {},
): Promise<string> {
const result = await Deno.emit(file, {
bundle: "module",
check: true,
...options,
});
return Object.values(result.files)[0] as string;
try {
const result = await Deno.emit(file, {
bundle: "module",
check: true,
...options,
});
return Object.values(result.files)[0] as string;
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
throw error(`File not found: ${file}`);
} else if (err instanceof Deno.errors.PermissionDenied) {
throw error(`Permission denied: ${file}`);
}
throw error(err);
}
}

// async function getShebang(script: string): Promise<string> {
Expand Down

0 comments on commit 8e4b385

Please sign in to comment.