You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: NPM_RELEASE.md
+73-39Lines changed: 73 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,12 @@ This document describes how to release the Kosli CLI as an npm package.
4
4
5
5
## Overview
6
6
7
-
The Kosli CLI is primarily a Go binary, but we also publish it as an npm package for easy installation in JavaScript/TypeScript projects. The npm package downloads the appropriate platform-specific binary during installation.
7
+
The Kosli CLI is primarily a Go binary, but we also publish it as an npm package for easy installation in JavaScript/TypeScript projects.
8
+
9
+
**Important:** The published npm package is small (~5KB) and does NOT include the binary. Instead, it downloads the appropriate platform-specific binary from GitHub releases during installation. This approach:
10
+
- ✅ Keeps the package small
11
+
- ✅ Works on all platforms (downloads the correct binary for each user)
12
+
- ✅ Requires that a GitHub release exists before publishing to npm
8
13
9
14
## Package Structure
10
15
@@ -19,38 +24,49 @@ All npm packaging files are located in the `npm-package/` directory:
19
24
20
25
## Release Process
21
26
27
+
### Prerequisites
28
+
29
+
**IMPORTANT:** Before publishing to npm, ensure that:
30
+
1. A GitHub release exists for the version you want to publish
31
+
2. The release includes binaries for all supported platforms (darwin/linux/windows, amd64/arm64)
32
+
3. You have publish permissions to the `@kosli` organization on npm
33
+
22
34
### 1. Test Locally
23
35
24
-
The test script automatically extracts the version from the kosli binary and updates `package.json`. Before publishing, test the package locally:
36
+
Test the package with a bundled binary (for local validation):
25
37
26
38
```bash
27
39
# Run the automated test script
28
40
./test-npm-package.sh
29
41
```
30
42
31
-
This script will:
32
-
- Build the kosli binary (if not already built)
33
-
- Copy the binary to `npm-package/bin/`
34
-
- Extract the version from the binary and update `package.json`
35
-
- Pack the npm package
36
-
- Install it in a temporary directory
37
-
- Run tests to verify installation
38
-
- Clean up
43
+
This script:
44
+
- Builds the kosli binary (if not already built)
45
+
-**Includes the binary** in the package for testing
46
+
- Extracts the version from the binary and updates `package.json`
47
+
- Packs and installs the package in a temporary directory
48
+
- Runs tests to verify installation
39
49
40
-
### 2. Publish to npm
50
+
**Note:** This test includes the binary, but production publishing should NOT include it.
41
51
42
-
```bash
43
-
# Login to npm (first time only)
44
-
npm login
52
+
### 2. Publish to npm (Small Package Approach)
45
53
46
-
# Navigate to npm-package directory
47
-
cd npm-package
54
+
Use the dedicated publish script that publishes WITHOUT the binary:
48
55
49
-
# Publish the package (npm will automatically pack it)
50
-
npm publish --access public
56
+
```bash
57
+
# Run the publish script
58
+
./npm-publish.sh
51
59
```
52
60
53
-
**Note:** Make sure you have permission to publish to the `@kosli` organization on npm.
61
+
This script will:
62
+
- Extract the version from the kosli binary
63
+
- Update `package.json` version
64
+
- Verify that the GitHub release exists
65
+
- Show you what will be published
66
+
- Prompt for confirmation
67
+
- Publish the small package (~5KB) to npm
68
+
69
+
**Note:** The published package will download binaries from GitHub releases during user installation.
54
70
55
71
### 3. Automate with GitHub Actions (Recommended)
56
72
@@ -98,14 +114,17 @@ npx @kosli/cli version
98
114
99
115
## How It Works
100
116
117
+
### For End Users (npm install):
101
118
1. When `npm install` runs, the `postinstall` script (`install.js`) executes
102
-
2. The script checks if the binary already exists (for local testing)
103
-
3. If not present, it detects the platform (OS and architecture)
104
-
4. It downloads the appropriate binary from GitHub releases
105
-
5. The binary is extracted to the `bin/` directory
106
-
6. The `index.js` wrapper script forwards all commands to the binary
119
+
2. The script detects the platform (OS and architecture)
120
+
3. It downloads the appropriate binary from GitHub releases:
0 commit comments