feat(npm): support OIDC trusted publishing#763
Merged
Conversation
Add auto-detection and opt-in support for npm's OIDC trusted publishing (https://docs.npmjs.com/trusted-publishers), eliminating the need for long-lived NPM_TOKEN secrets. - Auto-detect OIDC from CI env vars (GitHub Actions ACTIONS_ID_TOKEN_* and GitLab NPM_ID_TOKEN) when NPM_TOKEN is absent - Add explicit `oidc: true` config option to force OIDC mode - Skip temp .npmrc injection in OIDC mode so npm's native OIDC detection is not overridden - Validate npm >= 11.5.1 when OIDC is in use; hard-error on explicit `oidc: true` with incompatible environments, warn and fall through to token error on auto-detected OIDC with old npm - getLatestVersion() runs without auth when no token is available (works for public packages; warns and skips check for private packages) - Token auth and all existing behavior unchanged when NPM_TOKEN is set
Contributor
|
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
- Extract duplicated isNewEnough version check to isNpmVersionSufficientForOidc() helper
- Propagate oidc config option to expanded workspace targets in expand()
- Fix test assertion that was checking NPM_BIN ('npm') instead of 'NPM_TOKEN'
- Add test coverage for oidc propagation through workspace expand()
Replace the ad-hoc NPM_OIDC_MIN_{MAJOR,MINOR,PATCH} constants and the
isNpmVersionSufficientForOidc() helper with the existing SemVer utilities
already imported in npm.ts:
- Single NPM_OIDC_MIN_VERSION: SemVer constant instead of three separate ones
- versionGreaterOrEqualThan(npmVersion, NPM_OIDC_MIN_VERSION) replaces the
custom comparison logic
- this.npmVersion now stores the full SemVer from parseVersion() directly
- TestNpmTarget.mockVersion typed as SemVer to match
7 tasks
BYK
added a commit
to BYK/opencode-lore
that referenced
this pull request
Feb 27, 2026
Now that Craft supports OIDC auto-detection (getsentry/craft#763), restore the npm target in .craft.yml and let craft publish handle both GitHub release and npm publish in one command. Removes the separate npm publish step and the preReleaseCommand workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
NPM_TOKENis absent and the CI environment exposes OIDC credentials (GitHub ActionsACTIONS_ID_TOKEN_REQUEST_*env vars, GitLabNPM_ID_TOKEN). Zero config change required for the common case.oidc: truetarget option to force OIDC mode (useful when migrating while both a token and OIDC are configured)..npmrcinjection in OIDC mode so npm's native OIDC detection is not overridden; require npm >= 11.5.1 for OIDC; hard-error on explicitoidc: truewith incompatible environments.getLatestVersion()runs unauthenticated when no token is available (works for public packages; warns and skips thecheckPackageNamecheck for private ones).Auth Decision Logic
oidcconfigNPM_TOKENsettrueFiles Changed
src/targets/npm.ts— core implementation:isOidcEnvironment()helper, updatedcheckRequirements,getNpmConfig,publishPackage, andgetLatestVersionsrc/targets/__tests__/npm.test.ts— 13 new tests covering all OIDC pathsdocs/src/content/docs/targets/npm.md— OIDC Trusted Publishing sectionTesting