Skip to content

fix(intent): walk up to meta/ instead of hardcoded depth#194

Merged
LadyBluenotes merged 2 commits into
TanStack:mainfrom
SutuSebastian:fix/getmetadir-walk-up
Jul 3, 2026
Merged

fix(intent): walk up to meta/ instead of hardcoded depth#194
LadyBluenotes merged 2 commits into
TanStack:mainfrom
SutuSebastian:fix/getmetadir-walk-up

Conversation

@SutuSebastian

@SutuSebastian SutuSebastian commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Closes #193.

What

getMetaDir() hardcoded ../../meta. That's right in source (src/commands/ → two up → package root → meta/), but the build ships the module flat in dist/, where two .. overshoots to @tanstack/meta and meta/ is actually one .. up at @tanstack/intent/meta. Result: setup, setup-github-actions, meta, and scaffold all fail in the published package with "No templates directory found" / "Meta-skills directory not found".

Fix: walk up from the module dir to the first meta/ instead of a fixed depth. Handles both the deep source layout and the flat dist/ layout, plus symlinked installs (pnpm). Falls back to the old ../../meta if nothing's found, so it's never worse than before.

Extracted findMetaDir(startDir) so the resolution is unit-testable without depending on import.meta.url.

Verification

  • vitest run tests/support.test.ts tests/setup.test.ts → 29 passed (new findMetaDir tests cover the flat-dist/ layout, the deep src/commands/ layout, and the no-meta/ fallback; getMetaDir resolves to the real meta/templates/workflows/check-skills.yml).
  • tsc --noEmit clean; eslint + prettier clean on touched files.
  • Built the package and ran the bundled CLI end-to-end:
    • node dist/cli.mjs meta → lists the meta-skills (was "Meta-skills directory not found.")
    • node dist/cli.mjs setup in a temp project → ✓ Copied workflow: …/check-skills.yml + template vars applied (was "No templates directory found.")
  • Full package suite: 591 passed, 1 skipped, 1 pre-existing failure (tests/integration/source-policy-surfaces.test.ts:79) — confirmed failing on pristine main with this branch's changes stashed, so unrelated to this fix (it's about intent list source-policy notices, a different code path).

Changeset

@tanstack/intent: patch.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed template and metadata resolution in published builds so setup, scaffolding, and related workflows can reliably locate meta/ assets.
    • Updated metadata lookup to correctly handle both source and bundled directory layouts by searching upward for the nearest meta/ folder.
  • Tests
    • Added/expanded test coverage for metadata directory discovery across dist/, src/ layouts, fallback behavior, and symlinked installs.

getMetaDir hardcoded ../../meta, which is correct for the src/commands/
source layout but overshoots to @tanstack/meta from the flat dist/ layout
the build ships — so setup, setup-github-actions, meta, and scaffold fail
with "No templates directory found" / "Meta-skills directory not found"
in the published package. Walk up to the first meta/ directory so
resolution works in both layouts and symlinked installs.
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 284e173f-385d-4662-9799-e7a8853e8af7

📥 Commits

Reviewing files that changed from the base of the PR and between 17059ec and 2891205.

📒 Files selected for processing (2)
  • packages/intent/src/commands/support.ts
  • packages/intent/tests/support.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/intent/src/commands/support.ts

📝 Walkthrough

Walkthrough

getMetaDir() now resolves meta/ by walking upward from the current module location with a new findMetaDir(startDir) helper, instead of relying on a fixed relative path. Tests cover multiple filesystem layouts, and a changeset documents the patch.

Changes

getMetaDir Resolution Fix

Layer / File(s) Summary
findMetaDir implementation and integration
packages/intent/src/commands/support.ts
Adds findMetaDir(startDir) with upward directory lookup and fallback resolution, and updates getMetaDir() to call it.
Tests and changeset for meta resolution
packages/intent/tests/support.test.ts, .changeset/getmetadir-walk-up.md
Adds Vitest coverage for flat, nested, fallback, stray-file, symlinked, and real-file meta resolution cases, and records the fix in a changeset.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Suggested reviewers: KevinVandy

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: replacing the hardcoded meta path with an upward search.
Description check ✅ Passed The description explains the fix, motivation, verification, and changeset, but it does not follow the template’s checklist and release-impact sections.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/intent/src/commands/support.ts (1)

