Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace peerDeps with runtime checks #201

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
23 changes: 20 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -823,6 +842,4 @@ class ForkTsCheckerWebpackPlugin {

export = ForkTsCheckerWebpackPlugin;

namespace ForkTsCheckerWebpackPlugin {

}
namespace ForkTsCheckerWebpackPlugin {}
1 change: 1 addition & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"suppressImplicitAnyIndexErrors": true,
"strict": true,
"lib": ["es2015", "es2016.array.include", "dom"],
Expand Down
1 change: 1 addition & 0 deletions src/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"allow-pascal-case"
],
"no-namespace": false,
"no-implicit-dependencies": false,
"array-type": [true, "array"]
}
}
50 changes: 50 additions & 0 deletions test/unit/index.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

Expand Down