Skip to content

Commit

Permalink
Remove react dependency requirement when using react-jsx in `tsconf…
Browse files Browse the repository at this point in the history
…ig.json` (#264)

* remove jsx related check

* remove the right code

* fix lint
  • Loading branch information
jgoux authored Sep 24, 2023
1 parent 7a98051 commit 503fdd1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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]);
};

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 503fdd1

Please sign in to comment.