File tree Expand file tree Collapse file tree 4 files changed +35
-7
lines changed Expand file tree Collapse file tree 4 files changed +35
-7
lines changed Original file line number Diff line number Diff line change 1
1
import fs from 'fs' ;
2
2
import path from 'path' ;
3
3
import { CLIEngine } from 'eslint' ;
4
+ import { PackageJson } from './types' ;
5
+ import { getReactVersion } from './utils' ;
4
6
5
7
interface CreateEslintConfigArgs {
8
+ pkg : PackageJson ;
6
9
rootDir : string ;
7
10
writeFile : boolean ;
8
11
}
9
12
export function createEslintConfig ( {
13
+ pkg,
10
14
rootDir,
11
15
writeFile,
12
16
} : CreateEslintConfigArgs ) : CLIEngine . Options [ 'baseConfig' ] {
17
+ const isReactLibrary = Boolean ( getReactVersion ( pkg ) ) ;
18
+
13
19
const config = {
14
20
extends : [
15
21
'react-app' ,
16
22
'prettier/@typescript-eslint' ,
17
23
'plugin:prettier/recommended' ,
18
24
] ,
25
+ settings : {
26
+ react : {
27
+ // Fix for https://github.com/jaredpalmer/tsdx/issues/279
28
+ version : isReactLibrary ? 'detect' : '999.999.999' ,
29
+ } ,
30
+ } ,
19
31
} ;
20
32
21
33
if ( writeFile ) {
Original file line number Diff line number Diff line change @@ -33,18 +33,13 @@ import { concatAllArray } from 'jpjs';
33
33
import getInstallCmd from './getInstallCmd' ;
34
34
import getInstallArgs from './getInstallArgs' ;
35
35
import { Input , Select } from 'enquirer' ;
36
- import { TsdxOptions } from './types' ;
36
+ import { PackageJson , TsdxOptions } from './types' ;
37
37
import { createProgressEstimator } from './createProgressEstimator' ;
38
38
const pkg = require ( '../package.json' ) ;
39
39
40
40
const prog = sade ( 'tsdx' ) ;
41
41
42
- let appPackageJson : {
43
- name: string ;
44
- source ?: string ;
45
- jest ? : any ;
46
- eslint ? : any ;
47
- } ;
42
+ let appPackageJson : PackageJson ;
48
43
49
44
try {
50
45
appPackageJson = fs . readJSONSync ( resolveApp ( 'package.json' ) ) ;
606
601
const cli = new CLIEngine ( {
607
602
baseConfig : {
608
603
...createEslintConfig ( {
604
+ pkg : appPackageJson ,
609
605
rootDir : paths . appRoot ,
610
606
writeFile : opts [ 'write-file' ] ,
611
607
} ) ,
Original file line number Diff line number Diff line change @@ -18,3 +18,12 @@ export interface TsdxOptions {
18
18
// Is this the very first rollup config (and thus should one-off metadata be extracted)?
19
19
writeMeta ?: boolean ;
20
20
}
21
+
22
+ export interface PackageJson {
23
+ name : string ;
24
+ source ?: string ;
25
+ jest ?: any ;
26
+ eslint ?: any ;
27
+ dependencies ?: { [ packageName : string ] : string } ;
28
+ devDependencies ?: { [ packageName : string ] : string } ;
29
+ }
Original file line number Diff line number Diff line change 1
1
import fs from 'fs-extra' ;
2
2
import path from 'path' ;
3
3
import camelCase from 'camelcase' ;
4
+ import { PackageJson } from './types' ;
4
5
5
6
// Remove the package name scope if it exists
6
7
export const removeScope = ( name : string ) => name . replace ( / ^ @ .* \/ / , '' ) ;
@@ -35,3 +36,13 @@ export function clearConsole() {
35
36
process . platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H'
36
37
) ;
37
38
}
39
+
40
+ export function getReactVersion ( {
41
+ dependencies,
42
+ devDependencies,
43
+ } : PackageJson ) {
44
+ return (
45
+ ( dependencies && dependencies . react ) ||
46
+ ( devDependencies && devDependencies . react )
47
+ ) ;
48
+ }
You can’t perform that action at this time.
0 commit comments