Skip to content

Commit c358dfb

Browse files
authored
Merge pull request #697 from TypeStrong/feature/merge-main-into-alpha
2 parents 03abe7b + 050cdae commit c358dfb

File tree

13 files changed

+121
-63
lines changed

13 files changed

+121
-63
lines changed

README.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Options for the TypeScript checker (`typescript` option object).
106106
| `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`. |
107107
| `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`. |
108108
| `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
109-
| `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`. |
109+
| `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. |
110110
| `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
111111
| `extensions` | `object` | `{}` | See [TypeScript extensions options](#typescript-extensions-options). |
112112
| `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
@@ -299,24 +299,37 @@ When we call this method with a [webpack compiler instance](https://webpack.js.o
299299
[tapable](https://github.com/webpack/tapable) hooks where you can pass in your callbacks.
300300

301301
```js
302-
const webpack = require('webpack');
302+
// ./src/webpack/MyWebpackPlugin.js
303303
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
304304

305-
const compiler = webpack({
306-
// ... webpack config
307-
});
305+
class MyWebpackPlugin {
306+
apply(compiler) {
307+
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
308+
309+
// log some message on waiting
310+
hooks.waiting.tap('MyPlugin', () => {
311+
console.log('waiting for issues');
312+
});
313+
// don't show warnings
314+
hooks.issues.tap('MyPlugin', (issues) =>
315+
issues.filter((issue) => issue.severity === 'error')
316+
);
317+
}
318+
}
308319

309-
// optionally add the plugin to the compiler
310-
// **don't do this if already added through configuration**
311-
new ForkTsCheckerWebpackPlugin().apply(compiler);
320+
module.exports = MyWebpackPlugin;
312321

313-
// now get the plugin hooks from compiler
314-
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
322+
// webpack.config.js
323+
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
324+
const MyWebpackPlugin = require('./src/webpack/MyWebpackPlugin');
315325

316-
// say we want to show some message when plugin is waiting for issues results
317-
hooks.waiting.tap('yourListenerName', () => {
318-
console.log('waiting for issues');
319-
});
326+
module.exports = {
327+
/* ... */
328+
plugins: [
329+
new ForkTsCheckerWebpackPlugin(),
330+
new MyWebpackPlugin()
331+
]
332+
};
320333
```
321334

322335
## Typings
@@ -334,7 +347,7 @@ yarn add --dev @types/webpack
334347

335348
## Profiling types resolution
336349

337-
Starting from TypeScript 4.1.0 (currently in beta), you can profile long type checks by
350+
Starting from TypeScript 4.1.0, you can profile long type checks by
338351
setting "generateTrace" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
339352

340353
1. Set "generateTrace": "{folderName}" in your `tsconfig.json`

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@
7070
},
7171
"peerDependencies": {
7272
"typescript": ">3.6.0",
73-
"webpack": "^5.11.0"
73+
"webpack": "^5.11.0",
74+
"vue-template-compiler": "*"
75+
},
76+
"peerDependenciesMeta": {
77+
"vue-template-compiler": {
78+
"optional": true
79+
}
7480
},
7581
"devDependencies": {
7682
"@commitlint/config-conventional": "^13.1.0",

src/plugin-options.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@
129129
"enum": [
130130
"readonly",
131131
"write-tsbuildinfo",
132+
"write-dts",
132133
"write-references"
133134
],
134-
"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"
135+
"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"
135136
},
136137
"compilerOptions": {
137138
"type": "object",

src/typescript/type-script-worker-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface TypeScriptWorkerConfig {
1616
configOverwrite: TypeScriptConfigOverwrite;
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: TypeScriptVueExtensionConfig;

src/typescript/type-script-worker-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type TypeScriptWorkerOptions = {
88
configOverwrite?: TypeScriptConfigOverwrite;
99
context?: string;
1010
build?: boolean;
11-
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-references';
11+
mode?: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
1212
diagnosticOptions?: Partial<TypeScriptDiagnosticsOptions>;
1313
extensions?: {
1414
vue?: TypeScriptVueExtensionOptions;

src/typescript/worker/get-issues-worker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const getIssuesWorker = async (
3333
watching: boolean
3434
): Promise<Issue[]> => {
3535
system.invalidateCache();
36+
invalidateDependencies();
3637

3738
if (didConfigFileChanged({ changedFiles, deletedFiles })) {
3839
invalidateConfig();
39-
invalidateDependencies();
4040
invalidateArtifacts();
4141
invalidateDiagnostics();
4242

@@ -46,7 +46,6 @@ const getIssuesWorker = async (
4646

4747
invalidateTsBuildInfo();
4848
} else if (didRootFilesChanged()) {
49-
invalidateDependencies();
5049
invalidateArtifacts();
5150

5251
invalidateWatchProgramRootFileNames();

src/typescript/worker/lib/system.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ const ignoredPaths = ['/node_modules/.', '/.git', '/.#'];
6868
export const system: ControlledTypeScriptSystem = {
6969
...typescript.sys,
7070
useCaseSensitiveFileNames: true,
71+
realpath(path: string): string {
72+
return getReadFileSystem(path).realPath(path);
73+
},
7174
fileExists(path: string): boolean {
7275
const stats = getReadFileSystem(path).readStats(path);
7376

@@ -278,8 +281,19 @@ function isArtifact(path: string) {
278281
}
279282

280283
function getReadFileSystem(path: string) {
281-
if (!isInitialRun && (mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
282-
return memFileSystem;
284+
if ((mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
285+
if (isInitialRun && !memFileSystem.exists(path) && passiveFileSystem.exists(path)) {
286+
// copy file to memory on initial run
287+
const stats = passiveFileSystem.readStats(path);
288+
if (stats?.isFile()) {
289+
const content = passiveFileSystem.readFile(path);
290+
if (content) {
291+
memFileSystem.writeFile(path, content);
292+
memFileSystem.updateTimes(path, stats.atime, stats.mtime);
293+
}
294+
}
295+
return memFileSystem;
296+
}
283297
}
284298

285299
return passiveFileSystem;
@@ -288,7 +302,9 @@ function getReadFileSystem(path: string) {
288302
function getWriteFileSystem(path: string) {
289303
if (
290304
mode === 'write-references' ||
291-
(mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo'))
305+
(mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo')) ||
306+
(mode === 'write-dts' &&
307+
['.tsbuildinfo', '.d.ts', '.d.ts.map'].some((suffix) => path.endsWith(suffix)))
292308
) {
293309
return realFileSystem;
294310
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"extends": "../../tsconfig",
2+
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"rootDir": "./src",
55
"outDir": "./lib",
6+
"tsBuildInfoFile": "lib/tsconfig.tsbuildinfo",
67
"sourceRoot": "./src",
78
"baseUrl": "./src"
89
},
910
"references": [{ "path": "../shared" }],
10-
"include": ["src"],
11-
"exclude": ["node_modules", "lib"]
11+
"include": ["src"]
1212
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"extends": "../../tsconfig",
2+
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
44
"rootDir": "./src",
55
"outDir": "./lib",
6+
"tsBuildInfoFile": "lib/tsconfig.tsbuildinfo",
67
"sourceRoot": "./src",
78
"baseUrl": "./src"
89
},
9-
"include": ["src"],
10-
"exclude": ["node_modules", "lib"]
10+
"include": ["src"]
1111
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"lib": ["es5", "scripthost"],
6+
"moduleResolution": "node",
7+
"esModuleInterop": true,
8+
"importHelpers": false,
9+
"skipLibCheck": true,
10+
"skipDefaultLibCheck": true,
11+
"strict": true,
12+
"baseUrl": ".",
13+
"composite": true,
14+
"incremental": true,
15+
"declaration": true,
16+
"declarationMap": true,
17+
"sourceMap": true,
18+
"rootDir": "./packages"
19+
}
20+
}

0 commit comments

Comments
 (0)