Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typings #3

Merged
merged 43 commits into from
Mar 17, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a220279
Modified package.json to support typings.
SzybkiSasza Feb 4, 2019
477d590
Added typings file.
SzybkiSasza Feb 4, 2019
8d4c510
Fixed export to be aligned with JS files.
SzybkiSasza Feb 4, 2019
0227d3c
Updated packages along the way.
SzybkiSasza Feb 8, 2019
8268e78
Removed old lint files and index typing.
SzybkiSasza Feb 8, 2019
64fe587
Added new base config files (tslint, tsconfig) and new packages.
SzybkiSasza Feb 8, 2019
8d07954
Added new Babel config. Next step - enabling Babel + Typescript
SzybkiSasza Feb 8, 2019
0f22143
Fixed input files. Added better type guarding and converting from Str…
SzybkiSasza Feb 8, 2019
adc622a
Fixed babel build pipeline and test runner. Working on rewriting the …
SzybkiSasza Feb 8, 2019
894ea0f
Rewrote utils to TS. Added simple test for CJS export.
SzybkiSasza Feb 8, 2019
093f259
Added missing typing. Enabled absolute path resolution.
SzybkiSasza Feb 8, 2019
c92566c
Rewrote the tests to Typescript. Re-enabled all the old tests. Will w…
SzybkiSasza Feb 8, 2019
97d0f7f
Fixed babel pipeline (added "test" to the paths list for dev purposes…
SzybkiSasza Feb 8, 2019
a547380
Removed "runInBand" (not needed with newer Jest and such simple tests).
SzybkiSasza Feb 8, 2019
875abf6
Fixed tests for older NodeJS versions
SzybkiSasza Feb 8, 2019
cbede3a
Fixed "security" step (was using obsolete package".
SzybkiSasza Feb 8, 2019
423249c
Improved coverage.
SzybkiSasza Feb 12, 2019
68c8a87
Added support for functions.
SzybkiSasza Feb 12, 2019
15b784b
Removed exclusive test...
SzybkiSasza Feb 12, 2019
a6a5f6d
Fixed entrypoints.
SzybkiSasza Feb 12, 2019
1b8afaf
Decided to seprarate CJS and ES configs (as usually done with two typ…
SzybkiSasza Feb 12, 2019
8dbf00c
Re-structured build config.
SzybkiSasza Feb 12, 2019
bd14893
Main TSConfig refined.
SzybkiSasza Feb 12, 2019
b1f1891
Source files separated into two branches (CJS and ES modules).
SzybkiSasza Feb 12, 2019
376b57d
Leveraged Babelrc overrides, to create two separate configs.
SzybkiSasza Feb 12, 2019
7786478
NPM ignore added.
SzybkiSasza Feb 12, 2019
4616b35
Adjusted build tools. Added tool for renaming indexes.
SzybkiSasza Feb 13, 2019
b22585b
Adjusted all the configuration files. Two parallel builds configured!
SzybkiSasza Feb 13, 2019
32ba98b
Another round of fixing config.
SzybkiSasza Feb 13, 2019
939b168
Fixed the tests. All of the tests are passing again!
SzybkiSasza Feb 13, 2019
f17a56d
More tests! Updated snapshots as well.
SzybkiSasza Feb 13, 2019
a57b2d6
Merged class and ES export (no need for additional file). Updated sna…
SzybkiSasza Feb 13, 2019
c440301
Updated README.md
SzybkiSasza Feb 13, 2019
429623f
Moved Webpack types to peerDependencies. Updated README with info on …
SzybkiSasza Mar 15, 2019
b32d4a2
New package.lock
SzybkiSasza Mar 15, 2019
358fcf5
Simplified the source. Skipped default exports.
SzybkiSasza Mar 15, 2019
d6697b4
Updated dependencies. Moved @types/webpack to devDependencies so buil…
SzybkiSasza Mar 15, 2019
312c2f2
@types/webpack in peer dependencies as well.
SzybkiSasza Mar 15, 2019
df5047b
Updated README.
SzybkiSasza Mar 15, 2019
2bbd06a
Removed uneeded tsconfigs (using main one for the project now).
SzybkiSasza Mar 16, 2019
743b7a8
Cleaned up package.json. Got rid of Webpack types in peerDependencies…
SzybkiSasza Mar 16, 2019
8ee5dfc
fix: use correct entry points
mattlewis92 Mar 17, 2019
288746a
docs: update readme
mattlewis92 Mar 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
{
"presets": [
[
"env",
"@babel/preset-env",
{
"useBuiltIns": true,
"targets": {
"node": "4.3"
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
"esmodules": true
}
}
]
],
"env": {
"test": {
"overrides": [
{
"test": "ts-out/es",
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
[
"@babel/preset-env",
{
"targets": {
"esmodules": true
}
}
]
]
},
{
"test": "ts-out/cjs",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "4.3"
}
}
]
]
}
}
}
]
}
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
# Tool-generated files
logs
*.log
npm-debug.log*
.eslintcache

# Directories
/coverage
/dist
/cjs
/es
/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
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ npm i -D webpack-filter-warnings-plugin
```

## Usage

Library supports both CommonJS and ES modules.

### Using CommonJS

```js
// webpack.config.js
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
Expand All @@ -27,8 +32,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 ES modules

Library exposes special ES modules - compatible export. Use it if you are working in environment supporting those.
Notice additional '/es' suffix in import string.

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

### Using with Typescript

Webpack Filter Warnings Plugin is completely written in Typescript. As such, it exposes Typescript bindings (no `@types/` dependency needed for now).

As exported module is CommonJS by default, one needs to use special Typescript syntax to import that module:

```typescript
// webpack.config.ts
import FilterWarningsPlugin = require('webpack-filter-warnings-plugin');

```

The recommended way would be to use ES module residing in `webpack-filter-warnings-plugin/es`, though, as in former examples.

## 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
40 changes: 40 additions & 0 deletions build-tools/renameIndexes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as fs from 'fs';
import glob from 'glob';
import * as path from 'path';

interface PathToReplace {
newPath: string;
originalPath: string;
}

/**
* Renames Typescript index files.
* As neither Typescript or Babel have capability of easily renaming files along transpiling,
* this one creates consistent file names that are easier to use for library consumers
*/
glob('ts-out/**/index.**', (err: Error | null, files: string[]) => {
const renameMap: PathToReplace[] = files.reduce((memo: PathToReplace[], file: string) => {
const newFilename: string = file.replace(/(.*\/index)\.(cjs|es)(\.d)*\.(ts|js)/, '$1$3.$4');

const originalPath: string = path.resolve(__dirname, '..', file);
const newPath: string = path.resolve(__dirname, '..', newFilename);

if (originalPath !== newPath) {
memo.push({
originalPath,
newPath,
});
}

return memo;
}, [] as PathToReplace[]);

if (renameMap.length > 0) {
console.log(`Found ${renameMap.length} index files to rename.`); // tslint:disable-line

renameMap.forEach((renameEntry: PathToReplace) => {
console.log(`Renaming ${renameEntry.originalPath} to ${path.basename(renameEntry.newPath)}`); // tslint:disable-line
fs.renameSync(renameEntry.originalPath, renameEntry.newPath);
});
}
});
10 changes: 10 additions & 0 deletions build-tools/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../ts-out/cjs"
},
"include": [
"../src/**/*.cjs.ts"
]
}
10 changes: 10 additions & 0 deletions build-tools/tsconfig-es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "../ts-out/es"
},
"include": [
"../src/**/*.es.ts"
]
}
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