mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-03 20:40:28 -05:00 
			
		
		
		
	Update
This commit is contained in:
		@@ -1,4 +1,12 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
 | 
			
		||||
    return new (P || (P = Promise))(function (resolve, reject) {
 | 
			
		||||
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
 | 
			
		||||
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
 | 
			
		||||
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
 | 
			
		||||
        step((generator = generator.apply(thisArg, _arguments || [])).next());
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
var __importStar = (this && this.__importStar) || function (mod) {
 | 
			
		||||
    if (mod && mod.__esModule) return mod;
 | 
			
		||||
    var result = {};
 | 
			
		||||
@@ -7,27 +15,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
 | 
			
		||||
    return result;
 | 
			
		||||
};
 | 
			
		||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
			
		||||
const fs = __importStar(require("fs"));
 | 
			
		||||
const os = __importStar(require("os"));
 | 
			
		||||
const path = __importStar(require("path"));
 | 
			
		||||
const exec = __importStar(require("@actions/exec"));
 | 
			
		||||
function configAuth(registryUrl) {
 | 
			
		||||
    let npmrc = path.resolve(process.cwd(), '.npmrc');
 | 
			
		||||
    let yarnrc = path.resolve(process.cwd(), '.yarnrc');
 | 
			
		||||
    writeRegistryToFile(registryUrl, npmrc, 'NPM_TOKEN');
 | 
			
		||||
    writeRegistryToFile(registryUrl, yarnrc, 'YARN_TOKEN');
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        let npmrc = path.resolve(process.cwd(), '.npmrc');
 | 
			
		||||
        let yarnrc = path.resolve(process.cwd(), '.yarnrc');
 | 
			
		||||
        writeRegistryToFile(registryUrl, 'npm', 'NPM_TOKEN');
 | 
			
		||||
        writeRegistryToFile(registryUrl, 'yarn', 'YARN_TOKEN');
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
exports.configAuth = configAuth;
 | 
			
		||||
function writeRegistryToFile(registryUrl, fileLocation, authTokenName) {
 | 
			
		||||
    let newContents = '';
 | 
			
		||||
    if (fs.existsSync(fileLocation)) {
 | 
			
		||||
        const curContents = fs.readFileSync(fileLocation, 'utf8');
 | 
			
		||||
        curContents.split(os.EOL).forEach((line) => {
 | 
			
		||||
            // Add current contents unless they are setting the registry
 | 
			
		||||
            if (!line.startsWith('registry')) {
 | 
			
		||||
                newContents += line + os.EOL;
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    newContents += 'registry=' + registryUrl + os.EOL + 'always-auth=true' + os.EOL + registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${' + authTokenName + '}';
 | 
			
		||||
    fs.writeFileSync(fileLocation, newContents);
 | 
			
		||||
function writeRegistryToFile(registryUrl, packageManager, authTokenName) {
 | 
			
		||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
			
		||||
        yield exec.exec(`${packageManager} config set registry=${registryUrl}`);
 | 
			
		||||
        yield exec.exec(`${packageManager} config set always-auth=true`);
 | 
			
		||||
        yield exec.exec(packageManager +
 | 
			
		||||
            ' config set ' +
 | 
			
		||||
            registryUrl.replace(/(^\w+:|^)/, '') +
 | 
			
		||||
            ':_authToken ${' +
 | 
			
		||||
            authTokenName +
 | 
			
		||||
            '}');
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user