Skip to content

Commit 4d381b1

Browse files
author
Danny McCormick
committed
Use userconfig and append trailing slash
1 parent b9164e8 commit 4d381b1

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

lib/authutil.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ const path = __importStar(require("path"));
1313
const core = __importStar(require("@actions/core"));
1414
const github = __importStar(require("@actions/github"));
1515
function configAuthentication(registryUrl) {
16-
// const npmrc: string = path.resolve(
17-
// process.env['RUNNER_TEMP'] || process.cwd(),
18-
// '.npmrc'
19-
// );
20-
const npmrc = path.resolve(process.cwd(), '.npmrc');
16+
const npmrc = path.resolve(process.env['RUNNER_TEMP'] || process.cwd(), '.npmrc');
17+
if (!registryUrl.endsWith('/')) {
18+
registryUrl += '/';
19+
}
2120
writeRegistryToFile(registryUrl, npmrc);
2221
}
2322
exports.configAuthentication = configAuthentication;
@@ -47,7 +46,7 @@ function writeRegistryToFile(registryUrl, fileLocation) {
4746
: `registry=${registryUrl}`;
4847
newContents += `${authString}${os.EOL}${registryString}`;
4948
fs.writeFileSync(fileLocation, newContents);
50-
// core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
49+
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
5150
// Export empty node_auth_token so npm doesn't complain about not being able to find it
52-
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
51+
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
5352
}

src/authutil.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import * as core from '@actions/core';
55
import * as github from '@actions/github';
66

77
export function configAuthentication(registryUrl: string) {
8-
// const npmrc: string = path.resolve(
9-
// process.env['RUNNER_TEMP'] || process.cwd(),
10-
// '.npmrc'
11-
// );
12-
const npmrc: string = path.resolve(process.cwd(), '.npmrc');
8+
const npmrc: string = path.resolve(
9+
process.env['RUNNER_TEMP'] || process.cwd(),
10+
'.npmrc'
11+
);
12+
if (!registryUrl.endsWith('/')) {
13+
registryUrl += '/';
14+
}
1315

1416
writeRegistryToFile(registryUrl, npmrc);
1517
}
@@ -42,7 +44,7 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
4244
: `registry=${registryUrl}`;
4345
newContents += `${authString}${os.EOL}${registryString}`;
4446
fs.writeFileSync(fileLocation, newContents);
45-
// core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
47+
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
4648
// Export empty node_auth_token so npm doesn't complain about not being able to find it
47-
// core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
49+
core.exportVariable('NODE_AUTH_TOKEN', 'XXXXX-XXXXX-XXXXX-XXXXX');
4850
}

0 commit comments

Comments
 (0)