Skip to content

Commit

Permalink
feat: rename tsconfig option to configFile for consistency (#436)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
piotr-oles committed Jun 3, 2020
1 parent 944e0c9 commit aa8f74d
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -157,9 +157,9 @@ Options for the TypeScript checker (`typescript` option object).
| -------------------- | --------- | -------------------------------------------------------------------------------------- | ----------- |
| `enabled` | `boolean` | `true` | If `true`, it enables TypeScript checker. |
| `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. |
| `tsconfig` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
| `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`. |
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. To enable `incremental` mode, set it in the `tsconfig.json` file. |
| `configFile` | `string` | `'tsconfig.json'` | Path to the `tsconfig.json` file (path relative to the `compiler.options.context` or absolute path) |
| `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`. |
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
| `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`. |
| `compilerOptions` | `object` | `{ skipLibCheck: true, sourceMap: false, inlineSourceMap: false, incremental: true }` | These options will overwrite compiler options from the `tsconfig.json` file. |
| `diagnosticsOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
Expand Down
2 changes: 1 addition & 1 deletion src/ForkTsCheckerWebpackPluginOptions.json
Expand Up @@ -113,7 +113,7 @@
"type": "number",
"description": "Memory limit for TypeScript reporter process."
},
"tsconfig": {
"configFile": {
"type": "string",
"description": "Path to tsconfig.json. By default plugin uses context or process.cwd() to localize tsconfig.json file."
},
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/tapAfterCompileToAddDependencies.ts
Expand Up @@ -9,7 +9,7 @@ function tapAfterCompileToAddDependencies(
compiler.hooks.afterCompile.tap('ForkTsCheckerWebpackPlugin', (compilation) => {
if (configuration.typescript.enabled) {
// watch tsconfig.json file
compilation.fileDependencies.add(path.normalize(configuration.typescript.tsconfig));
compilation.fileDependencies.add(path.normalize(configuration.typescript.configFile));
}
});
}
Expand Down
20 changes: 10 additions & 10 deletions src/typescript-reporter/TypeScriptReporterConfiguration.ts
Expand Up @@ -12,7 +12,7 @@ import {
interface TypeScriptReporterConfiguration {
enabled: boolean;
memoryLimit: number;
tsconfig: string;
configFile: string;
build: boolean;
context: string;
mode: 'readonly' | 'write-tsbuildinfo' | 'write-references';
Expand All @@ -29,14 +29,14 @@ function createTypeScriptReporterConfiguration(
compiler: webpack.Compiler,
options: TypeScriptReporterOptions | undefined
): TypeScriptReporterConfiguration {
let tsconfig =
typeof options === 'object' ? options.tsconfig || 'tsconfig.json' : 'tsconfig.json';
let configFile =
typeof options === 'object' ? options.configFile || 'tsconfig.json' : 'tsconfig.json';

// ensure that `tsconfig` is an absolute normalized path
tsconfig = path.normalize(
path.isAbsolute(tsconfig)
? tsconfig
: path.resolve(compiler.options.context || process.cwd(), tsconfig)
// ensure that `configFile` is an absolute normalized path
configFile = path.normalize(
path.isAbsolute(configFile)
? configFile
: path.resolve(compiler.options.context || process.cwd(), configFile)
);

const optionsAsObject: Exclude<TypeScriptReporterOptions, boolean> =
Expand All @@ -61,8 +61,8 @@ function createTypeScriptReporterConfiguration(
mode: 'write-tsbuildinfo',
profile: false,
...optionsAsObject,
tsconfig: tsconfig,
context: optionsAsObject.context || path.dirname(tsconfig),
configFile: configFile,
context: optionsAsObject.context || path.dirname(configFile),
compilerOptions: {
...defaultCompilerOptions,
...(optionsAsObject.compilerOptions || {}),
Expand Down
2 changes: 1 addition & 1 deletion src/typescript-reporter/TypeScriptReporterOptions.ts
Expand Up @@ -6,7 +6,7 @@ type TypeScriptReporterOptions =
| {
enabled?: boolean;
memoryLimit?: number;
tsconfig?: string;
configFile?: string;
context?: string;
build?: boolean;
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-references';
Expand Down
8 changes: 4 additions & 4 deletions src/typescript-reporter/TypeScriptSupport.ts
Expand Up @@ -36,14 +36,14 @@ function assertTypeScriptSupport(configuration: TypeScriptReporterConfiguration)
);
}

if (!fs.existsSync(configuration.tsconfig)) {
if (!fs.existsSync(configuration.configFile)) {
throw new Error(
[
`Cannot find the "${configuration.tsconfig}" file.`,
`Cannot find the "${configuration.configFile}" file.`,
`Please check webpack and ForkTsCheckerWebpackPlugin configuration.`,
`Possible errors:`,
' - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in the fork plugin configuration)',
' - wrong `typescript.tsconfig` path in the plugin configuration (should be a relative or absolute path)',
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
].join(os.EOL)
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/typescript-reporter/reporter/TypeScriptReporter.ts
Expand Up @@ -99,7 +99,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
if (
[...changedFiles, ...deletedFiles]
.map((affectedFile) => path.normalize(affectedFile))
.includes(path.normalize(configuration.tsconfig))
.includes(path.normalize(configuration.configFile))
) {
// we need to re-create programs
parsedConfiguration = undefined;
Expand All @@ -117,7 +117,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration

performance.markStart('Parse Configuration');
parsedConfiguration = parseTypeScriptConfiguration(
configuration.tsconfig,
configuration.configFile,
configuration.context,
configuration.compilerOptions,
{
Expand All @@ -140,7 +140,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration

issues.forEach((issue) => {
if (!issue.file) {
issue.file = configuration.tsconfig;
issue.file = configuration.configFile;
}
});

Expand Down Expand Up @@ -210,7 +210,7 @@ function createTypeScriptReporter(configuration: TypeScriptReporterConfiguration
performance.markStart('Create Solution Builder');
solutionBuilder = ts.createSolutionBuilderWithWatch(
watchSolutionBuilderHost,
[configuration.tsconfig],
[configuration.configFile],
{}
);
performance.markEnd('Create Solution Builder');
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/TypeScriptContextOption.spec.ts
Expand Up @@ -70,7 +70,7 @@ describe('TypeScript Context Option', () => {
[
' typescript: {',
' enabled: true,',
' tsconfig: "build/tsconfig.json",',
' configFile: "build/tsconfig.json",',
' context: __dirname,',
' },',
' logger: {',
Expand Down
Expand Up @@ -11,7 +11,7 @@ describe('typescript-reporter/TypeScriptsReporterConfiguration', () => {
const configuration: TypeScriptReporterConfiguration = {
enabled: true,
memoryLimit: 2048,
tsconfig: path.normalize(path.resolve(context, 'tsconfig.json')),
configFile: path.normalize(path.resolve(context, 'tsconfig.json')),
context: path.normalize(path.dirname(path.resolve(context, 'tsconfig.json'))),
build: false,
mode: 'write-tsbuildinfo',
Expand Down Expand Up @@ -63,10 +63,10 @@ describe('typescript-reporter/TypeScriptsReporterConfiguration', () => {
[{ enabled: false }, { ...configuration, enabled: false }],
[{ memoryLimit: 512 }, { ...configuration, memoryLimit: 512 }],
[
{ tsconfig: 'tsconfig.another.json' },
{ configFile: 'tsconfig.another.json' },
{
...configuration,
tsconfig: path.normalize(path.resolve(context, 'tsconfig.another.json')),
configFile: path.normalize(path.resolve(context, 'tsconfig.another.json')),
},
],
[{ build: true }, { ...configuration, build: true }],
Expand Down
6 changes: 3 additions & 3 deletions test/unit/typescript-reporter/TypeScriptSupport.spec.ts
Expand Up @@ -8,7 +8,7 @@ describe('typescript-reporter/TypeScriptSupport', () => {
jest.resetModules();

configuration = {
tsconfig: './tsconfig.json',
configFile: './tsconfig.json',
context: '.',
compilerOptions: {},
build: false,
Expand Down Expand Up @@ -97,8 +97,8 @@ describe('typescript-reporter/TypeScriptSupport', () => {
`Cannot find the "./tsconfig.json" file.`,
`Please check webpack and ForkTsCheckerWebpackPlugin configuration.`,
`Possible errors:`,
' - wrong `context` directory in webpack configuration (if `tsconfig` is not set or is a relative path in the fork plugin configuration)',
' - wrong `typescript.tsconfig` path in the plugin configuration (should be a relative or absolute path)',
' - wrong `context` directory in webpack configuration (if `configFile` is not set or is a relative path in the fork plugin configuration)',
' - wrong `typescript.configFile` path in the plugin configuration (should be a relative or absolute path)',
].join(os.EOL)
);
});
Expand Down

0 comments on commit aa8f74d

Please sign in to comment.