3
0
Fork 0
mirror of https://gitea.com/actions/setup-node.git synced 2024-11-22 10:09:33 +01:00

Add modification of scoped registry

This commit is contained in:
Sergey Dolin 2022-12-05 13:32:26 +01:00
parent 3ae886ede4
commit a69d45adcd

View file

@ -29,7 +29,7 @@ function writeRegistryToFile(
scope = '@' + scope; scope = '@' + scope;
} }
if (scope) { if (scope) {
scope = scope.toLowerCase(); scope = scope.toLowerCase() + ':';
} }
core.debug(`Setting auth in ${fileLocation}`); core.debug(`Setting auth in ${fileLocation}`);
@ -38,7 +38,7 @@ function writeRegistryToFile(
const curContents: string = fs.readFileSync(fileLocation, 'utf8'); const curContents: string = fs.readFileSync(fileLocation, 'utf8');
curContents.split(os.EOL).forEach((line: string) => { curContents.split(os.EOL).forEach((line: string) => {
// Add current contents unless they are setting the registry // Add current contents unless they are setting the registry
if (!line.toLowerCase().startsWith('registry')) { if (!line.toLowerCase().startsWith(`${scope}registry`)) {
newContents += line + os.EOL; newContents += line + os.EOL;
} }
}); });
@ -46,9 +46,7 @@ function writeRegistryToFile(
// Remove http: or https: from front of registry. // Remove http: or https: from front of registry.
const authString: string = const authString: string =
registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}';
const registryString: string = scope const registryString: string = `${scope}registry=${registryUrl}`;
? `${scope}:registry=${registryUrl}`
: `registry=${registryUrl}`;
const alwaysAuthString: string = `always-auth=${alwaysAuth}`; const alwaysAuthString: string = `always-auth=${alwaysAuth}`;
newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`; newContents += `${authString}${os.EOL}${registryString}${os.EOL}${alwaysAuthString}`;
fs.writeFileSync(fileLocation, newContents); fs.writeFileSync(fileLocation, newContents);