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 @percy/cli to use @percy/cli-command #676

Merged
merged 2 commits into from
Dec 16, 2021
Merged

Conversation

wwilsman
Copy link
Contributor

What is this?

This PR refactors @percy/cli to use the new @percy/cli-command foundation.

Historically, this package was used as the entry point to Percy CLI and its various commands through oclif plugins, which are defined by the package.json file's oclif entry. To support autoloading of plugins found within a project's dependencies, this package was adapted to modify its own package.json at load time before oclif reads it.

This alleviated requiring oclif's plugins plugin to manually install plugins and allowed us to rely on Node's normal module resolution. However, in part due to oclif's plugin loading, and in part due to our own plugin discovery, the CLI only worked with Node's native module loading (and not plug-n-play environments).

With the new @percy/cli-command as a foundation, oclif can be peeled away to give us complete control over plugin loading. This is done by using a function as the commands definition argument which when called will search for plugins within the projects dependencies as well as this packages own and sibling dependencies.

For environments with a native module loading, it will walk through top-level directories within node_modules (and recurse into the @percy scope). For Yarn 2+, it will use the PnP API to find declared package dependencies. Matching CLI plugins will be named either @percy/cli- or percy-cli- and contain a package.json entry for @percy/cli. And for legacy Percy oclif plugins, command classes are found and transformed into functional commands using the legacyCommand function from @percy/cli-command.

@wwilsman wwilsman added the ✨ enhancement New feature or request label Dec 15, 2021
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

🏁

With the new @percy/cli-command as a foundation, oclif can be peeled away to give us complete control over plugin loading

Ahh, this is pretty nice. So long, friend.

import os from 'os';
import fs from 'fs';
import path from 'path';
import { findPnpApi } from 'module';
Copy link
Contributor

Choose a reason for hiding this comment

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

lol yarn2

@wwilsman wwilsman merged commit 5464cc6 into master Dec 16, 2021
@wwilsman wwilsman deleted the ww/noclif-cli branch December 16, 2021 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants