Skip to content

Publishing to npm ​

When a package.json exists in the project root, @neosjs/release automatically enables the built-in npm plugin, which reads and bumps the version field in package.json and, when publishing is enabled, publishes the package to the npm registry.

Note the default: unlike release-it, npm.publish in @neosjs/release defaults to false (the version number is bumped but the package is not published). To publish to npm, set npm.publish: true explicitly in your configuration file or pass --npm.publish on the command line.

  • To skip only the publish step but still update the version in package.json: keep the default npm.publish: false (or set "private": true in package.json).
  • To neither read nor modify package.json, and not publish: use --no-npm or configure npm: false.

Pre-publish Checks and Automatic Login ​

When npm.publish: true, the package is not private (private !== true), and npm.skipChecks: true is not set, the following checks run in parallel during the init stage (default timeout 10 seconds, controlled by npm.timeout):

  1. Registry connectivity check: npm ping
  2. Authentication check: npm whoami
  3. Collaborator permission check: npm access list collaborators --json <pkg> (npm access ls-collaborators on npm <= 9), verifying that the current user has write access
  4. Published version check: npm show <pkg>@<tag> version; a warning is printed if the version has not been published yet or differs from the local package.json

Automatic Login in Interactive Mode ​

If you are not logged in (error code ENEEDAUTH or E401) in interactive mode (not --ci, not --dry-run, and stdin is a TTY), @neosjs/release automatically inherits the terminal and runs npm login; once login completes, it re-checks authentication and continues the release.

Automatic login happens during the init stage, and the before:init hook runs before login. For that reason, it is recommended to put time-consuming checks such as lint and test in after:init.

Private Registry Compatibility ​

  • publishConfig.registry in package.json (and any configuration key ending in registry) is automatically read as the target registry and passed along with the --registry argument.
  • publishConfig.publicPath lets you customize the URL path of the package page printed after a successful publish (default /package).
  • Some private registries (such as Nexus and Verdaccio) do not support npm ping, npm whoami, or npm access: on E400 / E404 responses, the tool prints a warning and continues; you can also set npm.skipChecks: true to skip all checks.

Pre-release Safety Checks ​

@neosjs/release ships with two safety checks that work out of the box. They are enabled by default and print warnings; setting npm.strictChecks to true turns the warnings into blocking errors (npm.skipChecks: true skips these checks as well).

1. Potential Breaking Change Detection (npm.checkBreakingChanges) ​

During the beforeBump stage, when the target version does not reach the breaking level (1.x+ without a major bump, or 0.x without a minor/major bump), the current package.json is compared with the one at the previous tag (<latestTag>:package.json) to automatically detect the following risks:

  • An engines.node restriction was added, or the minimum engines.node version was raised
  • The type field changed (commonjs ↔ module)
  • An existing entry field was removed: main, module, types, typings
  • An existing bin CLI command was removed
  • The exports field was added or removed, an existing exports subpath was removed, or the CommonJS (require) condition entry in exports was removed

(--canary mode and --no-increment mode skip this check automatically.)

2. Package Contents Scan (npm.checkFiles) ​

Before running publish, npm pack <publishPath> --dry-run --json is run automatically to print the number of files about to be published along with the packed and unpacked sizes, and to scan for two kinds of suspicious files:

  • Potentially sensitive files: .env / .env.* (.env.example / .sample / .template / .dist are allowed automatically), .npmrc, .pypirc, .netrc, id_rsa*, id_ed25519*, credentials.*, secret* / secrets.*, *.pem, *.key, *.p12, *.pfx.
  • Potentially development/test files: .git/, .github/, .vscode/, .idea/, coverage/, .nyc_output/, top-level test/ / tests/ / __tests__/ / __mocks__/ / __fixtures__/ / e2e/, .DS_Store, Thumbs.db, *.test.*, *.spec.*.

Example of enabling strict mode:

ts
export default {
  npm: {
    publish: true,
    checkFiles: true,
    checkBreakingChanges: true,
    strictChecks: true
  }
}

dist-tag Resolution Rules (npm.tag) ​

