From 5675ce7636c43c06826b4e9668d0bf74dfcd846e Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 30 Nov 2022 13:48:24 +0100 Subject: [PATCH] fix(playground): Script Type This PR fixes the Source Type `Script` option on the playground. The issue is that Rome only parses `cjs` and `cts` files as scripts and all other extensions as modules. This PR updates the playground's extension mapping to correctly use `cjs` and `cts` for scripts --- website/src/playground/utils.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/website/src/playground/utils.ts b/website/src/playground/utils.ts index 6c241e5173f..e94f9c121cb 100644 --- a/website/src/playground/utils.ts +++ b/website/src/playground/utils.ts @@ -275,7 +275,12 @@ export function classnames(...names: (undefined | boolean | string)[]): string { } export function isTypeScriptFilename(filename: string): boolean { - return filename.endsWith(".ts") || filename.endsWith(".tsx"); + return ( + filename.endsWith(".ts") || + filename.endsWith(".tsx") || + filename.endsWith(".mts") || + filename.endsWith(".cts") + ); } export function isJSXFilename(filename: string): boolean { @@ -283,7 +288,16 @@ export function isJSXFilename(filename: string): boolean { } export function isScriptFilename(filename: string): boolean { - return filename.endsWith(".js"); + return filename.endsWith(".cjs") || filename.endsWith(".cts"); +} + +export function isModuleFilename(filename: string): boolean { + return ( + filename.endsWith(".mjs") || + filename.endsWith(".mts") || + filename.endsWith(".js") || + filename.endsWith(".ts") + ); } export function modifyFilename( @@ -307,9 +321,9 @@ export function getExtension(opts: ExtensionOptions): string { let ext = ""; if (opts.script) { - ext = "js"; + ext = "cjs"; } else { - ext = "mjs"; + ext = "js"; } if (opts.typescript) { @@ -328,6 +342,7 @@ export function getExtension(opts: ExtensionOptions): string { export function isValidExtension(filename: string): boolean { return ( isScriptFilename(filename) || + isModuleFilename(filename) || isTypeScriptFilename(filename) || isJSXFilename(filename) );