Skip to content

Commit

Permalink
馃┕ fix: register command type error after extension uninstall (#2372)
Browse files Browse the repository at this point in the history
Fixes type error after uninstalling extension which registers commands.

Without this change users would need to run `yarn bud clean storage` in order to clean out the stale entry.

## Type of change

**PATCH: backwards compatible change**
  • Loading branch information
kellymears committed Jul 12, 2023
1 parent 813a336 commit 6e124e8
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class BudEslintCommand extends BudCommand {
public static override paths = [[`lint`, `js`], [`eslint`]]

public static override usage = BudCommand.Usage({
category: `tools`,
category: `tool`,
description: `eslint CLI passthrough`,
examples: [[`View eslint usage information`, `$0 eslint --help`]],
examples: [[`Run eslint on source files`, `$0 eslint`]],
})

public options = Option.Proxy({name: `eslint passthrough options`})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {dry} from '@roots/bud/cli/decorators/dry'
export class BudPrettierCommand extends BudCommand {
public static override paths = [[`format`], [`prettier`]]
public static override usage = Command.Usage({
category: `tools`,
category: `tool`,
description: `Prettier CLI`,
examples: [[`View prettier usage information`, `$0 prettier --help`]],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ export class BudStylelintCommand extends BudCommand {
* {@link BudCommand.usage}
*/
public static override usage = Command.Usage({
category: `tools`,
category: `tool`,
description: `stylelint CLI passthrough`,
examples: [
[`Run stylelint on source files`, `$0 lint css`],
[`View stylelint usage information`, `$0 lint css --help`],
],
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BudTailwindCommand extends BudCommand {
public static override paths = [[`tailwindcss`], [`tw`]]

public static override usage = BudCommand.Usage({
category: `tools`,
category: `tool`,
description: `tailwindcss CLI passthrough`,
examples: [
[`View tailwindcss usage information`, `$0 tailwindcss --help`],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BudTSCheckCommand extends BudCommand {
public static override paths = [[`ts`, `check`]]

public static override usage = BudCommand.Usage({
category: `tools`,
category: `tool`,
description: `Typecheck source code`,
details: `
This command runs the \`tsc\` command with the \`--noEmit\` flag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BudTSCCommand extends BudCommand {
public static override paths = [[`tsc`]]

public static override usage = Command.Usage({
category: `tools`,
category: `tool`,
description: `TypeScript CLI passthrough`,
examples: [[`View tsc usage information`, `$0 tsc --help`]],
})
Expand Down
26 changes: 13 additions & 13 deletions sources/@roots/bud/src/cli/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Error} from '@roots/bud-dashboard/components/error'
import {Builtins, Cli} from '@roots/bud-support/clipanion'
import {BudError} from '@roots/bud-support/errors'
import {render} from '@roots/bud-support/ink'
import isFunction from '@roots/bud-support/lodash/isFunction'
import * as args from '@roots/bud-support/utilities/args'
import BudCommand from '@roots/bud/cli/commands/bud'
import BudBuildCommand from '@roots/bud/cli/commands/bud.build'
Expand Down Expand Up @@ -60,19 +61,18 @@ application = new Cli({

commands.map(command => application.register(command))

await Commands.get(application, context)
.getCommands()
.then(Commands.importCommandsFromPaths)
.then(
async registrar =>
await Promise.all(
registrar.map(
async (registerCommand: (application: Cli) => Promise<any>) =>
await registerCommand(application).catch(onError),
),
),
)
.catch(onError)
const finder = new Commands(context, application)
await finder.init()
const extensions = await finder.importCommands()

await Promise.all(
extensions.map(
async (registerCommand: (application: Cli) => Promise<any>) => {
if (!isFunction(registerCommand)) return
await registerCommand(application).catch(onError)
},
),
)

application.runExit(args.raw, context).catch(onError)

Expand Down
19 changes: 4 additions & 15 deletions sources/@roots/bud/src/cli/commands/bud.build.development.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,12 @@ export default class BuildDevelopmentCommand extends BuildCommand {
*/
public static override usage = BuildCommand.Usage({
category: `build`,
description: `Compiles source assets in \`development\` mode.`,
details: `\
\`bud build development\` compiles source assets in \`development\` mode.
`,
description: `Compile source assets in \`development\` mode.`,
details: `Compile source assets in \`development\` mode.`,
examples: [
[`compile source and serve`, `$0 build development`],
[
`open project in system default browser`,
`$0 build development --browser`,
],
[
`do not force reload in the browser when encountering a fatal HMR error`,
`$0 build development --no-reload`,
],
[
`do not display an error overlay when encountering errors in application code`,
`$0 build development --no-overlay`,
`Compile source assets in \`development\` mode.`,
`$0 build development`,
],
],
})
Expand Down
1 change: 0 additions & 1 deletion sources/@roots/bud/src/cli/commands/bud.build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export default class BudBuildCommand extends BudCommand {
If you run this command without a configuration file \`bud\` will look for an entrypoint at \`@src/index.js\`.
`,
examples: [[`compile source assets`, `$0 build`]],
})

public [`cache`] = cache
Expand Down
11 changes: 7 additions & 4 deletions sources/@roots/bud/src/cli/commands/bud.clean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class BudCleanCommand extends BudCommand {
public static override paths = [[`clean`]]

public static override usage = Command.Usage({
category: `tasks`,
category: `task`,
description: `Clean project artifacts and caches`,
details: `
\`bud clean\` empties the \`@dist\` and \`@storage\` directories.
Expand All @@ -23,9 +23,9 @@ export default class BudCleanCommand extends BudCommand {
\`bud clean cache\` empties the \`@storage/cache\` directory.
`,
examples: [
[`Clean artifacts/caches`, `$0 clean`],
[`Clean dist`, `$0 clean @dist`],
[`Clean storage`, `$0 clean @storage`],
[`Clean all`, `$0 clean`],
[`Clean dist`, `$0 clean output`],
[`Clean storage`, `$0 clean storage`],
],
})

Expand All @@ -41,6 +41,9 @@ export default class BudCleanCommand extends BudCommand {
description: `empty @storage`,
})

@bind
public override async catch(error: Error) {}

@bind
public async cleanCache() {
if (this.bud.hasChildren) {
Expand Down
23 changes: 20 additions & 3 deletions sources/@roots/bud/src/cli/commands/bud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,28 @@ export default class BudCommand extends Command<CLIContext> {
public static override usage = Command.Usage({
description: `Run \`bud --help\` for usage information`,
details: `\
\`bud build production\` compiles source assets in \`production\` mode. Run \`bud build production --help\` for usage.
Documentation for this command is available at https://bud.js.org/.
\`bud build development\` compiles source assets in \`development\` mode and serves updated modules. Run \`bud build development --help\` for usage.
Any flags which accept a boolean can be negated with the \`--no-\` prefix. For example, \`--no-color\` will disable color output.
Any command can be exited with \`esc\` or \`ctrl+c\`.
Run this command with no arguments for an interactive menu of available subcommands.
Common tasks:
- \`bud build production\` compiles source assets in \`production\` mode.
- \`bud build development\` compiles source assets in \`development\` mode and updates modules in the browser.
- \`bud doctor\` checks your system and project for common configuration issues. Try this before making an issue in the bud.js repo.
Helpful flags:
- \`--help\` can be appened to any command for usage information.
- \`--basedir\` sets the working directory for bud and will be treated as project root.
- \`--storage\` sets the storage directory. Defaults to the system tmp dir.
- \`--log\` enables logging. Use \`--log\` in tandem with \`--verbose\` for more detailed output.
- \`--debug\` enables debug mode. It is very noisy in the terminal but also produces useful output files in the storage directory.
`,
examples: [[`compile source assets`, `$0 build`]],
})

public basedir = basedir
Expand Down
9 changes: 2 additions & 7 deletions sources/@roots/bud/src/cli/commands/bud.upgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class BudUpgradeCommand extends BudCommand {
* {@link Command.usage}
*/
public static override usage = Command.Usage({
category: `tasks`,
category: `task`,
description: `Set bud.js version`,
details: `
This command will upgrade your bud.js installation to the latest stable version.
Expand All @@ -34,12 +34,7 @@ export default class BudUpgradeCommand extends BudCommand {
This command is a passthrough to the package manager you are using.
`,
examples: [
[`Upgrade dependencies to latest`, `$0 upgrade`],
[`Upgrade dependencies to specific version`, `$0 upgrade 6.6.6`],
[
`Upgrade through a private registry`,
`$0 upgrade --registry http://localhost:4873`,
],
[`Upgrade all bud dependencies to latest version`, `$0 upgrade`],
],
})

Expand Down
8 changes: 3 additions & 5 deletions sources/@roots/bud/src/cli/commands/bud.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ export default class BudViewCommand extends BudCommand {
public static override paths = [[`view`]]

public static override usage = Command.Usage({
category: `debug`,
description: `Explore bud object`,
examples: [
[`view compiled config`, `$0 view`],
[`view`, `$0 view env store`],
],
examples: [[`view compiled config`, `$0 view build.config`]],
})

public indent = indent
Expand Down Expand Up @@ -47,7 +45,7 @@ export default class BudViewCommand extends BudCommand {
if (this.color) value = highlight(value)

BudViewCommand.renderStatic(
<Box>
<Box flexDirection="column">
<Text color="magenta">{this.subject ?? `build.config`}</Text>
<Text>{` `}</Text>
<Text>{value}</Text>
Expand Down
4 changes: 2 additions & 2 deletions sources/@roots/bud/src/cli/commands/bud.webpack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export default class BudWebpackCommand extends BudCommand {
* {@link Command.usage}
*/
public static override usage = Command.Usage({
category: `tools`,
category: `tool`,
description: `Webpack CLI passthrough`,
examples: [[`View webpack usage information`, `$0 webpack --help`]],
examples: [[`Run webpack`, `$0 webpack`]],
})

public options = Option.Proxy({name: `webpack passthrough options`})
Expand Down
3 changes: 2 additions & 1 deletion sources/@roots/bud/src/cli/commands/doctor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class DoctorCommand extends BudCommand {
public static override paths = [[`doctor`]]

public static override usage = Command.Usage({
category: `debug`,
description: `Check project for common errors`,
details: `\
The \`bud doctor\` command will:
Expand All @@ -39,7 +40,7 @@ In general, \`bud.js\` dependencies should be kept at the same version. This scr
for a lot of edge cases so it might return a false positive.
`,
examples: [
[`Check compiled configuration against webpack`, `$0 doctor`],
[`Check project for common configuration issues`, `$0 doctor`],
],
})

Expand Down
1 change: 1 addition & 0 deletions sources/@roots/bud/src/cli/commands/repl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class BudReplCommand extends BudCommand {
* {@link BudCommand.usage}
*/
public static override usage = Command.Usage({
category: `debug`,
description: `Use bud in a repl`,
examples: [[`repl`, `$0 repl`]],
})
Expand Down
Loading

0 comments on commit 6e124e8

Please sign in to comment.