monoship 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Peter Placzek (tada5hi)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # monoship 📦
2
+
3
+ [![npm version](https://badge.fury.io/js/monoship.svg)](https://badge.fury.io/js/monoship)
4
+ [![CI](https://github.com/Tada5hi/monoship/workflows/CI/badge.svg)](https://github.com/Tada5hi/monoship)
5
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
6
+
7
+ A CLI tool and library for publishing packages from npm workspaces to registries (npmjs.org, GitHub Packages, etc.).
8
+ It determines which workspace packages haven't been published yet by checking each package's version against the registry,
9
+ and publishes only what's needed — making it ideal for CI/CD pipelines alongside [release-please](https://github.com/googleapis/release-please).
10
+
11
+ When npm >= 10.0.0 is available, it shells out to `npm publish` directly (supporting OIDC, provenance, etc. out of the box).
12
+ Otherwise it falls back to [libnpmpublish](https://www.npmjs.com/package/libnpmpublish) / [libnpmpack](https://www.npmjs.com/package/libnpmpack).
13
+
14
+ **Table of Contents**
15
+ - [Requirements](#requirements)
16
+ - [Installation](#installation)
17
+ - [Usage](#usage)
18
+ - [Authentication](#authentication)
19
+ - [GitHub Action](#github-action)
20
+ - [Programmatic API](#programmatic-api)
21
+ - [CI](#ci)
22
+
23
+ ## Requirements
24
+
25
+ - **Node.js** >= 22.0.0
26
+ - **npm** 7+ (workspace support required)
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install monoship --save-dev
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ```bash
37
+ npx monoship \
38
+ --token <token> \
39
+ --registry <registry> \
40
+ --root <root> \
41
+ --rootPackage
42
+ ```
43
+
44
+ ### Options
45
+
46
+ | Option | Type | Default | Description |
47
+ |--------|------|---------|-------------|
48
+ | `--token <token>` | `string` | `NODE_AUTH_TOKEN` env var | Token for the registry. Optional when using OIDC trusted publishing. |
49
+ | `--registry <registry>` | `string` | `https://registry.npmjs.org/` | Registry URL to publish to. |
50
+ | `--root <root>` | `string` | `process.cwd()` | Directory where the root `package.json` is located. |
51
+ | `--rootPackage` | `boolean` | `true` | Also consider the root package for publishing (skipped if `private: true` or missing `name`/`version`). |
52
+
53
+ ## Authentication
54
+
55
+ The tool supports three authentication methods, resolved in the following order:
56
+
57
+ 1. **`--token` CLI flag** — Explicit npm access token, used as-is.
58
+ 2. **OIDC Trusted Publishing** — Tokenless publishing via GitHub Actions OIDC (auto-detected when no `--token` flag is given). Falls back to `NODE_AUTH_TOKEN` if OIDC fails.
59
+ 3. **`NODE_AUTH_TOKEN` environment variable** — Default fallback.
60
+
61
+ ### OIDC Trusted Publishing
62
+
63
+ When running in GitHub Actions with [trusted publishers](https://docs.npmjs.com/trusted-publishers/) configured, the tool automatically detects the OIDC environment and exchanges short-lived, per-package tokens with the npm registry — no long-lived `NPM_TOKEN` secret required.
64
+
65
+ **Requirements:**
66
+ - npm trusted publisher configured for each package on [npmjs.com](https://www.npmjs.com)
67
+ - GitHub Actions workflow with `id-token: write` permission
68
+ - No `--token` flag set (OIDC is bypassed when an explicit token is provided)
69
+
70
+ **How it works:**
71
+ 1. Detects `ACTIONS_ID_TOKEN_REQUEST_URL` and `ACTIONS_ID_TOKEN_REQUEST_TOKEN` environment variables
72
+ 2. Requests an OIDC identity token from GitHub with audience `npm:<registry-host>`
73
+ 3. Exchanges the identity token with the npm registry for a short-lived, package-scoped publish token
74
+ 4. Uses that token for publishing (each package gets its own scoped token)
75
+
76
+ If OIDC token exchange fails for a package, it falls back to `NODE_AUTH_TOKEN` automatically via the chain provider.
77
+
78
+ ## GitHub Action
79
+
80
+ monoship is also available as a GitHub Action:
81
+
82
+ ```yaml
83
+ - uses: tada5hi/monoship@v2
84
+ with:
85
+ token: ${{ secrets.NPM_TOKEN }}
86
+ ```
87
+
88
+ Or with OIDC trusted publishing (no token needed):
89
+
90
+ ```yaml
91
+ - uses: tada5hi/monoship@v2
92
+ ```
93
+
94
+ ### Action Inputs
95
+
96
+ | Input | Required | Default | Description |
97
+ |-------|----------|---------|-------------|
98
+ | `token` | No | — | npm auth token. Optional when using OIDC trusted publishing. |
99
+ | `registry` | No | `https://registry.npmjs.org/` | Registry URL to publish to. |
100
+ | `root-package` | No | `true` | Also consider the root package for publishing. |
101
+ | `dry-run` | No | `false` | Show what would be published without actually publishing. |
102
+
103
+ ## Programmatic API
104
+
105
+ ```typescript
106
+ import { publish } from 'monoship';
107
+
108
+ const packages = await publish({
109
+ cwd: '/path/to/monorepo',
110
+ registry: 'https://registry.npmjs.org/',
111
+ token: 'npm_...',
112
+ rootPackage: true,
113
+ dryRun: false,
114
+ });
115
+ ```
116
+
117
+ The `publish()` function returns an array of `Package` objects for each successfully published package.
118
+
119
+ ### Options
120
+
121
+ | Option | Type | Default | Description |
122
+ |--------|------|---------|-------------|
123
+ | `cwd` | `string` | `process.cwd()` | Root directory of the monorepo. |
124
+ | `registry` | `string` | `https://registry.npmjs.org/` | Registry URL. |
125
+ | `token` | `string` | — | Auth token (wrapped in `MemoryTokenProvider` internally). |
126
+ | `rootPackage` | `boolean` | `true` | Include the root package as a publish candidate. |
127
+ | `dryRun` | `boolean` | `false` | Resolve dependencies and check versions without actually publishing. |
128
+ | `fileSystem` | `IFileSystem` | `NodeFileSystem` | File system adapter. |
129
+ | `registryClient` | `IRegistryClient` | `HapicRegistryClient` | Registry metadata adapter. |
130
+ | `publisher` | `IPackagePublisher` | Auto-detected | Publisher adapter (npm CLI or libnpmpublish). |
131
+ | `tokenProvider` | `ITokenProvider` | `EnvTokenProvider` | Token resolution adapter (overrides `token`). |
132
+ | `logger` | `ILogger` | — | Logger adapter. |
133
+
134
+ ### Custom Adapters
135
+
136
+ The library uses a hexagonal architecture — all external I/O is behind port interfaces, making it fully testable and extensible:
137
+
138
+ ```typescript
139
+ import {
140
+ publish,
141
+ MemoryFileSystem,
142
+ MemoryRegistryClient,
143
+ MemoryPublisher,
144
+ MemoryTokenProvider,
145
+ NoopLogger,
146
+ } from 'monoship';
147
+
148
+ const packages = await publish({
149
+ cwd: '/project',
150
+ fileSystem: new MemoryFileSystem({ /* virtual files */ }),
151
+ registryClient: new MemoryRegistryClient({ /* virtual packuments */ }),
152
+ publisher: new MemoryPublisher(),
153
+ tokenProvider: new MemoryTokenProvider('test-token'),
154
+ logger: new NoopLogger(),
155
+ });
156
+ ```
157
+
158
+ Available port interfaces and their adapters:
159
+
160
+ | Port | Real Adapters | Test Adapter |
161
+ |------|--------------|--------------|
162
+ | `IFileSystem` | `NodeFileSystem` | `MemoryFileSystem` |
163
+ | `IRegistryClient` | `HapicRegistryClient` | `MemoryRegistryClient` |
164
+ | `IPackagePublisher` | `NpmCliPublisher`, `NpmPublisher` | `MemoryPublisher` |
165
+ | `ITokenProvider` | `MemoryTokenProvider`, `EnvTokenProvider`, `OidcTokenProvider`, `ChainTokenProvider` | `MemoryTokenProvider` |
166
+ | `ILogger` | `ConsolaLogger` | `NoopLogger` |
167
+
168
+ ## CI
169
+
170
+ ### GitHub Actions (with npm token)
171
+
172
+ Use with [release-please](https://github.com/googleapis/release-please) — it bumps versions and creates release PRs, then monoship handles the actual publishing:
173
+
174
+ ```yaml
175
+ on:
176
+ push:
177
+ branches:
178
+ - main
179
+
180
+ permissions:
181
+ contents: write
182
+ pull-requests: write
183
+
184
+ jobs:
185
+ release:
186
+ runs-on: ubuntu-latest
187
+ steps:
188
+ - uses: google-github-actions/release-please-action@v4
189
+ id: release
190
+ with:
191
+ token: ${{ secrets.GITHUB_TOKEN }}
192
+
193
+ - name: Checkout
194
+ if: steps.release.outputs.releases_created == 'true'
195
+ uses: actions/checkout@v4
196
+
197
+ - name: Publish
198
+ if: steps.release.outputs.releases_created == 'true'
199
+ uses: tada5hi/monoship@v2
200
+ with:
201
+ token: ${{ secrets.NPM_TOKEN }}
202
+ ```
203
+
204
+ ### GitHub Actions (with OIDC Trusted Publishing)
205
+
206
+ No npm token secrets needed — configure [trusted publishers](https://docs.npmjs.com/trusted-publishers/) on npmjs.com for each package instead:
207
+
208
+ ```yaml
209
+ on:
210
+ push:
211
+ branches:
212
+ - main
213
+
214
+ permissions:
215
+ contents: write
216
+ pull-requests: write
217
+ id-token: write
218
+
219
+ jobs:
220
+ release:
221
+ runs-on: ubuntu-latest
222
+ steps:
223
+ - uses: google-github-actions/release-please-action@v4
224
+ id: release
225
+ with:
226
+ token: ${{ secrets.GITHUB_TOKEN }}
227
+
228
+ - name: Checkout
229
+ if: steps.release.outputs.releases_created == 'true'
230
+ uses: actions/checkout@v4
231
+
232
+ - name: Publish
233
+ if: steps.release.outputs.releases_created == 'true'
234
+ uses: tada5hi/monoship@v2
235
+ ```
236
+
237
+ ## License
238
+
239
+ Made with 💚
240
+
241
+ Published under [MIT](./LICENSE).
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };