Skip to content

generateTrace does not work with newer TypeScript versions #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mkantor opened this issue Mar 12, 2022 · 7 comments · Fixed by #730
Closed

generateTrace does not work with newer TypeScript versions #722

mkantor opened this issue Mar 12, 2022 · 7 comments · Fixed by #730

Comments

@mkantor
Copy link
Contributor

mkantor commented Mar 12, 2022

Current behavior

The README describes how to profile slow type-checking by setting generateTrace in tsconfig.json. However this doesn't work with recent TypeScript versions.

Expected behavior

When building with "generateTrace": "./traces" in tsconfig.json, trace files should be created in ./traces as stated in the README.

Steps to reproduce the issue

  1. Set up a project with a recent version of TypeScript (I'm using 4.6.2, but I'm nearly certain this problem exists as far back as 4.2.x).
  2. Set up a tsconfig.json with "generateTrace": "{folderName}" as described in the README.
  3. Do a build.
  4. Observe that no trace files were created.

Environment

  • fork-ts-checker-webpack-plugin: 6.2.12
  • typescript: 4.6.2
  • eslint: 7.32.0
  • webpack: 4.46.0
  • os: macOS 12.0.1
@mkantor mkantor added the bug label Mar 12, 2022
@mkantor
Copy link
Contributor Author

mkantor commented Mar 12, 2022

I think this comes down to relying on internal TypeScript APIs which have changed.

For example:

const tracing: Tracing | undefined = (typescript as any).tracing;

Since microsoft/TypeScript#42323 it seems that typescript.tracing is undefined until typescript.startTracing is called, but startTracingIfNeeded is written to never call startTracing unless tracing is truthy:

if (compilerOptions.generateTrace && tracing) {
tracing.startTracing(
getConfigFilePathFromCompilerOptions(compilerOptions),
compilerOptions.generateTrace as string,
config.build
);
}

@mkantor
Copy link
Contributor Author

mkantor commented Mar 12, 2022

Also microsoft/TypeScript#43354 removed getTypeCatalog, but it's relied upon here in stopTracingIfNeeded:

tracing.stopTracing((program.getProgram() as any).getTypeCatalog());

@mkantor
Copy link
Contributor Author

mkantor commented Mar 12, 2022

Separately, if there was some kind of warning about tracing being skipped even though generateTrace was set it would have helped me understand what was going on much more quickly. Such a warning would be useful for folks using older versions of TypeScript as well (even once this issue is resolved).

@piotr-oles
Copy link
Collaborator

@mkantor given that you already know where is the issue and how to solve it, would you mind creating a PR?

@mkantor
Copy link
Contributor Author

mkantor commented Mar 14, 2022

Should generateTrace be supported for various TypeScript versions? I think I know how to address it for TypeScript 4.6.x, but am not sure about past/future releases, and would be worried that a fix which works with my setup might break things for others.

Relatedly, are there any tests that run against different TypeScript versions?

@piotr-oles
Copy link
Collaborator

piotr-oles commented Apr 3, 2022

Sorry for the late response. I think it's enough to support it for TypeScript 4.6.x+ - this feature is a minor one.
We have e2e tests that run on different versions of typescript - check the tests/e2e directory. So basically you would have to create a new test that uses generateTrace: './traces' in tsconfig.json, run a webpack build, and check if trace files exist :)

mkantor added a commit to mkantor/fork-ts-checker-webpack-plugin that referenced this issue Apr 9, 2022
mkantor added a commit to mkantor/fork-ts-checker-webpack-plugin that referenced this issue Apr 9, 2022
mkantor added a commit to mkantor/fork-ts-checker-webpack-plugin that referenced this issue Apr 9, 2022
mkantor added a commit to mkantor/fork-ts-checker-webpack-plugin that referenced this issue Apr 10, 2022
@piotr-oles
Copy link
Collaborator

🎉 This issue has been resolved in version 7.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants