question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter flag combination for dependencies or dependents only?

See original GitHub issue

Not a bug. More of a potential opportunity in the semantics of filter flags or a feature request: a filter flag combination that enables operating on dependents or dependencies only.

Expected Behavior

Given lerna --include-dependencies --scope packageC run build where packageC depends on packageA and packageB, all 3 will run build.

I have a scenario where I want to build the dependencies of packageC one time, then build and watch for changes on packageC. Unfortunately, packageC gets built twice, once when I run the command above, and again when I run lerna --scope packageC run dev—simply because by necessary convention all the packages have a build script (build number 1 build) and the build tool runs an initial build when watching (build number 2 dev).

Some of the builds are involved (and therefore take long) enough that it improves developer experience to optimize away a second build.

That can possibly be solved in other reasonable ways, but this isn’t the first time I’ve wished for the ability to filter this way.

Another case I’ve run into is when I’ve been working on packageC and now want to verify its dependents, packageD and packageE. While working on packageC, I’ve built it and verified it, so it’s actually extraneous in lerna --include-dependents --scope packageC run build && lerna --include-dependents --scope packageC run test.

Current Behavior

I tried npx lerna --include-dependen(t|cie)s --scope packageC --ignore packageC just in case it might work, but it errors as not matching any packages.

Possible Solution

I think the semantics of a command with --scope and --ignore being set to the same package and an --include-dependencies/--include-dependents flag could reasonably be interpreted to match the dependencies / dependents only. But that may not be widely intuitive and I understand implementation details might preclude it; another flag like --only-dependencies/--only-dependents could also meet the need.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:16
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
felixhayashicommented, Nov 24, 2019

Bump! I have the exact same requirement.

In a situation where one works with create-react-app (cra), it is required to first ensure all dependencies are build before actually starting or building the react app.

You need to transpile the packages and specify them correctly as dependencies. Webpack handles the rest without any special handling, as they are just npm modules. (@evocateur, https://github.com/lerna/lerna/issues/1156#issuecomment-441407468)

Now in my situation, during development, the main package (which would map to packageC mentioned in the OP) is executed via webpack and uses hot-reloading, however before the server is started I need to build all dependencies first while excluding the current package to avoid triggering (and waiting) for an unnecessary build of the main package (which handled by webpack).

Intuitively I used the same semantics as suggested in the OP (npx lerna --include-dependencies --scope main-app --ignore main-app), however this did not work.

Of course, I could add all build commands for my dependencies manually one-by-one and chain them via && in my app-main package before I start the webpack server but this is redundant and error-prone 👎

I would rather prefer being able to do this 👍

# prepare dependencies
npm run lerna -- build --include-dependencies --scope main-app --ignore main-app
# start webpack server
npm run lerna -- run start --scope main-app
1reaction
schmodcommented, Nov 10, 2020

this is the very sketchy shell script I came up with:

PKG=$1
LERNA=$(yarn bin lerna)

$LERNA ls -a -p --scope $PKG --include-dependencies --json \
  | jq -r '.[].name | select(contains("'$PKG'") | not) | "--scope " + .' \
  | xargs -t $LERNA run build
Read more comments on GitHub >

github_iconTop Results From Across the Web

Filtering | pnpm
Filtering allows you to restrict commands to specific subsets of packages. pnpm supports a rich selector syntax for picking packages by name or...
Read more >
pnpm vs Lerna: filtering in a multi-package repository - Medium
Filtering in Lerna​​ include-filtered-dependents - Include all transitive dependents when running a command regardless of --scope , --ignore , or ...
Read more >
Filtering Workspaces - Turborepo
You can use it to: Filter by workspace name; Filter by workspace directory; Include dependents and dependencies of matched workspaces; Execute tasks from...
Read more >
Filter Dependency Report view to only show cross-p...
We're long-time Jira users, but are only just getting our feet wet ... only cross-project dependencies (i.e. where a ticket is dependent on ......
Read more >
Intents and Intent Filters - Android Developers
The flags may instruct the Android system how to launch an activity (for example, ... but only in specific combinations of action, data,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found