Skip to content

Commit

Permalink
Support .tsx and .jsx files from CLI (#448)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ricardobeat authored and alangpierce committed Aug 26, 2019
1 parent fff991e commit 6ed6dff
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ async function buildDirectory(
outDirPath: string,
options: CLIOptions,
): Promise<void> {
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);
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 6ed6dff

Please sign in to comment.