Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
"$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"fixed": [
[
"@naverpay/commithelper-go",
"@naverpay/commithelper-go-darwin-arm64",
"@naverpay/commithelper-go-darwin-x64",
"@naverpay/commithelper-go-linux-x64",
"@naverpay/commithelper-go-win32-x64"
]
],
"linked": [],
"access": "public",
"baseBranch": "main",
Expand Down
17 changes: 17 additions & 0 deletions .changeset/platform-binary-packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@naverpay/commithelper-go": minor
"@naverpay/commithelper-go-darwin-arm64": minor
"@naverpay/commithelper-go-darwin-x64": minor
"@naverpay/commithelper-go-linux-x64": minor
"@naverpay/commithelper-go-win32-x64": minor
---

Split Go binaries into platform-specific npm packages

Each platform now has a dedicated package (`@naverpay/commithelper-go-darwin-arm64`, `-darwin-x64`, `-linux-x64`, `-win32-x64`) declared as `optionalDependencies`. pnpm/npm automatically installs only the package matching the current OS and CPU.

This removes the `postinstall` script that previously downloaded binaries via `curl` from GitHub Releases, which means:

- No more `onlyBuiltDependencies` registration required in consuming projects
- No more `--ignore-scripts` needed in CI
- Works in Nexus environments (binaries are bundled in the npm package, no external download)
72 changes: 72 additions & 0 deletions .github/workflows/test-commithelper-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: test commithelper-go

on:
pull_request:
paths:
- 'packages/commithelper-go/**'
- 'packages/commithelper-go-*/**'

jobs:
test:
strategy:
matrix:
include:
- os: ubuntu-latest
goos: linux
goarch: amd64
binary: commithelper-go
pkg: commithelper-go-linux-x64
- os: macos-latest
goos: darwin
goarch: arm64
binary: commithelper-go
pkg: commithelper-go-darwin-arm64
- os: windows-latest
goos: windows
goarch: amd64
binary: commithelper-go.exe
pkg: commithelper-go-win32-x64

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.24'

- uses: pnpm/action-setup@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build binary
working-directory: packages/commithelper-go
run: go build -o ../commithelper-go-${{ matrix.goos }}-test/${{ matrix.binary }} main.go
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}

- name: Copy binary to platform package
shell: bash
run: cp packages/commithelper-go-${{ matrix.goos }}-test/${{ matrix.binary }} packages/${{ matrix.pkg }}/${{ matrix.binary }}

- name: Verify binary exists
shell: bash
run: ls -la packages/${{ matrix.pkg }}/${{ matrix.binary }}

