Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EricCrosson/4a29c854d80a08f0b6676d2a6c754013 to your computer and use it in GitHub Desktop.
Save EricCrosson/4a29c854d80a08f0b6676d2a6c754013 to your computer and use it in GitHub Desktop.
Collate unhoistable lerna dependencies
npx lerna bootstrap --force-local --strict --hoist 2> >(jq --raw-input --slurp '
# create an array of relevant lines
split("\n")
| map(
select(. != "")
| select(contains("WARN EHOIST_PKG_VERSION"))
)
# create { hoisted: string, unhoisted: string }[]
| map(
match("depends on (\\S+), which differs from the hoisted (\\S+)")
| { unhoisted: .captures[0].string, hoisted: .captures[1].string }
)
# aggregate the data into Record<string, string[]>
# mapping a hoisted var to its unhoisted versions
| reduce .[] as $dep (
{};
if has($dep.hoisted) then
(. + { ($dep.hoisted): (.[($dep.hoisted)] + [ $dep.unhoisted ]) })
else
(. + { ($dep.hoisted): [ $dep.unhoisted ] })
end
)
')
@EricCrosson
Copy link
Author

Creates output like

  "lodash@4.17.19.": [
    "lodash@4.17.21",
    "lodash@4.17.21",
    "lodash@4.17.21",
    "lodash@4.17.21",
    "lodash@4.17.20",
    "lodash@^4.17.21",
    "lodash@^4.17.21",
    "lodash@^4.17.20",
    "lodash@~4.17.11"
  ],
  "yargs@17.0.1.": [
    "yargs@12.0.2",
    "yargs@14.0.0"
  ],

@EricCrosson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment