From d2b50264dcd3b030bab63f9cee69434b03d4f466 Mon Sep 17 00:00:00 2001 From: Kara Brightwell Date: Mon, 4 Nov 2024 12:22:27 +0000 Subject: [PATCH] fix: pass task cwd through via TaskRunContext --- core/cli/src/tasks.ts | 2 +- lib/base/src/task.ts | 1 + plugins/monorepo/src/tasks/workspace-command.ts | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/cli/src/tasks.ts b/core/cli/src/tasks.ts index 0ee445d08..d2043dbf0 100644 --- a/core/cli/src/tasks.ts +++ b/core/cli/src/tasks.ts @@ -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, command }) + await task.run({ files, command, cwd: config.root }) } catch (error) { // if there's an exit code, that's a request from the task to exit early if (error instanceof ToolKitError && error.exitCode) { diff --git a/lib/base/src/task.ts b/lib/base/src/task.ts index 45117b928..320df44ee 100644 --- a/lib/base/src/task.ts +++ b/lib/base/src/task.ts @@ -8,6 +8,7 @@ type Default = T extends undefined ? D : T export type TaskRunContext = { files?: string[] command: string + cwd: string } export abstract class Task< diff --git a/plugins/monorepo/src/tasks/workspace-command.ts b/plugins/monorepo/src/tasks/workspace-command.ts index 026975332..38d8ebc4c 100644 --- a/plugins/monorepo/src/tasks/workspace-command.ts +++ b/plugins/monorepo/src/tasks/workspace-command.ts @@ -14,8 +14,7 @@ export default class WorkspaceCommand extends Task<{ task: typeof WorkspaceComma return runTasksFromConfig(this.logger.child({ packageId }), config, [command], files) } - async run({ command, files }: TaskRunContext) { - const cwd = process.cwd() + async run({ command, files, cwd }: TaskRunContext) { const pkg = JSON.parse(await fs.readFile(path.join(cwd, 'package.json'), 'utf8')) const workspaces = await mapWorkspaces({ cwd, pkg })