-
-
Notifications
You must be signed in to change notification settings - Fork 5
refactor(intent): add shared project context resolver for validate and edit-package-json #93
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
Changes from all commits
d6344f4
9147184
6317916
1dd418d
e19a523
ed552c6
6471af5
8835975
63273a5
094609e
667e06f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/intent': patch | ||
| --- | ||
|
|
||
| Fix workspace package discovery for nested glob patterns, including support for `*` and `**`. Workspace patterns and resolved package roots are now normalized, deduped, and sorted, and the shared resolver has been extracted for reuse by internal workspace scanning. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/intent': patch | ||
| --- | ||
|
|
||
| Refactor @tanstack/intent to use a shared project context resolver for workspace and package detection. This fixes monorepo targeting bugs in validate and edit-package-json, including pnpm workspaces defined only by pnpm-workspace.yaml. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { existsSync, statSync } from 'node:fs' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { dirname, join, relative, resolve } from 'node:path' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findWorkspaceRoot, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| readWorkspacePatterns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '../workspace-patterns.js' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type ProjectContext = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceRoot: string | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| packageRoot: string | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMonorepo: boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspacePatterns: Array<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetPackageJsonPath: string | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetSkillsDir: string | null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Resolves project structure by walking up from targetPath (or cwd) to find the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * owning package.json, then searches for a workspace root from the package root. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Falls back to searching from cwd when targetPath points deep into a package. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function resolveProjectContext({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetPath, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetPath?: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }): ProjectContext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resolvedCwd = resolve(cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const resolvedTargetPath = targetPath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? resolve(resolvedCwd, targetPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : resolvedCwd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const packageRoot = findOwningPackageRoot(resolvedTargetPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const workspaceRoot = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findWorkspaceRoot(packageRoot ?? resolvedTargetPath) ?? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| findWorkspaceRoot(resolvedCwd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const workspacePatterns = workspaceRoot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? (readWorkspacePatterns(workspaceRoot) ?? []) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: resolvedCwd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspaceRoot, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| packageRoot, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMonorepo: workspaceRoot !== null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workspacePatterns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t mark the workspace root package as
[suggested fix] 🐛 Suggested fix const workspaceRoot =
findWorkspaceRoot(packageRoot ?? resolvedTargetPath) ??
findWorkspaceRoot(resolvedCwd)
+ const isMonorepo =
+ packageRoot !== null &&
+ workspaceRoot !== null &&
+ workspaceRoot !== packageRoot
const workspacePatterns = workspaceRoot
? (readWorkspacePatterns(workspaceRoot) ?? [])
: []
return {
cwd: resolvedCwd,
workspaceRoot,
packageRoot,
- isMonorepo: workspaceRoot !== null,
+ isMonorepo,Based on learnings: packaging-related monorepo checks should answer whether the package is inside the workspace, not whether the package root itself is the workspace root. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetPackageJsonPath: packageRoot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? join(packageRoot, 'package.json') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetSkillsDir: resolveTargetSkillsDir(resolvedTargetPath, packageRoot), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function findOwningPackageRoot(startPath: string): string | null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let dir = toSearchDir(startPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while (true) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (existsSync(join(dir, 'package.json'))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return dir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const next = dirname(dir) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (next === dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dir = next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function toSearchDir(path: string): string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!existsSync(path)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return statSync(path).isDirectory() ? path : dirname(path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function resolveTargetSkillsDir( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetPath: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| packageRoot: string | null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): string | null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!packageRoot) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const packageSkillsDir = join(packageRoot, 'skills') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isWithinOrEqual(targetPath, packageSkillsDir)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return packageSkillsDir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (targetPath === packageRoot && existsSync(packageSkillsDir)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return packageSkillsDir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function isWithinOrEqual(path: string, parentDir: string): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const rel = relative(parentDir, path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rel === '' || (!rel.startsWith('..') && !rel.startsWith('/')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.isMonorepois too broad for the_artifactsgate.resolveProjectContextmarks the workspace root package as monorepo too, so these branches now skip the localskills/_artifactsvalidation and!skills/_artifactswarning for a root package that still needs them. Gate this on “target package is a workspace sub-package” instead of “a workspace root exists”.Suggested direction
Also applies to: 171-173
🤖 Prompt for AI Agents