Skip to content

Commit c810ee5

Browse files
committed
feat: drop support for webpack 4
BREAKING CHANGE: 🧨 Webpack 4 is no longer supported. Please upgrade to Webpack ^5.11.0 or use older version of the plugin.
1 parent 3e23b88 commit c810ee5

27 files changed

+691
-1358
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
## Installation
2323

24-
This plugin requires minimum **Node.js 12**, **Webpack 5**, **TypeScript 3.6**
24+
This plugin requires minimum **Node.js 12+**, **Webpack ^5.11.0**, **TypeScript ^3.6.0**
2525

2626
* If you depend on **TypeScript 2.1 - 2.6.2**, please use [version 4](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v4.1.4) of the plugin.
2727
* If you depend on **Webpack 4**, **TypeScript 2.7 - 3.5.3** or **ESLint** feature, please use [version 6](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v6.2.6) of the plugin.

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@
7272
"minimatch": "^3.0.4",
7373
"schema-utils": "2.7.0",
7474
"semver": "^7.3.2",
75-
"tapable": "^1.0.0"
75+
"tapable": "^2.0.0"
76+
},
77+
"peerDependencies": {
78+
"webpack": "^5.11.0"
7679
},
7780
"devDependencies": {
7881
"@commitlint/config-conventional": "^11.0.0",
@@ -90,7 +93,6 @@
9093
"@types/node": "^14.11.10",
9194
"@types/rimraf": "^3.0.0",
9295
"@types/semver": "^7.3.4",
93-
"@types/webpack": "^4.41.22",
9496
"@typescript-eslint/eslint-plugin": "^2.27.0",
9597
"@typescript-eslint/parser": "^2.27.0",
9698
"commitlint": "^11.0.0",
@@ -115,7 +117,7 @@
115117
"tree-kill": "^1.2.2",
116118
"ts-jest": "^26.4.1",
117119
"typescript": "^3.8.3",
118-
"webpack": "^4.42.1"
120+
"webpack": "^5.11.0"
119121
},
120122
"engines": {
121123
"node": ">=10",

src/ForkTsCheckerWebpackPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { tapAfterEnvironmentToPatchWatching } from './hooks/tapAfterEnvironmentT
2121
import { createPool, Pool } from './utils/async/pool';
2222
import os from 'os';
2323

24-
class ForkTsCheckerWebpackPlugin implements webpack.Plugin {
24+
class ForkTsCheckerWebpackPlugin {
2525
/**
2626
* Current version of the plugin
2727
*/

src/ForkTsCheckerWebpackPluginState.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tap } from 'tapable';
1+
import { FullTap } from 'tapable';
22
import { FilesMatch, Report } from './reporter';
33
import { Issue } from './issue';
44

@@ -9,7 +9,7 @@ interface ForkTsCheckerWebpackPluginState {
99
lastDependencies: FilesMatch | undefined;
1010
watching: boolean;
1111
initialized: boolean;
12-
webpackDevServerDoneTap: Tap | undefined;
12+
webpackDevServerDoneTap: FullTap | undefined;
1313
}
1414

1515
function createForkTsCheckerWebpackPluginState(): ForkTsCheckerWebpackPluginState {

src/hooks/pluginHooks.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const compilerHookMap = new WeakMap<
1010

1111
function createForkTsCheckerWebpackPluginHooks() {
1212
return {
13-
start: new AsyncSeriesWaterfallHook<FilesChange, webpack.compilation.Compilation>([
13+
start: new AsyncSeriesWaterfallHook<[FilesChange, webpack.Compilation]>([
1414
'change',
1515
'compilation',
1616
]),
17-
waiting: new SyncHook<webpack.compilation.Compilation>(['compilation']),
18-
canceled: new SyncHook<webpack.compilation.Compilation>(['compilation']),
19-
error: new SyncHook<Error, webpack.compilation.Compilation>(['error', 'compilation']),
20-
issues: new SyncWaterfallHook<Issue[], webpack.compilation.Compilation | undefined, void>([
17+
waiting: new SyncHook<[webpack.Compilation]>(['compilation']),
18+
canceled: new SyncHook<[webpack.Compilation]>(['compilation']),
19+
error: new SyncHook<[Error, webpack.Compilation]>(['error', 'compilation']),
20+
issues: new SyncWaterfallHook<[Issue[], webpack.Compilation | undefined], void>([
2121
'issues',
2222
'compilation',
2323
]),

src/hooks/tapAfterEnvironmentToPatchWatching.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import webpack from 'webpack';
22
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
33
import { InclusiveNodeWatchFileSystem } from '../watch/InclusiveNodeWatchFileSystem';
4-
import { CompilerWithWatchFileSystem } from '../watch/CompilerWithWatchFileSystem';
4+
import { WatchFileSystem } from '../watch/WatchFileSystem';
55

66
function tapAfterEnvironmentToPatchWatching(
77
compiler: webpack.Compiler,
88
state: ForkTsCheckerWebpackPluginState
99
) {
1010
compiler.hooks.afterEnvironment.tap('ForkTsCheckerWebpackPlugin', () => {
11-
const watchFileSystem = (compiler as CompilerWithWatchFileSystem).watchFileSystem;
11+
const watchFileSystem = compiler.watchFileSystem;
1212
if (watchFileSystem) {
1313
// wrap original watch file system
14-
(compiler as CompilerWithWatchFileSystem).watchFileSystem = new InclusiveNodeWatchFileSystem(
15-
watchFileSystem,
14+
compiler.watchFileSystem = new InclusiveNodeWatchFileSystem(
15+
// we use some internals here
16+
watchFileSystem as WatchFileSystem,
1617
compiler,
1718
state
1819
);

src/issue/IssueWebpackError.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import webpack from 'webpack';
12
import { relative } from 'path';
23
import { Issue } from './Issue';
34
import { formatIssueLocation } from './IssueLocation';
45
import forwardSlash from '../utils/path/forwardSlash';
56

6-
class IssueWebpackError extends Error {
7+
class IssueWebpackError extends webpack.WebpackError {
78
readonly hideStack = true;
8-
readonly file: string | undefined;
9+
readonly file: string = '';
910

1011
constructor(message: string, readonly issue: Issue) {
1112
super(message);

src/watch/CompilerWithWatchFileSystem.ts

-9
This file was deleted.

src/watch/InclusiveNodeWatchFileSystem.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
22
import chokidar, { FSWatcher } from 'chokidar';
33
import { extname } from 'path';
4-
import { Watcher, WatchFileSystem, WatchFileSystemOptions } from './WatchFileSystem';
4+
import { WatchFileSystem } from './WatchFileSystem';
55
import { Compiler } from 'webpack';
66
import { clearFilesChange, updateFilesChange } from '../reporter';
77
import minimatch from 'minimatch';
88

99
const BUILTIN_IGNORED_DIRS = ['node_modules', '.git', '.yarn', '.pnp'];
1010

1111
function createIsIgnored(
12-
ignored: WatchFileSystemOptions['ignored'] | undefined
12+
ignored: string | RegExp | Function | (string | RegExp | Function)[] | undefined
1313
): (path: string) => boolean {
1414
const ignoredPatterns = ignored ? (Array.isArray(ignored) ? ignored : [ignored]) : [];
1515
const ignoredFunctions = ignoredPatterns.map((pattern) => {
@@ -50,15 +50,15 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
5050

5151
private paused = true;
5252

53-
watch(
54-
files: Iterable<string>,
55-
dirs: Iterable<string>,
56-
missing: Iterable<string>,
57-
startTime?: number,
58-
options?: Partial<WatchFileSystemOptions>,
59-
callback?: Function,
60-
callbackUndelayed?: Function
61-
): Watcher {
53+
watch: WatchFileSystem['watch'] = (
54+
files,
55+
dirs,
56+
missing,
57+
startTime,
58+
options,
59+
callback,
60+
callbackUndelayed
61+
) => {
6262
clearFilesChange(this.compiler);
6363
const isIgnored = createIsIgnored(options?.ignored);
6464

@@ -173,7 +173,7 @@ class InclusiveNodeWatchFileSystem implements WatchFileSystem {
173173
this.paused = true;
174174
},
175175
};
176-
}
176+
};
177177
}
178178

179179
export { InclusiveNodeWatchFileSystem };

src/watch/WatchFileSystem.ts

+4-34
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
11
import { EventEmitter } from 'events';
2-
3-
interface WatchFileSystemOptions {
4-
aggregateTimeout: number;
5-
poll: boolean;
6-
followSymlinks: boolean;
7-
ignored: string | RegExp | Function | (string | RegExp | Function)[];
8-
}
2+
import webpack from 'webpack';
93

104
// watchpack v1 and v2 internal interface
115
interface Watchpack extends EventEmitter {
126
_onChange(item: string, mtime: number, file: string, type?: string): void;
137
_onRemove(item: string, file: string, type?: string): void;
148
}
159

16-
// webpack 4 interface
17-
interface WatcherV4 {
18-
close(): void;
19-
pause(): void;
20-
getFileTimestamps(): Map<string, number>;
21-
getContextTimestamps(): Map<string, number>;
22-
}
23-
24-
// webpack 5 interface
25-
interface WatcherV5 {
26-
close(): void;
27-
pause(): void;
28-
getFileTimeInfoEntries(): Map<string, number>;
29-
getContextTimeInfoEntries(): Map<string, number>;
30-
}
31-
32-
type Watcher = WatcherV4 | WatcherV5;
10+
type Watch = webpack.Compiler['watchFileSystem']['watch'];
3311

3412
interface WatchFileSystem {
3513
watcher: Watchpack;
3614
wfs?: {
3715
watcher: Watchpack;
3816
};
39-
watch(
40-
files: Iterable<string>,
41-
dirs: Iterable<string>,
42-
missing: Iterable<string>,
43-
startTime?: number,
44-
options?: Partial<WatchFileSystemOptions>,
45-
callback?: Function,
46-
callbackUndelayed?: Function
47-
): Watcher;
17+
watch: Watch;
4818
}
4919

50-
export { WatchFileSystem, WatchFileSystemOptions, Watchpack, WatcherV4, WatcherV5, Watcher };
20+
export { WatchFileSystem, Watchpack };

test/e2e/OutOfMemoryAndCosmiconfig.spec.ts

+29-31
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,38 @@ import path from 'path';
22
import { createProcessDriver } from 'karton';
33

44
describe('ForkTsCheckerWebpackPlugin Out Of Memory and Cosmiconfig', () => {
5-
it.each([
6-
{ async: false, webpack: '4.0.0' },
7-
{ async: true, webpack: '^4.0.0' },
8-
{ async: false, webpack: '^5.0.0' },
9-
{ async: true, webpack: '^5.0.0' },
10-
])('handles out of memory for %p', async ({ async, webpack }) => {
11-
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
12-
await sandbox.install('yarn', { webpack });
13-
await sandbox.patch('webpack.config.js', 'async: false,', `async: ${JSON.stringify(async)},`);
5+
it.each([{ async: false }, { async: true }])(
6+
'handles out of memory for %p',
7+
async ({ async }) => {
8+
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
9+
await sandbox.install('yarn', {});
10+
await sandbox.patch('webpack.config.js', 'async: false,', `async: ${JSON.stringify(async)},`);
1411

15-
await sandbox.write(
16-
'fork-ts-checker.config.js',
17-
`module.exports = { typescript: { memoryLimit: 10 } };`
18-
);
12+
await sandbox.write(
13+
'fork-ts-checker.config.js',
14+
`module.exports = { typescript: { memoryLimit: 10 } };`
15+
);
1916

20-
const driver = createProcessDriver(sandbox.spawn('npm run webpack-dev-server'));
17+
const driver = createProcessDriver(sandbox.spawn('yarn webpack serve --mode=development'));
2118

22-
// we should see an error message about out of memory
23-
await driver.waitForStderrIncludes(
24-
'Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
25-
"If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."
26-
);
19+
// we should see an error message about out of memory
20+
await driver.waitForStderrIncludes(
21+
'Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
22+
"If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."
23+
);
2724

28-
// let's modify one file to check if plugin will try to restart the service
29-
await sandbox.patch(
30-
'src/index.ts',
31-
"import { getUserName } from './model/User';",
32-
"import { getUserName } from './model/User';\n"
33-
);
25+
// let's modify one file to check if plugin will try to restart the service
26+
await sandbox.patch(
27+
'src/index.ts',
28+
"import { getUserName } from './model/User';",
29+
"import { getUserName } from './model/User';\n"
30+
);
3431

35-
// we should see an error message about out of memory again
36-
await driver.waitForStderrIncludes(
37-
'Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
38-
"If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."
39-
);
40-
});
32+
// we should see an error message about out of memory again
33+
await driver.waitForStderrIncludes(
34+
'Issues checking service aborted - probably out of memory. Check the `memoryLimit` option in the ForkTsCheckerWebpackPlugin configuration.\n' +
35+
"If increasing the memory doesn't solve the issue, it's most probably a bug in the TypeScript."
36+
);
37+
}
38+
);
4139
});

test/e2e/TypeDefinitions.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ describe('Type Definitions', () => {
55
await sandbox.load(path.join(__dirname, 'fixtures/type-definitions'));
66
await sandbox.install('yarn', {});
77

8-
expect(await sandbox.exec('npm run tsc').catch((error) => error)).toContain(
8+
expect(await sandbox.exec('yarn tsc', { fail: true })).toContain(
99
"webpack.config.ts(7,7): error TS2322: Type 'string' is not assignable to type 'boolean | undefined'."
1010
);
1111

1212
await sandbox.patch('webpack.config.ts', "async: 'invalid_value'", 'async: true');
1313

14-
expect(await sandbox.exec('npm run tsc')).not.toContain('error TS');
14+
expect(await sandbox.exec('yarn tsc')).not.toContain('error TS');
1515
});
1616
});

test/e2e/TypeScriptConfiguration.spec.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66

77
describe('TypeScript Configuration', () => {
88
it.each([
9-
{ async: true, webpack: '~4.0.0', typescript: '2.7.1', 'ts-loader': '^5.0.0' },
10-
{ async: false, webpack: '^4.0.0', typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
11-
{ async: true, webpack: '^5.0.0', typescript: '~3.7.0', 'ts-loader': '^7.0.0' },
12-
{ async: false, webpack: '^5.0.0', typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
9+
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
10+
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
11+
{ async: true, typescript: '~3.7.0', 'ts-loader': '^7.0.0' },
12+
{ async: false, typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
1313
])(
1414
'change in the tsconfig.json affects compilation for %p',
1515
async ({ async, ...dependencies }) => {
@@ -18,7 +18,7 @@ describe('TypeScript Configuration', () => {
1818
await sandbox.patch('webpack.config.js', 'async: false,', `async: ${JSON.stringify(async)},`);
1919

2020
const driver = createWebpackDevServerDriver(
21-
sandbox.spawn('npm run webpack-dev-server'),
21+
sandbox.spawn('yarn webpack serve --mode=development'),
2222
async
2323
);
2424

@@ -55,7 +55,10 @@ describe('TypeScript Configuration', () => {
5555
'module.exports = { typescript: { configOverwrite: { compilerOptions: { target: "ES3", lib: ["ES3"] } } } };'
5656
);
5757

58-
driver = createWebpackDevServerDriver(sandbox.spawn('npm run webpack-dev-server'), false);
58+
driver = createWebpackDevServerDriver(
59+
sandbox.spawn('yarn webpack serve --mode=development'),
60+
false
61+
);
5962
errors = await driver.waitForErrors();
6063
expect(errors.length).toBeGreaterThan(0);
6164
await sandbox.kill(driver.process);
@@ -65,7 +68,10 @@ describe('TypeScript Configuration', () => {
6568
'module.exports = { typescript: { configOverwrite: { include: [] } } };'
6669
);
6770

68-
driver = createWebpackDevServerDriver(sandbox.spawn('npm run webpack-dev-server'), false);
71+
driver = createWebpackDevServerDriver(
72+
sandbox.spawn('yarn webpack serve --mode=development'),
73+
false
74+
);
6975
errors = await driver.waitForErrors();
7076
expect(errors.length).toBeGreaterThan(0);
7177
await sandbox.kill(driver.process);

test/e2e/TypeScriptContextOption.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ describe('TypeScript Context Option', () => {
6565

6666
const driver = createWebpackDevServerDriver(
6767
sandbox.spawn(
68-
`../node_modules/.bin/webpack-dev-server${os.platform() === 'win32' ? '.cmd' : ''}`,
68+
`../node_modules/.bin/webpack${
69+
os.platform() === 'win32' ? '.cmd' : ''
70+
} serve --mode=development`,
6971
{
7072
cwd: path.join(sandbox.context, 'foo'),
7173
}

test/e2e/TypeScriptFormatterOption.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('TypeScript Formatter Option', () => {
2525
);
2626

2727
const driver = createWebpackDevServerDriver(
28-
sandbox.spawn('npm run webpack-dev-server'),
28+
sandbox.spawn('yarn webpack serve --mode=development'),
2929
async
3030
);
3131

0 commit comments

Comments
 (0)