Skip to content
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

Reduce building types time by caching old types #152

Merged
merged 3 commits into from
Jul 13, 2022
Merged

Conversation

nvh95
Copy link
Owner

@nvh95 nvh95 commented Jun 19, 2022

Issues

Emitting types takes a long time. it took twice as long as bundling

comparation table

Features

  • Reduce building types time by caching old types

Related tweets

Important notes

  • Solution: Use incremental flag to cache last computation.
  • Caveats:
    • incremental cannot be used in CLI => add tsconfig.types.json to emit types
    • If I run npm run build, it leads to this command is executed rimraf dist, which means cache will be cleared => incremental flag have no effect
      => solution: write custom scripts/clearBuildFolder.js script to keep .d.ts, tsconfig.types.tsbuildinfo and .npmignore
    • tsconfig.types.tsbuildinfo appear in dist folder, which will be shipped to npm registry
      • Try to ignore by adding dist/tsconfig.types.tsbuildinfo to .npmignore at root of project => The reason is we whitelist dist by field files in package.json. files have highest priority
        => I have to add tsconfig.types.tsbuildinfo to dist/.npmignore => npm ignore when publish to registry
      • dist folder is ignored by .gitignore => I have to temporary un-ignore dist folder to commit dist/.npmignore

Concerns

  • I still have concerns about this strategy. It could be a serious issue if I accidentally mess up with the cache.
    => Possible solution:
  • Opt-out caching when build latest version

Reference

https://github.com/microsoft/TypeScript/wiki/Performance#incremental-project-emit

@netlify
Copy link

netlify bot commented Jun 19, 2022

Deploy Preview for jest-preview-library canceled.

Name Link
🔨 Latest commit e831017
🔍 Latest deploy log https://app.netlify.com/sites/jest-preview-library/deploys/62afc28eac61c00009df4dd4

@nvh95 nvh95 marked this pull request as draft June 19, 2022 18:58
@nvh95 nvh95 added the enhancement Enhancement to current features/ behaviors label Jun 19, 2022
@nvh95 nvh95 marked this pull request as ready for review June 20, 2022 00:43
@nvh95 nvh95 merged commit 63508a0 into main Jul 13, 2022
@nvh95 nvh95 deleted the speedup-building-types branch July 13, 2022 16:05
@nvh95
Copy link
Owner Author

nvh95 commented Jul 17, 2022

@all-contributors please add @nhducit for idea

@allcontributors
Copy link
Contributor

@nvh95

I've put up a pull request to add @nhducit! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to current features/ behaviors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant