Skip to content

Commit 1e7e2a6

Browse files
committed
Add JSDoc type safety (typescript)
1 parent b8de73f commit 1e7e2a6

File tree

5 files changed

+204
-27
lines changed

5 files changed

+204
-27
lines changed

packages/more/package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,12 @@
8686
"not dead",
8787
"not ie <= 11",
8888
"not op_mini all"
89-
]
89+
],
90+
"devDependencies": {
91+
"@types/html-webpack-plugin": "^3.2.0",
92+
"@types/mini-css-extract-plugin": "^0.2.0",
93+
"@types/node": "^10.12.18",
94+
"@types/webpack": "^4.4.21",
95+
"@types/webpack-dev-server": "^3.1.1"
96+
}
9097
}

packages/more/scripts/build.js

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ rimraf(buildDir, {}, () => {
4747
}
4848

4949
console.log(
50+
// todo: remove when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/31583 is merged
51+
// @ts-ignore: ANSI escape codes are not supported using current typings
5052
stats.toString({
5153
chunks: false,
5254
modules: false,

packages/more/webpack.config.js

+36-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable indent */
1+
// @ts-check
22
const path = require('path');
33
const webpack = require('webpack');
44
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
@@ -39,8 +39,6 @@ const stats = {
3939
},
4040
};
4141

42-
process.noDeprecation = true;
43-
4442
const isProd = NODE_ENV === 'production';
4543
const isDev = !isProd;
4644

@@ -63,23 +61,31 @@ const cacheLoaderDirectory = path.join(
6361
isProd ? 'prod' : 'dev'
6462
);
6563

66-
// common function to get style loaders
67-
const getStyleLoaders = (cssOptions, preProcessor) => {
68-
const loaders = [
64+
/**
65+
* Common function to get style loaders
66+
* @param {Object} cssOptions
67+
* @param {string=} preProcessor
68+
* @return { import('webpack').RuleSetUseItem[] }
69+
*
70+
*/
71+
const getStyleLoaders = (cssOptions, preProcessor) =>
72+
// todo: fix MiniCssExtractPlugin.loader type issue
73+
// @ts-ignore: There seems to be an issue with MiniCssExtractPlugin.loader
74+
[
6975
isDev && {
70-
loader: require.resolve('cache-loader'),
76+
loader: 'cache-loader',
7177
options: { cacheDirectory: cacheLoaderDirectory },
7278
},
73-
isDev && require.resolve('style-loader'),
79+
isDev && 'style-loader',
7480
isProd && {
7581
loader: MiniCssExtractPlugin.loader,
7682
},
7783
{
78-
loader: require.resolve('css-loader'),
84+
loader: 'css-loader',
7985
options: cssOptions,
8086
},
8187
{
82-
loader: require.resolve('postcss-loader'),
88+
loader: 'postcss-loader',
8389
options: {
8490
ident: 'postcss',
8591
plugins: () => [
@@ -94,20 +100,19 @@ const getStyleLoaders = (cssOptions, preProcessor) => {
94100
sourceMap: isProd && shouldUseSourceMap,
95101
},
96102
},
97-
].filter(Boolean);
98-
if (preProcessor) {
99-
loaders.push({
100-
loader: require.resolve(preProcessor),
103+
preProcessor && {
104+
loader: preProcessor,
101105
options: {
102106
sourceMap: isProd && shouldUseSourceMap,
103107
includePaths: [sourceDir],
104108
},
105-
});
106-
}
107-
return loaders;
108-
};
109+
},
110+
].filter(Boolean);
109111

110-
module.exports = {
112+
/**
113+
* @type {import('webpack').Configuration}
114+
*/
115+
const webpackConfig = {
111116
mode: isProd ? 'production' : 'development',
112117

113118
context: sourceDir,
@@ -133,11 +138,8 @@ module.exports = {
133138
: '[name].chunk.js',
134139
},
135140

136-
devtool: isProd
137-
? shouldUseSourceMap
138-
? 'source-map'
139-
: false
140-
: isDev && 'cheap-module-source-map',
141+
devtool:
142+
shouldUseSourceMap && isProd ? 'source-map' : 'cheap-module-source-map',
141143

142144
optimization: {
143145
minimize: isProd,
@@ -155,6 +157,8 @@ module.exports = {
155157
},
156158
},
157159

160+
// todo: fix WorkboxWebpackPlugin.GenerateSW to return the Plugin type
161+
// @ts-ignore: WorkboxWebpackPlugin doesn't have typings
158162
plugins: [
159163
// setting production environment will strip out
160164
// some of the development code from the app
@@ -238,7 +242,7 @@ module.exports = {
238242
new AddAssetHtmlPlugin([
239243
{
240244
filepath: path.join(dllDir, 'libs.dll.js'),
241-
includeSourcemap: false,
245+
includeRelatedFiles: false,
242246
},
243247
]),
244248

@@ -389,6 +393,8 @@ module.exports = {
389393
},
390394
},
391395

396+
// todo: remove when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/31583 is merged
397+
// @ts-ignore: ANSI escape codes are not supported using current typings
392398
stats,
393399

394400
node: {
@@ -415,6 +421,11 @@ module.exports = {
415421
inline: true,
416422
compress: false,
417423
disableHostCheck: true,
424+
425+
// todo: remove when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/31583 is merged
426+
// @ts-ignore: ANSI escape codes are not supported using current typings
418427
stats,
419428
},
420429
};
430+
431+
module.exports = webpackConfig;

packages/more/webpack.dll.config.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
const webpack = require('webpack');
23
const path = require('path');
34

@@ -7,7 +8,10 @@ const pkgJson = path.resolve(process.env.INIT_CWD, 'package.json');
78
const config = require(pkgJson);
89
const customLibs = Array.isArray(config && config.dll) ? config.dll : [];
910

10-
module.exports = {
11+
/**
12+
* @type {import('webpack').Configuration}
13+
*/
14+
const webpackConfig = {
1115
mode: 'development',
1216
entry: {
1317
libs: [
@@ -41,3 +45,5 @@ module.exports = {
4145
}),
4246
],
4347
};
48+
49+
module.exports = webpackConfig;

packages/more/yarn.lock

+151
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,157 @@
158158
dependencies:
159159
any-observable "^0.3.0"
160160

161+
"@types/anymatch@*":
162+
version "1.3.0"
163+
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.0.tgz#d1d55958d1fccc5527d4aba29fc9c4b942f563ff"
164+
integrity sha512-7WcbyctkE8GTzogDb0ulRAEw7v8oIS54ft9mQTU7PfM0hp5e+8kpa+HeQ7IQrFbKtJXBKcZ4bh+Em9dTw5L6AQ==
165+
166+
"@types/body-parser@*":
167+
version "1.17.0"
168+
resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.17.0.tgz#9f5c9d9bd04bb54be32d5eb9fc0d8c974e6cf58c"
169+
integrity sha512-a2+YeUjPkztKJu5aIF2yArYFQQp8d51wZ7DavSHjFuY1mqVgidGyzEQ41JIVNy82fXj8yPgy2vJmfIywgESW6w==
170+
dependencies:
171+
"@types/connect" "*"
172+
"@types/node" "*"
173+
174+
"@types/clean-css@*":
175+
version "3.4.30"
176+
resolved "https://registry.yarnpkg.com/@types/clean-css/-/clean-css-3.4.30.tgz#0052c136f5248002428e3638b37de4a39818641d"
177+
integrity sha1-AFLBNvUkgAJCjjY4s33ko5gYZB0=
178+
179+
"@types/connect@*":
180+
version "3.4.32"
181+
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.32.tgz#aa0e9616b9435ccad02bc52b5b454ffc2c70ba28"
182+
integrity sha512-4r8qa0quOvh7lGD0pre62CAb1oni1OO6ecJLGCezTmhQ8Fz50Arx9RUszryR8KlgK6avuSXvviL6yWyViQABOg==
183+
dependencies:
184+
"@types/node" "*"
185+
186+
"@types/events@*":
187+
version "1.2.0"
188+
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86"
189+
integrity sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==
190+
191+
"@types/express-serve-static-core@*":
192+
version "4.16.0"
193+
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.16.0.tgz#fdfe777594ddc1fe8eb8eccce52e261b496e43e7"
194+
integrity sha512-lTeoCu5NxJU4OD9moCgm0ESZzweAx0YqsAcab6OB0EB3+As1OaHtKnaGJvcngQxYsi9UNv0abn4/DRavrRxt4w==
195+
dependencies:
196+
"@types/events" "*"
197+
"@types/node" "*"
198+
"@types/range-parser" "*"
199+
200+
"@types/express@*":
201+
version "4.16.0"
202+
resolved "https://registry.yarnpkg.com/@types/express/-/express-4.16.0.tgz#6d8bc42ccaa6f35cf29a2b7c3333cb47b5a32a19"
203+
integrity sha512-TtPEYumsmSTtTetAPXlJVf3kEqb6wZK0bZojpJQrnD/djV4q1oB6QQ8aKvKqwNPACoe02GNiy5zDzcYivR5Z2w==
204+
dependencies:
205+
"@types/body-parser" "*"
206+
"@types/express-serve-static-core" "*"
207+
"@types/serve-static" "*"
208+
209+
"@types/html-minifier@*":
210+
version "3.5.2"
211+
resolved "https://registry.yarnpkg.com/@types/html-minifier/-/html-minifier-3.5.2.tgz#f897a13d847a774e9b6fd91497e9b0e0ead71c35"
212+
integrity sha512-yikK28/KlVyf8g9i/k+TDFlteLuZ6QQTUdVqvKtzEB+8DSLCTjxfh6IK45KnW4rYFI3Y8T4LWpYJMTmfJleWaQ==
213+
dependencies:
214+
"@types/clean-css" "*"
215+
"@types/relateurl" "*"
216+
"@types/uglify-js" "*"
217+
218+
"@types/html-webpack-plugin@^3.2.0":
219+
version "3.2.0"
220+
resolved "https://registry.yarnpkg.com/@types/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#26b20854124bbcccbc22ccec715a1ba74583526c"
221+
integrity sha512-in9rViBsTRB4ZApndZ12It68nGzSMHVK30JD7c49iLIHMFeTPbP7I7wevzMv7re2o0k5TlU6Ry/beyrmgWX7Bg==
222+
dependencies:
223+
"@types/html-minifier" "*"
224+
"@types/tapable" "*"
225+
"@types/webpack" "*"
226+
227+
"@types/http-proxy-middleware@*":
228+
version "0.19.1"
229+
resolved "https://registry.yarnpkg.com/@types/http-proxy-middleware/-/http-proxy-middleware-0.19.1.tgz#042559a6c45a8f1694b3119902f92890d6ba0909"
230+
integrity sha512-P4zpWTYFp1qXLjEPnjFVBB1KmR+b9Tt+RnzJxQSW4DTyh1lKDnYZi/Q1DzuupocX+7IYi2W7uIrbNybQg91H6A==
231+
dependencies:
232+
"@types/connect" "*"
233+
"@types/http-proxy" "*"
234+
"@types/node" "*"
235+
236+
"@types/http-proxy@*":
237+
version "1.16.2"
238+
resolved "https://registry.yarnpkg.com/@types/http-proxy/-/http-proxy-1.16.2.tgz#16cb373b52fff2aa2f389d23d940ed4a642349e5"
239+
integrity sha512-GgqePmC3rlsn1nv+kx5OviPuUBU2omhnlXOaJSXFgOdsTcScNFap+OaCb2ip9Bm4m5L8EOehgT5d9M4uNB90zg==
240+
dependencies:
241+
"@types/events" "*"
242+
"@types/node" "*"
243+
244+
"@types/mime@*":
245+
version "2.0.0"
246+
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-2.0.0.tgz#5a7306e367c539b9f6543499de8dd519fac37a8b"
247+
integrity sha512-A2TAGbTFdBw9azHbpVd+/FkdW2T6msN1uct1O9bH3vTerEHKZhTXJUQXy+hNq1B0RagfU8U+KBdqiZpxjhOUQA==
248+
249+
"@types/mini-css-extract-plugin@^0.2.0":
250+
version "0.2.0"
251+
resolved "https://registry.yarnpkg.com/@types/mini-css-extract-plugin/-/mini-css-extract-plugin-0.2.0.tgz#afb037dbbd76f6c13803927c2751d194188b5d47"
252+
integrity sha512-oHec+Vasp+K3C1Hb9HpwbA9Iw8ywqDgo9edWQJdBqxu05JH2AQsR56Zo5THpYbu1ieh/xJCvMRIHRdvrUBDmcA==
253+
dependencies:
254+
"@types/webpack" "*"
255+
256+
"@types/node@*", "@types/node@^10.12.18":
257+
version "10.12.18"
258+
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
259+
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
260+
261+
"@types/range-parser@*":
262+
version "1.2.3"
263+
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c"
264+
integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==
265+
266+
"@types/relateurl@*":
267+
version "0.2.28"
268+
resolved "https://registry.yarnpkg.com/@types/relateurl/-/relateurl-0.2.28.tgz#6bda7db8653fa62643f5ee69e9f69c11a392e3a6"
269+
integrity sha1-a9p9uGU/piZD9e5p6facEaOS46Y=
270+
271+
"@types/serve-static@*":
272+
version "1.13.2"
273+
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.2.tgz#f5ac4d7a6420a99a6a45af4719f4dcd8cd907a48"
274+
integrity sha512-/BZ4QRLpH/bNYgZgwhKEh+5AsboDBcUdlBYgzoLX0fpj3Y2gp6EApyOlM3bK53wQS/OE1SrdSYBAbux2D1528Q==
275+
dependencies:
276+
"@types/express-serve-static-core" "*"
277+
"@types/mime" "*"
278+
279+
"@types/tapable@*":
280+
version "1.0.4"
281+
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
282+
integrity sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==
283+
284+
"@types/uglify-js@*":
285+
version "3.0.4"
286+
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.0.4.tgz#96beae23df6f561862a830b4288a49e86baac082"
287+
integrity sha512-SudIN9TRJ+v8g5pTG8RRCqfqTMNqgWCKKd3vtynhGzkIIjxaicNAMuY5TRadJ6tzDu3Dotf3ngaMILtmOdmWEQ==
288+
dependencies:
289+
source-map "^0.6.1"
290+
291+
"@types/webpack-dev-server@^3.1.1":
292+
version "3.1.1"
293+
resolved "https://registry.yarnpkg.com/@types/webpack-dev-server/-/webpack-dev-server-3.1.1.tgz#12ae26194b3e1b8a317559592659921f282583c2"
294+
integrity sha512-TnEQPT+OZjWV2kRyNs0RPMDQmBCiLrr/ZhKSgFNF6aM4O/moUAfo2Yu3MIMUjoi3aE/02RH1iVR+Y6mWmXOlVA==
295+
dependencies:
296+
"@types/express" "*"
297+
"@types/http-proxy-middleware" "*"
298+
"@types/serve-static" "*"
299+
"@types/webpack" "*"
300+
301+
"@types/webpack@*", "@types/webpack@^4.4.21":
302+
version "4.4.21"
303+
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.4.21.tgz#1a80de6d3e465f35067dd2f4533bf6e04c2e7187"
304+
integrity sha512-QJfA6GeLSlnx8yyrEQ7fNLYj1MYKzqHlo89skOwnKG4nblpwAyXe9Gcm/eTz/BpX0vBEtiehrSv9b/W9TMkhKg==
305+
dependencies:
306+
"@types/anymatch" "*"
307+
"@types/node" "*"
308+
"@types/tapable" "*"
309+
"@types/uglify-js" "*"
310+
source-map "^0.6.0"
311+
161312
"@webassemblyjs/[email protected]":
162313
version "1.7.11"
163314
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.7.11.tgz#b988582cafbb2b095e8b556526f30c90d057cace"

0 commit comments

Comments
 (0)