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 })