When npm.tag is not set manually, the tool decides the publish tag automatically in the following order of priority:

  1. Stable versions: always latest.
  2. Pre-release versions:
    • The string pre-release identifier is extracted from the version number first (for example 2.0.0-beta.1 → beta, 1.0.0-rc.0 → rc).
    • If the pre-release segment of the version is purely numeric and cannot be inferred (for example 1.0.1-0), and a publish will actually run this time, the npm registry's dist-tags are queried: a non-latest tag that already points to the current version is reused first, otherwise the first existing non-latest tag is used; if the registry has no pre-release tags yet, next is used by default.
  3. --canary mode: set automatically to the identifier passed to --canary (default canary), so nothing is published to latest by mistake.

Publishing with pnpm or bun ​

npm.publishPackageManager specifies the package manager used to publish. It supports 'npm' (default), 'pnpm', or 'bun':

json
{
  "npm": {
    "publish": true,
    "publishPackageManager": "pnpm",
    "publishArgs": ["--no-git-checks"]
  }
}

About --no-git-checks with pnpm: the npm plugin runs before the git plugin during the release stage, when package.json and CHANGELOG.md have been modified but not yet committed. pnpm's default Git status check refuses to publish with ERR_PNPM_GIT_UNCLEAN, so --no-git-checks must be passed in publishArgs.

npm.publishPackageManager only affects the publish (and stage publish) command; the version bump (npm version) and the pre-checks still run through npm.

Two-Factor Authentication (2FA) ​

  • One-time password (TOTP):
    • In interactive mode, if npm returns an error requiring an OTP, you are prompted to enter the one-time password and the publish is retried automatically.
    • You can also provide it directly on the command line: release --npm.otp=123456.
  • Security keys / Passkeys (WebAuthn):
    • In interactive mode (including --only-version) and when not in npm.stage mode, the publish command inherits the current terminal's stdin/stdout so that npm can open the browser authorization link directly or wait for the hardware key confirmation.
    • CI mode (--ci) does not inherit the terminal.

Staged Publishing ​

With npm.stage: true enabled, the tool runs npm stage publish (or pnpm stage publish) and submits the package to npm's staging queue:

  • No 2FA is required at submission time, which makes it ideal for building and submitting packages automatically in CI/CD pipelines.
  • It requires npm >= 11.15.0 or pnpm >= 11.3.0 (the version is verified automatically during initialization; if the requirement is not met, the tool fails early).
  • After the submission completes, the tool prints the URL of the staging approval page along with the matching approval command:
bash
npm stage list                # List staged publishes
npm stage approve <stage-id>  # A maintainer completes 2FA approval and publishes

A successful staged submission does not mark isReleased as officially released (because it has not been approved and published yet).

Configuration Options ​

OptionTypeDefaultDescription
npm.publishbooleanfalseWhether to publish the package to the npm registry
npm.publishPathstring'.'Directory to publish (for example 'dist')
npm.publishArgsstring[] | string[]Extra arguments passed to the publish command (for example ['--access', 'public'], ['--provenance'])
npm.publishPackageManager'npm' | 'pnpm' | 'bun''npm'Package manager used to publish
npm.stagebooleanfalseEnable npm staged publishing (stage publish)
npm.tagstring | nullnullManually specify the dist-tag to publish to
npm.otpstring | nullnullOne-time password (TOTP)
npm.ignoreVersionbooleanfalseWhen true, the version in package.json is ignored and the current version is determined by Git tags or other plugins instead
npm.allowSameVersionbooleanfalseAllow the new version to be the same as the current package.json version (--allow-same-version)
npm.versionArgsstring[] | string[]Extra arguments passed to npm version
npm.skipChecksbooleanfalseSkip the registry connectivity, authentication, and collaborator checks as well as the checkFiles / checkBreakingChanges checks
npm.checkFilesbooleantrueRun npm pack --dry-run --json before publishing to scan for potentially sensitive or development/test files
npm.checkBreakingChangesbooleantrueCompare against the package.json at the previous tag to detect potential breaking changes
npm.strictChecksbooleanfalseWhen true, turns the checkFiles and checkBreakingChanges warnings into blocking errors
npm.timeoutnumber10Timeout of the npm registry pre-checks (in seconds)

Complete Default Configuration ​

ts
{
  npm: {
    publish: false,
    publishPath: '.',
    publishArgs: [],
    publishPackageManager: 'npm',
    tag: null,
    stage: false,
    otp: null,
    ignoreVersion: false,
    allowSameVersion: false,
    versionArgs: [],
    skipChecks: false,
    checkFiles: true,
    checkBreakingChanges: true,
    strictChecks: false,
    timeout: 10
  }
}