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

Confusing behaviour when having nested package.json #507

Open
janpaul123 opened this issue Jul 9, 2018 · 2 comments
Open

Confusing behaviour when having nested package.json #507

janpaul123 opened this issue Jul 9, 2018 · 2 comments

Comments

@janpaul123
Copy link
Contributor

I struggled with setting up import-js for a repo that had (mistakenly) two package.json files. This was the directory structure:

- import.js
- package.json
- client/
  - package.json
  - components/
    - some_file.js

I was trying to figure out why some_file.js was not picking up the configuration. So I tried to set minimumVersion to something large, but then it errored out. So it looked like it was picking up the configuration. But then I tried to use other config options, but it wouldn't pick them up.

The reason for this is that in this case Configuration is initialised multiple times but with different workingDirectory params. The first time it is initialised correctly, but the second and third time the working directory was pointing at the client/ directory.

This was particularly confusing since there was no error message and it even seemed like configuration was somewhat picked up (because of the minimumVersion thing working properly).

@trotzig
Copy link
Collaborator

trotzig commented Jul 11, 2018

The code that finds the project root is pretty naive, it simply looks for a package.json file:

if (fs.existsSync(pathToPackageJson)) {

There have been an (unmerged) attempt at resolving this: #462. One possible (different) way of solving this could be to let the presence of an .importjs.js file have precedence. So instead of just stopping at the first package.json we find we could first scan for .importjs.js, then make a fallback scan for package.json.

@mikabytes
Copy link
Collaborator

Yet another approach might be to put the highest precedence on .importjs-root file and keep the existing behavior the same. Very few people are using that file due to it being undocumented so we risk less breaking changes.

Could you let me know if this is still something that needs to be implemented? I could give it a go.

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

No branches or pull requests

3 participants