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

refactor(cli): make the CLI an even thinner wrapper around command functions #7583

Merged
merged 2 commits into from
Jun 15, 2022

Conversation

Josh-Cena
Copy link
Collaborator

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

The reason is because the commander functions are very weakly typed: basically action(fn: (...args: any[]) => void | Promise<void>). This makes TS-ESLint whine about unsafe arguments when we pass these any into our actual function, even when it's actually safe.

This also means people who try to use these functions on Node side do not immediately get feature parity with the CLI: they have to resolve site directory, they have to apply default values (see also #7220), they have to even change the order of parameters.

We should just handle these ourselves. The CLI is just a very thin wrapper that automatically invokes these functions. Now users can do await docusaurus.build(); without passing any arguments.

Test Plan

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

@Josh-Cena Josh-Cena added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Jun 8, 2022
@Josh-Cena Josh-Cena requested review from slorber and lex111 as code owners June 8, 2022 07:43
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 8, 2022
@netlify
Copy link

netlify bot commented Jun 8, 2022

[V2]

Name Link
🔨 Latest commit a16cf8b
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/62a4b36dd998c80008b39966
😎 Deploy Preview https://deploy-preview-7583--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Jun 8, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 85 🟢 100 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 84 🟢 100 🟢 100 🟢 100 🟢 90 Report

@github-actions
Copy link

github-actions bot commented Jun 8, 2022

Size Change: +79 B (0%)

Total Size: 801 kB

Filename Size Change
website/build/assets/js/main.********.js 603 kB +79 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 52.6 kB
website/build/assets/css/styles.********.css 106 kB
website/build/index.html 38.9 kB

compressed-size-action

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 👍

siteDir: string,
): Promise<void> {
export async function externalCommand(cli: CommanderStatic): Promise<void> {
const siteDir = await fs.realpath('.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 that looks different from the other cli commands 🤪

But same as before so maybe a different issue

@slorber slorber merged commit 0114f00 into main Jun 15, 2022
@slorber slorber deleted the jc/thin-cli branch June 15, 2022 17:28
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.

3 participants