Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np for monorepos #549

Closed
simonepri opened this issue Jul 5, 2020 · 3 comments
Closed

np for monorepos #549

simonepri opened this issue Jul 5, 2020 · 3 comments

Comments

@simonepri
Copy link

Description

Right now, np only support single package repositories, it would be nice to support multi packages repositories.

Possible implementation

For myself, I wrote the following bash script, which basically runs np on each package in the packages directory, then it updates the version in the root package.json, and finally, it publishes the tag on GitHub.
This scripts assumes that every package have the same version.

Folder structure:

  • scripts/
    • release.sh
  • packages/
    • package1/
      • package.json
    • package2/
      • package.json
  • package.json

release.sh

#!/bin/bash
np=$(npm bin)"/np"

npm i || exit 1

echo "Enter release version (major/minor/patch)."
read -r version

echo "Executing dryrun..."
for package in packages/* ; do
  cd "$package" || exit 2
  echo "CWD: $PWD"
  "$np" "$version" --no-publish --no-release-draft --preview || exit 3
  cd ../.. || exit 4
done
echo "CWD: $PWD"
"$np" "$version" --preview || exit 5

echo "Are you sure? (Y/[N])"
read -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
  echo "Executing release..."
  for package in packages/* ; do
    cd "$package" || exit 6
    echo "CWD: $PWD"
    "$np" "$version" --yolo --no-release-draft || exit 7
    git add package.json || exit 8
    git commit -m "Bump version for $package" || exit 9
    cd .. || exit 10
  done
  echo "CWD: $PWD"
  "$np" "$version" --yolo --no-publish || exit 11
fi

package.json

The root package.json looks something like this:

{
  "name": "root",
  "version": "1.0.0",
  "private": true,
  "engines": {
    "node": ">=10"
  },
  "scripts": {
    "release": "bash scripts/release.sh"
  },
  "devDependencies": {
    "np": "*"
  }
}

Alternatives

People generally use lerna to manage multi-packages repositories.

@fregante
Copy link
Collaborator

fregante commented Jul 7, 2020

Monorepos add a whole 'nother layer of complexity that np doesn't need. Just use lerna for monorepos.

@dopecodez
Copy link
Collaborator

I agree, this would be a completely different layer of complexity. Closing this for now.

@mesqueeb
Copy link

I would like to vote a +1 for monorepos.

The only thing I'd need from np is that its executed for each package, and that the package.json version is synced throughout all packages in the monorepo.

I don't think it's a completely different layer of complexity.

lerna release is waaaay less nice of a tool than np imo. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants