Skip to content

Commit 61f7cdf

Browse files
authored
feat: implement write-dts mode (#679)
1 parent b1c0d9a commit 61f7cdf

File tree

7 files changed

+30
-7
lines changed

7 files changed

+30
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Options for the TypeScript checker (`typescript` option object).
157157
| `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`. |
158158
| `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`. |
159159
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
160-
| `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 files emitted by the `ts-loader`. |
160+
| `mode` | `'readonly'` or `'write-tsbuildinfo'` or `'write-dts'` 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 files emitted by the `ts-loader`. If you use `ts-loader` with `transpileOnly` flag set to `true`, use `'write-dts` to emit the type definition files. |
161161
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
162162
| `extensions` | `object` | `{}` | See [TypeScript extensions options](#typescript-extensions-options). |
163163
| `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |

src/ForkTsCheckerWebpackPluginOptions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
},
139139
"mode": {
140140
"type": "string",
141-
"enum": ["readonly", "write-tsbuildinfo", "write-references"],
142-
"description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files and `write-references` which writes both .tsbuildinfo and referenced projects output"
141+
"enum": ["readonly", "write-tsbuildinfo", "write-dts", "write-references"],
142+
"description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files, `write-dts` writes .tsbuildinfo and type definition files, and `write-references` which writes both .tsbuildinfo and referenced projects output"
143143
},
144144
"compilerOptions": {
145145
"type": "object",

src/typescript-reporter/TypeScriptReporterConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface TypeScriptReporterConfiguration {
1616
configOverwrite: TypeScriptConfigurationOverwrite;
1717
build: boolean;
1818
context: string;
19-
mode: 'readonly' | 'write-tsbuildinfo' | 'write-references';
19+
mode: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
2020
diagnosticOptions: TypeScriptDiagnosticsOptions;
2121
extensions: {
2222
vue: TypeScriptVueExtensionConfiguration;

src/typescript-reporter/TypeScriptReporterOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type TypeScriptReporterOptions =
1111
configOverwrite?: TypeScriptConfigurationOverwrite;
1212
context?: string;
1313
build?: boolean;
14-
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-references';
14+
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
1515
diagnosticOptions?: Partial<TypeScriptDiagnosticsOptions>;
1616
extensions?: {
1717
vue?: TypeScriptVueExtensionOptions;

src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface ControlledTypeScriptSystem extends ts.System {
3939
setArtifacts(artifacts: FilesMatch): void;
4040
}
4141

42-
type FileSystemMode = 'readonly' | 'write-tsbuildinfo' | 'write-references';
42+
type FileSystemMode = 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
4343

4444
function createControlledTypeScriptSystem(
4545
typescript: typeof ts,
@@ -171,7 +171,9 @@ function createControlledTypeScriptSystem(
171171
function getWriteFileSystem(path: string) {
172172
if (
173173
mode === 'write-references' ||
174-
(mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo'))
174+
(mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo')) ||
175+
(mode === 'write-dts' &&
176+
['.tsbuildinfo', '.d.ts', '.d.ts.map'].some((prefix) => path.endsWith(prefix)))
175177
) {
176178
return realFileSystem;
177179
}

test/e2e/TypeScriptSolutionBuilderApi.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('TypeScript SolutionBuilder API', () => {
2626
it.each([
2727
{ async: false, typescript: '~3.6.0', mode: 'readonly' },
2828
{ async: true, typescript: '~3.8.0', mode: 'write-tsbuildinfo' },
29+
{ async: true, typescript: '~3.8.0', mode: 'write-dts' },
2930
{ async: false, typescript: '~3.8.0', mode: 'write-references' },
3031
])('reports semantic error for %p', async ({ async, typescript, mode }) => {
3132
await sandbox.load([
@@ -143,6 +144,25 @@ describe('TypeScript SolutionBuilder API', () => {
143144
await sandbox.remove('packages/client/lib');
144145
break;
145146

147+
case 'write-dts':
148+
expect(await sandbox.exists('packages/shared/lib/tsconfig.tsbuildinfo')).toEqual(true);
149+
expect(await sandbox.exists('packages/client/lib/tsconfig.tsbuildinfo')).toEqual(true);
150+
expect(await sandbox.exists('packages/shared/lib')).toEqual(true);
151+
expect(await sandbox.exists('packages/client/lib')).toEqual(true);
152+
expect(await sandbox.exists('packages/shared/lib/index.d.ts')).toEqual(true);
153+
expect(await sandbox.exists('packages/shared/lib/index.d.ts.map')).toEqual(true);
154+
expect(await sandbox.exists('packages/client/lib/index.d.ts')).toEqual(true);
155+
expect(await sandbox.exists('packages/client/lib/index.d.ts.map')).toEqual(true);
156+
expect(await sandbox.exists('packages/shared/lib/index.js')).toEqual(false);
157+
expect(await sandbox.exists('packages/client/lib/index.js')).toEqual(false);
158+
159+
expect(await sandbox.read('packages/shared/lib/tsconfig.tsbuildinfo')).not.toEqual('');
160+
expect(await sandbox.read('packages/client/lib/tsconfig.tsbuildinfo')).not.toEqual('');
161+
162+
await sandbox.remove('packages/shared/lib');
163+
await sandbox.remove('packages/client/lib');
164+
break;
165+
146166
case 'write-references':
147167
expect(await sandbox.exists('packages/shared/lib/tsconfig.tsbuildinfo')).toEqual(true);
148168
expect(await sandbox.exists('packages/client/lib/tsconfig.tsbuildinfo')).toEqual(true);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('typescript-reporter/TypeScriptsReporterConfiguration', () => {
7474
[{ build: true }, { ...configuration, build: true }],
7575
[{ mode: 'readonly' }, { ...configuration, mode: 'readonly' }],
7676
[{ mode: 'write-tsbuildinfo' }, { ...configuration, mode: 'write-tsbuildinfo' }],
77+
[{ mode: 'write-dts' }, { ...configuration, mode: 'write-dts' }],
7778
[{ mode: 'write-references' }, { ...configuration, mode: 'write-references' }],
7879
[
7980
{ configOverwrite: { compilerOptions: { strict: true }, include: ['src'] } },

0 commit comments

Comments
 (0)