- name: Test CLI execution
shell: bash
run: |
chmod +x packages/${{ matrix.pkg }}/${{ matrix.binary }}
echo "test commit message" > /tmp/test-msg.txt
node packages/commithelper-go/bin/cli.js /tmp/test-msg.txt
echo "CLI executed successfully with exit code $?"
18 changes: 0 additions & 18 deletions .size-limit.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@naverpay/cli",
"private": true,
"author": "@NaverPayDev/frontend",
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,10 +37,8 @@
"@naverpay/prettier-config": "^0.0.2",
"@size-limit/preset-big-lib": "^11.0.2",
"@types/node": "^20.12.7",
"glob": "^9.3.4",
"husky": "^8.0.3",
"lint-staged": "^15.0.1",
"size-limit": "^11.0.2",
"turbo": "^1.10.16",
"typescript": "^5.2.2"
},
Expand Down
1 change: 1 addition & 0 deletions packages/commithelper-go-darwin-arm64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
commithelper-go
20 changes: 20 additions & 0 deletions packages/commithelper-go-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@naverpay/commithelper-go-darwin-arm64",
"version": "1.2.0",
"description": "macOS ARM64 binary for @naverpay/commithelper-go",
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-darwin-arm64"
},
"homepage": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-darwin-arm64",
"files": [
"commithelper-go"
]
}
1 change: 1 addition & 0 deletions packages/commithelper-go-darwin-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
commithelper-go
20 changes: 20 additions & 0 deletions packages/commithelper-go-darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@naverpay/commithelper-go-darwin-x64",
"version": "1.2.0",
"description": "macOS x64 binary for @naverpay/commithelper-go",
"os": [
"darwin"
],
"cpu": [
"x64"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-darwin-x64"
},
"homepage": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-darwin-x64",
"files": [
"commithelper-go"
]
}
1 change: 1 addition & 0 deletions packages/commithelper-go-linux-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
commithelper-go
20 changes: 20 additions & 0 deletions packages/commithelper-go-linux-x64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@naverpay/commithelper-go-linux-x64",
"version": "1.2.0",
"description": "Linux x64 binary for @naverpay/commithelper-go",
"os": [
"linux"
],
"cpu": [
"x64"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-linux-x64"
},
"homepage": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-linux-x64",
"files": [
"commithelper-go"
]
}
1 change: 1 addition & 0 deletions packages/commithelper-go-win32-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
commithelper-go.exe
20 changes: 20 additions & 0 deletions packages/commithelper-go-win32-x64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@naverpay/commithelper-go-win32-x64",
"version": "1.2.0",
"description": "Windows x64 binary for @naverpay/commithelper-go",
"os": [
"win32"
],
"cpu": [
"x64"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-win32-x64"
},
"homepage": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go-win32-x64",
"files": [
"commithelper-go.exe"
]
}
36 changes: 10 additions & 26 deletions packages/commithelper-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ npm install -g @naverpay/commithelper-go
### .husky/commit-msg

```bash
npx --yes @naverpay/commithelper-go@latest "$1"
node node_modules/@naverpay/commithelper-go/bin/cli.js "$1"
```

> `@latest` is not necessary but this option always provides latest version of commithelper-go.
Expand All @@ -39,14 +39,14 @@ npx --yes @naverpay/commithelper-go@latest "$1"
commit-msg:
commands:
commithelper:
run: npx --yes @naverpay/commithelper-go@latest {1}
run: node node_modules/@naverpay/commithelper-go/bin/cli.js {1}
```

### Manual execution

```bash
npx @naverpay/commithelper-go "your commit message"
```
> [!TIP]
>
> `npx` adds ~460ms of overhead even when the package is installed locally.
> Calling `node cli.js` directly takes ~76ms — **about 6x faster** than `npx`.
> For hooks that run on every commit, direct `node` invocation is recommended.

## What it does

Expand Down Expand Up @@ -125,7 +125,7 @@ This is Basic rule of `.commithelperrc.json`.
"rules": {
"feature": null
},
"template": "{{.Message}}\n\nRef. #{{.Number}}"
"template": "{{.Message}}\n\nRef. [#{{.Number}}]"
}
```

Expand All @@ -134,7 +134,7 @@ Result:
```
:memo: Update documentation

Ref. #123
Ref. [#123]
```

**Example 2: Custom format with repository**
Expand Down Expand Up @@ -192,25 +192,9 @@ Result:
> - commit on `qa/1` branch will be tagged as `[your-org/your-repo#1]`.
> - direct commit attempt toward `main`, `master`, `develop`, `epic/*` branch will be blocked

## Environment Variables

### SKIP_COMMIT_HELPER_POSTINSTALL

You can skip the postinstall script (binary download) by setting the `SKIP_COMMIT_HELPER_POSTINSTALL` environment variable:

```bash
SKIP_COMMIT_HELPER_POSTINSTALL=1 npm install @naverpay/commithelper-go
```

This is useful in environments where:

- Network access is restricted
- You want to manage binary installation manually
- Running in CI/CD environments where postinstall scripts should be skipped

## Platform Support

The CLI automatically downloads the appropriate binary for your platform during installation:
The appropriate platform-specific binary package is automatically installed via `optionalDependencies`.

