Skip to content

Commit 3bf18dd

Browse files
committed
feat(scripts): add async typecheck report
fork ts checker in sync mode was pretty slow. So we add async typechecking and tap into the plugin hooks for showing up in console.
1 parent 3f3face commit 3bf18dd

File tree

14 files changed

+3059
-1927
lines changed

14 files changed

+3059
-1927
lines changed

examples/plugin/src/ts/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export function strRepeat(item: string, times: number): string {
2-
return item.repeat(times);
2+
return item.repeat(times + 1);
33
}

examples/plugin/wpackio.project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
main: ['./src/app/index.js'],
3636
mobile: ['./src/app/mobile.js'],
3737
},
38-
hasTypeScript: false,
38+
// hasTypeScript: false,
3939
// Extra webpack config to be passed directly
4040
webpackConfig: (config, merge, appDir, isDev) => {
4141
const svgoLoader = {
@@ -99,7 +99,7 @@ module.exports = {
9999
entry: {
100100
main: ['./src/foo/foo.js'],
101101
},
102-
hasTypeScript: false,
102+
// hasTypeScript: false,
103103
// Extra webpack config to be passed directly
104104
webpackConfig: undefined,
105105
},
@@ -110,7 +110,7 @@ module.exports = {
110110
entry: {
111111
main: ['./src/reactapp/index.jsx'],
112112
},
113-
hasTypeScript: false,
113+
// hasTypeScript: false,
114114
webpackConfig: (config, merge, appDir, isDev) => {
115115
const customRules = {
116116
module: {

examples/theme/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
"private": true,
99
"devDependencies": {
1010
"@wpackio/scripts": "file:../../packages/scripts",
11-
"node-sass": "^4.10.0"
11+
"node-sass": "^4.12.0"
1212
},
1313
"scripts": {
1414
"bootstrap": "wpackio-scripts bootstrap",
1515
"build": "wpackio-scripts build",
1616
"start": "wpackio-scripts start",
17-
"archive": "wpackio-scripts pack"
17+
"archive": "wpackio-scripts pack",
18+
"dev": "../../packages/scripts/lib/bin/index.js"
1819
},
1920
"dependencies": {
2021
"@wpackio/entrypoint": "file:../../packages/entrypoint"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import foo from './module';
2+
3+
console.log('hello!');

examples/theme/wpackio.project.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ module.exports = {
3636
webpackConfig: undefined,
3737
},
3838
// If has more length, then multi-compiler
39+
{
40+
name: 'single',
41+
entry: {
42+
main: ['./src/single/single.js'],
43+
},
44+
},
3945
],
4046
// Output path relative to the context directory
4147
// We need relative path here, else, we can not map to publicPath

examples/theme/yarn.lock

Lines changed: 2637 additions & 1764 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'react-dev-utils/typescriptFormatter' {
2+
export default function formatter(message: any, useColors: boolean): string;
3+
}

packages/scripts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"ora": "^3.4.0",
6767
"postcss-loader": "^3.0.0",
6868
"pretty-error": "^2.1.1",
69-
"react-dev-utils": "^6.0.4",
69+
"react-dev-utils": "^9.0.0",
7070
"sass-loader": "^7.1.0",
7171
"slugify": "^1.3.4",
7272
"style-loader": "^0.23.1",

packages/scripts/src/bin/serve.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import {
2222
printGeneralInfoMessage,
2323
printCompileTimeMessages,
2424
webpackStatToJsonOptions,
25+
printErrorHeading,
26+
printWarningHeading,
2527
} from './utils';
2628

2729
/**
@@ -81,22 +83,28 @@ export function serve(options: ProgramOptions | undefined): void {
8183
done: () => {
8284
printSuccessfullyCompiledMessage();
8385
},
86+
onWatching() {
87+
printWatchingMessage();
88+
},
8489
onError: msg => {
85-
console.log('');
86-
console.log(`${chalk.bgRed.black(' ERROR ')} please review`);
87-
console.log('');
88-
msg.errors.forEach(e => console.log(e));
89-
console.log('');
90+
printErrorHeading('ERROR');
91+
msg.errors.forEach(e => {
92+
console.log(e);
93+
console.log('');
94+
});
9095
printFailedCompileMEssage();
9196
},
9297
onWarn: msg => {
98+
printWarningHeading('WARNING');
99+
msg.warnings.forEach(e => {
100+
console.log(e);
101+
console.log('');
102+
});
93103
printCompiledWithWarnMessage();
94-
msg.warnings.forEach(e => console.log(e));
95104
},
96105
onEmit: stats => {
97106
printCompileTimeMessages(stats, lastWebpackStat);
98107
lastWebpackStat = stats.toJson(webpackStatToJsonOptions);
99-
printWatchingMessage();
100108
},
101109
firstCompile: (stats: webpack.Stats) => {
102110
spinner.stop();
@@ -107,27 +115,55 @@ export function serve(options: ProgramOptions | undefined): void {
107115
console.log('');
108116

109117
if (stats.hasErrors()) {
110-
console.log('');
111-
console.log(
112-
`${chalk.bgRed.black(' ERROR ')} please review`
113-
);
114-
messages.errors.forEach(e => console.log(e));
115-
console.log('');
118+
printErrorHeading('ERROR');
119+
messages.errors.forEach(e => {
120+
console.log(e);
121+
console.log('');
122+
});
116123
printFailedCompileMEssage();
117124
} else if (stats.hasWarnings()) {
125+
printWarningHeading('WARNING');
126+
messages.warnings.forEach(e => {
127+
console.log(e);
128+
console.log('');
129+
});
118130
printCompiledWithWarnMessage();
119-
messages.warnings.forEach(e => console.log(e));
120131
} else {
121132
printSuccessfullyCompiledMessage();
122133
}
123134
printCompileTimeMessages(stats, lastWebpackStat);
124-
printWatchingMessage();
125135
lastWebpackStat = stats.toJson(webpackStatToJsonOptions);
126136
},
127137
onBsChange(file) {
128138
printGeneralInfoMessage(`changed: ${chalk.bold(file)}`);
129139
printGeneralInfoMessage('reloading browser');
130140
},
141+
onTcStart() {
142+
printGeneralInfoMessage('waiting for typecheck results...');
143+
},
144+
onTcEnd(messages) {
145+
if (messages.errors.length || messages.warnings.length) {
146+
if (messages.errors.length) {
147+
printErrorHeading('TS ERROR');
148+
messages.errors.forEach(e => {
149+
console.log(e);
150+
console.log('');
151+
});
152+
}
153+
if (messages.warnings.length) {
154+
printWarningHeading('TS WARNING');
155+
messages.warnings.forEach(e => {
156+
console.log(e);
157+
console.log('');
158+
});
159+
}
160+
} else {
161+
printGeneralInfoMessage(
162+
'no typecheck errors',
163+
logSymbols.success
164+
);
165+
}
166+
},
131167
});
132168
server.serve();
133169

0 commit comments

Comments
 (0)