Open shobhitchittora opened 6 years ago
Right now, no, there isn't, but I'll definitely look into adding proper support for both lerna and yarn.
@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. :)
@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.
@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.
Cool. Let me know If I can help implement some part of the feature. I would be more than happy to contribute. :)
@jasonnutter I do want this feature 💯 I can volunteer if you need some help 😉
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.
Check out my PR for solving this issue: #11
When using tools like
yarn
andlerna
, it's very common to have the below folder structures -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, whilelerna
projects have a predefined structure.