From 6ed6dff94e235fd1fc6bb9b2bc27b3caca71a20d Mon Sep 17 00:00:00 2001 From: Ricardo Tomasi Date: Mon, 26 Aug 2019 02:18:35 +0200 Subject: [PATCH] Support .tsx and .jsx files from CLI (#448) Despite the transforms being supported, the CLI will currently only compile `.ts` files. This makes sure the correct file extensions are used when running something like `sucrase ./src -d ./out --transforms imports,typescript,jsx`. --- src/cli.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index d36ac2ce..aab20f60 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -75,7 +75,9 @@ async function buildDirectory( outDirPath: string, options: CLIOptions, ): Promise { - const extension = options.sucraseOptions.transforms.includes("typescript") ? ".ts" : ".js"; + const extensions = options.sucraseOptions.transforms.includes("typescript") + ? [".ts", ".tsx"] + : [".js", ".jsx"]; if (!(await exists(outDirPath))) { await mkdir(outDirPath); } @@ -87,10 +89,8 @@ async function buildDirectory( const outChildPath = join(outDirPath, child); if ((await stat(srcChildPath)).isDirectory()) { await buildDirectory(srcChildPath, outChildPath, options); - } else if (srcChildPath.endsWith(extension)) { - const outPath = `${outChildPath.substr(0, outChildPath.length - extension.length)}.${ - options.outExtension - }`; + } else if (extensions.some((ext) => srcChildPath.endsWith(ext))) { + const outPath = outChildPath.replace(/\.\w+$/, `.${options.outExtension}`); await buildFile(srcChildPath, outPath, options); } }