Skip to content

Commit

Permalink
feat: remove support for TypeScript < 3.6.0 (#643)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 馃Ж Drop support for TypeScript < 3.6.0
  • Loading branch information
piotr-oles committed Aug 24, 2021
1 parent 6ffbbed commit 82e8448
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 63 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
"tapable": "^2.0.0"
},
"peerDependencies": {
"webpack": "^5.11.0"
"webpack": "^5.11.0",
"typescript": ">3.6.0"
},
"devDependencies": {
"@commitlint/config-conventional": "^13.1.0",
Expand Down
14 changes: 2 additions & 12 deletions src/typescript-reporter/TypeScriptSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,11 @@ function assertTypeScriptSupport(configuration: TypeScriptReporterConfiguration)
);
}

if (semver.lt(typescriptVersion, '2.7.0')) {
if (semver.lt(typescriptVersion, '3.6.0')) {
throw new Error(
[
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of ${typescriptVersion}.`,
'The minimum required version is 2.7.0.',
].join(os.EOL)
);
}

if (configuration.build && semver.lt(typescriptVersion, '3.6.0')) {
throw new Error(
[
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of ${typescriptVersion} because of the "build" option enabled.`,
'The minimum version that supports "build" option is 3.6.0.',
'Consider upgrading `typescript` or disabling "build" option.',
'The minimum required version is 3.6.0.',
].join(os.EOL)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as ts from 'typescript';
import { normalize, dirname, basename, resolve, relative } from 'path';
import { TypeScriptConfigurationOverwrite } from '../TypeScriptConfigurationOverwrite';
import { FilesMatch } from '../../reporter';
import forwardSlash from '../../utils/path/forwardSlash';

function parseTypeScriptConfiguration(
typescript: typeof ts,
Expand All @@ -10,8 +11,9 @@ function parseTypeScriptConfiguration(
configOverwriteJSON: TypeScriptConfigurationOverwrite,
parseConfigFileHost: ts.ParseConfigFileHost
): ts.ParsedCommandLine {
const configFilePath = forwardSlash(configFileName);
const parsedConfigFileJSON = typescript.readConfigFile(
configFileName,
configFilePath,
parseConfigFileHost.readFile
);

Expand All @@ -34,7 +36,7 @@ function parseTypeScriptConfiguration(
...parsedConfigFile,
options: {
...parsedConfigFile.options,
configFilePath: configFileName,
configFilePath: configFilePath,
},
errors: parsedConfigFileJSON.error ? [parsedConfigFileJSON.error] : parsedConfigFile.errors,
};
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/TypeScriptConfiguration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {

describe('TypeScript Configuration', () => {
it.each([
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
{ async: true, typescript: '~3.7.0', 'ts-loader': '^7.0.0' },
{ async: false, typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
{ async: false, typescript: '~3.8.0', 'ts-loader': '^8.0.0' },
{ async: true, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
{ async: false, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
])(
'change in the tsconfig.json affects compilation for %p',
async ({ async, ...dependencies }) => {
Expand Down Expand Up @@ -39,10 +39,10 @@ describe('TypeScript Configuration', () => {
);

it.each([
{ typescript: '2.7.1' },
{ typescript: '~3.0.0' },
{ typescript: '~3.6.0' },
{ typescript: '^3.8.0' },
{ typescript: '^4.0.0' },
{ typescript: '^4.3.0' },
])('reports errors because of the misconfiguration', async (dependencies) => {
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
await sandbox.install('yarn', { ...dependencies });
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/TypeScriptContextOption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';

describe('TypeScript Context Option', () => {
it.each([
{ async: true, typescript: '2.7.1' },
{ async: false, typescript: '~3.0.0' },
{ async: true, typescript: '~3.6.0' },
{ async: false, typescript: '~3.8.0' },
{ async: true, typescript: '~4.0.0' },
{ async: false, typescript: '~4.3.0' },
])('uses context and cwd to resolve project files for %p', async ({ async, typescript }) => {
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
await sandbox.install('yarn', { typescript });
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/TypeScriptFormatterOption.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
describe('TypeScript Formatter Option', () => {
it.each([
{ async: true, typescript: '~3.6.0' },
{ async: false, typescript: '~3.8.0' },
{ async: false, typescript: '~4.3.0' },
])(
'uses the custom formatter to format the error message for %p',
async ({ async, typescript }) => {
Expand Down
11 changes: 7 additions & 4 deletions test/e2e/TypeScriptPnpSupport.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from 'path';
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
import semver from 'semver';

describe('TypeScript PnP Support', () => {
it.each([
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
{ async: true, typescript: '~3.8.0', 'ts-loader': '^7.0.0' },
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
{ async: false, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
{ async: true, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
])('reports semantic error for %p', async ({ async, ...dependencies }) => {
await sandbox.load(path.join(__dirname, 'fixtures/typescript-pnp'));
await sandbox.install('yarn', { ...dependencies });
Expand Down Expand Up @@ -70,7 +71,9 @@ describe('TypeScript PnP Support', () => {
expect(errors).toContain(
[
'ERROR in ./src/index.ts 1:23-39',
"TS2307: Cannot find module './authenticate'.",
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
: "TS2307: Cannot find module './authenticate'.",
" > 1 | import { login } from './authenticate';",
' | ^^^^^^^^^^^^^^^^',
" 2 | import { getUserName } from './model/User';",
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/TypeScriptSolutionBuilderApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import path from 'path';
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
import semver from 'semver';

describe('TypeScript SolutionBuilder API', () => {
it.each([
{ async: false, typescript: '~3.6.0', mode: 'readonly' },
{ async: true, typescript: '~3.8.0', mode: 'write-tsbuildinfo' },
{ async: false, typescript: '~3.8.0', mode: 'write-references' },
{ async: false, typescript: '~4.0.0', mode: 'write-references' },
{ async: true, typescript: '~4.3.0', mode: 'readonly' },
])('reports semantic error for %p', async ({ async, typescript, mode }) => {
await sandbox.load(path.join(__dirname, 'fixtures/typescript-monorepo'));
await sandbox.install('yarn', { typescript });
Expand Down Expand Up @@ -53,7 +55,7 @@ describe('TypeScript SolutionBuilder API', () => {
[
'ERROR in ./packages/client/src/index.ts 4:42-48',
"TS2345: Argument of type 'T[]' is not assignable to parameter of type 'T'.",
typescript === '~4.0.0'
semver.satisfies(semver.minVersion(typescript), '>=4.0.0')
? " 'T' could be instantiated with an arbitrary type which could be unrelated to 'T[]'."
: " 'T[]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.",
' 2 |',
Expand Down
13 changes: 8 additions & 5 deletions test/e2e/TypeScriptWatchApi.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import { createWebpackDevServerDriver } from './driver/WebpackDevServerDriver';
import semver from 'semver';

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

it.each([
{ async: true, typescript: '2.7.1', 'ts-loader': '^5.0.0' },
{ async: false, typescript: '~3.0.0', 'ts-loader': '^6.0.0' },
{ async: true, typescript: '~3.6.0', 'ts-loader': '^7.0.0' },
{ async: false, typescript: '~3.8.0', 'ts-loader': '^6.0.0' },
{ async: true, typescript: '~3.6.0', 'ts-loader': '^6.0.0' },
{ async: false, typescript: '~3.8.0', 'ts-loader': '^7.0.0' },
{ async: true, typescript: '~4.0.0', 'ts-loader': '^8.0.0' },
{ async: false, typescript: '~4.3.0', 'ts-loader': '^8.0.0' },
])('reports semantic error for %p', async ({ async, ...dependencies }) => {
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));
await sandbox.install('yarn', { ...dependencies });
Expand Down Expand Up @@ -277,7 +278,9 @@ describe('TypeScript Watch API', () => {
expect(errors).toContain(
[
'ERROR in ./src/index.ts 1:23-39',
"TS2307: Cannot find module './authenticate'.",
semver.satisfies(semver.minVersion(dependencies.typescript), '>=4.0.0')
? "TS2307: Cannot find module './authenticate' or its corresponding type declarations."
: "TS2307: Cannot find module './authenticate'.",
" > 1 | import { login } from './authenticate';",
' | ^^^^^^^^^^^^^^^^',
" 2 | import { getUserName } from './model/User';",
Expand Down
33 changes: 5 additions & 28 deletions test/unit/typescript-reporter/TypeScriptSupport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,20 @@ describe('typescript-reporter/TypeScriptSupport', () => {
);
});

it('throws error if typescript version is lower then 2.7.0', async () => {
jest.setMock('typescript', { version: '2.6.9' });

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

expect(() => assertTypeScriptSupport(configuration)).toThrowError(
[
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 2.6.9.`,
'The minimum required version is 2.7.0.',
].join(os.EOL)
);
});

it("doesn't throw error if typescript version is greater or equal 2.7.0", async () => {
jest.setMock('typescript', { version: '2.7.0' });
jest.setMock('fs-extra', { existsSync: () => true });

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

expect(() => assertTypeScriptSupport(configuration)).not.toThrowError();
});

it('throws error if typescript version is lower then 3.6.0 and configuration has enabled build option', async () => {
it('throws error if typescript version is lower then 3.6.0', async () => {
jest.setMock('typescript', { version: '3.5.9' });

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

expect(() => assertTypeScriptSupport({ ...configuration, build: true })).toThrowError(
expect(() => assertTypeScriptSupport(configuration)).toThrowError(
[
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 3.5.9 because of the "build" option enabled.`,
'The minimum version that supports "build" option is 3.6.0.',
'Consider upgrading `typescript` or disabling "build" option.',
`ForkTsCheckerWebpackPlugin cannot use the current typescript version of 3.5.9.`,
'The minimum required version is 3.6.0.',
].join(os.EOL)
);
});

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

Expand Down

0 comments on commit 82e8448

Please sign in to comment.