GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cli/npm at main · kosli-dev/cli

Expand file tree

/

npm

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

npm

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
cli-darwin-arm64
cli-darwin-arm64
 
 
cli-darwin-x64
cli-darwin-x64
 
 
cli-linux-arm
cli-linux-arm
 
 
cli-linux-arm64
cli-linux-arm64
 
 
cli-linux-x64
cli-linux-x64
 
 
cli-win32-arm64
cli-win32-arm64
 
 
cli-win32-x64
cli-win32-x64
 
 
wrapper
wrapper
 
 
README.md
README.md
 
 

README.md

Outline

NPM Packaging

This directory contains the npm package structure for distributing the Kosli CLI via npm, following the same pattern used by esbuild.

Structure

npm/
├── wrapper/              # @kosli/cli — the package users install
│   ├── bin/kosli         # JS shim that detects the platform and runs the binary
│   ├── install.js        # postinstall script that validates the binary
│   └── package.json      # declares optionalDependencies for all platforms
├── cli-darwin-arm64/     # @kosli/cli-darwin-arm64
│   ├── bin/kosli         # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
├── cli-darwin-x64/       # @kosli/cli-darwin-x64
│   ├── bin/kosli         # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
├── cli-linux-arm/        # @kosli/cli-linux-arm
│   ├── bin/kosli         # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
├── cli-linux-arm64/      # @kosli/cli-linux-arm64
│   ├── bin/kosli         # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
├── cli-linux-x64/        # @kosli/cli-linux-x64
│   ├── bin/kosli         # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
├── cli-win32-arm64/      # @kosli/cli-win32-arm64
│   ├── bin/kosli.exe     # the native binary — see below
│   └── package.json      # declares os/cpu fields for platform filtering
└── cli-win32-x64/        # @kosli/cli-win32-x64
    ├── bin/kosli.exe     # the native binary — see below
    └── package.json      # declares os/cpu fields for platform filtering

How it works

Users install a single package:

npm install @kosli/cli

or if using in continuous integration you can install globally:

npm install -g @kosli/cli

npm resolves the optionalDependencies declared in the wrapper's package.json and installs only the platform-specific package that matches the current OS and CPU architecture — all non-matching packages are silently skipped. The wrapper's bin/kosli JS shim then locates the binary inside the installed platform package and executes it.

npx is not supported. npx @kosli/cli does not install optional dependencies, so the platform binary is never fetched and the command fails. Always install the package before running it.

The bin/ directories are populated by goreleaser

The platform package bin/ directories are not committed to git. They are populated automatically during the release process by a post-build hook in .goreleaser.yml:

hooks:
  post:
    - cmd: >-
        bash -c '
        OS="{{ .Os }}";
        ARCH="{{ .Arch }}";
        [ "$OS" = "windows" ] && OS="win32";
        [ "$ARCH" = "amd64" ] && ARCH="x64";
        EXT="";
        [ "{{ .Os }}" = "windows" ] && EXT=".exe";
        mkdir -p npm/cli-${OS}-${ARCH}/bin &&
        cp "{{ .Path }}" npm/cli-${OS}-${ARCH}/bin/kosli${EXT} &&
        chmod +x npm/cli-${OS}-${ARCH}/bin/kosli${EXT}'

This hook runs once per build target immediately after goreleaser compiles the binary. It applies the following naming conventions:

goreleaser npm package dir
linux linux
darwin darwin
windows win32
amd64 x64
arm64 arm64
arm arm

Windows binaries are copied as kosli.exe; all others as kosli. The windows/arm combination is excluded from builds.

The before hooks in .goreleaser.yml clean up stale artifacts before each build run:

before:
  hooks:
    - rm -rf npm/cli-*/bin
    - find npm -name "*.tgz" -delete

Publishing

Packages are published to the npm public registry. Platform packages must be published before the wrapper, since the wrapper's optionalDependencies references them by version. After a goreleaser build has populated the bin/ directories:

# Publish platform packages first
(cd npm/cli-linux-x64    && npm publish)
(cd npm/cli-linux-arm64  && npm publish)
(cd npm/cli-linux-arm    && npm publish)
(cd npm/cli-darwin-x64   && npm publish)
(cd npm/cli-darwin-arm64 && npm publish)
(cd npm/cli-win32-x64    && npm publish)
(cd npm/cli-win32-arm64  && npm publish)

# Then publish the wrapper
(cd npm/wrapper && npm publish)

The package publishing expects the package is configured for Trusted publishing - so if more platforms are added you must configure the new packages accordingly.

Automated Publishing with npm-publish.sh

The scripts/npm-publish.sh script automates the npm packaging and publishing process. It injects the version into all package.json files, packs each package into a .tgz, and optionally publishes them.

Usage

scripts/npm-publish.sh <version> [--dry-run]

Arguments

  • <version>: Required. A SemVer string — either X.Y.Z (stable) or X.Y.Z-TAG (pre-release).
  • --dry-run (optional second argument): Pack packages but skip publishing.

Behavior

  1. Injects <version> into the version field of all package.json files.
  2. Updates the optionalDependencies version references in npm/wrapper/package.json to match.
  3. Runs npm pack on each platform package, then on the wrapper.
  4. Unless --dry-run is set, runs npm publish --tag <tag> on each package.

The dist-tag is determined by the version format:

Version format npm dist-tag
X.Y.Z latest
X.Y.Z-* snapshot

Integration with GoReleaser

GoReleaser calls this script automatically via the after hook once all platform binaries have been built and copied into the bin/ directories:

after:
  hooks:
    - cmd: bash scripts/npm-publish.sh "{{ .Version }}" ...
      output: true

The script output is surfaced in the goreleaser log (output: true).

Versioning

All packages share the same version number. When releasing, npm-publish.sh updates it automatically in all eight package.json files — the seven platform packages and the wrapper — as well as the optionalDependencies version pins in npm/wrapper/package.json. There is no need to edit these files manually.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.