Setup npm package for trusted publishing with OIDC
npm install setup-npm-trusted-publishA tool to create and publish placeholder npm packages for setting up OIDC (OpenID Connect) trusted publishing.
Unlike PyPI which allows configuring OIDC for not-yet-existing packages, npm requires a package to exist before you can configure trusted publishing. This tool helps work around that limitation by automatically creating and publishing minimal placeholder packages that clearly indicate they exist solely for OIDC setup purposes.
See: GitHub Community Discussion #127011
``bash`
npm install -g setup-npm-trusted-publish
Or run directly with npx:
`bash`
npx setup-npm-trusted-publish
`bash`
setup-npm-trusted-publish
Options:
- --dry-run - Create the package but don't publish--access
- - Access level for scoped packages (default: public)
Examples:
`bashCreate and publish a regular package
setup-npm-trusted-publish my-package
What it does
This tool:
1. Creates a minimal npm package in a temporary directory
2. Generates a
package.json with basic metadata for OIDC setup
3. Creates a README.md that clearly states the package is for OIDC setup only
4. Automatically publishes the package to npm
5. Cleans up the temporary directory
6. Provides a direct link to configure OIDC at https://www.npmjs.com/package/The generated README explicitly indicates:
- The package is NOT functional
- It contains NO code
- It exists ONLY for OIDC configuration
- It should NOT be used as a dependency
Workflow
1. Run this tool to create and publish a placeholder package
2. Visit the provided URL (
https://www.npmjs.com/package/) to configure OIDC trusted publishing
3. Set up your CI/CD workflow to publish the real package version with OIDCExample Output
`bash
$ setup-npm-trusted-publish @myorg/my-package๐ฆ Creating placeholder package: @myorg/my-package
๐ Temp directory: /tmp/npm-oidc-setup-abc123def456
โ
Created placeholder package files
๐ค Publishing package to npm...
โ
Successfully published: @myorg/my-package
๐ View your package at: https://www.npmjs.com/package/@myorg/my-package
Next steps:
1. Go to https://www.npmjs.com/package/@myorg/my-package/access
2. Configure OIDC trusted publishing
3. Set up your CI/CD workflow to publish with OIDC
๐งน Cleaned up temp directory
``npm's current implementation requires a package to exist before you can:
- Configure OIDC trusted publishing
- Generate granular access tokens
This tool provides a responsible way to "reserve" a package name for OIDC setup by creating a package that:
- Clearly communicates its purpose
- Cannot be mistaken for a functional package
- Enables the OIDC configuration workflow
- This tool is specifically for OIDC setup, not for name squatting
- The generated packages clearly indicate they are placeholders
- Always follow npm's policies and best practices
- Replace the placeholder with your actual package as soon as possible
MIT