From 4d381b188af80c19d42691c04489bc7a035c9ce5 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Tue, 6 Aug 2019 14:08:18 -0400 Subject: [PATCH] Use userconfig and append trailing slash --- lib/authutil.js | 13 ++++++------- src/authutil.ts | 16 +++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/authutil.js b/lib/authutil.js index e5a8e2b..d428b4e 100644 --- a/lib/authutil.js +++ b/lib/authutil.js @@ -13,11 +13,10 @@ const path = __importStar(require("path")); const core = __importStar(require("@actions/core")); const github = __importStar(require("@actions/github")); function configAuthentication(registryUrl) { - // const npmrc: string = path.resolve( - // process.env['RUNNER_TEMP'] || process.cwd(), - // '.npmrc' - // ); - const npmrc = path.resolve(process.cwd(), '.npmrc'); + const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc'); + if (!registryUrl.endsWith('/')) { + registryUrl += '/'; + } writeRegistryToFile(registryUrl, npmrc); } exports.configAuthentication = configAuthentication; @@ -47,7 +46,7 @@ function writeRegistryToFile(registryUrl, fileLocation) { : `registry=${registryUrl}`; newContents += `${authString}${os.EOL}${registryString}`; fs.writeFileSync(fileLocation, newContents); - // core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); + core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); // Export empty node_auth_token so npm doesn't complain about not being able to find it - // core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX'); + core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX'); } diff --git a/src/authutil.ts b/src/authutil.ts index f496559..9285bb9 100644 --- a/src/authutil.ts +++ b/src/authutil.ts @@ -5,11 +5,13 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; export function configAuthentication(registryUrl: string) { - // const npmrc: string = path.resolve( - // process.env['RUNNER_TEMP'] || process.cwd(), - // '.npmrc' - // ); - const npmrc: string = path.resolve(process.cwd(), '.npmrc'); + const npmrc: string = path.resolve( + process.env['RUNNER_TEMP'] || process.cwd(), + '.npmrc' + ); + if (!registryUrl.endsWith('/')) { + registryUrl += '/'; + } writeRegistryToFile(registryUrl, npmrc); } @@ -42,7 +44,7 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) { : `registry=${registryUrl}`; newContents += `${authString}${os.EOL}${registryString}`; fs.writeFileSync(fileLocation, newContents); - // core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); + core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation); // Export empty node_auth_token so npm doesn't complain about not being able to find it - // core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX'); + core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX'); }