From 2af878bd6b2dfaa7258498253421d7ddc5696c83 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Sun, 1 Apr 2018 14:48:32 -0700 Subject: [PATCH 1/5] Add types for ReactLoadablePlugin, getBundles --- types/react-loadable/index.d.ts | 1 + types/react-loadable/test/webpack.ts | 25 +++++++++++++++++++++++++ types/react-loadable/tsconfig.json | 4 +++- types/react-loadable/webpack.d.ts | 23 +++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 types/react-loadable/test/webpack.ts create mode 100644 types/react-loadable/webpack.d.ts diff --git a/types/react-loadable/index.d.ts b/types/react-loadable/index.d.ts index d2229d4bf6..beeb569d4c 100644 --- a/types/react-loadable/index.d.ts +++ b/types/react-loadable/index.d.ts @@ -4,6 +4,7 @@ // Oden S. // Ian Ker-Seymer // Tomek Łaziuk +// Ian Mobley // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.6 diff --git a/types/react-loadable/test/webpack.ts b/types/react-loadable/test/webpack.ts new file mode 100644 index 0000000000..089994a23d --- /dev/null +++ b/types/react-loadable/test/webpack.ts @@ -0,0 +1,25 @@ +import * as webpack from 'webpack'; +import { ReactLoadablePlugin, getBundles, Manifest } from 'react-loadable/webpack'; + +const config: webpack.Configuration = { + plugins: [ + new ReactLoadablePlugin(), + new ReactLoadablePlugin({ + filename: 'react-loadable.json' + }) + ] +}; + +const manifest: Manifest = { + react: [ + { + id: 0, + name: "./node_modules/react/index.js", + file: "main.js" + } + ] +}; + +const manifestIds = ['react']; + +const bundles = getBundles(manifest, manifestIds); diff --git a/types/react-loadable/tsconfig.json b/types/react-loadable/tsconfig.json index 9d46ae0de9..a2ad20875b 100644 --- a/types/react-loadable/tsconfig.json +++ b/types/react-loadable/tsconfig.json @@ -19,8 +19,10 @@ }, "files": [ "index.d.ts", + "webpack.d.ts", "test/index.tsx", + "test/webpack.ts", "test/imports/no-default.tsx", "test/imports/with-default.tsx" ] -} \ No newline at end of file +} diff --git a/types/react-loadable/webpack.d.ts b/types/react-loadable/webpack.d.ts new file mode 100644 index 0000000000..0e67a1a0bd --- /dev/null +++ b/types/react-loadable/webpack.d.ts @@ -0,0 +1,23 @@ +import * as webpack from 'webpack'; + +export namespace ReactLoadablePlugin { + interface Options { + filename: string; + } +} + +export class ReactLoadablePlugin extends webpack.Plugin { + constructor(opts?: ReactLoadablePlugin.Options); +} + +export interface Bundle { + id: number; + name: string; + file: string; +} + +export interface Manifest { + [moduleId: string]: Bundle[]; +} + +export function getBundles(manifest: Manifest, moduleIds: string[]): Bundle[]; From 781b4af34b7d3a0f0e7847c773dc8ed72ef23170 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Mon, 2 Apr 2018 09:06:19 -0700 Subject: [PATCH 2/5] Convert to match commonJS export syntax. I'm not entirely sure how to get the interfaces to export as well, but they're not really necessary beside for checking sanity of arguments. --- types/react-loadable/test/webpack.ts | 4 +-- types/react-loadable/webpack.d.ts | 39 ++++++++++++++++------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/types/react-loadable/test/webpack.ts b/types/react-loadable/test/webpack.ts index 089994a23d..741d0d4733 100644 --- a/types/react-loadable/test/webpack.ts +++ b/types/react-loadable/test/webpack.ts @@ -1,5 +1,5 @@ import * as webpack from 'webpack'; -import { ReactLoadablePlugin, getBundles, Manifest } from 'react-loadable/webpack'; +import { ReactLoadablePlugin, getBundles } from 'react-loadable/webpack'; const config: webpack.Configuration = { plugins: [ @@ -10,7 +10,7 @@ const config: webpack.Configuration = { ] }; -const manifest: Manifest = { +const manifest = { react: [ { id: 0, diff --git a/types/react-loadable/webpack.d.ts b/types/react-loadable/webpack.d.ts index 0e67a1a0bd..54732527d8 100644 --- a/types/react-loadable/webpack.d.ts +++ b/types/react-loadable/webpack.d.ts @@ -1,23 +1,30 @@ -import * as webpack from 'webpack'; +import webpack = require("webpack"); -export namespace ReactLoadablePlugin { +declare namespace LoadableExport { interface Options { filename: string; } + + class ReactLoadablePlugin extends webpack.Plugin { + constructor(opts?: Options); + } + + interface Bundle { + id: number; + name: string; + file: string; + } + + interface Manifest { + [moduleId: string]: Bundle[]; + } + + function getBundles(manifest: Manifest, moduleIds: string[]): Bundle[]; } -export class ReactLoadablePlugin extends webpack.Plugin { - constructor(opts?: ReactLoadablePlugin.Options); -} +declare const exports: { + getBundles: typeof LoadableExport.getBundles; + ReactLoadablePlugin: typeof LoadableExport.ReactLoadablePlugin; +}; -export interface Bundle { - id: number; - name: string; - file: string; -} - -export interface Manifest { - [moduleId: string]: Bundle[]; -} - -export function getBundles(manifest: Manifest, moduleIds: string[]): Bundle[]; +export = exports; From fac20c19ebeb6961ed9269371469546b44fe243d Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Mon, 2 Apr 2018 10:10:57 -0700 Subject: [PATCH 3/5] quotes consistency --- types/react-loadable/test/webpack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-loadable/test/webpack.ts b/types/react-loadable/test/webpack.ts index 741d0d4733..08885e418d 100644 --- a/types/react-loadable/test/webpack.ts +++ b/types/react-loadable/test/webpack.ts @@ -14,8 +14,8 @@ const manifest = { react: [ { id: 0, - name: "./node_modules/react/index.js", - file: "main.js" + name: './node_modules/react/index.js', + file: 'main.js' } ] }; From d1713bc84226d2a3656e609c2c351fb04cf9b747 Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Mon, 2 Apr 2018 19:27:04 -0700 Subject: [PATCH 4/5] Convert react-loadable/webpack test to commonJS It doesn't look like destructuring will work when using require. --- types/react-loadable/test/webpack.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/types/react-loadable/test/webpack.ts b/types/react-loadable/test/webpack.ts index 08885e418d..5549dfdc4e 100644 --- a/types/react-loadable/test/webpack.ts +++ b/types/react-loadable/test/webpack.ts @@ -1,11 +1,10 @@ -import * as webpack from 'webpack'; -import { ReactLoadablePlugin, getBundles } from 'react-loadable/webpack'; +import webpack = require('webpack'); +import Loadable = require('react-loadable/webpack'); const config: webpack.Configuration = { plugins: [ - new ReactLoadablePlugin(), - new ReactLoadablePlugin({ - filename: 'react-loadable.json' + new Loadable.ReactLoadablePlugin(), + new Loadable.ReactLoadablePlugin({ filename: 'react-loadable.json' }) ] }; @@ -22,4 +21,4 @@ const manifest = { const manifestIds = ['react']; -const bundles = getBundles(manifest, manifestIds); +const bundles = Loadable.getBundles(manifest, manifestIds); From adb4937be9078febc05980a7d96c2f81a5de2e5a Mon Sep 17 00:00:00 2001 From: Ian Mobley Date: Mon, 2 Apr 2018 19:42:46 -0700 Subject: [PATCH 5/5] move filename back to newline --- types/react-loadable/test/webpack.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/react-loadable/test/webpack.ts b/types/react-loadable/test/webpack.ts index 5549dfdc4e..ecfa79cd53 100644 --- a/types/react-loadable/test/webpack.ts +++ b/types/react-loadable/test/webpack.ts @@ -4,7 +4,8 @@ import Loadable = require('react-loadable/webpack'); const config: webpack.Configuration = { plugins: [ new Loadable.ReactLoadablePlugin(), - new Loadable.ReactLoadablePlugin({ filename: 'react-loadable.json' + new Loadable.ReactLoadablePlugin({ + filename: 'react-loadable.json' }) ] };