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

feat(typescript): allow override of forced noEmit and emitDeclarationOnly compiler options #1242

Merged
merged 6 commits into from Aug 23, 2022

Conversation

Harris-Miller
Copy link
Contributor

@Harris-Miller Harris-Miller commented Aug 14, 2022

Rollup Plugin Name: typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

This MR is a replacement for the closed #1206. the suggested feature of a transpilerMode option, which unfortunately was discovered to be a breaking change.

Why

Currently, this plugin forced the compilerOptions noEmit and emitDeclarationOnly to be false. There is a note // Typescript needs to emit the code for us to work with.

This is false

The way that the plugin is written, the load hook looks for if typescript did transpilation for a file and returns that if found, null otherwise. This means for emitDeclarationOnly rollup will simply load from the output of the previous plugin or from the file system. This is ideal to mimic the following:

// package.json
{
  "scripts": {
    "build": "babel src --out-dir dist" 
    "typecheck": "tsc --emitDeclarationOnly"
  }
}

Where build uses babel to do all transpilation, including typescript via @babel/preset-typescript, and tsc is used to only emit declaration files.

Currently, rollup can more or less do this by running all code though @rollup/plugin-typescript first and then @rollup/plugin-babel, however with the forced emitDeclarationOnly: false being on, all the code is run through the typescript transpiler first. If @rollup/plugin-babel is set up to do to typescript, there isn't a need to actually do this

By allowing emitDeclarationOnly: true, @rollup/plugin-typescript is drastically faster! Since it only has to emit declaration file (which are emitted by rollup separately as "asset" files in the generateBundle step). On the large projects I tested this out at my work, I say initial builds drop from 20 seconds down to 2 seconds

Copy link
Member

@NotWoods NotWoods left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change!

@shellscape
Copy link
Collaborator

Looks like there are some snapshot mismatches in the tests for this change. Please see the CI output for Validate Monorepo.

@Harris-Miller
Copy link
Contributor Author

I fixed the tests. Let me know if you need anything additional

@Harris-Miller
Copy link
Contributor Author

Anything needed from me to get this merged?

@shellscape
Copy link
Collaborator

nope :)

@shellscape shellscape merged commit a21db7d into rollup:master Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants