mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 13:29:12 +08:00 
			
		
		
		
	Respect package.json's engines.node field when used as a node-version-file (#485)
				
					
				
			* Allow reading 'package.json' as node-version-file
* Run 'npm run build'
* Read package.json contents directly during tests
- this eliminates OS-specific line-ending issues
* Run project Prettier 💅
			
			
This commit is contained in:
		
							
								
								
									
										24
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										24
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@@ -71768,15 +71768,25 @@ function translateArchToDistUrl(arch) {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
function parseNodeVersionFile(contents) {
 | 
			
		||||
    var _a;
 | 
			
		||||
    var _a, _b;
 | 
			
		||||
    let nodeVersion;
 | 
			
		||||
    const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m);
 | 
			
		||||
    const nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
 | 
			
		||||
    if (nodeVersion) {
 | 
			
		||||
        return nodeVersion;
 | 
			
		||||
    nodeVersion = (_a = found === null || found === void 0 ? void 0 : found.groups) === null || _a === void 0 ? void 0 : _a.version;
 | 
			
		||||
    if (!nodeVersion) {
 | 
			
		||||
        try {
 | 
			
		||||
            // Try parsing the file as an NPM `package.json`
 | 
			
		||||
            // file.
 | 
			
		||||
            nodeVersion = (_b = JSON.parse(contents).engines) === null || _b === void 0 ? void 0 : _b.node;
 | 
			
		||||
            if (!nodeVersion)
 | 
			
		||||
                throw new Error();
 | 
			
		||||
        }
 | 
			
		||||
        catch (err) {
 | 
			
		||||
            // In the case of an unknown format,
 | 
			
		||||
            // return as is and evaluate the version separately.
 | 
			
		||||
            nodeVersion = contents.trim();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // In the case of an unknown format,
 | 
			
		||||
    // return as is and evaluate the version separately.
 | 
			
		||||
    return contents.trim();
 | 
			
		||||
    return nodeVersion;
 | 
			
		||||
}
 | 
			
		||||
exports.parseNodeVersionFile = parseNodeVersionFile;
 | 
			
		||||
function isLatestSyntax(versionSpec) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user