Skip to content

Commit

Permalink
add log 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mizerski committed Nov 11, 2023
1 parent be8d33d commit 3ef5cae
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/react/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ type CompilerOptions = {
denyList?: string[];
};

async function getSourceFile(fileUrl: URL) {
try {
return await Deno.readTextFile(fileUrl);
} catch (_) {
return await (await fetch(fileUrl, {
headers: {
"Content-Type": "application/javascript",
}
})).text();
}
}

export function createCompilerHandler(
options: CompilerOptions,
): RequestHandler {
Expand All @@ -27,7 +39,7 @@ export function createCompilerHandler(
const fileUrl = join(root, filePath);

log.debug(`[react/compiler.ts] Compiling ${fileUrl}`)
const source = await Deno.readTextFile(fileUrl);
const source = await getSourceFile(fileUrl);
const result = await compile(fileUrl.toString(), source, {
jsxImportSource: "react",
development: true,
Expand Down

0 comments on commit 3ef5cae

Please sign in to comment.