From 0815951cfa42c009649ffda90141d44f2c78ea9a Mon Sep 17 00:00:00 2001 From: fargito Date: Sun, 30 Jun 2024 23:02:12 +0200 Subject: [PATCH 1/2] fix: exclude internal js files from compilation process --- packages/register/register.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/register/register.ts b/packages/register/register.ts index 89a579dc4..cced5a398 100644 --- a/packages/register/register.ts +++ b/packages/register/register.ts @@ -89,10 +89,7 @@ export function compile( }, async = false, ) { - if ( - (filename.includes('node_modules') && !AVAILABLE_TS_EXTENSION_PATTERN.test(filename)) || - !AVAILABLE_EXTENSION_PATTERN.test(filename) - ) { + if (!AVAILABLE_TS_EXTENSION_PATTERN.test(filename)) { return sourcecode } if (options && typeof options.fallbackToTs === 'function' && options.fallbackToTs(filename)) { From ef80c024b6bf20afb94dbf4fecde74c60ff9437e Mon Sep 17 00:00:00 2001 From: fargito Date: Sun, 30 Jun 2024 23:07:50 +0200 Subject: [PATCH 2/2] chore: remove unused AVAILABLE_EXTENSION_PATTERN regex --- .../__tests__/extention/extention.spec.ts | 15 +-------------- packages/register/register.ts | 5 ----- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/integrate/__tests__/extention/extention.spec.ts b/packages/integrate/__tests__/extention/extention.spec.ts index 0d078b8ec..89b83ae71 100644 --- a/packages/integrate/__tests__/extention/extention.spec.ts +++ b/packages/integrate/__tests__/extention/extention.spec.ts @@ -1,10 +1,9 @@ -import { AVAILABLE_EXTENSION_PATTERN, AVAILABLE_TS_EXTENSION_PATTERN } from '@swc-node/register/register.ts' +import { AVAILABLE_TS_EXTENSION_PATTERN } from '@swc-node/register/register.ts' import test from 'ava' import * as ts from 'typescript' const tsExtensions = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts, ts.Extension.Cts] const nonTsExtensions = [ts.Extension.Js, ts.Extension.Jsx, ts.Extension.Mjs, ts.Extension.Cjs, '.es6', '.es'] -const defaultExtensions = [...tsExtensions, ...nonTsExtensions] const ignoreExtensions = ['.txt', '.json', '.xml'] test(`AVAILABLE_TS_EXTENSION_PATTERN matches TypeScript extensions`, (t) => { @@ -24,15 +23,3 @@ test(`AVAILABLE_TS_EXTENSION_PATTERN does not match non-ts extensions`, (t) => { t.false(AVAILABLE_TS_EXTENSION_PATTERN.test(`file${ext}`)) }) }) - -test(`AVAILABLE_EXTENSION_PATTERN matches default extensions`, (t) => { - defaultExtensions.forEach((ext) => { - t.true(AVAILABLE_EXTENSION_PATTERN.test(`file${ext}`)) - }) -}) - -test(`AVAILABLE_EXTENSION_PATTERN does not match non-default extensions`, (t) => { - ignoreExtensions.forEach((ext) => { - t.false(AVAILABLE_EXTENSION_PATTERN.test(`file${ext}`)) - }) -}) diff --git a/packages/register/register.ts b/packages/register/register.ts index cced5a398..b6653c348 100644 --- a/packages/register/register.ts +++ b/packages/register/register.ts @@ -23,11 +23,6 @@ export const AVAILABLE_TS_EXTENSION_PATTERN = new RegExp( 'i', ) -export const AVAILABLE_EXTENSION_PATTERN = new RegExp( - `((? ext.replace(/^\./, '\\.')).join('|')}))$`, - 'i', -) - const injectInlineSourceMap = ({ filename, code,