From 4a856368ece10e15654c8bcf2b839ba844d33f78 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Fri, 9 Feb 2018 13:11:52 -0500 Subject: [PATCH 1/5] Fix Loader type in webpack The sourcemap parameter passed to loaders, and that loaders pass to the callback, is a `RawSourceMap`, not a `string | Buffer`. --- types/webpack/index.d.ts | 6 ++++-- types/webpack/package.json | 6 ++++++ types/webpack/webpack-tests.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 types/webpack/package.json diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index f8aa375210..e8b59f2994 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -9,12 +9,14 @@ // Ahmed T. Ali // Alan Agius // Spencer Elliott +// Jason Cheatham // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// import Tapable = require('tapable'); import * as UglifyJS from 'uglify-js'; +import { RawSourceMap } from 'source-map'; export = webpack; @@ -1020,7 +1022,7 @@ declare namespace webpack { namespace loader { interface Loader extends Function { - (this: LoaderContext, source: string | Buffer, sourceMap: string | Buffer): string | Buffer | void | undefined; + (this: LoaderContext, source: string | Buffer, sourceMap?: RawSourceMap): string | Buffer | void | undefined; /** * The order of chained loaders are always called from right to left. @@ -1040,7 +1042,7 @@ declare namespace webpack { raw?: boolean; } - type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: string | Buffer) => void; + type loaderCallback = (err: Error | undefined | null, content?: string | Buffer, sourceMap?: RawSourceMap) => void; interface LoaderContext { /** diff --git a/types/webpack/package.json b/types/webpack/package.json new file mode 100644 index 0000000000..96c1491edd --- /dev/null +++ b/types/webpack/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "source-map": "^0.7.0" + } +} diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index d74960e4db..6bf8fb443b 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -637,7 +637,7 @@ configuration = { performance, }; -function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap: string | Buffer): void { +function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap?: object): void { this.cacheable(); this.async(); From fe7e66e3ae7ac443a134a322d27c69a956cfeaab Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Sat, 10 Feb 2018 11:30:14 -0500 Subject: [PATCH 2/5] Update webpack typings to fix build issues * Add TypeScript version line * Remove some non-functional linter rules --- types/webpack/index.d.ts | 1 + types/webpack/package.json | 1 - types/webpack/tslint.json | 5 +---- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index e8b59f2994..e5124323fd 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -11,6 +11,7 @@ // Spencer Elliott // Jason Cheatham // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// diff --git a/types/webpack/package.json b/types/webpack/package.json index 96c1491edd..3d76ab4528 100644 --- a/types/webpack/package.json +++ b/types/webpack/package.json @@ -1,5 +1,4 @@ { - "private": true, "dependencies": { "source-map": "^0.7.0" } diff --git a/types/webpack/tslint.json b/types/webpack/tslint.json index 590af11d7e..ef5b615685 100644 --- a/types/webpack/tslint.json +++ b/types/webpack/tslint.json @@ -1,10 +1,7 @@ { "extends": "dtslint/dt.json", "rules": { - // TODO - "no-any-union": false, "no-unnecessary-qualifier": false, - "no-void-expression": false, - "space-within-parens": false + "no-void-expression": false } } From 63af4393ec5603a947e2a21976c6785446666809 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Sat, 10 Feb 2018 11:52:31 -0500 Subject: [PATCH 3/5] Use RawSourceMap rather than object in tests, remove TS version line The default TS 2.1 compat doesn't understand `object`, but specifying version 2.2 breaks other types that depend on this one. --- types/webpack/index.d.ts | 1 - types/webpack/webpack-tests.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/webpack/index.d.ts b/types/webpack/index.d.ts index e5124323fd..e8b59f2994 100644 --- a/types/webpack/index.d.ts +++ b/types/webpack/index.d.ts @@ -11,7 +11,6 @@ // Spencer Elliott // Jason Cheatham // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 /// diff --git a/types/webpack/webpack-tests.ts b/types/webpack/webpack-tests.ts index 6bf8fb443b..2cde2ee48c 100644 --- a/types/webpack/webpack-tests.ts +++ b/types/webpack/webpack-tests.ts @@ -1,4 +1,5 @@ import webpack = require('webpack'); +import { RawSourceMap } from 'source-map'; const { optimize, @@ -637,7 +638,7 @@ configuration = { performance, }; -function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap?: object): void { +function loader(this: webpack.loader.LoaderContext, source: string | Buffer, sourcemap?: RawSourceMap): void { this.cacheable(); this.async(); From 0c415565f31e9cb38ff7df0fe1f475fc65179154 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Sat, 10 Feb 2018 12:07:42 -0500 Subject: [PATCH 4/5] Make webpack package private. --- types/webpack/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/webpack/package.json b/types/webpack/package.json index 3d76ab4528..96c1491edd 100644 --- a/types/webpack/package.json +++ b/types/webpack/package.json @@ -1,4 +1,5 @@ { + "private": true, "dependencies": { "source-map": "^0.7.0" } From 147e526e7d0a8394ceebf0f43a1382b764dd51f5 Mon Sep 17 00:00:00 2001 From: Jason Cheatham Date: Sat, 10 Feb 2018 12:14:49 -0500 Subject: [PATCH 5/5] Restore tslint rules to webpack plugin --- types/webpack/tslint.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/webpack/tslint.json b/types/webpack/tslint.json index ef5b615685..590af11d7e 100644 --- a/types/webpack/tslint.json +++ b/types/webpack/tslint.json @@ -1,7 +1,10 @@ { "extends": "dtslint/dt.json", "rules": { + // TODO + "no-any-union": false, "no-unnecessary-qualifier": false, - "no-void-expression": false + "no-void-expression": false, + "space-within-parens": false } }