-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Workspace commands + passthrough (#591)
**Problem:** Looking at #554 and #555, there are too many unknowns with passing through to commands like vite and astro (and webpack, next, etc, for that matter). It doesn't seem sustainable to attempt to curate plugins to every single npx command available. Nor does it seem helpful for users of oneRepo to leave them to need to write the entire passthrough on their own. **Solution:** Passthrough commands. Discussion in #590 **Related issues:** Fixes #554 Fixes #555 **Checklist:** - [x] Added or updated tests - [x] Added or updated documentation - [x] Ensured the pre-commit hooks ran successfully
- Loading branch information
1 parent
5ee9c67
commit b797bba
Showing
33 changed files
with
657 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
'onerepo': minor | ||
--- | ||
|
||
Workspace-specific commands will require `workspace` or `ws` before the workspace name when running. | ||
|
||
**Before:** | ||
|
||
```sh | ||
one docs start | ||
``` | ||
|
||
**After:** | ||
|
||
```sh | ||
one workspace docs start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'onerepo': minor | ||
--- | ||
|
||
Added `passthrough` command ability to Workspace configurations. Use with caution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import type { Config } from 'onerepo'; | ||
|
||
export default { | ||
commands: { | ||
passthrough: { | ||
start: { description: 'Start the Astro dev server.', command: 'astro dev --host' }, | ||
build: { description: 'Build the documentation site for production.', command: 'astro build' }, | ||
check: { description: 'Check Astro pages for errors.', command: 'astro check' }, | ||
astro: { description: 'Run Astro directly.' }, | ||
}, | ||
}, | ||
tasks: { | ||
'pre-commit': { | ||
serial: [ | ||
{ match: '**/*.{astro}', cmd: '$0 ws docs astro -- check' }, | ||
{ match: '**/*.{astro}', cmd: '$0 ws docs check' }, | ||
{ match: '../modules/**/*.ts', cmd: '$0 ws docs typedoc --add' }, | ||
{ match: '../**/*', cmd: '$0 ws docs collect-content -w ${workspaces} --add' }, | ||
{ match: '../**/CHANGELOG.md', cmd: '$0 ws docs pull-changelogs --add' }, | ||
], | ||
}, | ||
'pre-merge': { | ||
serial: [{ match: '**/*.{astro}', cmd: '$0 ws docs astro -- check' }], | ||
serial: [{ match: '**/*.{astro}', cmd: '$0 ws docs check' }], | ||
}, | ||
build: { | ||
serial: ['$0 ws docs astro -- build'], | ||
serial: ['$0 ws docs build'], | ||
}, | ||
}, | ||
} satisfies Config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
title: Workspace commands | ||
description: Run commands in Workspaces. | ||
meta: | ||
stability: stable | ||
--- | ||
|
||
import FileTree from '../../../components/FileTree.astro'; | ||
|
||
Your monorepo's Workspaces may end up having unique needs that differ from other Workspaces. When this occurs, you may want to have commands that are specific to an individual Workspace. There are two ways to configure oneRepo to enable Workspace-specific commands. | ||
|
||
## Custom commands | ||
|
||
Workspaces can have custom commands that work identically to commands at the root of your repository. The [`RootConfig.commands.directory`](/docs/config/#commandsdirectory) configuration value enables a directory within _each_ Workspace of your application, if present, to contain command files that will automatically be included in the `one` CLI when invoked. | ||
|
||
By default, the `commands.directory` is set to `'commands'`. | ||
|
||
```ts title="onerepo.config.ts" | ||
import type { Config } from 'onerepo'; | ||
|
||
export default { | ||
commands: { | ||
directory: 'commands', | ||
}, | ||
} satisfies Config; | ||
``` | ||
|
||
This setting will automatically enable each Workspace to add command files: | ||
|
||
<FileTree> | ||
|
||
- apps | ||
- public-app | ||
- commands/ | ||
- start.ts # one ws public-app start | ||
- build.ts | ||
- private-app | ||
- commands/ | ||
- start.ts # one ws private-app start | ||
- build.ts | ||
|
||
</FileTree> | ||
|
||
And in turn, our custom commands will be exposed on the `one workspace` (or `one ws` alias, for short) command: | ||
|
||
```sh title="Run public-app commands." | ||
# Run the `start` command | ||
one workspace public-app start | ||
|
||
# Run the `build` command | ||
one workspace public-app build | ||
``` | ||
|
||
```sh title="Build private-app commands." | ||
one workspace private-app build | ||
# ↑ Equivalent to ↓ | ||
one ws private-app build | ||
``` | ||
|
||
Read the [writing commands documentation](/docs/commands/) for a tutorial and in-depth information on the structure, shape, and strategies for commands. | ||
|
||
## Passthrough commands | ||
|
||
Alternatively, for quick access to third-party commands that don't require extra configuration, we can configure _passthrough_ commands in Workspace configuration files: | ||
|
||
```ts title="apps/public-app/onerepo.config.ts" | ||
export default { | ||
commands: { | ||
passthrough: { | ||
start: { command: 'astro dev', description: 'Start the Astro dev server.' }, | ||
build: { command: 'astro build', description: 'Build the app using Astro.' }, | ||
}, | ||
}, | ||
} satisfies WorkspaceConfig; | ||
``` | ||
|
||
Some third-party spackages expose executables for running servers and quick helpers that use configuration files instead of command-line flags, like [Astro](https://astro.build) and [Vite](https://vitejs.dev). These types of commands are great candidates for passthroughs. | ||
|
||
:::danger | ||
This configuration is a shortcut for quick one-offs with little to no extra options necessary. Avoid over-using this configuration to avoid [script overload](/concepts/why-onerepo/#script-overload) pitfalls. | ||
::: | ||
|
||
By enabling the passthrough using the above configuration for `public-app`, we add two commands to the Workspace: `start` and `build` and can be called with either form of the `workspace` command using `one workspace …` or the alias `one ws …`: | ||
|
||
```sh title="Run the Astro dev server." | ||
one workspace public-app start | ||
# ↑ Equivalent to ↓ | ||
one ws public-app start | ||
``` | ||
|
||
```sh title="Build the app using Astro." | ||
one workspace public-app build | ||
# ↑ Equivalent to ↓ | ||
one ws public-app build | ||
``` | ||
|
||
If you need a little bit more and want to pass arguments through to the underlying command (in this case `astro …`), include any extra argument flags after the CLI parser stop point (`--`): | ||
|
||
```sh title="Pass arguments to Astro" | ||
one workspace public app start -- --port=8000 --open | ||
``` | ||
|
||
## Command usage | ||
|
||
{/* start-auto-generated-from-cli-workspace */} | ||
{/* @generated SignedSource<<88b5edb9556a0953b6fc2f856d4b6c5d>> */} | ||
|
||
### `one workspace` | ||
|
||
Aliases: `one ws` | ||
|
||
Run commands within individual Workspaces. | ||
|
||
```sh | ||
one workspace <workspace-name> <command...> [options...] -- [passthrough...] | ||
``` | ||
|
||
This enables running both custom commands as defined via the `commands.directory` configuration option within each Workspace as well as `commands.passthrough` aliases. | ||
|
||
Arguments for passthrough commands meant for the underlying command must be sent after `--`. | ||
|
||
| Positional | Type | Description | | ||
| ---------------- | -------- | --------------------------------- | | ||
| `command` | `string` | Command to run. | | ||
| `workspace-name` | `string` | The name or alias of a Workspace. | | ||
|
||
{/* end-auto-generated-from-cli-workspace */} |
Oops, something went wrong.