2121 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222 * SOFTWARE.
2323 */
24- import fs from 'fs'
25- import path from 'path'
26- import os from 'os'
2724import semver from 'semver'
2825import pkgUtils from '@instructure/pkg-utils'
2926import {
@@ -34,11 +31,6 @@ import {
3431} from '@instructure/command-utils'
3532
3633import { Project } from '@lerna/project'
37-
38- const NPM_SCOPE = '@instructure:registry=https://registry.npmjs.org/'
39-
40- // Track user .npmrc backup for cleanup
41- let userNpmrcBackup = null
4234const syncRootPackageVersion = async ( useProjectVersion ) => {
4335 const project = new Project ( process . cwd ( ) )
4436 const rootPkg = pkgUtils . getPackage ( )
@@ -111,76 +103,23 @@ export async function bumpPackages(packageName, requestedVersion) {
111103}
112104
113105export function createNPMRCFile ( ) {
114- const { NPM_TOKEN , NPM_EMAIL , NPM_USERNAME } = process . env
115-
116- // Only write an npmrc file if these are defined, otherwise assume the system is properly configured
117- if ( NPM_TOKEN ) {
118- const userHome = os . homedir ( )
119- const userNpmrcPath = path . join ( userHome , '.npmrc' )
120-
121- // Backup existing user .npmrc if it exists
122- if ( fs . existsSync ( userNpmrcPath ) ) {
123- const existingContent = fs . readFileSync ( userNpmrcPath , 'utf8' )
124- userNpmrcBackup = {
125- path : userNpmrcPath ,
126- content : existingContent ,
127- existed : true
128- }
129- info ( `📦 Backing up existing ${ userNpmrcPath } ` )
130- } else {
131- userNpmrcBackup = {
132- path : userNpmrcPath ,
133- content : null ,
134- existed : false
135- }
136- }
137-
138- // Write auth credentials to user .npmrc
139- const authConfig = `//registry.npmjs.org/:_authToken=${ NPM_TOKEN } \n${ NPM_SCOPE } \nemail=${ NPM_EMAIL } \nname=${ NPM_USERNAME } \n`
140-
141- if ( userNpmrcBackup . existed ) {
142- // Append to existing content
143- fs . writeFileSync ( userNpmrcPath , userNpmrcBackup . content + '\n' + authConfig )
144- } else {
145- // Create new file
146- fs . writeFileSync ( userNpmrcPath , authConfig )
147- }
148-
149- info ( `📦 Written auth config to ${ userNpmrcPath } ` )
150- }
106+ info ( '📦 Using OIDC authentication (npm trusted publishing)' )
151107
108+ // Verify OIDC authentication works
152109 try {
153- info ( 'running pnpm whoami:' )
110+ info ( '📦 Running pnpm whoami to verify OIDC auth :' )
154111 runCommandSync ( 'pnpm' , [ 'whoami' ] )
155112 } catch ( e ) {
156- error ( `Could not determine if NPM auth was successful: ${ e } ` )
113+ error ( `Could not verify OIDC authentication: ${ e } ` )
114+ error ( 'Make sure:' )
115+ error ( ' 1. Workflow has id-token: write permissions' )
116+ error ( ' 2. npm packages are configured for trusted publishing' )
117+ error ( ' 3. Workflow is running in GitHub Actions' )
157118 process . exit ( 1 )
158119 }
159120}
160121
161122export function cleanupNPMRCFile ( ) {
162- if ( ! userNpmrcBackup ) {
163- // Nothing to cleanup
164- return
165- }
166-
167- try {
168- if ( userNpmrcBackup . existed ) {
169- // Restore original content
170- fs . writeFileSync ( userNpmrcBackup . path , userNpmrcBackup . content )
171- info ( `📦 Restored original ${ userNpmrcBackup . path } ` )
172- } else {
173- // Remove the file we created
174- if ( fs . existsSync ( userNpmrcBackup . path ) ) {
175- fs . unlinkSync ( userNpmrcBackup . path )
176- info ( `📦 Removed ${ userNpmrcBackup . path } ` )
177- }
178- }
179- } catch ( e ) {
180- error ( `Failed to cleanup .npmrc: ${ e } ` )
181- // Don't exit - cleanup failure shouldn't break the release
182- } finally {
183- // Reset backup state
184- userNpmrcBackup = null
185- }
123+ // No cleanup needed with OIDC authentication
124+ // This function is kept for backward compatibility
186125}
0 commit comments