Skip to content

Conversation

@Zih0
Copy link
Collaborator

@Zih0 Zih0 commented Jan 20, 2026

Summary

Add support for running CLI commands from subdirectories in a monorepo by resolving process.cwd() behavior differences across package managers.

Problem

When running docflow commands from a subdirectory (e.g., packages/web), path calculations failed because process.cwd() behaves differently across package managers:

Package Manager process.cwd() INIT_CWD
npm/pnpm Repo root Invocation directory
yarn Invocation directory Invocation directory

This inconsistency caused incorrect relative path calculations for workspace packages.

Solution

getWorkingDirectory()
Returns INIT_CWD ?? process.cwd() to get consistent invocation directory across all package managers.

Package manager

  • NpmPackageManager: Calculate path.relative(cwd, pkgPath) from absolute path field
  • YarnPackageManager: Find repo root via yarn.lock location, then calculate relative paths

Command updates
Replace process.cwd() with getWorkingDirectory() in commands.

Result

Users can now run docflow build, docflow check, and docflow generate from any subdirectory in a monorepo, regardless of which package manager they use.

@vercel
Copy link

vercel bot commented Jan 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docflow-docs Ready Ready Preview, Comment Jan 26, 2026 5:15am

Request Review

@Zih0 Zih0 changed the base branch from main to v0.0.2 January 20, 2026 12:16
@Zih0 Zih0 self-assigned this Jan 20, 2026
}

private getRepoRootPath(): string {
const root = findUp("yarn.lock", this.cwd);
Copy link

@raon0211 raon0211 Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: What do you think about using the find-up library here? It's more robust and battle-tested than maintaining our own implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied review.
a4871cf

}

return findUp(name, path.dirname(absoluteCwd));
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing EOL here. Might be worth checking our formatter settings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repository doesn't have a formatter (prettier or biome) configured.

I'll create a separate PR to apply formatting across the codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18

Copy link

@raon0211 raon0211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for two minor comments. Feel free to merge if you don't think they're relevant.

@Zih0 Zih0 force-pushed the feat/sub-directory branch from 8443491 to a4871cf Compare January 26, 2026 05:14
@Zih0 Zih0 merged commit 34b4411 into v0.0.2 Jan 26, 2026
3 checks passed
@Zih0 Zih0 deleted the feat/sub-directory branch January 26, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants