From 3ef5caea1c278dd1f0d32197a179f4750dda822d Mon Sep 17 00:00:00 2001 From: Daniel Mizerski Date: Sat, 11 Nov 2023 19:58:55 +0100 Subject: [PATCH] add log 4 --- lib/react/compiler.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/react/compiler.ts b/lib/react/compiler.ts index e3f15859..64a1825c 100644 --- a/lib/react/compiler.ts +++ b/lib/react/compiler.ts @@ -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 { @@ -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,