Skip to content

Commit d79dee1

Browse files
committed
feat: Add typechecks
1 parent f32cde8 commit d79dee1

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22
'use strict';
33
const assert = require('assert');
44

5-
module.exports = function IconfontWebpackPlugin (userOptions) {
5+
/**
6+
* The main plugin
7+
*
8+
* Options:
9+
* @param {{
10+
11+
fontNamePrefix?: string,
12+
enforcedSvgHeight?: number,
13+
resolve?: any
14+
15+
}} [userOptions]
16+
*/
17+
function IconfontWebpackPlugin (userOptions) {
618
// Default options
719
const options = Object.assign({
820

@@ -35,4 +47,6 @@ module.exports = function IconfontWebpackPlugin (userOptions) {
3547

3648
// Call postcss plugin
3749
return require('./lib/postcss-plugin')(options);
38-
};
50+
}
51+
52+
module.exports = IconfontWebpackPlugin;

lib/icons-to-woff.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function createIconFont (fs, icons, options) {
2222
normalize: true,
2323
fontHeight: options.enforcedSvgHeight ? options.enforcedSvgHeight : undefined,
2424
log: function () {},
25-
error: function (err) {
25+
error: /** @param {any} err */function (err) {
2626
reject(err);
2727
}
2828
});

lib/postcss-plugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function parseFontIconValue (value) {
4343
* Returns a promise with the result of all `icon-font:url(...)` svg paths of the given file
4444
*
4545
* @param postCssRoot {postcss.Root} The name of the font (font-family)
46-
* @param webpackResolve {function} The webpack resolve helper
46+
* @param webpackResolve {(context: string, path: string, callback: (err: any, result: string) => void) => void} The webpack resolve helper
4747
* @param context {string} The css loader path context to resolve relative urls
4848
*
4949
* @returns {Promise<{resolved: string[], unresolved: string[], relative: string[]}>}
@@ -85,7 +85,7 @@ function getSvgPaths (postCssRoot, webpackResolve, context) {
8585

8686
/**
8787
* @param fontName {string} The name of the font (font-family)
88-
* @param postCssRoot {object} The postCss root object
88+
* @param postCssRoot {postcss.Root} The postCss root object
8989
* @param svgPaths {object} The svg path information
9090
*/
9191
function replaceIconFontDeclarations (fontName, postCssRoot, svgPaths) {
@@ -170,10 +170,14 @@ function addFontDeclaration (fontName, postCssRoot, enforcedSvgHeight, svgPaths)
170170
* PostCSS Plugin factory
171171
*/
172172
module.exports = postcss.plugin('iconfont-webpack', config => function (root, result) {
173+
/* istanbul ignore if: Skip processing empty results */
174+
if (!result || !result.opts || !result.opts.from) {
175+
return;
176+
}
173177
const cssFilename = result.opts.from;
174178
const context = path.dirname(cssFilename);
175179
return getSvgPaths(root, config.resolve, context)
176-
.then(function (svgPaths) {
180+
.then(/** @returns {any} */function (svgPaths) {
177181
// Stop if the css file contains no `font-icon:url('..');` declarations
178182
if (svgPaths.resolved.length === 0) {
179183
return;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"test": "ava -v",
2020
"posttest": "npm-run-all posttest:*",
2121
"posttest:semistandard": "semistandard",
22+
"posttest:typecheck": "tsc",
2223
"posttest:coverage": "nyc ava",
2324
"posttest:coverage-report": "nyc report --reporter=html",
2425
"posttest:coverage-check": "nyc check-coverage --lines 100 --functions 100 --branches 100"
@@ -40,6 +41,7 @@
4041
},
4142
"homepage": "https://github.com/jantimon/iconfont-webpack-plugin",
4243
"devDependencies": {
44+
"@types/node": "12.0.12",
4345
"ava": "0.25.0",
4446
"commitizen": "3.1.1",
4547
"conventional-changelog-cli": "2.0.21",
@@ -52,6 +54,7 @@
5254
"semistandard": "13.0.1",
5355
"standard-version": "6.0.1",
5456
"style-loader": "0.23.1",
57+
"typescript": "3.5.2",
5558
"webpack": "4.33.0",
5659
"webpack-cli": "3.3.3"
5760
},

tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"noEmit": true,
5+
"target": "es6",
6+
"lib": ["es6"],
7+
"rootDir": "src",
8+
"module": "commonjs",
9+
"moduleResolution": "node",
10+
"strict": true,
11+
"declaration": true,
12+
"sourceMap": true,
13+
"inlineSources": true,
14+
"types": ["node"],
15+
"maxNodeModuleJsDepth": 2,
16+
"skipLibCheck": true
17+
},
18+
"lib": ["es6", "es7"],
19+
"exclude": [
20+
"**/node_modules/**/*",
21+
"**/test/**/*",
22+
]
23+
}

0 commit comments

Comments
 (0)