Skip to content

Commit aa8f74d

Browse files
authored
feat: rename tsconfig option to configFile for consistency (#436)
As ts-loader and tsconfig-paths-webpack-plugin uses `configFile` option, the plugin should use the same for consistency. BREAKING CHANGE: 🧨 `typescript.tsconfig` option renamed to the `tsconfig.configFile`
1 parent 944e0c9 commit aa8f74d

10 files changed

+31
-31
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ Options for the TypeScript checker (`typescript` option object).
157157
| -------------------- | --------- | -------------------------------------------------------------------------------------- | ----------- |
158158
| `enabled` | `boolean` | `true` | If `true`, it enables TypeScript checker. |
159159
| `memoryLimit` | `number` | `2048` | Memory limit for the checker process in MB. If the process exits with the allocation failed error, try to increase this number. |
160-
| `tsconfig` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
161-
| `context` | `string` | `dirname(configuration.tsconfig)` | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `fork-ts-checker-webpack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `tsconfig`. |
162-
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. To enable `incremental` mode, set it in the `tsconfig.json` file. |
160+
| `configFile` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
161+
| `context` | `string` | `dirname(configuration.configFile)` | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `fork-ts-checker-webpack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `configFile`. |
162+
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
163163
| `mode` | `'readonly'` or `'write-tsbuildinfo'` or `'write-references'` | `'write-tsbuildinfo'` | If you use the `babel-loader`, it's recommended to use `write-references` mode to improve initial compilation time. If you use `ts-loader`, it's recommended to use `write-tsbuildinfo` mode to not overwrite filed emitted by the `ts-loader`. |
164164
| `compilerOptions` | `object` | `{ skipLibCheck: true, sourceMap: false, inlineSourceMap: false, incremental: true }` | These options will overwrite compiler options from the `tsconfig.json` file. |
165165
| `diagnosticsOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |

src/ForkTsCheckerWebpackPluginOptions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"type": "number",
114114
"description": "Memory limit for TypeScript reporter process."
115115
},
116-
"tsconfig": {
116+
"configFile": {
117117
"type": "string",
118118
"description": "Path to tsconfig.json. By default plugin uses context or process.cwd() to localize tsconfig.json file."
119119
},

src/hooks/tapAfterCompileToAddDependencies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function tapAfterCompileToAddDependencies(
99
compiler.hooks.afterCompile.tap('ForkTsCheckerWebpackPlugin', (compilation) => {
1010
if (configuration.typescript.enabled) {
1111
// watch tsconfig.json file
12-
compilation.fileDependencies.add(path.normalize(configuration.typescript.tsconfig));
12+
compilation.fileDependencies.add(path.normalize(configuration.typescript.configFile));
1313
}
1414
});
1515
}

src/typescript-reporter/TypeScriptReporterConfiguration.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
interface TypeScriptReporterConfiguration {
1313
enabled: boolean;
1414
memoryLimit: number;
15-
tsconfig: string;
15+
configFile: string;
1616
build: boolean;
1717
context: string;
1818
mode: 'readonly' | 'write-tsbuildinfo' | 'write-references';
@@ -29,14 +29,14 @@ function createTypeScriptReporterConfiguration(
2929
compiler: webpack.Compiler,
3030
options: TypeScriptReporterOptions | undefined
3131
): TypeScriptReporterConfiguration {
32-
let tsconfig =
33-
typeof options === 'object' ? options.tsconfig || 'tsconfig.json' : 'tsconfig.json';
32+
let configFile =
33+
typeof options === 'object' ? options.configFile || 'tsconfig.json' : 'tsconfig.json';
3434

35-
// ensure that `tsconfig` is an absolute normalized path
36-
tsconfig = path.normalize(
37-
path.isAbsolute(tsconfig)
38-
? tsconfig
39-
: path.resolve(compiler.options.context || process.cwd(), tsconfig)
35+
// ensure that `configFile` is an absolute normalized path
36+
configFile = path.normalize(
37+
path.isAbsolute(configFile)
38+
? configFile
39+
: path.resolve(compiler.options.context || process.cwd(), configFile)
4040
);
4141

4242
const optionsAsObject: Exclude<TypeScriptReporterOptions, boolean> =
@@ -61,8 +61,8 @@ function createTypeScriptReporterConfiguration(
6161
mode: 'write-tsbuildinfo',
6262
profile: false,
6363
...optionsAsObject,
64-
tsconfig: tsconfig,
65-
context: optionsAsObject.context || path.dirname(tsconfig),
64+
configFile: configFile,
65+
context: optionsAsObject.context || path.dirname(configFile),
6666
compilerOptions: {
6767
...defaultCompilerOptions,
6868
...(optionsAsObject.compilerOptions || {}),

src/typescript-reporter/TypeScriptReporterOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type TypeScriptReporterOptions =
66
| {
77
enabled?: boolean;
88
memoryLimit?: number;
9-
tsconfig?: string;
9+
configFile?: string;
1010
context?: string;
1111
build?: boolean;
1212
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-references';

src/typescript-reporter/TypeScriptSupport.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ function assertTypeScriptSupport(configuration: TypeScriptReporterConfiguration)
3636
);
3737
}
3838

39-
if (!fs.existsSync(configuration.tsconfig)) {
39+
if (!fs.existsSync(configuration.configFile)) {
4040
throw new Error(
4141
[
42-
`Cannot find the "${configuration.tsconfig}" file.`,
42+
`Cannot find the "${configuration.configFile}" file.`,
4343
`Please check webpack and ForkTsCheckerWebpackPlugin configuration.`,
4444
`Possible errors:`,
45-
' - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in the fork plugin configuration)',
46-
' - wrong `typescript.tsconfig` path in the plugin configuration (should be a relative or absolute path)',
45+
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
46+
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
4747
].join(os.EOL)
4848
);
4949
}

src/typescript-reporter/reporter/TypeScriptReporter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
9999
if (
100100
[...changedFiles, ...deletedFiles]
101101
.map((affectedFile) => path.normalize(affectedFile))
102-
.includes(path.normalize(configuration.tsconfig))
102+
.includes(path.normalize(configuration.configFile))
103103
) {
104104
// we need to re-create programs
105105
parsedConfiguration = undefined;
@@ -117,7 +117,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
117117

118118
performance.markStart('Parse Configuration');
119119
parsedConfiguration = parseTypeScriptConfiguration(
120-
configuration.tsconfig,
120+
configuration.configFile,
121121
configuration.context,
122122
configuration.compilerOptions,
123123
{
@@ -140,7 +140,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
140140

141141
issues.forEach((issue) => {
142142
if (!issue.file) {
143-
issue.file = configuration.tsconfig;
143+
issue.file = configuration.configFile;
144144
}
145145
});
146146

@@ -210,7 +210,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
210210
performance.markStart('Create Solution Builder');
211211
solutionBuilder = ts.createSolutionBuilderWithWatch(
212212
watchSolutionBuilderHost,
213-
[configuration.tsconfig],
213+
[configuration.configFile],
214214
{}
215215
);
216216
performance.markEnd('Create Solution Builder');

test/e2e/TypeScriptContextOption.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('TypeScript Context Option', () => {
7070
[
7171
' typescript: {',
7272
' enabled: true,',
73-
' tsconfig: "build/tsconfig.json",',
73+
' configFile: "build/tsconfig.json",',
7474
' context: __dirname,',
7575
' },',
7676
' logger: {',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('typescript-reporter/TypeScriptsReporterConfiguration', () => {
1111
const configuration: TypeScriptReporterConfiguration = {
1212
enabled: true,
1313
memoryLimit: 2048,
14-
tsconfig: path.normalize(path.resolve(context, 'tsconfig.json')),
14+
configFile: path.normalize(path.resolve(context, 'tsconfig.json')),
1515
context: path.normalize(path.dirname(path.resolve(context, 'tsconfig.json'))),
1616
build: false,
1717
mode: 'write-tsbuildinfo',
@@ -63,10 +63,10 @@ describe('typescript-reporter/TypeScriptsReporterConfiguration', () => {
6363
[{ enabled: false }, { ...configuration, enabled: false }],
6464
[{ memoryLimit: 512 }, { ...configuration, memoryLimit: 512 }],
6565
[
66-
{ tsconfig: 'tsconfig.another.json' },
66+
{ configFile: 'tsconfig.another.json' },
6767
{
6868
...configuration,
69-
tsconfig: path.normalize(path.resolve(context, 'tsconfig.another.json')),
69+
configFile: path.normalize(path.resolve(context, 'tsconfig.another.json')),
7070
},
7171
],
7272
[{ build: true }, { ...configuration, build: true }],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('typescript-reporter/TypeScriptSupport', () => {
88
jest.resetModules();
99

1010
configuration = {
11-
tsconfig: './tsconfig.json',
11+
configFile: './tsconfig.json',
1212
context: '.',
1313
compilerOptions: {},
1414
build: false,
@@ -97,8 +97,8 @@ describe('typescript-reporter/TypeScriptSupport', () => {
9797
`Cannot find the "./tsconfig.json" file.`,
9898
`Please check webpack and ForkTsCheckerWebpackPlugin configuration.`,
9999
`Possible errors:`,
100-
' - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in the fork plugin configuration)',
101-
' - wrong `typescript.tsconfig` path in the plugin configuration (should be a relative or absolute path)',
100+
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
101+
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
102102
].join(os.EOL)
103103
);
104104
});

0 commit comments

Comments
 (0)