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

Allow to search in node_modules of workspaces (yarn / lerna workspaces) #10

Open
shobhitchittora opened this issue Aug 21, 2018 · 8 comments

Comments

@shobhitchittora
Copy link

When using tools like yarn and lerna, it's very common to have the below folder structures -

/node_modules
/package.json

workspace-a 
  /node_modules
  /package.json

workspace-b/
  /node_modules
  /package.json

We should have a config to allow search for child packages' node_modules. Is there a way to do that now that I'm not aware of ?

NOTE: for yarn workspaces we can read the root package.json to get workspace config, while lerna projects have a predefined structure.

@jasonnutter
Copy link
Owner

Right now, no, there isn't, but I'll definitely look into adding proper support for both lerna and yarn.

@hardikmodha
Copy link

hardikmodha commented Sep 13, 2018

@jasonnutter I also need this feature. I have a monorepo where the code for both the frontend and the backend repo is stored. Both the repos have node_modules directory.

I have thought of a solution.

Currently, The search-node-modules configuration option takes a single relative path to the node_modules directory. Along with that, We can make it accept an object, Where keys of the object will be user identifiable name and the value will be the path of the node_modules directory.

e.g.

// When the user wants to search inside a monorepo
"search-node-modules-path": {
  "Frontend repo": "./frontend/node_modules",
  "Backend repo": "./backend/node_modules"
}

// Normal scenarios
"search-node-modules-path": "node_modules"

Now, When the user executes the command > search node_modules via command palette we can check the value of the search-node-modules-path. If the value is an object we can display quick-pick to select the repo and user can choose which repo's node_modules to search for.

What do you think? I would be more than happy to raise a PR for this. :)

@shobhitchittora
Copy link
Author

@hardikmodha Great thinking! But can you think of reading this configuration from a more generalized place like the main package.json, which can use any major mono-repo manager like lerna (lerna.json in this case )or yarn. Please look into each of these and tell me your thoughts.

@jasonnutter
Copy link
Owner

@hardikmodha That's a potential approach, however, I prefer that the extension is able to support vscode/lerna/yarn workspaces without any need for manual configuration. I am starting work now to make that happen, will update here when that is complete.

@hardikmodha
Copy link

hardikmodha commented Sep 17, 2018

Cool. Let me know If I can help implement some part of the feature. I would be more than happy to contribute. :)

@hemal7735
Copy link

@jasonnutter I do want this feature 💯 I can volunteer if you need some help 😉

@elektronik2k5
Copy link

Thanks for creating this package!

I believe there's an easier way to handle this scenario - without any configuration. We just need to follow node's native module resolution protocol, starting from the location of the current file/tab, looking for node_modules, recursing up the directory tree until we find a match.

So in the original example, if I'm in workspace-a/package.json, the traversal will start from workspace-a/node_modules. If none is found, we'd search in the parent directory.
This isn't specific to yarn/lerna or any other tool/convention.

@OriMarron
Copy link
Contributor

Check out my PR for solving this issue: #11

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

6 participants