Skip to main content

@glpkg/publisher

A CLI tool for publishing NPM packages to GitLab Package Registry.

Installation

# Install globally
npm install -g @glpkg/publisher

# Or as a dev dependency
npm install -D @glpkg/publisher

Features

  • Automatic project detection using glab CLI or git remote
  • Support for project-level and group-level registries
  • Version management (latest, dev, beta tags)
  • Secure token management
  • Dry-run mode for testing
  • Git tag support

Quick Start

1. Configure your token

Create a .env file:

GITLAB_AUTH_TOKEN=your-personal-access-token

2. Add scripts to package.json

{
"scripts": {
"prepublishOnly": "npm run build",
"publish:gitlab": "gitlab-publish",
"publish:dev": "gitlab-publish dev",
"publish:beta": "gitlab-publish beta --bump minor"
}
}

3. Publish

gitlab-publish

Usage

gitlab-publish [type] [options]

Arguments

ArgumentDescriptionDefault
typePublish type: latest, dev, betalatest

Options

OptionDescription
--bump <type>Version bump: patch, minor, major
--dry-runRun without actually publishing
--registry-type <type>Registry type: project, group
--token <token>GitLab token (overrides .env)
--project-id <id>GitLab Project ID
--no-buildSkip prepublishOnly script
--git-tagCreate git commit and tag
--pushPush commits and tags to remote
--verboseShow detailed output

Examples

Basic Publishing

# Publish current version
gitlab-publish

# Publish with patch version bump (1.0.0 -> 1.0.1)
gitlab-publish --bump patch

# Publish with git commit/tag and push
gitlab-publish --bump patch --git-tag --push

Development Versions

# Publish dev version with git commit hash
# Example: 1.0.0 -> 1.0.1-dev.abc1234
gitlab-publish dev

Beta Versions

# Publish beta version
gitlab-publish beta

# Publish beta with minor bump (1.0.0 -> 1.1.0-beta.0)
gitlab-publish beta --bump minor

Testing

# Test configuration without publishing
gitlab-publish --dry-run

# Verbose output for debugging
gitlab-publish --verbose --dry-run

Group-Level Registry

# Use group-level registry instead of project-level
gitlab-publish --registry-type group

Configuration

Environment Variables

VariableDescriptionRequired
GITLAB_AUTH_TOKENGitLab Personal Access TokenYes

Required Token Scopes

  • api - Full API access
  • write_registry - Write package registry
  • read_registry - Read package registry (recommended)

Package.json Requirements

Your package must have:

  • A scoped name (e.g., @yourscope/package-name)
  • A prepublishOnly script (if building is required)
{
"name": "@yourscope/your-package",
"version": "1.0.0",
"scripts": {
"build": "your-build-command",
"prepublishOnly": "npm run build"
}
}

How It Works

  1. Auto-detection: Detects project info from git remote or glab CLI
  2. Configuration: Creates temporary .npmrc with GitLab registry settings
  3. Build: Runs prepublishOnly script (if exists)
  4. Publishing: Runs npm publish with appropriate settings
  5. Cleanup: Removes temporary .npmrc for security

Troubleshooting

403 Forbidden

Ensure your token has the correct scopes:

  • api
  • write_registry
  • read_registry

Project ID Not Found

Make sure:

  1. You have authenticated with glab auth login
  2. You are in a Git repository with GitLab remote
  3. The repository exists on GitLab

No prepublishOnly Script

Either add a prepublishOnly script or use --no-build flag.