Skip to content

Commit 82e8448

Browse files
authored
feat: remove support for TypeScript < 3.6.0 (#643)
BREAKING CHANGE: 🧨 Drop support for TypeScript < 3.6.0
1 parent 6ffbbed commit 82e8448

10 files changed

+41
-63
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"tapable": "^2.0.0"
7070
},
7171
"peerDependencies": {
72-
"webpack": "^5.11.0"
72+
"webpack": "^5.11.0",
73+
"typescript": ">3.6.0"
7374
},
7475
"devDependencies": {
7576
"@commitlint/config-conventional": "^13.1.0",

src/typescript-reporter/TypeScriptSupport.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,11 @@ function assertTypeScriptSupport(configuration: TypeScriptReporterConfiguration)
2020
);
2121
}
2222

23-
if (semver.lt(typescriptVersion, '2.7.0')) {
23+
if (semver.lt(typescriptVersion, '3.6.0')) {
2424
throw new Error(
2525
[
2626
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of ${typescriptVersion}.`,
27-
'The minimum required version is 2.7.0.',
28-
].join(os.EOL)
29-
);
30-
}
31-
32-
if (configuration.build && semver.lt(typescriptVersion, '3.6.0')) {
33-
throw new Error(
34-
[
35-
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of ${typescriptVersion} because of the "build" option enabled.`,
36-
'The minimum version that supports "build" option is 3.6.0.',
37-
'Consider upgrading `typescript` or disabling "build" option.',
27+
'The minimum required version is 3.6.0.',
3828
].join(os.EOL)
3929
);
4030
}

src/typescript-reporter/reporter/TypeScriptConfigurationParser.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as ts from 'typescript';
22
import { normalize, dirname, basename, resolve, relative } from 'path';
33
import { TypeScriptConfigurationOverwrite } from '../TypeScriptConfigurationOverwrite';
44
import { FilesMatch } from '../../reporter';
5+
import forwardSlash from '../../utils/path/forwardSlash';
56

67
function parseTypeScriptConfiguration(
78
typescript: typeof ts,
@@ -10,8 +11,9 @@ function parseTypeScriptConfiguration(
1011
configOverwriteJSON: TypeScriptConfigurationOverwrite,
1112
parseConfigFileHost: ts.ParseConfigFileHost
1213
): ts.ParsedCommandLine {
14+
const configFilePath = forwardSlash(configFileName);
1315
const parsedConfigFileJSON = typescript.readConfigFile(
14-
configFileName,
16+
configFilePath,
1517
parseConfigFileHost.readFile
1618
);
1719

@@ -34,7 +36,7 @@ function parseTypeScriptConfiguration(
3436
...parsedConfigFile,
3537
options: {
3638
...parsedConfigFile.options,
37-
configFilePath: configFileName,
39+
configFilePath: configFilePath,
3840
},
3941
errors: parsedConfigFileJSON.error ? [parsedConfigFileJSON.error] : parsedConfigFile.errors,
4042
};

test/e2e/TypeScriptConfiguration.spec.ts

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

77
describe('TypeScript Configuration', () => {
88
it.each([
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' },
9+
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
10+
{ async: false, typescript: '~3.8.0', 'ts-loader': '^8.0.0' },
11+
{ async: true, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
12+
{ async: false, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
1313
])(
1414
'change in the tsconfig.json affects compilation for %p',
1515
async ({ async, ...dependencies }) => {
@@ -39,10 +39,10 @@ describe('TypeScript Configuration', () => {
3939
);
4040

4141
it.each([
42-
{ typescript: '2.7.1' },
43-
{ typescript: '~3.0.0' },
4442
{ typescript: '~3.6.0' },
4543
{ typescript: '^3.8.0' },
44+
{ typescript: '^4.0.0' },
45+
{ typescript: '^4.3.0' },
4646
])('reports errors because of the misconfiguration', async (dependencies) => {
4747
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
4848
await sandbox.install('yarn', { ...dependencies });

test/e2e/TypeScriptContextOption.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
44

55
describe('TypeScript Context Option', () => {
66
it.each([
7-
{ async: true, typescript: '2.7.1' },
8-
{ async: false, typescript: '~3.0.0' },
97
{ async: true, typescript: '~3.6.0' },
108
{ async: false, typescript: '~3.8.0' },
9+
{ async: true, typescript: '~4.0.0' },
10+
{ async: false, typescript: '~4.3.0' },
1111
])('uses context and cwd to resolve project files for %p', async ({ async, typescript }) => {
1212
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
1313
await sandbox.install('yarn', { typescript });

test/e2e/TypeScriptFormatterOption.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
44
describe('TypeScript Formatter Option', () => {
55
it.each([
66
{ async: true, typescript: '~3.6.0' },
7-
{ async: false, typescript: '~3.8.0' },
7+
{ async: false, typescript: '~4.3.0' },
88
])(
99
'uses the custom formatter to format the error message for %p',
1010
async ({ async, typescript }) => {

test/e2e/TypeScriptPnpSupport.spec.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import path from 'path';
22
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
3+
import semver from 'semver';
34

45
describe('TypeScript PnP Support', () => {
56
it.each([
6-
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
7-
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
8-
{ async: true, typescript: '~3.8.0', 'ts-loader': '^7.0.0' },
7+
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
8+
{ async: false, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
9+
{ async: true, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
910
])('reports semantic error for %p', async ({ async, ...dependencies }) => {
1011
await sandbox.load(path.join(__dirname, 'fixtures/typescript-pnp'));
1112
await sandbox.install('yarn', { ...dependencies });
@@ -70,7 +71,9 @@ describe('TypeScript PnP Support', () => {
7071
expect(errors).toContain(
7172
[
7273
'ERROR in ./src/index.ts 1:23-39',
73-
"TS2307: Cannot find module './authenticate'.",
74+
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
75+
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
76+
: "TS2307: Cannot find module './authenticate'.",
7477
" > 1 | import { login } from './authenticate';",
7578
' | ^^^^^^^^^^^^^^^^',
7679
" 2 | import { getUserName } from './model/User';",

test/e2e/TypeScriptSolutionBuilderApi.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import path from 'path';
22
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
3+
import semver from 'semver';
34

45
describe('TypeScript SolutionBuilder API', () => {
56
it.each([
67
{ async: false, typescript: '~3.6.0', mode: 'readonly' },
78
{ async: true, typescript: '~3.8.0', mode: 'write-tsbuildinfo' },
8-
{ async: false, typescript: '~3.8.0', mode: 'write-references' },
9+
{ async: false, typescript: '~4.0.0', mode: 'write-references' },
10+
{ async: true, typescript: '~4.3.0', mode: 'readonly' },
911
])('reports semantic error for %p', async ({ async, typescript, mode }) => {
1012
await sandbox.load(path.join(__dirname, 'fixtures/typescript-monorepo'));
1113
await sandbox.install('yarn', { typescript });
@@ -53,7 +55,7 @@ describe('TypeScript SolutionBuilder API', () => {
5355
[
5456
'ERROR in ./packages/client/src/index.ts 4:42-48',
5557
"TS2345: Argument of type 'T[]' is not assignable to parameter of type 'T'.",
56-
typescript === '~4.0.0'
58+
semver.satisfies(semver.minVersion(typescript), '>=4.0.0')
5759
? " 'T' could be instantiated with an arbitrary type which could be unrelated to 'T[]'."
5860
: " 'T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.",
5961
' 2 |',

test/e2e/TypeScriptWatchApi.spec.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
3+
import semver from 'semver';
34

45
describe('TypeScript Watch API', () => {
56
it.each([{ async: false }, { async: true }])(
@@ -209,10 +210,10 @@ describe('TypeScript Watch API', () => {
209210
);
210211

211212
it.each([
212-
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
213-
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
214-
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
215-
{ async: false, typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
213+
{ async: true, typescript: '~3.6.0', 'ts-loader': '^6.0.0' },
214+
{ async: false, typescript: '~3.8.0', 'ts-loader': '^7.0.0' },
215+
{ async: true, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
216+
{ async: false, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
216217
])('reports semantic error for %p', async ({ async, ...dependencies }) => {
217218
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
218219
await sandbox.install('yarn', { ...dependencies });
@@ -277,7 +278,9 @@ describe('TypeScript Watch API', () => {
277278
expect(errors).toContain(
278279
[
279280
'ERROR in ./src/index.ts 1:23-39',
280-
"TS2307: Cannot find module './authenticate'.",
281+
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
282+
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
283+
: "TS2307: Cannot find module './authenticate'.",
281284
" > 1 | import { login } from './authenticate';",
282285
' | ^^^^^^^^^^^^^^^^',
283286
" 2 | import { getUserName } from './model/User';",

test/unit/typescript-reporter/TypeScriptSupport.spec.ts

+5-28
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,20 @@ describe('typescript-reporter/TypeScriptSupport', () => {
4242
);
4343
});
4444

45-
it('throws error if typescript version is lower then 2.7.0', async () => {
46-
jest.setMock('typescript', { version: '2.6.9' });
47-
48-
const { assertTypeScriptSupport } = await import('lib/typescript-reporter/TypeScriptSupport');
49-
50-
expect(() => assertTypeScriptSupport(configuration)).toThrowError(
51-
[
52-
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 2.6.9.`,
53-
'The minimum required version is 2.7.0.',
54-
].join(os.EOL)
55-
);
56-
});
57-
58-
it("doesn't throw error if typescript version is greater or equal 2.7.0", async () => {
59-
jest.setMock('typescript', { version: '2.7.0' });
60-
jest.setMock('fs-extra', { existsSync: () => true });
61-
62-
const { assertTypeScriptSupport } = await import('lib/typescript-reporter/TypeScriptSupport');
63-
64-
expect(() => assertTypeScriptSupport(configuration)).not.toThrowError();
65-
});
66-
67-
it('throws error if typescript version is lower then 3.6.0 and configuration has enabled build option', async () => {
45+
it('throws error if typescript version is lower then 3.6.0', async () => {
6846
jest.setMock('typescript', { version: '3.5.9' });
6947

7048
const { assertTypeScriptSupport } = await import('lib/typescript-reporter/TypeScriptSupport');
7149

72-
expect(() => assertTypeScriptSupport({ ...configuration, build: true })).toThrowError(
50+
expect(() => assertTypeScriptSupport(configuration)).toThrowError(
7351
[
74-
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 3.5.9 because of the "build" option enabled.`,
75-
'The minimum version that supports "build" option is 3.6.0.',
76-
'Consider upgrading `typescript` or disabling "build" option.',
52+
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 3.5.9.`,
53+
'The minimum required version is 3.6.0.',
7754
].join(os.EOL)
7855
);
7956
});
8057

81-
it("doesn't throw error if typescript version is greater or equal 3.6.0 and configuration has enabled build option", async () => {
58+
it("doesn't throw error if typescript version is greater or equal 3.6.0", async () => {
8259
jest.setMock('typescript', { version: '3.6.0' });
8360
jest.setMock('fs-extra', { existsSync: () => true });
8461

0 commit comments

Comments
 (0)