(question)
Is there a way to use lerna exec/run to run a specific script/command in the root scope?
We already use something like lerna run --scope=a <script>, but we'd like to be able to use lerna to execute a root script from a package script. Given a structure like:
.
โโโ lerna.json
โโโ package-lock.json
โโโ package.json
โโโ packages
โย ย โโโ a
โย ย โโโ b
โโโ ...
Is there a way that a script "prestart" in packages/a/package.json can use lerna to run a script "xyz" which is in root package.json.
Something like:
// package.json
"xyz": "do-something-in-root-scope"
// packages/a/package.json
"prestart": "npx lerna run --scope <root> xyz"
According to this comment, it's a bad idea to add the root as a managed package.
Unsure how to proceed. Any help would be appreciated! Thank you :)
lerna.json
{
"packages": [
"packages/*"
],
"version": "0.0.0"
}
| Executable | Version |
| ---: | :--- |
| lerna --version | 3.16.4 |
| npm --version | 6.10.2 |
| yarn --version | N/A |
| node --version | 12.8.1 |
| OS | Version |
| --- | --- |
| macOS Mojave | 10.14.5 |
This seems more than sufficient for your use case:
"prestart": "cd ../.. && npm run xyz"
@evocateur I strongly disagree that this is sufficient, as it relies on assuming a directory structure and the point is to keep the scope. if lerna kept track of the root path, that would be more stable and useful. Please reopen this.
it relies on assuming a directory structure
I mean, yes? Like, your packages don't have a habit of changing their location in the directory tree often, do they?
if lerna kept track of the root path
$LERNA_ROOT_PATH is available to lerna exec.
Most helpful comment
I mean, yes? Like, your packages don't have a habit of changing their location in the directory tree often, do they?
$LERNA_ROOT_PATHis available tolerna exec.