Skip to content

refactor: improve setup of type declaration files #5914

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

Merged
merged 5 commits into from
Nov 12, 2021
Merged

Conversation

Josh-Cena
Copy link
Collaborator

Motivation

There are three types of declaration files:

  • <name>.d.ts, which contains the exported types used with import xxx from '@docusaurus/<name>' or /// <reference types="@docusaurus/<name>" /> (I think it actually makes sense to further separate them, but not right now);
  • types.d.ts, types that should be globally available within the package (yet aren't exported). Commonly includes the module aliases, but in the future we can merge the types.ts idiom in here so we don't have the cluttering of import xxx from './types' everywhere
  • deps.d.ts, types for missing dependency types, may be gradually removed in the future when types are available / we move to other deps

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Build & typecheck

Verified

This commit was signed with the committer’s verified signature.
Josh-Cena Joshua Chen

Verified

This commit was signed with the committer’s verified signature.
Josh-Cena Joshua Chen
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 9, 2021
@Josh-Cena Josh-Cena added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Nov 9, 2021
@netlify
Copy link

netlify bot commented Nov 9, 2021

✔️ [V2]

🔨 Explore the source changes: f3a4c62

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/618b12dc2b3e190007abcb80

😎 Browse the preview: https://deploy-preview-5914--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Nov 9, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 74
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-5914--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Nov 9, 2021

Size Change: -185 B (0%)

Total Size: 881 kB

Filename Size Change
website/build/assets/js/main.********.js 474 kB -184 B (0%)
ℹ️ View Unchanged
Filename Size Change
website/.docusaurus/globalData.json 38.2 kB 0 B
website/build/assets/css/styles.********.css 94 kB 0 B
website/build/blog/2017/12/14/introducing-docusaurus/index.html 66.1 kB 0 B
website/build/blog/index.html 36.8 kB 0 B
website/build/docs/index.html 44 kB +1 B (0%)
website/build/docs/installation/index.html 51.5 kB -2 B (0%)
website/build/index.html 29.5 kB 0 B
website/build/tests/docs/index.html 25.2 kB 0 B
website/build/tests/docs/standalone/index.html 21.7 kB 0 B

compressed-size-action

}

// TODO public api surface types should rather be exposed as "@docusaurus/plugin-content-docs"
declare module '@docusaurus/plugin-content-docs-types' {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if merging '@docusaurus/plugin-content-docs-types' with '@docusaurus/plugin-content-docs' has deeper implications (e.g. implying that these types are public API while they can be breaking), but IMO type-related changes are never breaking changes as they can be easily ignored and TS-users are generally more aware of tech-related stuff anyways

Copy link
Collaborator

Choose a reason for hiding this comment

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

That should be fine, as we don't document this '@docusaurus/plugin-content-docs-types' anywhere afaik.

(but otherwise TS changes are to be considered as breaking changes too)

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM and looks cleaner 👍

Was wondering if you can find a way to preserve the Git history of packages/docusaurus-theme-classic/src/types.d.ts ?

It's a large file with some useful history context and Git currently understands it as a del+add instead of a move

}

// TODO public api surface types should rather be exposed as "@docusaurus/plugin-content-docs"
declare module '@docusaurus/plugin-content-docs-types' {
Copy link
Collaborator

Choose a reason for hiding this comment

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

That should be fine, as we don't document this '@docusaurus/plugin-content-docs-types' anywhere afaik.

(but otherwise TS changes are to be considered as breaking changes too)

@Josh-Cena
Copy link
Collaborator Author

I don't know why GH doesn't resolve the diff🧐

Beware though that even if it's resolved as a rename / mv, after merging git will treat it as a new file. e.g. https://github.com/facebook/docusaurus/blob/main/packages/create-docusaurus/templates/classic-typescript/src/components/HomepageFeatures.tsx only has one contributor because it was renamed

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

LGTM 👍 not sure how to preserve the history as it's not even a real file move but a partial move of inner content.

@slorber slorber merged commit d1308a8 into main Nov 12, 2021
@slorber slorber deleted the jc/types-refactor branch November 12, 2021 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants