Skip to content

feat: distribute CLI via npm#213

Open
tkrugg wants to merge 6 commits intomainfrom
feat/npm-package
Open

feat: distribute CLI via npm#213
tkrugg wants to merge 6 commits intomainfrom
feat/npm-package

Conversation

@tkrugg
Copy link
Copy Markdown
Collaborator

@tkrugg tkrugg commented May 7, 2026

Summary

  • Adds @algolia/cli to npm so users can install/run the CLI without Homebrew or a direct binary download
  • Uses the platform-specific optional packages pattern (same as esbuild, bun, turbo): one coordinator package with 6 platform packages as optionalDependencies
  • Publish runs automatically after GoReleaser on every v* tag; npm version is offset by +4 (Go v1.x → npm 5.x) to supersede the old abandoned @algolia/cli v4 package

Usage after release

# global install
npm install -g @algolia/cli
algolia --version

# one-off
npx @algolia/cli --help

What's included

File Purpose
npm/algolia/ Coordinator package (@algolia/cli) with Node.js shim
npm/algolia-{darwin,linux,win32}-{x64,arm64}/ Per-platform binary packages
scripts/npm-publish.sh Copies GoReleaser dist binaries and publishes all 7 packages
.github/workflows/releases.yml Adds Node.js setup + publish step after GoReleaser
.gitignore Scopes the algolia ignore rule to repo root so npm/algolia/ is tracked

Pre-requisites (already done)

  • NPM_TOKEN secret added to repo GitHub Actions secrets

Adds @algolia/cli to npm so users can install with `npm install -g @algolia/cli`
or run with `npx @algolia/cli`. Uses the esbuild/bun pattern: one coordinator
package with six platform-specific optional dependencies that each ship the
native Go binary. The publish step runs automatically after GoReleaser on
every v* tag push.

- npm/algolia/ — coordinator package (@algolia/cli) with Node.js shim
- npm/algolia-{darwin,linux,win32}-{x64,arm64}/ — per-platform binary packages
- scripts/npm-publish.sh — copies dist binaries and publishes all 7 packages
- .github/workflows/releases.yml — adds Node.js setup + publish step after GoReleaser
- .gitignore — scope the `algolia` ignore rule to the repo root to allow npm/algolia/
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 7, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes.

@sarahdayan
Copy link
Copy Markdown
Member

You can do without NPM_TOKEN and instead use OIDC, which is the recommended way of publishing to npm since they sunsetted classic tokens.

This way, we will never need to rotate tokens.

@tkrugg
Copy link
Copy Markdown
Collaborator Author

tkrugg commented May 7, 2026

You can do without NPM_TOKEN and instead use OIDC, which is the recommended way of publishing to npm since they sunsetted classic tokens.

This way, we will never need to rotate tokens.

Thanks! I didn't know about OIDC ☺️
reading the docs it looks like I need to publish the 6 packages manually first before I can claim them on NPM (currently packages don't exist, I wanted this PR to create them)
is that correct?

I see an issue confirming this it seems: npm/cli#8544

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an npm distribution channel for the Algolia CLI using a coordinator package (@algolia/cli) plus platform-specific optional dependency packages, and wires publishing into the tag-based release workflow.

Changes:

  • Introduces npm packages under npm/ (coordinator + 6 platform packages) and a Node.js shim to execute the packaged Go binary.
  • Adds scripts/npm-publish.sh to version/copy binaries from GoReleaser dist/ and publish all npm packages.
  • Updates the release GitHub Actions workflow to set up Node.js and publish to npm after GoReleaser; adjusts .gitignore to allow tracking npm/algolia/.

Reviewed changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/npm-publish.sh New publish script to version/copy GoReleaser artifacts into npm packages and publish them
npm/algolia/README.md Coordinator package README and usage/docs
npm/algolia/package.json Defines @algolia/cli coordinator with optionalDependencies and algolia bin shim
npm/algolia/bin/run.js Node shim that selects and executes the correct platform binary
npm/algolia-darwin-x64/package.json macOS x64 binary package metadata
npm/algolia-darwin-x64/index.js Exports bin path for macOS x64 package
npm/algolia-darwin-arm64/package.json macOS arm64 binary package metadata
npm/algolia-darwin-arm64/index.js Exports bin path for macOS arm64 package
npm/algolia-linux-x64/package.json Linux x64 binary package metadata
npm/algolia-linux-x64/index.js Exports bin path for Linux x64 package
npm/algolia-linux-arm64/package.json Linux arm64 binary package metadata
npm/algolia-linux-arm64/index.js Exports bin path for Linux arm64 package
npm/algolia-win32-x64/package.json Windows x64 binary package metadata
npm/algolia-win32-x64/index.js Exports bin path for Windows x64 package
npm/algolia-win32-arm64/package.json Windows arm64 binary package metadata
npm/algolia-win32-arm64/index.js Exports bin path for Windows arm64 package
.gitignore Scopes /algolia ignore rule so npm/algolia/ is not ignored
.github/workflows/releases.yml Adds Node setup + npm publish step after GoReleaser

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/npm-publish.sh
pkg="${entry%%:*}"
dist_path="${entry#*:}"
src="$DIST_DIR/$dist_path"
dest_dir="$NPM_DIR/$pkg/bin"
Comment thread scripts/npm-publish.sh
Comment on lines +53 to +56
for entry in "${PLATFORMS[@]}"; do
pkg="${entry%%:*}"
# Pin the optionalDependency version in the coordinator package.json to match the published platform packages
sed -i.bak "s|\"@algolia/$pkg\": \"[^\"]*\"|\"@algolia/$pkg\": \"$VERSION\"|g" "$NPM_DIR/algolia/package.json"
Comment thread scripts/npm-publish.sh
Comment on lines +41 to +43
if [[ -z "$DRY_RUN" ]]; then
cp "$src" "$dest_dir/$binary_name"
if [[ "$binary_name" != *.exe ]]; then
Comment thread npm/algolia/README.md

The official Algolia CLI lets you manage your Algolia resources — indices, records, API keys, and synonyms — directly from the command line.

> This package installs a prebuilt Go binary. No Node.js runtime dependency is required after install.
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

Successfully merging this pull request may close these issues.

3 participants