From 503fdd1f29626d8e96c39c5be89c8f02ebb049a3 Mon Sep 17 00:00:00 2001 From: Julien Goux Date: Sun, 24 Sep 2023 21:49:00 +0200 Subject: [PATCH] Remove react dependency requirement when using `react-jsx` in `tsconfig.json` (#264) * remove jsx related check * remove the right code * fix lint --- src/plugins/typescript/index.ts | 9 +-------- tests/plugins/typescript.test.ts | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/plugins/typescript/index.ts b/src/plugins/typescript/index.ts index 57bb4886a..b390df06b 100644 --- a/src/plugins/typescript/index.ts +++ b/src/plugins/typescript/index.ts @@ -1,4 +1,3 @@ -import ts from 'typescript'; import { compact } from '../../util/array.js'; import { dirname, isInternal, toAbsolute } from '../../util/path.js'; import { timerify } from '../../util/Performance.js'; @@ -34,8 +33,6 @@ const resolveExtensibleConfig = async (configFilePath: string) => { return config; }; -const jsxWithReact = [ts.JsxEmit.React, ts.JsxEmit.ReactJSX, ts.JsxEmit.ReactJSXDev, ts.JsxEmit.ReactNative]; - export const findTypeScriptDependencies: GenericPluginCallback = async configFilePath => { const compilerOptions: CompilerOptions = await loadTSConfig(configFilePath); const config: TsConfigJson = await resolveExtensibleConfig(configFilePath); // Dual loader to get external `extends` dependencies @@ -48,11 +45,7 @@ export const findTypeScriptDependencies: GenericPluginCallback = async configFil ? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : '')) : []; const importHelpers = compilerOptions?.importHelpers ? ['tslib'] : []; - const jsx = compilerOptions?.jsxImportSource - ? [compilerOptions.jsxImportSource] - : compilerOptions?.jsx && jsxWithReact.includes(compilerOptions.jsx) - ? ['react'] - : []; + const jsx = compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []; return compact([...extend, ...types, ...plugins, ...importHelpers, ...jsx]); }; diff --git a/tests/plugins/typescript.test.ts b/tests/plugins/typescript.test.ts index 002aa6823..1f9961a43 100644 --- a/tests/plugins/typescript.test.ts +++ b/tests/plugins/typescript.test.ts @@ -25,7 +25,7 @@ test('Find dependencies in typescript configuration (jsx-preserve)', async () => test('Find dependencies in typescript configuration (jsx)', async () => { const configFilePath = join(cwd, 'tsconfig-jsx.json'); const dependencies = await typescript.findDependencies(configFilePath); - assert.deepEqual(dependencies, ['react']); + assert.deepEqual(dependencies, []); }); test('Find dependencies in typescript configuration (jsx-import-source)', async () => {