@@ -17,10 +17,22 @@ const inquirer = require('inquirer');
17
17
const clearConsole = require ( './clearConsole' ) ;
18
18
const formatWebpackMessages = require ( './formatWebpackMessages' ) ;
19
19
const getProcessForPort = require ( './getProcessForPort' ) ;
20
- const typescriptFormatter = require ( './typescriptFormatter' ) ;
21
- const forkTsCheckerWebpackPlugin = require ( 'fork-ts-checker-webpack-plugin' ) ;
22
20
23
21
const isInteractive = process . stdout . isTTY ;
22
+ let handleCompile ;
23
+
24
+ // You can safely remove this after ejecting.
25
+ // We only use this block for testing of Create React App itself:
26
+ const isSmokeTest = process . argv . some ( arg => arg . indexOf ( '--smoke-test' ) > - 1 ) ;
27
+ if ( isSmokeTest ) {
28
+ handleCompile = ( err , stats ) => {
29
+ if ( err || stats . hasErrors ( ) || stats . hasWarnings ( ) ) {
30
+ process . exit ( 1 ) ;
31
+ } else {
32
+ process . exit ( 0 ) ;
33
+ }
34
+ } ;
35
+ }
24
36
25
37
function prepareUrls ( protocol , host , port ) {
26
38
const formatUrl = hostname =>
@@ -101,20 +113,12 @@ function printInstructions(appName, urls, useYarn) {
101
113
console . log ( ) ;
102
114
}
103
115
104
- function createCompiler (
105
- webpack ,
106
- config ,
107
- appName ,
108
- urls ,
109
- useYarn ,
110
- useTypeScript ,
111
- devSocket
112
- ) {
116
+ function createCompiler ( webpack , config , appName , urls , useYarn ) {
113
117
// "Compiler" is a low-level interface to Webpack.
114
118
// It lets us listen to some events and provide our own custom messages.
115
119
let compiler ;
116
120
try {
117
- compiler = webpack ( config ) ;
121
+ compiler = webpack ( config , handleCompile ) ;
118
122
} catch ( err ) {
119
123
console . log ( chalk . red ( 'Failed to compile.' ) ) ;
120
124
console . log ( ) ;
@@ -135,35 +139,10 @@ function createCompiler(
135
139
} ) ;
136
140
137
141
let isFirstCompile = true ;
138
- let tsMessagesPromise ;
139
- let tsMessagesResolver ;
140
-
141
- if ( useTypeScript ) {
142
- compiler . hooks . beforeCompile . tap ( 'beforeCompile' , ( ) => {
143
- tsMessagesPromise = new Promise ( resolve => {
144
- tsMessagesResolver = msgs => resolve ( msgs ) ;
145
- } ) ;
146
- } ) ;
147
-
148
- forkTsCheckerWebpackPlugin
149
- . getCompilerHooks ( compiler )
150
- . receive . tap ( 'afterTypeScriptCheck' , ( diagnostics , lints ) => {
151
- const allMsgs = [ ...diagnostics , ...lints ] ;
152
- const format = message =>
153
- `${ message . file } \n${ typescriptFormatter ( message , true ) } ` ;
154
-
155
- tsMessagesResolver ( {
156
- errors : allMsgs . filter ( msg => msg . severity === 'error' ) . map ( format ) ,
157
- warnings : allMsgs
158
- . filter ( msg => msg . severity === 'warning' )
159
- . map ( format ) ,
160
- } ) ;
161
- } ) ;
162
- }
163
142
164
143
// "done" event fires when Webpack has finished recompiling the bundle.
165
144
// Whether or not you have warnings or errors, you will get this event.
166
- compiler . hooks . done . tap ( 'done' , async stats => {
145
+ compiler . hooks . done . tap ( 'done' , stats => {
167
146
if ( isInteractive ) {
168
147
clearConsole ( ) ;
169
148
}
@@ -173,43 +152,9 @@ function createCompiler(
173
152
// them in a readable focused way.
174
153
// We only construct the warnings and errors for speed:
175
154
// https://github.com/facebook/create-react-app/issues/4492#issuecomment-421959548
176
- const statsData = stats . toJson ( {
177
- all : false ,
178
- warnings : true ,
179
- errors : true ,
180
- } ) ;
181
-
182
- if ( useTypeScript && statsData . errors . length === 0 ) {
183
- const delayedMsg = setTimeout ( ( ) => {
184
- console . log (
185
- chalk . yellow (
186
- 'Files successfully emitted, waiting for typecheck results...'
187
- )
188
- ) ;
189
- } , 100 ) ;
190
-
191
- const messages = await tsMessagesPromise ;
192
- clearTimeout ( delayedMsg ) ;
193
- statsData . errors . push ( ...messages . errors ) ;
194
- statsData . warnings . push ( ...messages . warnings ) ;
195
-
196
- // Push errors and warnings into compilation result
197
- // to show them after page refresh triggered by user.
198
- stats . compilation . errors . push ( ...messages . errors ) ;
199
- stats . compilation . warnings . push ( ...messages . warnings ) ;
200
-
201
- if ( messages . errors . length > 0 ) {
202
- devSocket . errors ( messages . errors ) ;
203
- } else if ( messages . warnings . length > 0 ) {
204
- devSocket . warnings ( messages . warnings ) ;
205
- }
206
-
207
- if ( isInteractive ) {
208
- clearConsole ( ) ;
209
- }
210
- }
211
-
212
- const messages = formatWebpackMessages ( statsData ) ;
155
+ const messages = formatWebpackMessages (
156
+ stats . toJson ( { all : false , warnings : true , errors : true } )
157
+ ) ;
213
158
const isSuccessful = ! messages . errors . length && ! messages . warnings . length ;
214
159
if ( isSuccessful ) {
215
160
console . log ( chalk . green ( 'Compiled successfully!' ) ) ;
@@ -249,27 +194,6 @@ function createCompiler(
249
194
) ;
250
195
}
251
196
} ) ;
252
-
253
- // You can safely remove this after ejecting.
254
- // We only use this block for testing of Create React App itself:
255
- const isSmokeTest = process . argv . some (
256
- arg => arg . indexOf ( '--smoke-test' ) > - 1
257
- ) ;
258
- if ( isSmokeTest ) {
259
- compiler . hooks . failed . tap ( 'smokeTest' , async ( ) => {
260
- await tsMessagesPromise ;
261
- process . exit ( 1 ) ;
262
- } ) ;
263
- compiler . hooks . done . tap ( 'smokeTest' , async stats => {
264
- await tsMessagesPromise ;
265
- if ( stats . hasErrors ( ) || stats . hasWarnings ( ) ) {
266
- process . exit ( 1 ) ;
267
- } else {
268
- process . exit ( 0 ) ;
269
- }
270
- } ) ;
271
- }
272
-
273
197
return compiler ;
274
198
}
275
199
0 commit comments