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

Monorepo plugin #630

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8b8c418
feat: load workspace package tool kit configs
apaleslimghost Nov 8, 2024
33ab433
feat: run workspace commands in parallel
apaleslimghost Apr 24, 2024
23e33aa
refactor: use map instead of a for loop for runPackageCommand calls
apaleslimghost Apr 24, 2024
7328ff0
feat: allow overriding which command to run in the workspace via a ta…
apaleslimghost Apr 24, 2024
875f6bd
build: don't throw in generate-docs when no readme
apaleslimghost May 9, 2024
e617775
build: inherit volta config from root
apaleslimghost Jul 25, 2024
9dcf9c8
backstage: update monorepo plugin dependency versions
apaleslimghost Nov 4, 2024
d109a1c
docs(monorepo): add readme
apaleslimghost Nov 4, 2024
98fb745
docs(monorepo): add high-level workflow explanation
apaleslimghost Nov 4, 2024
7fb683d
docs(monorepo): document plugin vs `npm run --workspaces` considerations
apaleslimghost Nov 4, 2024
de8ed39
build: compile the monorepo plugin
apaleslimghost Nov 7, 2024
170f67f
feat(monorepo): add a packageFilter option
apaleslimghost Nov 18, 2024
681a250
docs: automatically regenerate schema docs
apaleslimghost Nov 18, 2024
27dbe2a
feat: use an AggregateError for workspace package command errors
apaleslimghost Nov 26, 2024
0dbd7ea
feat: pass cwd into init
apaleslimghost Nov 27, 2024
891ae01
fix: run init before printing help
apaleslimghost Nov 27, 2024
6315513
refactor: load workspace configs at init not task run
apaleslimghost Nov 27, 2024
ea7936e
feat: only attempt to run workspace command in packages that have it,…
apaleslimghost Nov 27, 2024
1072966
feat: print workspace package name in task run errors
apaleslimghost Nov 27, 2024
b8225b2
test: add basic test for LoadWorkspaceConfigs
apaleslimghost Dec 2, 2024
57fea91
test: add tests for LoadWorkspaceConfigs failure behaviour
apaleslimghost Dec 2, 2024
fdc19ef
fix(typescript): resolve tsc path from cwd
apaleslimghost Dec 2, 2024
81ebda7
fix: prevent running nodemon in non-root directories
apaleslimghost Dec 2, 2024
50b1606
test(monorepo): strip ansi in snapshots
apaleslimghost Dec 2, 2024
3aacc49
test: relative paths in snapshots (again)
apaleslimghost Dec 2, 2024
4d706d1
backstage: update package-lock.json
apaleslimghost Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/cli/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import YAML from 'yaml'
import $t from 'endent'
import { CommandTask, OptionsForTask } from '@dotcom-tool-kit/plugin'
import { ValidConfig } from '@dotcom-tool-kit/config'
import { runInit } from './init'

const toolKitIntro = s.box(
$t`
Expand Down Expand Up @@ -84,6 +85,8 @@ export default async function showHelp(logger: Logger, commands: string[]): Prom
commands = Object.keys(config.commandTasks).sort()
}

await runInit(logger, config)

logger.info(toolKitIntro)

const definedCommands = commands.filter((command) => config.commandTasks[command])
Expand Down
4 changes: 3 additions & 1 deletion core/cli/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export async function runInit(logger: Logger, config: ValidConfig): Promise<void
const initResults = await loadInitEntrypoints(logger, config)
const inits = initResults.unwrap('plugin initialisation classes were invalid!')

await Promise.all(inits.map(async (init) => init.init()))
await Promise.all(inits.map(async (init) => init.init({
cwd: config.root
})))
}
6 changes: 5 additions & 1 deletion lib/base/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { Logger } from 'winston'
import { initSymbol, typeSymbol } from './symbols'
import { Base } from './base'

export type InitContext = {
cwd: string
}

export abstract class Init extends Base {
logger: Logger

Expand All @@ -18,7 +22,7 @@ export abstract class Init extends Base {
return initSymbol
}

abstract init(): Promise<void>
abstract init(context: InitContext): Promise<void>
}

export type InitConstructor = {
Expand Down
4 changes: 3 additions & 1 deletion lib/schemas/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SmokeTestSchema } from './tasks/n-test'
import { CypressSchema } from './tasks/cypress'
import { HerokuProductionSchema } from './tasks/heroku-production'
import { ServerlessRunSchema } from './tasks/serverless-run'
import { WorkspaceCommandSchema } from './tasks/workspace-command'
import { z } from 'zod'

export const TaskSchemas = {
Expand All @@ -39,7 +40,8 @@ export const TaskSchemas = {
ServerlessTeardown: z.object({}).describe('Tear down existing serverless functions'),
TypeScript: TypeScriptSchema,
UploadAssetsToS3: UploadAssetsToS3Schema,
Webpack: WebpackSchema
Webpack: WebpackSchema,
WorkspaceCommand: WorkspaceCommandSchema
}

export type TaskOptions = InferSchemaOptions<typeof TaskSchemas>
65 changes: 65 additions & 0 deletions lib/schemas/src/tasks/workspace-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { z } from 'zod'

export const WorkspaceCommandSchema = z.object({
command: z.string().optional().describe('A specific command to run instead of the command that ran this task.'),
packageFilter: z.string().optional().describe('By default, the command will run in every workspace command that has that command assigned to a task. This option is a glob pattern to filter the packages the command will run on. For example, if your workspace has packages in the `plugins` and `lib` folders, set `packageFilter` to `plugins/*` to only run only in the packages in `plugins`.'),
}).describe(`Runs a Tool Kit command in all workspace packages that have that command. By default, runs the command that was used to run this task.

For example, imagine a monorepo with these \`.toolkitrc.yml\` files:

<details><summary><code>.toolkitrc.yml</code></summary>

~~~yml
commands:
run:local: WorkspaceCommand
build:local: WorkspaceCommand
~~~

</details>

<details><summary><code>packages/api/.toolkitrc.yml</code></summary>

~~~yml
commands:
run:local: Node
~~~

</details>

<details><summary><code>packages/client/.toolkitrc.yml</code></summary>

~~~yml
commands:
build:local: TypeScript
~~~

</details>

<details><summary><code>packages/components/.toolkitrc.yml</code></summary>

~~~yml
commands:
build:local: Webpack
run:local:
Webpack:
watch: true
~~~

</details>

Running \`dotcom-tool-kit run:local\` at the root level will run the \`Node\` task in \`packages/api\` and the \`Webpack\` task in watch mode in \`packages/components\`; running \`dotcom-tool-kit build:local\` will run \`TypeScript\` in \`packages/client\` and \`Webpack\` in \`packages/components\`.

To run a particular command in the workspace instead of dynamically inferring the command from which was run at root level, set the \`command\` option for the task:

~~~yml
commands:
build:ci:
WorkspaceCommand:
command: build:local
~~~

`)

export type WorkspaceCommandOptions = z.infer<typeof WorkspaceCommandSchema>

export const Schema = WorkspaceCommandSchema
Loading
Loading