From eff932eb37b8c35b14ea45bf806abb8519373de3 Mon Sep 17 00:00:00 2001 From: Edward Romero Date: Tue, 23 Jun 2020 20:50:52 -0400 Subject: [PATCH] add ability to include both types of registries on complex repos --- action.yml | 3 +++ src/authutil.ts | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 240d7d5d..66161d39 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,9 @@ inputs: description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN' scope: description: 'Optional scope for authenticating against scoped registries' + include-both-registries: + description: 'Include both registry url and scoped' + default: 'false' token: description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user. default: ${{ github.token }} diff --git a/src/authutil.ts b/src/authutil.ts index 59035862..c43eb1d1 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -43,6 +43,7 @@ async function getAuthToken( const startIndex = body.indexOf('_auth') + 8; const endIndex = body.indexOf('\n'); const authToken = body.substring(startIndex, endIndex); + console.log(authToken); return authToken; } @@ -91,11 +92,20 @@ async function writeRegistryToFile( /(^\w+:|^)/, '' )}:_authToken=${nodeAuthToken}`; + + const includeBothRegistries: string = core.getInput('include-both-registries'); const registryString: string = scope - ? `${scope}:registry=${registryUrl}` - : `registry=${registryUrl}`; + ? `${scope}:registry=${registryUrl}` + : `registry=${registryUrl}`; + const alwaysAuthString: string = `always-auth=${alwaysAuth}`; - newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; + if(scope && includeBothRegistries) { + const registryStringNoScope = `registry=${registryUrl}`; + newContents += `${authString}${os.EOL}${registryString}${os.EOL}${registryStringNoScope}${os.EOL}${alwaysAuthString}`; + } else { + newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; + } + fs.writeFileSync(fileLocation, newContents); core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); // Export empty node_auth_token so npm doesn't complain about not being able to find it