This commit is contained in:
Danny McCormick 2019-08-05 13:12:37 -04:00
parent 8e12aec29e
commit 920661f1be
5 changed files with 15 additions and 18 deletions

View file

@ -3,22 +3,20 @@ import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
export function configAuth(registryUrl: string) {
let npmrc: string = path.resolve(process.cwd(), '.npmrc');
let yarnrc: string = path.resolve(process.cwd(), '.yarnrc');
export function configAuthentication(registryUrl: string) {
const npmrc: string = path.resolve(process.cwd(), '.npmrc');
writeRegistryToFile(registryUrl, npmrc);
writeRegistryToFile(registryUrl, yarnrc);
}
function writeRegistryToFile(registryUrl: string, fileLocation: string) {
core.debug(`Setting auth in ${fileLocation}`);
let newContents = '';
if (fs.existsSync(fileLocation)) {
const curContents = fs.readFileSync(fileLocation, 'utf8');
const curContents: string = fs.readFileSync(fileLocation, 'utf8');
curContents.split(os.EOL).forEach((line: string) => {
// Add current contents unless they are setting the registry
if (!line.startsWith('registry')) {
if (!line.toLowerCase().startsWith('registry')) {
newContents += line + os.EOL;
}
});
@ -29,7 +27,7 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
os.EOL +
'always-auth=true' +
os.EOL +
registryUrl.replace(/(^\w+:|^)/, '') +
registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry.
':_authToken=${NODE_AUTH_TOKEN}';
fs.writeFileSync(fileLocation, newContents);
}

View file

@ -15,9 +15,9 @@ async function run() {
await installer.getNode(version);
}
const registryUrl = core.getInput('registry-url');
const registryUrl: string = core.getInput('registry-url');
if (registryUrl) {
auth.configAuth(registryUrl);
auth.configAuthentication(registryUrl);
}
// TODO: setup proxy from runner proxy config