Skip to content

Fix parent XO config resolution from nested package cwd#883

Open
sjh9714 wants to merge 3 commits into
xojs:mainfrom
sjh9714:fix-monorepo-package-config-resolution
Open

Fix parent XO config resolution from nested package cwd#883
sjh9714 wants to merge 3 commits into
xojs:mainfrom
sjh9714:fix-monorepo-package-config-resolution

Conversation

@sjh9714

@sjh9714 sjh9714 commented May 17, 2026

Copy link
Copy Markdown

Summary

Fixes XO config resolution when running from a nested package in a monorepo.

What changed

  • Added regression coverage for resolving a parent package.json XO config from a nested package cwd.
  • Updated config discovery to search parent project directories instead of stopping at the package parent directory.

Why

Issue #733 reports that packages in a monorepo do not pick up the root XO config. The previous search stopped before reaching the monorepo root.

Testing

  • npm run build
  • npm run test:setup
  • npx ava dist/test/resolve-config.test.js
  • node dist/cli.js lib/resolve-config.ts test/resolve-config.test.ts
  • git diff --check

Note: I also checked npm test; it currently stops at the lint step on both this branch and upstream/main with the same pre-existing @typescript-eslint/no-unnecessary-type-assertion reports in lib/utils.ts and lib/xo.ts.

Fixes #733

@sindresorhus

Copy link
Copy Markdown
Member

I think this is still a bit risky. The fix depends on searchStrategy: 'project' walking past a nested package.json to find the parent config, but cosmiconfig documents that strategy as stopping once it finds a package.{json,yaml}. It happens to work with the current implementation, but if cosmiconfig changes to match its docs, this regression comes back.

It also means XO can now pick up an unrelated ancestor config above the actual project, which feels broader than the issue needs. I think we should either avoid relying on this undocumented behavior, or add an explicit test that shows this wider ancestor lookup is intentional.

I suggest opening an issue on cosmicconfig to clarify.

@sjh9714

sjh9714 commented Jun 13, 2026

Copy link
Copy Markdown
Author

Thanks, agreed. I removed the searchStrategy: 'project' change and restored the bounded cosmiconfig search.

The follow-up now uses an explicit fallback only for a parent package.json that declares workspaces matching the nested cwd, so XO can pick up the intended monorepo root config without relying on cosmiconfig walking past a nested package.json or grabbing an unrelated ancestor config.

I also added a regression test for the negative case where an ancestor package.json has xo config but does not declare the nested package as a workspace.

Ran:

  • npm run build
  • npm run test:setup && npx ava dist/test/resolve-config.test.js
  • node dist/cli.js lib/resolve-config.ts test/resolve-config.test.ts
  • npm test
  • git diff --check

I did not open a cosmiconfig issue for now because this PR no longer depends on that undocumented behavior.

@sjh9714 sjh9714 force-pushed the fix-monorepo-package-config-resolution branch from 2732f23 to 63d7c84 Compare June 14, 2026 14:02
@sjh9714 sjh9714 force-pushed the fix-monorepo-package-config-resolution branch from 63d7c84 to 87862e0 Compare June 18, 2026 05:46
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.

Projects in a Turborepo monorepo not using workspace package.json config

2 participants