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: support emitDeclarationOnly #366

Merged
merged 1 commit into from
Jun 24, 2022

Conversation

agilgur5
Copy link
Collaborator

@agilgur5 agilgur5 commented Jun 23, 2022

Summary

Support emitDeclarationOnly by, well, only emitting declarations and type-checking, and otherwise passing to the next plugin to transform TS

Details

  • when emitDeclarationOnly is set, only perform type-checking and emit declarations, don't transform TS

    • result.code actually doesn't exist when emitDeclarationOnly is set anyway
      • this caused a confusing situation for users who were trying to use Babel (with Babel plugins) on TS and only use rpt2 for declarations
        • instead of getting any JS code, they would just get empty chunks, bc result.code is undefined
          • that's kind of buggy, it should probably either be forced to false or do what we're doing now, which is likely more intuitive / intended
            • note that other Rollup TS plugins just force it to false, but I'm not sure that's the most optimal behavior
    • so now, instead of getting an empty chunk, rpt2 will just pass to the next plugin, allowing for other plugins on the chain to process TS
      • this opens up some new use cases, like using in tandem with Babel plugins (e.g. with babel-plugin-typescript-to-proptypes) or using for type-checking and declaration generation while using Vite / ESBuild for compilation
  • add a new paragraph to "Declarations" docs about this new feature and what it does and some examples of how it could be used

    • note that these are unexplored / untested integrations, so point that out in the docs too
    • also modify a self-reference further up in the docs to use code backticks for rollup-plugin-typescript2
  • while at it, also add a line about declaration maps

  • and reformat the existing paragraph a bit to match the style and improve readability

    • one sentence per line, which is all on the same paragraph in Markdown anyway
    • add a <br /> element to add a new-line within the paragraph for better readability / spacing
      • Markdown supports this only with two trailing spaces, which is difficult to see and the trailing whitespace can be trimmed by editors, so prefer <br />

Can see my root cause analysis in #268 (comment)

- when `emitDeclarationOnly` is set, only perform type-checking and emit declarations, don't transform TS
  - `result.code` actually doesn't exist when `emitDeclarationOnly` is set anyway
    - this caused a confusing situation for users who were trying to use Babel (with Babel plugins) on TS and only use rpt2 for declarations
      - instead of getting any JS code, they would just get empty chunks, bc `result.code` is `undefined`
        - that's kind of buggy, it should probably either be forced to `false` or do what we're doing now, which is likely more intuitive / intended
  - so now, instead of getting an empty chunk, rpt2 will just pass to the next plugin, allowing for other plugins on the chain to process TS
    - this opens up some new use cases, like using in tandem with Babel plugins (as the issue illustrates) or using for type-checking and declaration generation while using Vite / ESBuild for compilation

- add a new paragraph to "Declarations" docs about this new feature and what it does and some examples of how it could be used
  - note that these are unexplored / untested integrations, so point that out in the docs too
  - also modify a self-reference further up in the docs to use code backticks for `rollup-plugin-typescript2`
- while at it, also add a line about declaration maps
- and reformat the existing paragraph a bit to match the style and improve readability
  - one sentence per line, which is all on the same paragraph in Markdown anyway
  - add a `<br />` element to add a new-line _within_ the paragraph for better readability / spacing
    - Markdown supports this only with two trailing spaces, which is difficult to see and the trailing whitespace can be trimmed by editors, so prefer `<br />`
@agilgur5 agilgur5 added kind: feature New feature or request scope: docs Documentation could be improved. Or changes that only affect docs labels Jun 23, 2022
src/index.ts Show resolved Hide resolved
@godPaimon
Copy link

Hi, when will the 0.32.2 version be released?

@godPaimon
Copy link

Hi, when will the 0.32.2 version be released?

I don't see version 0.32.2 on npm

@agilgur5
Copy link
Collaborator Author

agilgur5 commented Jul 1, 2022

I don't see version 0.32.2 on npm

It hasn't been released yet. Could be good for a release after my current batch of PRs, but ezolenko handles releases currently.

If you're wondering why the package.json on GitHub lists 0.32.2 already, can see an explanation for that here. It supports a different installation method and is always upped immediately after a release (i.e. before a new release is even ready).

P.S. Didn't know Paimon was interested in my work 😝

@godPaimon
Copy link

OK, thx.

P.S. Paimon is not only a tour guide, but also a programmer

@godPaimon
Copy link

I found that dist is still 0.32.1, please help me to build 0.32.2 dist :(

@agilgur5
Copy link
Collaborator Author

agilgur5 commented Jul 4, 2022

I found that dist is still 0.32.1

Yea I typically only build during a release. Makes for much cleaner diffs (and smaller diffs means smaller git history size too).
Personally, I don't keep dist in source control at all in my own repos (it isn't "source" after all).

please help me to build 0.32.2 dist :(

You're welcome to fork and build it yourself and use that until a release is cut if you need this more urgently.
See the docs in CONTRIBUTING.md for directions. Can also view the CI flow as well.

@agilgur5
Copy link
Collaborator Author

@godPaimon thought I'd update you that this PR was released in 0.33.0 recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request scope: docs Documentation could be improved. Or changes that only affect docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using together with Babel plugins and emitDeclarationOnly overwrites output files with no content
3 participants