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(types): export Rollup namespace #12316

Merged
merged 1 commit into from Mar 11, 2023
Merged

Conversation

sun0day
Copy link
Member

@sun0day sun0day commented Mar 7, 2023

Description

fix #12270

export origin rollup types as Rollup namespace in index.d.ts

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Mar 7, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sun0day sun0day changed the title chore: export rollup types from pure-dep-types (fix #12270) chore: export rollup types from dep-types (fix #12270) Mar 7, 2023
packages/vite/package.json Outdated Show resolved Hide resolved
@bluwy bluwy added the p2-nice-to-have Not breaking anything but nice to have (priority) label Mar 7, 2023
bluwy
bluwy previously approved these changes Mar 7, 2023
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Nice!

@patak-dev
Copy link
Member

Hey @sun0day! We discussed the PR in today's team meeting at the end we decided that the best approach is to export all types as a namespace, export * as Rollup from 'rollup'; in Vite's index.d.ts

The rationale is that it avoids the need for a new exported path (that as we saw, it wasn't easy to define), and it isn't bad that the imported types would end up being more explicit Rollup.

We would also like to export other deps types in the same way (for example the ones for Chokidar), and in a future major remove the flat exports we have for them. The types for Terser require extra attention as we are no longer bundling them, but we should be able to do the same. And we also discussed exposing Esbuild types but the consensus there was to wait until we have a feature request for them with a real use case.

I think we don't need to rename dep-types to bundled-types now either (it sounds like a better name for me but there isn't enough justification for the change now). Let us know if you would like to work on this PR, or we can take it over if not. Thanks for your patience with these changes!

@sun0day
Copy link
Member Author

sun0day commented Mar 9, 2023

That's ok. I'd love to continue working on this pr. So I just need to add export * as Rollup from 'rollup'; in Vite's index.d.ts in this PR ? Or maybe you can offer me a list of dep-types to export as namespaces for now?

@patak-dev
Copy link
Member

patak-dev commented Mar 9, 2023

I think we could do this in several PRs.

  • One to expose Rollup, that could be this one.

  • Then another one to expose as a namespace the types of the bundled deps we have exposed as flat named exports. So here:

// dep types
export type {
  AliasOptions,
  MapToFunction,
  ResolverFunction,
  ResolverObject,
  Alias,
} from 'dep-types/alias'
export type { Connect } from 'dep-types/connect'
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
export type { HttpProxy } from 'dep-types/http-proxy'
export type {
  FSWatcher,
  WatchOptions,
  AwaitWriteFinishOptions,
} from 'dep-types/chokidar'
export type { Terser } from 'dep-types/terser'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'

It looks like Connect, HttpProxy, and Terser are already using a namespace.

We would need to do the same for WS, Chokidar, RollupCommonJS, RollupDynamicImportVars (we can discuss if we should add Plugin in the name or not)

I'm not sure about Anymatch (we are renaming Matcher in it), and Alias should be RollupAlias.* I think. cc @bluwy

  • Later on a PR to remove the named exports.

@sun0day
Copy link
Member Author

sun0day commented Mar 9, 2023

Cool. I'd love to work on these 3 PRs.

@sun0day sun0day changed the title chore: export rollup types from dep-types (fix #12270) chore: export Rollup namespace Mar 10, 2023
@@ -1,3 +1,6 @@
import type * as Rollup from 'rollup'
Copy link
Member Author

Choose a reason for hiding this comment

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

api-extractor hasn't support export * as ... syntax, so use import type * as ... instead.

@bluwy bluwy changed the title chore: export Rollup namespace feat(types): export Rollup namespace Mar 11, 2023
@patak-dev patak-dev merged commit 6e49e52 into vitejs:main Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Typescript: Missing all Rollup types
3 participants