mirror of
				https://kkgithub.com/actions/setup-node.git
				synced 2025-10-31 18:51:54 +08:00 
			
		
		
		
	new toolkit and scoped registries
This commit is contained in:
		| @ -11,12 +11,20 @@ const fs = __importStar(require("fs")); | ||||
| const os = __importStar(require("os")); | ||||
| const path = __importStar(require("path")); | ||||
| const core = __importStar(require("@actions/core")); | ||||
| const github = __importStar(require("@actions/github")); | ||||
| function configAuthentication(registryUrl) { | ||||
|     const npmrc = path.resolve(process.cwd(), '.npmrc'); | ||||
|     writeRegistryToFile(registryUrl, npmrc); | ||||
| } | ||||
| exports.configAuthentication = configAuthentication; | ||||
| function writeRegistryToFile(registryUrl, fileLocation) { | ||||
|     let scope = core.getInput('scope'); | ||||
|     if (!scope && registryUrl.indexOf('npm.pkg.github.com') > -1) { | ||||
|         scope = github.context.repo.owner; | ||||
|     } | ||||
|     if (scope && scope[0] != '@') { | ||||
|         scope = '@' + scope; | ||||
|     } | ||||
|     core.debug(`Setting auth in ${fileLocation}`); | ||||
|     let newContents = ''; | ||||
|     if (fs.existsSync(fileLocation)) { | ||||
| @ -28,13 +36,9 @@ function writeRegistryToFile(registryUrl, fileLocation) { | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
|     newContents += | ||||
|         'registry=' + | ||||
|             registryUrl + | ||||
|             os.EOL + | ||||
|             'always-auth=true' + | ||||
|             os.EOL + | ||||
|             registryUrl.replace(/(^\w+:|^)/, '') + // Remove http: or https: from front of registry. | ||||
|             ':_authToken=${NODE_AUTH_TOKEN}'; | ||||
|     // Remove http: or https: from front of registry. | ||||
|     const authString = registryUrl.replace(/(^\w+:|^)/, '') + ':_authToken=${NODE_AUTH_TOKEN}'; | ||||
|     const registryString = scope ? `${scope}:registry=${registryUrl}` : `registry=${registryUrl}`; | ||||
|     newContents += `${registryString}${os.EOL}always-auth=true${os.EOL}${authString}`; | ||||
|     fs.writeFileSync(fileLocation, newContents); | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Danny McCormick
					Danny McCormick