From 48025857ba42fd6d6efe0577118eefcfc5fc128e Mon Sep 17 00:00:00 2001 From: Ryan Roemer Date: Fri, 21 Jan 2022 10:54:32 -0800 Subject: [PATCH] Bug: TS fixes (#341) - Move types to `pluing/types.d.ts` - Update plugin signature to webpack 5 inclusive format - Add webpack type check to `check-ts` - Add `yarn dev-ts` TS-based configuration example to our examples... --- .github/workflows/ci.yml | 8 +++- CHANGELOG.md | 4 +- examples/config/webpack.config.ts | 35 ++++++++++++++ index.d.ts | 24 ---------- package.json | 4 +- plugin/index.d.ts | 21 ++++++++ yarn.lock | 80 +++++++++++++++++++++++++++++++ 7 files changed, 149 insertions(+), 27 deletions(-) create mode 100644 examples/config/webpack.config.ts delete mode 100644 index.d.ts create mode 100644 plugin/index.d.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6168b36..ce4321c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,12 @@ name: CI -on: [push] +on: + push: + branches: + - master + pull_request: + branches: + - master jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index ad039f4..7c8cbdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog -This project adheres to [Semantic Versioning](http://semver.org/). +## UNRELEASED + +- Bug: Move plugin types and update to webpack v5. [#324](https://github.com/FormidableLabs/webpack-dashboard/issues/324) ## 3.3.6 diff --git a/examples/config/webpack.config.ts b/examples/config/webpack.config.ts new file mode 100644 index 0000000..6f6ee3f --- /dev/null +++ b/examples/config/webpack.config.ts @@ -0,0 +1,35 @@ +/** + * No-op build with TS config to see if webpack-cli bombs out. + */ + +import DashboardPlugin from '../../plugin'; + +import * as path from 'path'; +import * as webpack from 'webpack'; +const webpackVers = webpack.version; + +const cwd = `${process.cwd()}/examples/${process.env.EXAMPLE}`; +if (!process.env.EXAMPLE) { + throw new Error("EXAMPLE is required"); +} + +const mode = process.env.WEBPACK_MODE || "development"; + +const config: webpack.Configuration = { + mode: 'development', + entry: { + bundle: "./src/index.js" + }, + context: path.resolve(cwd), + output: { + path: path.resolve(cwd, `dist-ts-${mode}-${webpackVers}`), + pathinfo: true, + filename: "[name].js" + }, + devtool: false, + plugins: [ + new DashboardPlugin() + ] +}; + +export default config; diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 5bef531..0000000 --- a/index.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Type definitions for webpack-dashboard 2.x.x -// Project: https://github.com/FormidableLabs/webpack-dashboard -// Definitions by: Parker Ziegler -// TypeScript Version: 3.2 - -declare module 'webpack-dashboard/plugin' { - interface IMessage { - type: string; - value: string | number | { [key: string]: any } - error?: boolean; - } - - interface IDashboardOptions { - port?: number; - host?: string; - handler?: (dataArray: IMessage[]) => void; - } - - class DashboardPlugin { - constructor(options?: IDashboardOptions); - } - - export = DashboardPlugin; -} diff --git a/package.json b/package.json index 40edaee..e8630ac 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,9 @@ "lint": "eslint .", "check": "run-s format-check lint test check-ts", "check-ci": "run-s format-check lint test-cov check-ts", - "check-ts": "tsc index.d.ts --noEmit", + "check-ts": "tsc plugin/index.d.ts examples/config/webpack.config.ts --noEmit", "dev": "cross-env EXAMPLE=duplicates-esm node bin/webpack-dashboard.js -- webpack-cli --config examples/config/webpack.config.js --watch", + "dev-ts": "cross-env EXAMPLE=duplicates-esm node bin/webpack-dashboard.js -- webpack-cli --config examples/config/webpack.config.ts --watch", "format": "prettier --write \"./{bin,examples,plugin,test,utils}/**/*.js\"", "format-check": "prettier --list-different \"./{bin,examples,plugin,test,utils}/**/*.js\"" }, @@ -67,6 +68,7 @@ "prettier": "^2.3.2", "sinon": "^11.1.1", "sinon-chai": "^3.7.0", + "ts-node": "^10.4.0", "typescript": "^4.3.5", "webpack": "^5.44.0", "webpack-cli": "^4.7.2", diff --git a/plugin/index.d.ts b/plugin/index.d.ts new file mode 100644 index 0000000..3b600fe --- /dev/null +++ b/plugin/index.d.ts @@ -0,0 +1,21 @@ +interface IMessage { + type: string; + value: string | number | { [key: string]: any } + error?: boolean; +} + +interface IDashboardOptions { + port?: number; + host?: string; + handler?: (dataArray: IMessage[]) => void; +} + +interface ICompiler { + hooks?: any; + plugin?: (name: string, callback: () => void) => void; +} + +export default class DashboardPlugin { + constructor(options?: IDashboardOptions); + apply(compiler: ICompiler): void; +} diff --git a/yarn.lock b/yarn.lock index 90d091e..1a1727f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -208,6 +208,18 @@ "@babel/helper-validator-identifier" "^7.14.5" to-fast-properties "^2.0.0" +"@cspotcode/source-map-consumer@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" + integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== + +"@cspotcode/source-map-support@0.7.0": + version "0.7.0" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" + integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== + dependencies: + "@cspotcode/source-map-consumer" "0.8.0" + "@discoveryjs/json-ext@^0.5.0": version "0.5.3" resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz#90420f9f9c6d3987f176a19a7d8e764271a2f55d" @@ -291,6 +303,26 @@ resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== +"@tsconfig/node10@^1.0.7": + version "1.0.8" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" + integrity sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg== + +"@tsconfig/node12@^1.0.7": + version "1.0.9" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c" + integrity sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw== + +"@tsconfig/node14@^1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2" + integrity sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg== + +"@tsconfig/node16@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.2.tgz#423c77877d0569db20e1fc80885ac4118314010e" + integrity sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA== + "@types/component-emitter@^1.2.10": version "1.2.10" resolved "https://registry.yarnpkg.com/@types/component-emitter/-/component-emitter-1.2.10.tgz#ef5b1589b9f16544642e473db5ea5639107ef3ea" @@ -503,6 +535,11 @@ acorn-jsx@^5.3.1: resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937" integrity sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ== +acorn-walk@^8.1.1: + version "8.2.0" + resolved "https://registry.yarnpkg.com/acorn-walk/-/acorn-walk-8.2.0.tgz#741210f2e2426454508853a2f44d0ab83b7f69c1" + integrity sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA== + acorn@^7.4.0: version "7.4.1" resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa" @@ -602,6 +639,11 @@ archy@^1.0.0: resolved "https://registry.yarnpkg.com/archy/-/archy-1.0.0.tgz#f9c8c13757cc1dd7bc379ac77b2c62a5c2868c40" integrity sha1-+cjBN1fMHde8N5rHeyxipcKGjEA= +arg@^4.1.0: + version "4.1.3" + resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" + integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA== + argparse@^1.0.7: version "1.0.10" resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" @@ -936,6 +978,11 @@ cors@~2.8.5: object-assign "^4" vary "^1" +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-env@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" @@ -1032,6 +1079,11 @@ diff@5.0.0, diff@^5.0.0: resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w== +diff@^4.0.1: + version "4.0.2" + resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d" + integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A== + doctrine@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" @@ -2146,6 +2198,11 @@ make-dir@^3.0.0, make-dir@^3.0.2: dependencies: semver "^6.0.0" +make-error@^1.1.1: + version "1.3.6" + resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" + integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== + memorystream@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2" @@ -3151,6 +3208,24 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" +ts-node@^10.4.0: + version "10.4.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7" + integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A== + dependencies: + "@cspotcode/source-map-support" "0.7.0" + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.2" + acorn "^8.4.1" + acorn-walk "^8.1.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + yn "3.1.1" + tsconfig-paths@^3.9.0: version "3.10.1" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.10.1.tgz#79ae67a68c15289fdf5c51cb74f397522d795ed7" @@ -3499,6 +3574,11 @@ yeast@0.1.2: resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" integrity sha1-AI4G2AlDIMNy28L47XagymyKxBk= +yn@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50" + integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q== + yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"