ls-engines icon indicating copy to clipboard operation
ls-engines copied to clipboard

Add option to scan sub-directories and combine results

Open therealsujitk opened this issue 1 year ago • 7 comments

Some of my projects have sub projects, for example my express project will have a react sub project for the frontend. It would be nice if there were an option, if true it will check sub folders as well for node_modules or a .lock file.

.
├── node_modules
├── frontend
│   ├── admin
|   |   ├── node_modules
|   |   ├── package.json
|   |   └── yarn.lock
│   └── home
|   |   ├── node_modules
|   |   ├── package.json
|   |   └── yarn.lock
├── package.json
└── yarn.lock

Currently I run them individually for all three projects and get three different results. So maybe something like a --recursive option to do this?

yarn ls-engines --recursive=true

therealsujitk avatar Dec 16 '23 05:12 therealsujitk

hmm, that complicates things a bit, especially because in many workspaces setups there won't be a nested node_modules, it'll be only at the top level.

The primary use case for this package is to block CI on failure, and in that case, provide helpful information to locate the incompatibility. In a multi-package repo like that, the engines declarations for each package would be independent, so I'm not sure I see why it'd be useful to combine the results. Can you elaborate?

ljharb avatar Dec 16 '23 05:12 ljharb

@ljharb thanks for your prompt repsponse!

In my specific case, my build command calls the build commands of the sub projects as well. So in order for the build to succeed I need the node engine to be the maximum of all three projects. My top project happened to be v14 and sub projects v18. So after running the command for all three projects, I set the node version for the top project to v18. I didn't have to install this package in all three projects either, just the top level one, and then ran.

$ yarn ls-engines --dev=true
$ cd frontend/admin
$ node ../../node_modules/ls-engines/bin/ls-engines --dev=true
$ cd ../docs
$ node ../../node_modules/ls-engines/bin/ls-engines --dev=true

And with this I got three different results that I manually combined. So instead I was thinking it would be convenient to have this package check all directories and combine the results for you. This can be done by default as well, however It'll be a lot slower, hence I suggested the --recursive flag to check all sub-directories only if true.

therealsujitk avatar Dec 16 '23 06:12 therealsujitk

(npx ls-engines should work instead of yarn or that gnarly path, btw, for all three commands)

what happens if you add all of the subprojects as explicit deps/dev deps of the root, and then run it in the root? Would that cover it?

ljharb avatar Jan 16 '24 18:01 ljharb

You mean by using local paths? I assume this would work, however it causes other issues for my subprojects.

therealsujitk avatar Jan 17 '24 06:01 therealsujitk

yes, but i think if you include the root in the workspace, you can just list them by name?

ljharb avatar Jan 17 '24 06:01 ljharb

Sorry, I don't follow.

therealsujitk avatar Jan 17 '24 07:01 therealsujitk

https://docs.npmjs.com/cli/v9/commands/npm-docs#include-workspace-root - set this to true in npmrc, and then i think you can add child workspaces directly by name to the root as deps.

ljharb avatar Jan 17 '24 07:01 ljharb