From 01208d2b66a40d7805ffb8d3269cd3443af8275c Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 06:28:22 +0800 Subject: [PATCH 01/12] chore: update tsconfig/tslint config --- webpack/tsconfig.json | 4 ++-- webpack/tslint.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 webpack/tslint.json diff --git a/webpack/tsconfig.json b/webpack/tsconfig.json index f85a099ac3..1a1c5440ce 100644 --- a/webpack/tsconfig.json +++ b/webpack/tsconfig.json @@ -5,7 +5,7 @@ "es6" ], "noImplicitAny": true, - "noImplicitThis": false, + "noImplicitThis": true, "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ @@ -19,4 +19,4 @@ "index.d.ts", "webpack-tests.ts" ] -} \ No newline at end of file +} diff --git a/webpack/tslint.json b/webpack/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/webpack/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } From 469a20b7a711e75fa08ae5ac4ad452b7ddfedf60 Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 06:28:31 +0800 Subject: [PATCH 02/12] style: fix lint errors --- webpack/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index a557034131..d172cd4bc6 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -472,7 +472,7 @@ declare namespace webpack { apply(thisArg: Webpack, ...args: any[]): void; } - type UglifyCommentFunction = (astNode: any, comment: any) => boolean + type UglifyCommentFunction = (astNode: any, comment: any) => boolean; interface UglifyPluginOptions extends UglifyJS.MinifyOptions { beautify?: boolean; @@ -810,7 +810,7 @@ declare namespace webpack { data?: any; - callback: loaderCallback | void; + callback: loaderCallback | undefined; /** @@ -861,7 +861,7 @@ declare namespace webpack { * The resource file. * In the example: "/abc/resource.js" */ - resourcePath: string + resourcePath: string; /** * The query of the resource. @@ -898,14 +898,14 @@ declare namespace webpack { * @param request * @param callback */ - resolve(context: string, request: string, callback: (err: Error, result: string) => void): any + resolve(context: string, request: string, callback: (err: Error, result: string) => void): any; /** * Resolve a request like a require expression. * @param context * @param request */ - resolveSync(context: string, request: string): string + resolveSync(context: string, request: string): string; /** @@ -928,7 +928,7 @@ declare namespace webpack { * Add a directory as dependency of the loader result. * @param directory */ - addContextDependency(directory: string): void + addContextDependency(directory: string): void; /** * Remove all dependencies of the loader result. Even initial dependencies and these of other loaders. Consider using pitch. @@ -991,7 +991,7 @@ declare namespace webpack { * @param content * @param sourceMap */ - emitFile(name: string, content: Buffer|String, sourceMap: any): void + emitFile(name: string, content: Buffer|string, sourceMap: any): void; /** From c42802e29d38a7636d2ea5bdd7e43b09b6f5e17f Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 06:41:18 +0800 Subject: [PATCH 03/12] style: fix indentation --- webpack/index.d.ts | 18 ++-- webpack/webpack-tests.ts | 192 +++++++++++++++++++-------------------- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index d172cd4bc6..09e1a22421 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -832,16 +832,16 @@ declare namespace webpack { * In the example: * [ * { request: "/abc/loader1.js?xyz", - * path: "/abc/loader1.js", - * query: "?xyz", - * module: [Function] - * }, + * path: "/abc/loader1.js", + * query: "?xyz", + * module: [Function] + * }, * { request: "/abc/node_modules/loader2/index.js", - * path: "/abc/node_modules/loader2/index.js", - * query: "", - * module: [Function] - * } - *] + * path: "/abc/node_modules/loader2/index.js", + * query: "", + * module: [Function] + * } + * ] */ loaders: any[]; diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 7c1f109a2d..be36076307 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -196,9 +196,9 @@ configuration = { }; configuration = { - resolve: { - root: __dirname - } + resolve: { + root: __dirname + } }; rule = { @@ -289,12 +289,12 @@ plugin = new webpack.optimize.UglifyJsPlugin({ } }); plugin = new webpack.optimize.UglifyJsPlugin({ - sourceMap: false, - comments: true, - beautify: true, - test: 'foo', - exclude: /node_modules/, - include: 'test' + sourceMap: false, + comments: true, + beautify: true, + test: 'foo', + exclude: /node_modules/, + include: 'test' }); plugin = new webpack.optimize.UglifyJsPlugin({ mangle: { @@ -302,9 +302,9 @@ plugin = new webpack.optimize.UglifyJsPlugin({ } }); plugin = new webpack.optimize.UglifyJsPlugin({ - comments: function(astNode: any, comment: any) { - return false; - } + comments: function(astNode: any, comment: any) { + return false; + } }); plugin = new webpack.optimize.CommonsChunkPlugin(options); plugin = new CommonsChunkPlugin({ @@ -383,7 +383,7 @@ plugin = new webpack.NoErrorsPlugin(); plugin = new webpack.NoEmitOnErrorsPlugin(); plugin = new webpack.WatchIgnorePlugin(paths); plugin = new webpack.LoaderOptionsPlugin({ - debug: true + debug: true }); // @@ -412,19 +412,19 @@ compiler.watch({ // watch options: // pass a number to set the polling interval }, function(err, stats) { // ... - }); +}); // or compiler.watch({ // watch options: ignored: 'foo/**/*' }, function(err, stats) { // ... - }); +}); // or compiler.watch({ // watch options: ignored: /node_modules/ }, function(err, stats) { // ... - }); +}); declare function handleFatalError(err: Error): void; declare function handleSoftErrors(errs: string[]): void; @@ -438,26 +438,26 @@ webpack({ return handleFatalError(err); var jsonStats = stats.toJson(); var jsonStatsWithAllOptions = stats.toJson({ - assets: true, - assetsSort: "field", - cached: true, - children: true, - chunks: true, - chunkModules: true, - chunkOrigins: true, - chunksSort: "field", - context: "../src/", - errors: true, - errorDetails: true, - hash: true, - modules: true, - modulesSort: "field", - publicPath: true, - reasons: true, - source: true, - timings: true, - version: true, - warnings: true + assets: true, + assetsSort: "field", + cached: true, + children: true, + chunks: true, + chunkModules: true, + chunkOrigins: true, + chunksSort: "field", + context: "../src/", + errors: true, + errorDetails: true, + hash: true, + modules: true, + modulesSort: "field", + publicPath: true, + reasons: true, + source: true, + timings: true, + version: true, + warnings: true }); if(jsonStats.errors.length > 0) return handleSoftErrors(jsonStats.errors); @@ -491,51 +491,51 @@ rule = { } configuration = { - module: { - rules: [ - { oneOf: [ - { - test: { - and: [ - /a.\.js$/, - /b\.js$/ - ] - }, - loader: "./loader?first" - }, - { - test: [ - require.resolve("./a"), - require.resolve("./c"), - ], - issuer: require.resolve("./b"), - use: [ - "./loader?second-1", - { - loader: "./loader", - options: "second-2" - }, - { - loader: "./loader", - options: { - get: function() { return "second-3"; } - } - } - ] - }, - { - test: { - or: [ - require.resolve("./a"), - require.resolve("./c"), - ] - }, - loader: "./loader", - options: "third" - } - ]} - ] - } + module: { + rules: [ + { oneOf: [ + { + test: { + and: [ + /a.\.js$/, + /b\.js$/ + ] + }, + loader: "./loader?first" + }, + { + test: [ + require.resolve("./a"), + require.resolve("./c"), + ], + issuer: require.resolve("./b"), + use: [ + "./loader?second-1", + { + loader: "./loader", + options: "second-2" + }, + { + loader: "./loader", + options: { + get: function() { return "second-3"; } + } + } + ] + }, + { + test: { + or: [ + require.resolve("./a"), + require.resolve("./c"), + ] + }, + loader: "./loader", + options: "third" + } + ]} + ] + } } const resolve: webpack.Resolve = { @@ -543,35 +543,35 @@ const resolve: webpack.Resolve = { } const performance: webpack.PerformanceOptions = { - hints: 'error', - maxEntrypointSize: 400000, - maxAssetSize: 100000, - assetFilter: function(assetFilename) { - return assetFilename.endsWith('.js'); - }, + hints: 'error', + maxEntrypointSize: 400000, + maxAssetSize: 100000, + assetFilter: function(assetFilename) { + return assetFilename.endsWith('.js'); + }, }; configuration = { - performance, + performance, }; function loader(this: webpack.loader.LoaderContext, source: string, sourcemap: string): void { - this.cacheable(); + this.cacheable(); - this.async(); + this.async(); - this.addDependency(''); + this.addDependency(''); - this.resolve('context', 'request', ( err: Error, result: string) => {}); + this.resolve('context', 'request', ( err: Error, result: string) => {}); - this.emitError('wraning'); + this.emitError('wraning'); - this.callback(null, source); + this.callback(null, source); } module loader { - export const raw: boolean = true; - export const pitch = (remainingRequest: string, precedingRequest: string, data: any) => {}; + export const raw: boolean = true; + export const pitch = (remainingRequest: string, precedingRequest: string, data: any) => {}; } const loaderRef: webpack.loader.Loader = loader; console.log(loaderRef.raw === true); From 7463c5be2d100666880d980478395a0a18a89d8f Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 09:18:30 +0800 Subject: [PATCH 04/12] fix: pass failing tests remove undefined from LoaderContext.callback type --- webpack/index.d.ts | 2 +- webpack/webpack-tests.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 09e1a22421..5f3dcb1688 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -810,7 +810,7 @@ declare namespace webpack { data?: any; - callback: loaderCallback | undefined; + callback: loaderCallback; /** diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index be36076307..0969070323 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -217,7 +217,8 @@ declare var require: any; declare var path: any; configuration = { plugins: [ - function() { + /** @todo `this` should be typed as webpack.compiler.Compiler (which should be webpack.Compiler), not webpack.Webpack */ + function(this: any) { this.plugin("done", function(stats: any) { require("fs").writeFileSync( path.join(__dirname, "...", "stats.json"), From 2b25f6b2b8bfff0d8d4ee24a39daa1bfceb82a42 Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 09:22:28 +0800 Subject: [PATCH 05/12] chore: remove OccurenceOrderPlugin --- webpack/index.d.ts | 6 ++---- webpack/webpack-tests.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 5f3dcb1688..5def0965ff 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -598,9 +598,7 @@ declare namespace webpack { * Assign the module and chunk ids by occurrence count. Ids that are used often get lower (shorter) ids. * This make ids predictable, reduces to total file size and is recommended. */ - // TODO: This is a typo, and will be removed in Webpack 2. - OccurenceOrderPlugin: optimize.OccurenceOrderPluginStatic; - OccurrenceOrderPlugin: optimize.OccurenceOrderPluginStatic; + OccurrenceOrderPlugin: optimize.OccurrenceOrderPluginStatic; /** * Minimize all JavaScript output of chunks. Loaders are switched into minimizing mode. * You can pass an object containing UglifyJs options. @@ -1027,7 +1025,7 @@ declare namespace webpack { interface MinChunkSizePluginStatic { new (options: any): Plugin; } - interface OccurenceOrderPluginStatic { + interface OccurrenceOrderPluginStatic { new (preferEntry: boolean): Plugin; } interface UglifyJsPluginStatic { diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 0969070323..a536a2713f 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -280,7 +280,7 @@ plugin = new webpack.BannerPlugin(banner, options); plugin = new webpack.optimize.DedupePlugin(); plugin = new webpack.optimize.LimitChunkCountPlugin(options); plugin = new webpack.optimize.MinChunkSizePlugin(options); -plugin = new webpack.optimize.OccurenceOrderPlugin(preferEntry); +plugin = new webpack.optimize.OccurrenceOrderPlugin(preferEntry); plugin = new webpack.optimize.OccurrenceOrderPlugin(preferEntry); plugin = new webpack.optimize.UglifyJsPlugin(options); plugin = new webpack.optimize.UglifyJsPlugin(); From dca67839219fbffde30a367397bdd54b6a52a68d Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Mon, 6 Feb 2017 09:56:31 +0800 Subject: [PATCH 06/12] chore: remove LabeledModulesPlugin BREAKING CHANGE: remove webpack.Dependencies interface --- webpack/index.d.ts | 12 +----------- webpack/webpack-tests.ts | 1 - 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 5def0965ff..c077ef232a 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -492,7 +492,7 @@ declare namespace webpack { /** * dependencies namespace */ - dependencies: Dependencies; + dependencies: {}; /** * Replace resources that matches resourceRegExp with newResource. * If newResource is relative, it is resolve relative to the previous resource. @@ -613,13 +613,6 @@ declare namespace webpack { AggressiveMergingPlugin: optimize.AggressiveMergingPluginStatic; } - interface Dependencies { - /** - * Support Labeled Modules. - */ - LabeledModulesPlugin: dependencies.LabeledModulesPluginStatic; - } - interface DirectoryDescriptionFilePluginStatic { new (file: string, files: string[]): Plugin; } @@ -1041,9 +1034,6 @@ declare namespace webpack { } namespace dependencies { - interface LabeledModulesPluginStatic { - new (): Plugin; - } } namespace compiler { diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index a536a2713f..9515f6045b 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -345,7 +345,6 @@ plugin = new CommonsChunkPlugin({ // (3 children must share the module before it's separated) }); plugin = new webpack.optimize.AggressiveMergingPlugin(options); -plugin = new webpack.dependencies.LabeledModulesPlugin(); plugin = new webpack.DefinePlugin(definitions); plugin = new webpack.DefinePlugin({ VERSION: JSON.stringify("5fa3b9"), From f522cb689bda7db05d6cd951820ed43988370cd5 Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Tue, 7 Feb 2017 08:23:53 +0800 Subject: [PATCH 07/12] chore: remove ResolverPlugin --- webpack/index.d.ts | 23 ----------------------- webpack/webpack-tests.ts | 20 -------------------- 2 files changed, 43 deletions(-) diff --git a/webpack/index.d.ts b/webpack/index.d.ts index c077ef232a..9801249051 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -515,10 +515,6 @@ declare namespace webpack { * This can boost performance. Try to profile the build first to determine clever prefetching points. */ PrefetchPlugin: PrefetchPluginStatic; - /** - * Apply a plugin (or array of plugins) to one or more resolvers (as specified in types). - */ - ResolverPlugin: ResolverPluginStatic; /** * Adds a banner to the top of each generated chunk. */ @@ -613,10 +609,6 @@ declare namespace webpack { AggressiveMergingPlugin: optimize.AggressiveMergingPluginStatic; } - interface DirectoryDescriptionFilePluginStatic { - new (file: string, files: string[]): Plugin; - } - interface NormalModuleReplacementPluginStatic { new (resourceRegExp: any, newResource: any): Plugin; } @@ -635,21 +627,6 @@ declare namespace webpack { new (request: any): Plugin; } - interface ResolverPluginStatic { - new (plugins: Plugin[], files?: string[]): Plugin; - DirectoryDescriptionFilePlugin: DirectoryDescriptionFilePluginStatic; - /** - * This plugin will append a path to the module directory to find a match, - * which can be useful if you have a module which has an incorrect “main” entry in its package.json/bower.json etc (e.g. "main": "Gruntfile.js"). - * You can use this plugin as a special case to load the correct file for this module. Example: - */ - FileAppendPlugin: FileAppendPluginStatic; - } - - interface FileAppendPluginStatic { - new (files: string[]): Plugin; - } - interface BannerPluginStatic { new (banner: any, options: any): Plugin; } diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index 9515f6045b..e2e643a1da 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -32,18 +32,6 @@ rule = { query: { mimetype: "image/png" } }; -// -// https://webpack.github.io/docs/using-plugins.html -// - -configuration = { - plugins: [ - new webpack.ResolverPlugin([ - new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"]) - ], ["normal", "loader"]) - ] -}; - // // http://webpack.github.io/docs/tutorials/getting-started/ // @@ -268,14 +256,6 @@ plugin = new webpack.IgnorePlugin(requestRegExp, contextRegExp); plugin = new webpack.PrefetchPlugin(context, request); plugin = new webpack.PrefetchPlugin(request); -plugin = new webpack.ResolverPlugin(plugins, types); -plugin = new webpack.ResolverPlugin(plugins); -plugin = new webpack.ResolverPlugin([ - new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"]) -], ["normal", "loader"]); -plugin = new webpack.ResolverPlugin([ - new webpack.ResolverPlugin.FileAppendPlugin(['/dist/compiled-moduled.js']) -]); plugin = new webpack.BannerPlugin(banner, options); plugin = new webpack.optimize.DedupePlugin(); plugin = new webpack.optimize.LimitChunkCountPlugin(options); From f0bebc6824ff1ba77616f660c87928f4eb8a72ad Mon Sep 17 00:00:00 2001 From: Benjamin Lim Date: Tue, 7 Feb 2017 08:31:40 +0800 Subject: [PATCH 08/12] chore: remove overloaded CommonsChunkPlugin constructor https://github.com/webpack/webpack/blob/d7384e2f6a17187e59ec2831b41ee813ec158f14/lib/optimize/CommonsChunkPlugin.js#L10-L25 --- .../extract-text-webpack-plugin-tests.ts | 5 ++++- webpack/index.d.ts | 1 - webpack/webpack-tests.ts | 14 ++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts b/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts index 62e522a348..63177ebde3 100644 --- a/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts +++ b/extract-text-webpack-plugin/extract-text-webpack-plugin-tests.ts @@ -58,7 +58,10 @@ configuration = { configuration = { // ... plugins: [ - new optimize.CommonsChunkPlugin("commons", "commons.js"), + new optimize.CommonsChunkPlugin({ + name: "commons", + filename: "commons.js", + }), new ExtractTextPlugin("[name].css") ] }; diff --git a/webpack/index.d.ts b/webpack/index.d.ts index 9801249051..43ced0bce5 100644 --- a/webpack/index.d.ts +++ b/webpack/index.d.ts @@ -1002,7 +1002,6 @@ declare namespace webpack { new (options?: UglifyPluginOptions): Plugin; } interface CommonsChunkPluginStatic { - new (chunkName: string, filenames?: string | string[]): Plugin; new (options?: any): Plugin; } interface AggressiveMergingPluginStatic { diff --git a/webpack/webpack-tests.ts b/webpack/webpack-tests.ts index e2e643a1da..4ed9fc3b31 100644 --- a/webpack/webpack-tests.ts +++ b/webpack/webpack-tests.ts @@ -62,7 +62,10 @@ configuration = { filename: "bundle.js" }, plugins: [ - new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js") + new webpack.optimize.CommonsChunkPlugin({ + name: "vendor", + filename: "vendor.bundle.js", + }), ] }; @@ -126,10 +129,6 @@ configuration = { output: { filename: "[name].js" }, - plugins: [ - new CommonsChunkPlugin("admin-commons.js", ["ap1", "ap2"]), - new CommonsChunkPlugin("commons.js", ["p1", "p2", "admin-commons.js"]) - ] }; //