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

Relative 'extends' can fail; should resolve relative to config file #685

Closed
andrewdbond opened this issue Aug 28, 2022 · 1 comment · Fixed by #686
Closed

Relative 'extends' can fail; should resolve relative to config file #685

andrewdbond opened this issue Aug 28, 2022 · 1 comment · Fixed by #686
Labels

Comments

@andrewdbond
Copy link
Contributor

Description
'extends' using relative paths aren't always resolved relative to the configuration file.

To Reproduce
Steps to reproduce the behavior:

  1. Create a config file that extends from another config file that exists, using a relative path. Example: xo.config.js:
module.exports = {
 extends: ['./xo.and.eslint.shared.overrides.yaml']
};
  1. Use the XO Visual Studio Code extension.
  2. XO produces an error. XO's output:
[Info  - 7:52:41 PM] XO Server Starting in Node v16.13.2
[Info  - 7:52:42 PM] XO Library 0.52.2
                Resolved in Workspace d:\src
                Cached for Folder d:\src
[Info  - 7:52:42 PM] XO Library 0.52.2
                Resolved in Workspace d:\src
                Cached for Folder d:\src
[19:52:44:936] Cannot find module 'eslint-config-./xo.and.eslint.shared.overrides.yaml'
Require stack:
- d:\src\__placeholder__.js 
[19:52:44:937] Error: Cannot find module 'eslint-config-./xo.and.eslint.shared.overrides.yaml'
Require stack:
- d:\src\__placeholder__.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at resolve (file:///d:/src/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js:23:46)
    at resolveFrom (file:///d:/src/node_modules/xo/lib/options-manager.js:35:66)
    at file:///d:/src/node_modules/xo/lib/options-manager.js:425:24
    at Array.map (<anonymous>)
    at file:///d:/src/node_modules/xo/lib/options-manager.js:414:35
    at file:///d:/src/node_modules/lodash-es/_createFlow.js:71:31
    at buildConfig (file:///d:/src/node_modules/xo/lib/options-manager.js:283:3)
    at parseOptions (file:///d:/src/node_modules/xo/lib/options-manager.js:588:52)

Alternatively, in place of step 2 above, run XO from a different folder with the cwd option set to the config folder:

xo --cwd=<configFileDir>

Expected behavior
XO loads the extended config file.

Additional context
For comparison, "ESLint resolves a relative path to a base configuration file relative to the configuration file that uses it."

Tested on Node.js v16.

andrewdbond added a commit to andrewdbond/xo that referenced this issue Aug 28, 2022
Allow relative 'extends' when starting XO from a folder different than
the config file. This can also occur when using the XO VS Code
extension. Fixes xojs#685
@spence-s spence-s added the bug label Aug 29, 2022
@spence-s
Copy link
Contributor

@andrewdbond - the extension latest update has changed the logic and I believe the cwd will always be where it finds a package.json with xo as a dependency, so as a hack if you make the extends relative to that directory it will probably work as expected until this issue is fully resolved.

andrewdbond added a commit to andrewdbond/xo that referenced this issue Aug 31, 2022
Add a basic test for 'extends' using a relative path.

Related to xojs#685
andrewdbond added a commit to andrewdbond/xo that referenced this issue Aug 31, 2022
Improve previous extends test to use a relative path instead of a
test-created absolute path. The config in issue 71 was initially
described as relative, and is likely the more normal case.

Related to xojs#685
andrewdbond added a commit to andrewdbond/xo that referenced this issue Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants