From 88e666516841a9da771429ae9824cac19832f497 Mon Sep 17 00:00:00 2001 From: Ethan Marsh Date: Mon, 1 Jul 2024 08:48:25 -0700 Subject: [PATCH] feat: recognize mts files (#128) Resolve `.mts` files as TypeScript files. Co-authored-by: Ethan Marsh --- src/index.ts | 4 ++-- src/resolve.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index c08b58b3..fc1c89cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ type SWCOptions = WithRequiredProperty export default createUnplugin( ({ tsconfigFile, minify, include, exclude, ...options } = {}) => { const filter = createFilter( - include || /\.[jt]sx?$/, + include || /\.m?[jt]sx?$/, exclude || /node_modules/, ) @@ -44,7 +44,7 @@ export default createUnplugin( tsconfigFile === true ? undefined : tsconfigFile, )?.data?.compilerOptions || {} - const isTs = /\.tsx?$/.test(id) + const isTs = /\.m?tsx?$/.test(id) let jsc: SWCOptions = { parser: { diff --git a/src/resolve.ts b/src/resolve.ts index 97fb54e5..fef2fe25 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import { pathExists } from 'path-exists' -const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs'] +const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.mts', '.jsx', '.js', '.mjs', '.cjs'] const resolveFile = async(resolved: string, index = false) => { for (const ext of RESOLVE_EXTENSIONS) {