- **macOS**: Intel (x64) and Apple Silicon (arm64)
- **Linux**: x64
Expand Down
29 changes: 21 additions & 8 deletions packages/commithelper-go/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
#!/usr/bin/env node
const {spawnSync} = require('child_process')
const fs = require('fs')
const {platform, arch} = require('os')
const path = require('path')

const binaries = {
'darwin-x64': 'commithelper-go-darwin-amd64',
'darwin-arm64': 'commithelper-go-darwin-arm64',
'linux-x64': 'commithelper-go-linux-amd64',
'win32-x64': 'commithelper-go-windows-amd64.exe',
const pkgMap = {
'darwin-x64': '@naverpay/commithelper-go-darwin-x64',
'darwin-arm64': '@naverpay/commithelper-go-darwin-arm64',
'linux-x64': '@naverpay/commithelper-go-linux-x64',
'win32-x64': '@naverpay/commithelper-go-win32-x64',
}

const key = `${platform()}-${arch()}`
const binaryName = binaries[key]
const pkgName = pkgMap[key]

if (!binaryName) {
if (!pkgName) {
// eslint-disable-next-line no-console
console.error(`Unsupported platform: ${platform()} ${arch()}`)
process.exit(1)
}

const binaryPath = path.join(__dirname, binaryName)
let binaryPath
try {
const pkgDir = path.dirname(require.resolve(`${pkgName}/package.json`))
const binaryName = platform() === 'win32' ? 'commithelper-go.exe' : 'commithelper-go'
binaryPath = path.join(pkgDir, binaryName)
try {
fs.chmodSync(binaryPath, 0o755)
} catch (_) {}
} catch (e) {
// eslint-disable-next-line no-console
console.error(`Platform package ${pkgName} is not installed. Please reinstall @naverpay/commithelper-go.`)
process.exit(1)
}

const args = process.argv.slice(2)
const result = spawnSync(binaryPath, args, {stdio: 'inherit'})
Expand Down
20 changes: 12 additions & 8 deletions packages/commithelper-go/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
},
"homepage": "https://github.com/NaverPayDev/cli/tree/main/packages/commithelper-go",
"scripts": {
"build:windows": "GOOS=windows GOARCH=amd64 go build -o dist/commithelper-go-windows-amd64.exe main.go",
"build:macos:amd64": "GOOS=darwin GOARCH=amd64 go build -o dist/commithelper-go-darwin-amd64 main.go",
"build:macos:arm64": "GOOS=darwin GOARCH=arm64 go build -o dist/commithelper-go-darwin-arm64 main.go",
"build:linux": "GOOS=linux GOARCH=amd64 go build -o dist/commithelper-go-linux-amd64 main.go",
"build": "pnpm build:windows && pnpm build:macos:amd64 && pnpm build:macos:arm64 && pnpm build:linux",
"postinstall": "node ./scripts/downloadBinary.js"
"build:windows": "GOOS=windows GOARCH=amd64 go build -o ../commithelper-go-win32-x64/commithelper-go.exe main.go",
"build:macos:amd64": "GOOS=darwin GOARCH=amd64 go build -o ../commithelper-go-darwin-x64/commithelper-go main.go",
"build:macos:arm64": "GOOS=darwin GOARCH=arm64 go build -o ../commithelper-go-darwin-arm64/commithelper-go main.go",
"build:linux": "GOOS=linux GOARCH=amd64 go build -o ../commithelper-go-linux-x64/commithelper-go main.go",
"build": "pnpm build:windows && pnpm build:macos:amd64 && pnpm build:macos:arm64 && pnpm build:linux"
},
"optionalDependencies": {
"@naverpay/commithelper-go-darwin-arm64": "workspace:*",
"@naverpay/commithelper-go-darwin-x64": "workspace:*",
"@naverpay/commithelper-go-linux-x64": "workspace:*",
"@naverpay/commithelper-go-win32-x64": "workspace:*"
},
"author": "",
"license": "MIT",
"files": [
"bin",
"scripts"
"bin"
]
}
Loading
Loading