From bf037c9886d303ddf8fbf0b7713112f9f9ff3448 Mon Sep 17 00:00:00 2001 From: Luka Maljic Date: Wed, 13 Dec 2017 10:07:05 +0100 Subject: [PATCH 1/4] Added types for koa-webpack --- types/koa-webpack/index.d.ts | 33 +++++++++++++++++ types/koa-webpack/koa-webpack-tests.ts | 50 ++++++++++++++++++++++++++ types/koa-webpack/tsconfig.json | 22 ++++++++++++ types/koa-webpack/tslint.json | 1 + 4 files changed, 106 insertions(+) create mode 100644 types/koa-webpack/index.d.ts create mode 100644 types/koa-webpack/koa-webpack-tests.ts create mode 100644 types/koa-webpack/tsconfig.json create mode 100644 types/koa-webpack/tslint.json diff --git a/types/koa-webpack/index.d.ts b/types/koa-webpack/index.d.ts new file mode 100644 index 0000000000..363c9cb5b0 --- /dev/null +++ b/types/koa-webpack/index.d.ts @@ -0,0 +1,33 @@ +// Type definitions for koa-webpack 1.0 +// Project: https://github.com/shellscape/koa-webpack#readme +// Definitions by: Luka Maljic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as Koa from 'koa' +import * as webpack from 'webpack' +import * as webpackDevMiddleware from 'webpack-dev-middleware' +import * as webpackHotMiddleware from 'webpack-hot-middleware' +import { NextHandleFunction } from 'connect' + +declare function koaWebpack( + options?: koaWebpack.Options +): Koa.Middleware & koaWebpack.CombinedWebpackMiddleware + +declare namespace koaWebpack +{ + interface Options + { + compiler?: webpack.Compiler + config?: webpack.Configuration + dev?: webpackDevMiddleware.Options + hot?: webpackHotMiddleware.Options + } + + interface CombinedWebpackMiddleware + { + dev: NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware + hot: NextHandleFunction & webpackHotMiddleware.EventStream + } +} + +export = koaWebpack diff --git a/types/koa-webpack/koa-webpack-tests.ts b/types/koa-webpack/koa-webpack-tests.ts new file mode 100644 index 0000000000..eaa3468ce1 --- /dev/null +++ b/types/koa-webpack/koa-webpack-tests.ts @@ -0,0 +1,50 @@ +import * as Koa from 'koa' +import * as webpack from 'webpack' +import * as koaWebpack from 'koa-webpack' + +const app = new Koa() +const config: webpack.Configuration = {} +const compiler = webpack(config) + + +// Using the middleware + +const middleware = koaWebpack({ + compiler, + config, + dev: { + noInfo: false, + quiet: false, + lazy: true, + watchOptions: { + aggregateTimeout: 300, + poll: true, + }, + publicPath: '/assets/', + index: 'index.html', + headers: { + 'X-Custom-Header': 'yes' + }, + stats: { + colors: true, + }, + reporter: null, + serverSideRender: false + }, + hot: { + log: console.log.bind(console), + path: '/__what', + heartbeat: 2000 + } +}) + +app.use(middleware) + + +// Accessing the underlying middleware + +middleware.dev.close() +middleware.dev.invalidate() +middleware.dev.waitUntilValid() +middleware.hot.publish(null) + diff --git a/types/koa-webpack/tsconfig.json b/types/koa-webpack/tsconfig.json new file mode 100644 index 0000000000..57a4aac117 --- /dev/null +++ b/types/koa-webpack/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "koa-webpack-tests.ts" + ] +} diff --git a/types/koa-webpack/tslint.json b/types/koa-webpack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/koa-webpack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 329c092b7e3abde88ded597e8fba968c6d3cc312 Mon Sep 17 00:00:00 2001 From: Luka Maljic Date: Wed, 13 Dec 2017 10:13:46 +0100 Subject: [PATCH 2/4] Fixed dtslint warnings --- types/koa-webpack/index.d.ts | 35 ++++++++++++-------------- types/koa-webpack/koa-webpack-tests.ts | 27 +++++++++----------- types/koa-webpack/tsconfig.json | 1 + 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/types/koa-webpack/index.d.ts b/types/koa-webpack/index.d.ts index 363c9cb5b0..4a598d3ac5 100644 --- a/types/koa-webpack/index.d.ts +++ b/types/koa-webpack/index.d.ts @@ -3,31 +3,28 @@ // Definitions by: Luka Maljic // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import * as Koa from 'koa' -import * as webpack from 'webpack' -import * as webpackDevMiddleware from 'webpack-dev-middleware' -import * as webpackHotMiddleware from 'webpack-hot-middleware' -import { NextHandleFunction } from 'connect' +import * as Koa from 'koa'; +import * as webpack from 'webpack'; +import * as webpackDevMiddleware from 'webpack-dev-middleware'; +import * as webpackHotMiddleware from 'webpack-hot-middleware'; +import { NextHandleFunction } from 'connect'; declare function koaWebpack( options?: koaWebpack.Options -): Koa.Middleware & koaWebpack.CombinedWebpackMiddleware +): Koa.Middleware & koaWebpack.CombinedWebpackMiddleware; -declare namespace koaWebpack -{ - interface Options - { - compiler?: webpack.Compiler - config?: webpack.Configuration - dev?: webpackDevMiddleware.Options - hot?: webpackHotMiddleware.Options +declare namespace koaWebpack { + interface Options { + compiler?: webpack.Compiler; + config?: webpack.Configuration; + dev?: webpackDevMiddleware.Options; + hot?: webpackHotMiddleware.Options; } - interface CombinedWebpackMiddleware - { - dev: NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware - hot: NextHandleFunction & webpackHotMiddleware.EventStream + interface CombinedWebpackMiddleware { + dev: NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware; + hot: NextHandleFunction & webpackHotMiddleware.EventStream; } } -export = koaWebpack +export = koaWebpack; diff --git a/types/koa-webpack/koa-webpack-tests.ts b/types/koa-webpack/koa-webpack-tests.ts index eaa3468ce1..235bb67056 100644 --- a/types/koa-webpack/koa-webpack-tests.ts +++ b/types/koa-webpack/koa-webpack-tests.ts @@ -1,11 +1,10 @@ -import * as Koa from 'koa' -import * as webpack from 'webpack' -import * as koaWebpack from 'koa-webpack' - -const app = new Koa() -const config: webpack.Configuration = {} -const compiler = webpack(config) +import * as Koa from 'koa'; +import * as webpack from 'webpack'; +import * as koaWebpack from 'koa-webpack'; +const app = new Koa(); +const config: webpack.Configuration = {}; +const compiler = webpack(config); // Using the middleware @@ -36,15 +35,13 @@ const middleware = koaWebpack({ path: '/__what', heartbeat: 2000 } -}) - -app.use(middleware) +}); +app.use(middleware); // Accessing the underlying middleware -middleware.dev.close() -middleware.dev.invalidate() -middleware.dev.waitUntilValid() -middleware.hot.publish(null) - +middleware.dev.close(); +middleware.dev.invalidate(); +middleware.dev.waitUntilValid(); +middleware.hot.publish(null); diff --git a/types/koa-webpack/tsconfig.json b/types/koa-webpack/tsconfig.json index 57a4aac117..d3cef374db 100644 --- a/types/koa-webpack/tsconfig.json +++ b/types/koa-webpack/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From ac1790e653a206b23abfc786435446bfbb21f157 Mon Sep 17 00:00:00 2001 From: Luka Maljic Date: Wed, 13 Dec 2017 11:25:34 +0100 Subject: [PATCH 3/4] Added TypeScript version --- types/koa-webpack/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/koa-webpack/index.d.ts b/types/koa-webpack/index.d.ts index 4a598d3ac5..93e2c54fdd 100644 --- a/types/koa-webpack/index.d.ts +++ b/types/koa-webpack/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/shellscape/koa-webpack#readme // Definitions by: Luka Maljic // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 import * as Koa from 'koa'; import * as webpack from 'webpack'; From 78066c57bdaa1c326331ff5240d498b67451ff21 Mon Sep 17 00:00:00 2001 From: Luka Maljic Date: Wed, 13 Dec 2017 22:52:26 +0100 Subject: [PATCH 4/4] Updated module import syntax --- types/koa-webpack/index.d.ts | 14 +++++++------- types/koa-webpack/koa-webpack-tests.ts | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/types/koa-webpack/index.d.ts b/types/koa-webpack/index.d.ts index 93e2c54fdd..b425956f03 100644 --- a/types/koa-webpack/index.d.ts +++ b/types/koa-webpack/index.d.ts @@ -4,11 +4,11 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as Koa from 'koa'; -import * as webpack from 'webpack'; -import * as webpackDevMiddleware from 'webpack-dev-middleware'; -import * as webpackHotMiddleware from 'webpack-hot-middleware'; -import { NextHandleFunction } from 'connect'; +import Koa = require('koa'); +import webpack = require('webpack'); +import webpackDevMiddleware = require('webpack-dev-middleware'); +import webpackHotMiddleware = require('webpack-hot-middleware'); +import connect = require('connect'); declare function koaWebpack( options?: koaWebpack.Options @@ -23,8 +23,8 @@ declare namespace koaWebpack { } interface CombinedWebpackMiddleware { - dev: NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware; - hot: NextHandleFunction & webpackHotMiddleware.EventStream; + dev: connect.NextHandleFunction & webpackDevMiddleware.WebpackDevMiddleware; + hot: connect.NextHandleFunction & webpackHotMiddleware.EventStream; } } diff --git a/types/koa-webpack/koa-webpack-tests.ts b/types/koa-webpack/koa-webpack-tests.ts index 235bb67056..c153a874d5 100644 --- a/types/koa-webpack/koa-webpack-tests.ts +++ b/types/koa-webpack/koa-webpack-tests.ts @@ -1,6 +1,6 @@ -import * as Koa from 'koa'; -import * as webpack from 'webpack'; -import * as koaWebpack from 'koa-webpack'; +import Koa = require('koa'); +import webpack = require('webpack'); +import koaWebpack = require('koa-webpack'); const app = new Koa(); const config: webpack.Configuration = {};