Skip to content
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

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

Open
jbadavis opened this issue Oct 11, 2023 · 2 comments
Open

Comments

@jbadavis
Copy link

Hello,

I have a very simple XO configuration I'd like to share between all the packages and apps in my Turborepo monorepo:

"xo": {
  "prettier": true,
  "rules": {
    "import/extensions": 0
  }
}

The project README states that I should just need one version of this in the root package.json file:

However, I'm seeing linting errors in each of my packages if I don't have this XO config in every package.json. Have I configured something incorrectly?

@Navigatron
Copy link

I'm seeing the same behavior / having the same problem. Running xo in a sub-package does not seem to "search upwards" and find the parent package.json config.

- package.json         # Includes XO config
- packages/
    - packageName/
        - package.json # Does not include XO config

I believe there are some magic filenames that might work - I'll try those out and report back. I'll watch this issue with interest though, as I'd rather not have yet another root config file.

@Navigatron
Copy link

I've found the discrepancy!

From lines 103 and 104 of lib/options-manager.js:

options.cwd = path.resolve(options.cwd || process.cwd());
const configExplorer = cosmiconfig(MODULE_NAME, {searchPlaces: CONFIG_FILES, loaders: {noExt: defaultLoaders['.json']}, stopDir: options.cwd});

Note that stopDir is set to options.cwd, which defaults to process.cwd().

From the comsiconfig readme:

  • If none of those searches reveal a configuration object, move up one directory level and try again. So the search continues in ./, ../, ../../, ../../../, etc., checking the same places in each directory.
  • Continue searching until arriving at your home directory (or some other directory defined by the cosmiconfig option stopDir).

In short, xo does not search upwards - the search is stopped in the current working directory.

Workaround

  1. Use the --cwd flag to start xo from your monorepo root (overriding options.cwd)
  2. Narrow scope back down by specifying the subfolder you want
{
    "scripts": {
        "lint": "xo --cwd=../.. $(pwd)"
    }
}

There's probably a better way to identify the monorepo root than just hard-coding ../.., but that's all I've got for now.

joakimbeng added a commit to aboviq/emigrate that referenced this issue Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants