Skip to content

Commit

Permalink
feat: convert to typescript
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 

node 8 or higher is now required to use this package. 

commonjs users will now need to import the library as a named export instead. To migrate:

Before:
```
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
```

After:
```
const { FilterWarningsPlugin } = require('webpack-filter-warnings-plugin');
```
  • Loading branch information
SzybkiSasza authored and mattlewis92 committed Mar 17, 2019
1 parent 81dac11 commit af1ad14
Show file tree
Hide file tree
Showing 24 changed files with 4,780 additions and 6,253 deletions.
33 changes: 5 additions & 28 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
{
"presets": [
[
"env",
"@babel/preset-env",
{
"useBuiltIns": true,
"targets": {
"node": "4.3"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
"node": "8.0"
}
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
}
]
}
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# Tool-generated files
logs
*.log
npm-debug.log*
.eslintcache

# Directories
/coverage
/dist
/ts-out
/local
/reports
/node_modules

# System meta files
.DS_Store
Thumbs.db

# Editors
.idea
.vscode
*.sublime-project
*.sublime-workspace
*.sublime-workspace
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
test
ts-out
68 changes: 65 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ npm i -D webpack-filter-warnings-plugin
```

## Usage

```js
// webpack.config.js
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
const { FilterWarningsPlugin } = require('webpack-filter-warnings-plugin');

module.exports = {
// ... rest of webpack config
Expand All @@ -27,8 +28,69 @@ module.exports = {
}
```

### Why not use the built in stats.warningsFilter option?
Currently karma-webpack does not respect the stats.warningsFilter option. Also when excluding all warnings, webpack still says `Compiled with warnings.` when all warnings are filtere. Hopefully this plugin will no longer need to exist one day.
### Using with Typescript

Webpack Filter Warnings Plugin is completely written in Typescript. As such, it exposes Typescript bindings.

Before using it, install webpack typings:

```bash
npm i --save-dev @types/webpack
```

or

```bash
yarn add --dev @types/webpack
```

Use ES imports:

```typescript
// webpack.config.ts
import { FilterWarningsPlugin } from 'webpack-filter-warnings-plugin';

```

## Options

Library exposes only one option: `exclude`. It may be one of `RegExp`, `String` or `Function`.

### String as `exclude` filter

When passing string as exclude parameter, phrase is converted to wildcard and matches any phrase that contains it.

```js
// webpack.config.js
module.exports = {
// ... rest of webpack config
plugins: [
new FilterWarningsPlugin({
exclude: 'hide me'
})
]
}

```

This config will match any of `Should hide me`, `Hide me, please`, `HiDe Me` (filter is case insensitive) etc.

### Function as `exclude` filter

```js
// webpack.config.js
module.exports = {
// ... rest of webpack config
plugins: [
new FilterWarningsPlugin({
exclude: (input) => /.*hide.*/.test(input),
})
]
}
```

## Why not use the built in stats.warningsFilter option?
Currently karma-webpack does not respect the stats.warningsFilter option. Also when excluding all warnings, webpack still says `Compiled with warnings.` when all warnings are filtered. Hopefully this plugin will no longer need to exist one day.

## Licence
MIT
Expand Down
30 changes: 30 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
collectCoverageFrom: [
'build-tools/**/*.ts',
'src/**/*.ts'
],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [
'/node_modules/'
],
coverageReporters: [
'lcov'
],
globals: {
'ts-jest': {
tsConfig: '<rootDir>/test/tsconfig.json',
}
},
moduleDirectories: [
'node_modules',
'src',
'test/unit'
],
preset: 'ts-jest',
roots: [
'<rootDir>/build-tools',
'<rootDir>/src',
'<rootDir>/test'
],
testEnvironment: 'node'
};
Loading

0 comments on commit af1ad14

Please sign in to comment.