@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
glabCLI 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
| Argument | Description | Default |
|---|---|---|
type | Publish type: latest, dev, beta | latest |
Options
| Option | Description |
|---|---|
--bump <type> | Version bump: patch, minor, major |
--dry-run | Run without actually publishing |
--registry-type <type> | Registry type: project, group |
--token <token> | GitLab token (overrides .env) |
--project-id <id> | GitLab Project ID |
--no-build | Skip prepublishOnly script |
--git-tag | Create git commit and tag |
--push | Push commits and tags to remote |
--verbose | Show 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
| Variable | Description | Required |
|---|---|---|
GITLAB_AUTH_TOKEN | GitLab Personal Access Token | Yes |
Required Token Scopes
api- Full API accesswrite_registry- Write package registryread_registry- Read package registry (recommended)
Package.json Requirements
Your package must have:
- A scoped name (e.g.,
@yourscope/package-name) - A
prepublishOnlyscript (if building is required)
{
"name": "@yourscope/your-package",
"version": "1.0.0",
"scripts": {
"build": "your-build-command",
"prepublishOnly": "npm run build"
}
}
How It Works
- Auto-detection: Detects project info from git remote or
glabCLI - Configuration: Creates temporary
.npmrcwith GitLab registry settings - Build: Runs
prepublishOnlyscript (if exists) - Publishing: Runs
npm publishwith appropriate settings - Cleanup: Removes temporary
.npmrcfor security
Troubleshooting
403 Forbidden
Ensure your token has the correct scopes:
apiwrite_registryread_registry
Project ID Not Found
Make sure:
- You have authenticated with
glab auth login - You are in a Git repository with GitLab remote
- The repository exists on GitLab
No prepublishOnly Script
Either add a prepublishOnly script or use --no-build flag.