diff --git a/CHANGELOG.md b/CHANGELOG.md index 5244b400..fa61eb9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.0.0-alpha.3 + +* [replace peerDeps with runtime checks](/~https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/201) + ## v1.0.0-alpha.2 * [Add `useTypescriptIncrementalApi`](/~https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/198) (#196) diff --git a/package.json b/package.json index 9920032c..0338904c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fork-ts-checker-webpack-plugin", - "version": "1.0.0-alpha.2", + "version": "1.0.0-alpha.3", "description": "Runs typescript type checker and linter on separate process.", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -55,6 +55,7 @@ "@types/micromatch": "^3.1.0", "@types/minimatch": "^3.0.1", "@types/node": "^8.10.38", + "@types/semver": "^5.5.0", "@types/webpack": "^4.4.19", "chai": "^4.2.0", "css-loader": "0.28.11", @@ -78,17 +79,13 @@ "vue-template-compiler": "^2.5.16", "webpack": "^5.0.0-alpha.0" }, - "peerDependencies": { - "tslint": "^4.0.0 || ^5.0.0", - "typescript": "^2.1.0 || ^3.0.0", - "webpack": "^2.3.0 || ^3.0.0 || ^4.0.0" - }, "dependencies": { "babel-code-frame": "^6.22.0", "chalk": "^2.4.1", "chokidar": "^2.0.4", "micromatch": "^3.1.10", "minimatch": "^3.0.4", + "semver": "^5.6.0", "tapable": "^1.0.0" }, "husky": { diff --git a/src/index.ts b/src/index.ts index b7dcc751..2940cd6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import * as path from 'path'; import * as process from 'process'; import { performance } from 'perf_hooks'; import * as childProcess from 'child_process'; +import * as semver from 'semver'; import chalk, { Chalk } from 'chalk'; import * as micromatch from 'micromatch'; import * as os from 'os'; @@ -181,10 +182,28 @@ class ForkTsCheckerWebpackPlugin { ? require('tslint').Linter.VERSION : undefined; + this.validateVersions(); + this.vue = options.vue === true; // default false this.measureTime = options.measureCompilationTime === true; } + private validateVersions() { + if (semver.lt(this.typescriptVersion, '2.1.0')) { + throw new Error( + `Cannot use current typescript version of ${ + this.typescriptVersion + }, the minimum required version is 2.1.0` + ); + } else if (this.tslintVersion && semver.lt(this.tslintVersion, '4.0.0')) { + throw new Error( + `Cannot use current tslint version of ${ + this.tslintVersion + }, the minimum required version is 4.0.0` + ); + } + } + private static createFormatter(type: 'default' | 'codeframe', options: any) { switch (type) { case 'default': @@ -823,6 +842,4 @@ class ForkTsCheckerWebpackPlugin { export = ForkTsCheckerWebpackPlugin; -namespace ForkTsCheckerWebpackPlugin { - -} +namespace ForkTsCheckerWebpackPlugin {} diff --git a/src/tsconfig.json b/src/tsconfig.json index ddd47b13..5ca40180 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -4,6 +4,7 @@ "noImplicitReturns": true, "noUnusedLocals": true, "noUnusedParameters": true, + "skipLibCheck": true, "suppressImplicitAnyIndexErrors": true, "strict": true, "lib": ["es2015", "es2016.array.include", "dom"], diff --git a/src/tslint.json b/src/tslint.json index 6c112cb5..2a303896 100644 --- a/src/tslint.json +++ b/src/tslint.json @@ -23,6 +23,7 @@ "allow-pascal-case" ], "no-namespace": false, + "no-implicit-dependencies": false, "array-type": [true, "array"] } } diff --git a/test/unit/index.spec.js b/test/unit/index.spec.js new file mode 100644 index 00000000..95761ffe --- /dev/null +++ b/test/unit/index.spec.js @@ -0,0 +1,50 @@ +var describe = require('mocha').describe; +var it = require('mocha').it; +// var beforeEach = require('mocha').beforeEach; +var afterEach = require('mocha').afterEach; +var expect = require('chai').expect; +var mockRequire = require('mock-require'); + +describe('[UNIT] ForkTsCheckerWebpackPlugin', function() { + afterEach(function() { + mockRequire.stopAll(); + }); + + it('should not throw if typescript version >= 2.1.0', function() { + mockRequire('typescript', { version: '2.1.0' }); + var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index'); + + expect(function() { + new ForkTsCheckerWebpackPlugin(); + }).to.not.throw(); + }); + + it('should throw if typescript version < 2.1.0', function() { + mockRequire('typescript', { version: '2.0.8' }); + var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index'); + + expect(function() { + new ForkTsCheckerWebpackPlugin(); + }).to.throw(); + }); + + it('should not throw if tslint version >= 4.0.0', function() { + mockRequire('typescript', { version: '2.1.0' }); + mockRequire('tslint', { Linter: { VERSION: '4.0.0' } }); + var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index'); + + expect(function() { + new ForkTsCheckerWebpackPlugin({ tslint: true }); + }).to.not.throw(); + }); + + it('should throw if tslint version < 4.0.0', function() { + mockRequire('typescript', { version: '2.1.0' }); + mockRequire('tslint', { Linter: { VERSION: '3.15.1' } }); + var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index'); + + expect(function() { + new ForkTsCheckerWebpackPlugin({ tslint: true }); + }).to.throw(); + }); +}); diff --git a/yarn.lock b/yarn.lock index 84b0ae94..822f6b35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -96,6 +96,10 @@ version "8.10.39" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.39.tgz#e7e87ad00364dd7bc485c940926345b8ec1a26ca" +"@types/semver@^5.5.0": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-5.5.0.tgz#146c2a29ee7d3bae4bf2fcb274636e264c813c45" + "@types/tapable@*": version "1.0.4" resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370" @@ -3217,7 +3221,7 @@ semver-compare@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" -"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.3.0, semver@^5.5.0, semver@^5.5.1: +"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.3.0, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.6.0.tgz#7e74256fbaa49c75aa7c7a205cc22799cac80004"