Skip to content

Commit 66948d7

Browse files
committed
fix: support generateTrace in non-build mode
1 parent 1f12810 commit 66948d7

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,12 @@ yarn add --dev @types/webpack
347347

348348
## Profiling types resolution
349349

350-
When using TypeScript 4.3.0 or newer in `build` mode you can profile long type checks by
350+
When using TypeScript 4.3.0 or newer you can profile long type checks by
351351
setting "generateTrace" compiler option. This is an instruction from [microsoft/TypeScript#40063](https://github.com/microsoft/TypeScript/pull/40063):
352352

353353
1. Set "generateTrace": "{folderName}" in your `tsconfig.json` (under `compilerOptions`)
354-
2. Look in the resulting folder. There will be a `legend.json` telling you what went where.
354+
2. Look in the resulting folder. If you used build mode, there will be a `legend.json` telling you what went where.
355+
Otherwise, there will be `trace.json` file and `types.json` files.
355356
3. Navigate to [edge://tracing](edge://tracing) or [chrome://tracing](chrome://tracing) and load `trace.json`
356357
4. Expand Process 1 with the little triangle in the left sidebar
357358
5. Click on different blocks to see their payloads in the bottom pane

src/typescript/worker/lib/program/program.ts

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getConfigFilePathFromProgram, getParsedConfig } from '../config';
44
import { updateDiagnostics, getDiagnosticsOfProgram } from '../diagnostics';
55
import { emitDtsIfNeeded } from '../emit';
66
import { createCompilerHost } from '../host/compiler-host';
7+
import { startTracingIfNeeded, stopTracingIfNeeded } from '../tracing';
78
import { typescript } from '../typescript';
89

910
let compilerHost: ts.CompilerHost | undefined;
@@ -16,6 +17,7 @@ export function useProgram() {
1617
compilerHost = createCompilerHost(parsedConfig);
1718
}
1819
if (!program) {
20+
startTracingIfNeeded(parsedConfig.options);
1921
program = typescript.createProgram({
2022
rootNames: parsedConfig.fileNames,
2123
options: parsedConfig.options,
@@ -26,6 +28,7 @@ export function useProgram() {
2628

2729
updateDiagnostics(getConfigFilePathFromProgram(program), getDiagnosticsOfProgram(program));
2830
emitDtsIfNeeded(program);
31+
stopTracingIfNeeded(program);
2932
}
3033

3134
export function invalidateProgram(withHost = false) {

src/typescript/worker/lib/tracing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function startTracingIfNeeded(compilerOptions: ts.CompilerOptions) {
3333
}
3434
}
3535

36-
export function stopTracingIfNeeded(program: ts.BuilderProgram) {
36+
export function stopTracingIfNeeded(program: ts.Program | ts.BuilderProgram) {
3737
const compilerOptions = program.getCompilerOptions();
3838

3939
if (

test/e2e/type-script-tracing.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import { extractWebpackErrors } from './driver/webpack-errors-extractor';
44

55
describe('TypeScript Tracing', () => {
66
it.each([
7+
{ build: false, typescript: '~4.3.0' },
78
{ build: true, typescript: '~4.3.0' },
9+
{ build: false, typescript: '~4.4.0' },
810
{ build: true, typescript: '~4.4.0' },
11+
{ build: false, typescript: '~4.5.0' },
912
{ build: true, typescript: '~4.5.0' },
13+
{ build: false, typescript: '~4.6.0' },
1014
{ build: true, typescript: '~4.6.0' },
1115
])('can generate trace files for %p', async ({ build, ...dependencies }) => {
1216
await sandbox.load(path.join(__dirname, 'fixtures/typescript-basic'));

0 commit comments

Comments
 (0)