@@ -15,17 +15,36 @@ const path = require('path');
15
15
const paths = require ( '../../config/paths' ) ;
16
16
const os = require ( 'os' ) ;
17
17
const immer = require ( 'react-dev-utils/immer' ) . produce ;
18
+ const globby = require ( 'react-dev-utils/globby' ) . sync ;
18
19
19
20
function writeJson ( fileName , object ) {
20
21
fs . writeFileSync ( fileName , JSON . stringify ( object , null , 2 ) + os . EOL ) ;
21
22
}
22
23
24
+ function verifyNoTypeScript ( ) {
25
+ const typescriptFiles = globby ( '**/*.(ts|tsx)' , { cwd : paths . appSrc } ) ;
26
+ if ( typescriptFiles . length > 0 ) {
27
+ console . warn (
28
+ chalk . yellow (
29
+ `We detected TypeScript in your project (${ chalk . bold (
30
+ `src${ path . sep } ${ typescriptFiles [ 0 ] } `
31
+ ) } ) and created a ${ chalk . bold ( 'tsconfig.json' ) } file for you.`
32
+ )
33
+ ) ;
34
+ console . warn ( ) ;
35
+ return false ;
36
+ }
37
+ return true ;
38
+ }
39
+
23
40
function verifyTypeScriptSetup ( ) {
24
41
let firstTimeSetup = false ;
25
42
26
43
if ( ! fs . existsSync ( paths . appTsConfig ) ) {
27
44
if ( ! paths . appIndexJs . match ( / \. t s x ? $ / ) ) {
28
- return ;
45
+ if ( verifyNoTypeScript ( ) ) {
46
+ return ;
47
+ }
29
48
}
30
49
writeJson ( paths . appTsConfig , { } ) ;
31
50
firstTimeSetup = true ;
@@ -41,14 +60,12 @@ function verifyTypeScriptSetup() {
41
60
} ) ) ;
42
61
} catch ( _ ) {
43
62
console . error (
44
- chalk . red (
45
- 'We detected a' ,
46
- chalk . bold ( 'tsconfig.json' ) ,
47
- "in your package root but couldn't find an installation of" ,
48
- chalk . bold ( 'typescript' ) + '.'
63
+ chalk . bold . red (
64
+ `It looks like you're trying to use TypeScript but do not have ${ chalk . bold (
65
+ 'typescript'
66
+ ) } installed.`
49
67
)
50
68
) ;
51
- console . error ( ) ;
52
69
console . error (
53
70
chalk . bold (
54
71
'Please install' ,
@@ -60,9 +77,11 @@ function verifyTypeScriptSetup() {
60
77
)
61
78
) ;
62
79
console . error (
63
- 'If you are not trying to use TypeScript, please remove the ' +
64
- chalk . cyan ( 'tsconfig.json' ) +
65
- ' file from your package root.'
80
+ chalk . bold (
81
+ 'If you are not trying to use TypeScript, please remove the ' +
82
+ chalk . cyan ( 'tsconfig.json' ) +
83
+ ' file from your package root (and any TypeScript files).'
84
+ )
66
85
) ;
67
86
console . error ( ) ;
68
87
process . exit ( 1 ) ;
0 commit comments