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

Improve type of RollupOutput.output #2679

Merged
merged 4 commits into from Feb 15, 2019

Conversation

MattiasBuelens
Copy link
Contributor

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

List any relevant issue numbers:

Description

Now that microsoft/TypeScript#24897 has landed in TypeScript 3.2, we can more precisely define the type of RollupOutput.output to assert that the first element will be an OutputChunk.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Nice one!

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Seems you broke the type check, though

@MattiasBuelens
Copy link
Contributor Author

Seems you broke the type check, though

Woops! 😅

Right, so createOutput builds the output array by mapping over the keys of outputBundle which is a Record<string, OutputChunk | OutputAsset>. The compiler doesn't know that outputBundle will have at least one property that is an OutputChunk, and it also doesn't know that the subsequent sort() will move any OutputChunks to the front of the array.

Should we just put in a type cast? Something like:

Object.keys(outputBundle)
  .map(...)
  .sort(...) as [OutputChunk, ...(OutputChunk | OutputAsset)[]]

@lukastaegert
Copy link
Member

Sounds good

@MattiasBuelens
Copy link
Contributor Author

Very weird. Some unit tests are failing on Node 6 according to CircleCI:

  2759 passing (34s)
  1 pending
  14 failing

  1) rollup
       function
         export-global: any global variables in scope can be re-exported:
     Error: Export 'Buffer' is not defined
      at error (src/utils/error.ts:7:11)
      at Module.error (src/Module.ts:558:3)
      at tryParse (src/Module.ts:127:5)
      at Module.setSource (src/Module.ts:235:29)
      at /home/circleci/project/src/Graph.ts:545:10

  2) rollup
       form
         system-uninitialized: supports uninitialized binding exports:
     Error: Export 'globalVar' is not defined
      at error (src/utils/error.ts:7:11)
      at Module.error (src/Module.ts:558:3)
      at tryParse (src/Module.ts:127:5)
      at Module.setSource (src/Module.ts:235:29)
      at /home/circleci/project/src/Graph.ts:545:10

  ...

But I only changed some types! 😭

@lukastaegert
Copy link
Member

Sorry for the wait, finally managed to address those test issues. Basically, it was caused by version drift on Node 6 (which should no longer happen) and a breaking change in a patch version of acorn.

@lukastaegert lukastaegert merged commit 1ae20fc into rollup:master Feb 15, 2019
@MattiasBuelens MattiasBuelens deleted the improve-output-type branch February 15, 2019 09:50
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

2 participants