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

Draft
wants to merge 7 commits into
base: split-config-loading
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 12 additions & 4 deletions core/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,22 @@ export function validateConfig(config: ValidPluginsConfig): ValidConfig {
return validConfig
}

export function loadConfig(logger: Logger, options?: { validate?: true }): Promise<ValidConfig>
export function loadConfig(logger: Logger, options?: { validate?: false }): Promise<RawConfig>
export function loadConfig(logger: Logger, options?: { validate?: true; root?: string }): Promise<ValidConfig>
export function loadConfig(logger: Logger, options?: { validate?: false; root?: string }): Promise<RawConfig>

export async function loadConfig(logger: Logger, { validate = true } = {}): Promise<ValidConfig | RawConfig> {
export async function loadConfig(
logger: Logger,
{ validate = true, root }: { validate?: boolean; root?: string } = {}
): Promise<ValidConfig | RawConfig> {
const config = createConfig()

// start loading config and child plugins, starting from the consumer app directory
const rootPlugin = await loadPlugin('app root', config, logger)
const rootPlugin = await loadPlugin(
'app root',
config,
logger,
root ? { id: 'workspace root', root } : undefined
)
const validRootPlugin = rootPlugin.unwrap('root plugin was not valid!')

const validatedPluginConfig = validatePlugins(config)
Expand Down
2 changes: 1 addition & 1 deletion core/cli/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function runTasksFromConfig(logger: Logger, config: ValidConfig, co
for (const task of tasks) {
try {
logger.info(styles.taskHeader(`running ${styles.task(task.id)} task`))
await task.run({ files })
await task.run({ files, command })
} catch (error) {
// TODO use validated for this
// allow subsequent command tasks to run on error
Expand Down
1 change: 1 addition & 0 deletions lib/base/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Default<T, D> = T extends undefined ? D : T

export type TaskRunContext = {
files?: string[]
command: string
}

export abstract class Task<
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 @@ -14,6 +14,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 @@ -40,7 +41,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>
9 changes: 9 additions & 0 deletions lib/schemas/src/tasks/workspace-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { z } from 'zod'

export const WorkspaceCommandSchema = z.object({
command: z.string().optional()
})

export type WorkspaceCommandOptions = z.infer<typeof WorkspaceCommandSchema>

export const Schema = WorkspaceCommandSchema
Loading