From e1c615f4e04c8d9d2dfa31fc0c5278d97c5dd663 Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Fri, 7 Jan 2022 23:29:07 +0000 Subject: [PATCH] Ignore non-JS files when compiling Pages Functions (#216) * Ignore non-JS files when compiling Pages Functions * Add support for `jsx` and `tsx` file extensions Co-authored-by: Sunil Pai Co-authored-by: Sunil Pai --- .changeset/fluffy-insects-clap.md | 5 +++++ packages/wrangler/pages/functions/filepath-routing.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/fluffy-insects-clap.md diff --git a/.changeset/fluffy-insects-clap.md b/.changeset/fluffy-insects-clap.md new file mode 100644 index 000000000000..0d46600b4872 --- /dev/null +++ b/.changeset/fluffy-insects-clap.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Ignore non-JS files when compiling Pages Functions diff --git a/packages/wrangler/pages/functions/filepath-routing.ts b/packages/wrangler/pages/functions/filepath-routing.ts index 1ecc6e5074de..401893fc5a97 100644 --- a/packages/wrangler/pages/functions/filepath-routing.ts +++ b/packages/wrangler/pages/functions/filepath-routing.ts @@ -27,7 +27,7 @@ export async function generateConfigFromFileTree({ await forEachFile(baseDir, async (filepath) => { const ext = path.extname(filepath); - if (/\.(mjs|js|ts)/.test(ext)) { + if (/^\.(mjs|js|ts|tsx|jsx)$/.test(ext)) { // transform the code to ensure we're working with vanilla JS + ESM const { code } = await transform(await fs.readFile(filepath, "utf-8"), { loader: ext === ".ts" ? "ts" : "js",