Skip to content

This library facilitates the publication of packages encompassing multiple workspaces as defined in a package.json file.

Notifications You must be signed in to change notification settings

tada5hi/workspaces-publish

Repository files navigation

workspaces-publish 📦

npm version Master Workflow Known Vulnerabilities Conventional Commits

This library facilitates the publication of packages encompassing multiple workspaces as defined in a package.json file. It determines the unpublished packages by checking each package manifest of the registry, if one already exists.

At best, it should be used with a library that increments the version of the packages beforehand (e.g. release-please).

It is based on the packages (libnpmpublish, libnpmpack) that the npm cli uses to publish packages.

Table of Contents

Installation

npm install workspaces-publish --save-dev

Usage

npx workspaces-publish \
  --token <token> \
  --registry <registry> \
  --root <root> \
  --rootPackage <rootPackage>

token

  • Type: String
  • Default: process.env.NODE_AUTH_TOKEN
  • Description: Token for the registry.

registry

  • Type: String
  • Default: https://registry.npmjs.org/
  • Description: Registry url.

root

  • Type: String
  • Default: process.cwd()
  • Description: Directory where the root package is located.

rootPackage

  • Type: Boolean
  • Default: true
  • Description: Also consider the root package for publishing. The library still checks whether a name- & version-property is set and whether the private property evaluates to false.

CI

GitHub Action

The library can also be used in combination with release-please, as release-please only increases the versions in the monorepo, but does not release the packages.

on:
    push:
        branches:
            - main

permissions:
    contents: write
    pull-requests: write

jobs:
    release:
        runs-on: ubuntu-latest
        steps:
            -   uses: google-github-actions/release-please-action@v4
                id: release
                with:
                    token: ${{ secrets.GITHUB_TOKEN }}

            -   name: Checkout
                if: steps.release.outputs.releases_created == 'true'
                uses: actions/checkout@v4

            -   name: Install Node.JS
                if: steps.release.outputs.releases_created == 'true'
                uses: actions/setup-node@v4
                with:
                    node-version: 18
            
            -   name: Install dependencies
                if: steps.release.outputs.releases_created == 'true'
                run: npm ci

            -   name: Publish
                if: steps.release.outputs.releases_created == 'true'
                run: npx workspaces-publish
                env:
                    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}