48-48: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Unexplained magic number 10.

The iteration limit isn't documented — a brief comment on why 10 is sufficient (e.g., deepest expected nesting) would aid future maintenance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/intent/src/commands/support.ts` at line 48, The loop in support.ts
uses an unexplained magic number for the iteration cap, so add a brief inline
comment near the for loop in the support command explaining why the chosen limit
is sufficient. Keep the reference tied to the support command’s retry/nesting
logic around the limit variable so future readers understand why the bound in
this iteration is 10.
packages/intent/tests/support.test.ts (1)

33-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No test for symlinked installs.

The PR objective explicitly calls out symlinked installs (e.g., pnpm) as a case this fix should handle, but no test exercises a symlinked module path. Consider adding a case that creates a symlink to the module directory and asserts findMetaDir still resolves correctly, since that scenario is the actual motivating bug fix beyond the dist/src layout difference.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/intent/tests/support.test.ts` around lines 33 - 58, Add coverage for
symlinked installs in the findMetaDir tests, since the current cases only cover
flat dist and deep src/commands paths. Extend support.test.ts with a scenario
that creates a symlinked module directory (pnpm-like install layout) and verify
findMetaDir still resolves the expected meta directory from that symlinked start
path. Use the existing findMetaDir helper and seedMeta setup to keep the new
case aligned with the current test structure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/intent/src/commands/support.ts`:
- Around line 46-55: findMetaDir currently treats any existing path named meta
as valid, even if it is a file, which can break downstream commands that expect
a directory. Update the check in findMetaDir to verify the candidate is both
present and a directory before returning it, and keep the fallback behavior
unchanged; this affects callers like runMetaCommand, runScaffoldCommand, and
runSetupGithubActionsCommand that rely on the returned path being a real meta
folder.

---

Nitpick comments:
In `@packages/intent/src/commands/support.ts`:
- Line 48: The loop in support.ts uses an unexplained magic number for the
iteration cap, so add a brief inline comment near the for loop in the support
command explaining why the chosen limit is sufficient. Keep the reference tied
to the support command’s retry/nesting logic around the limit variable so future
readers understand why the bound in this iteration is 10.

In `@packages/intent/tests/support.test.ts`:
- Around line 33-58: Add coverage for symlinked installs in the findMetaDir
tests, since the current cases only cover flat dist and deep src/commands paths.
Extend support.test.ts with a scenario that creates a symlinked module directory
(pnpm-like install layout) and verify findMetaDir still resolves the expected
meta directory from that symlinked start path. Use the existing findMetaDir
helper and seedMeta setup to keep the new case aligned with the current test
structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fa0b3de2-b118-42bd-9b3d-00aabe4e1830

📥 Commits

Reviewing files that changed from the base of the PR and between 3620cca and 17059ec.

📒 Files selected for processing (3)
  • .changeset/getmetadir-walk-up.md
  • packages/intent/src/commands/support.ts
  • packages/intent/tests/support.test.ts

Comment thread packages/intent/src/commands/support.ts
…ray-file cases

Address review: statSync(candidate).isDirectory() so a stray file named
`meta` can't short-circuit the walk-up; add a comment on the iteration cap;
add tests for the stray-file skip and a pnpm-style symlinked install path.
@nx-cloud

nx-cloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 2891205

Command Status Duration Result
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-03 15:39:32 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/TanStack/intent/@tanstack/intent@194

commit: 2891205

@LadyBluenotes LadyBluenotes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for fixing this!

@LadyBluenotes LadyBluenotes merged commit e885566 into TanStack:main Jul 3, 2026
9 checks passed
@SutuSebastian SutuSebastian deleted the fix/getmetadir-walk-up branch July 3, 2026 15:44
@github-actions github-actions Bot mentioned this pull request Jul 3, 2026
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.

setup / meta / scaffold can't find meta/ in the published package (getMetaDir off-by-one)

2 participants