mirror of
				https://github.com/actions/setup-node.git
				synced 2025-11-04 12:13:35 +00:00 
			
		
		
		
	Merge 872987f82bb21c42537c7263b72f8ed55efa13f9 into 92a57f4a935efe978b0a4d8e5b19fb42658c7ef7
This commit is contained in:
		
						commit
						768feb38f7
					
				@ -138,6 +138,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du
 | 
				
			|||||||
8. [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
 | 
					8. [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
 | 
				
			||||||
9. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
 | 
					9. [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
 | 
				
			||||||
10. [Using private packages](docs/advanced-usage.md#use-private-packages)
 | 
					10. [Using private packages](docs/advanced-usage.md#use-private-packages)
 | 
				
			||||||
 | 
					11. [Enabling Corepack](docs/advanced-usage.md#enabling-corepack)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## License
 | 
					## License
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1253,6 +1253,44 @@ describe('setup-node', () => {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe('corepack flag', () => {
 | 
				
			||||||
 | 
					    it('use corepack if specified', async () => {
 | 
				
			||||||
 | 
					      inputs['corepack'] = 'true';
 | 
				
			||||||
 | 
					      await main.run();
 | 
				
			||||||
 | 
					      expect(getExecOutputSpy).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
					        'corepack',
 | 
				
			||||||
 | 
					        ['enable'],
 | 
				
			||||||
 | 
					        expect.anything()
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('use corepack with given package manager', async () => {
 | 
				
			||||||
 | 
					      inputs['corepack'] = 'npm';
 | 
				
			||||||
 | 
					      await main.run();
 | 
				
			||||||
 | 
					      expect(getExecOutputSpy).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
					        'corepack',
 | 
				
			||||||
 | 
					        ['enable', 'npm'],
 | 
				
			||||||
 | 
					        expect.anything()
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('use corepack with multiple package managers', async () => {
 | 
				
			||||||
 | 
					      inputs['corepack'] = 'npm yarn';
 | 
				
			||||||
 | 
					      await main.run();
 | 
				
			||||||
 | 
					      expect(getExecOutputSpy).toHaveBeenCalledWith(
 | 
				
			||||||
 | 
					        'corepack',
 | 
				
			||||||
 | 
					        ['enable', 'npm', 'yarn'],
 | 
				
			||||||
 | 
					        expect.anything()
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('fails to use corepack with an invalid package manager', async () => {
 | 
				
			||||||
 | 
					      await expect(im.enableCorepack('npm turbo')).rejects.toThrowError(
 | 
				
			||||||
 | 
					        `One or more of the specified package managers [ npm turbo ] are not supported by corepack`
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
describe('helper methods', () => {
 | 
					describe('helper methods', () => {
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,9 @@ inputs:
 | 
				
			|||||||
    description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
 | 
					    description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
 | 
				
			||||||
  cache-dependency-path:
 | 
					  cache-dependency-path:
 | 
				
			||||||
    description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
 | 
					    description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
 | 
				
			||||||
 | 
					  corepack:
 | 
				
			||||||
 | 
					    description: 'Used to specify whether to enable Corepack. Set to true to enable all package managers or set it to one or more package manager names (separate package manager names by a space. Supported package manager names: npm, yarn, pnpm.'
 | 
				
			||||||
 | 
					    default: 'false'
 | 
				
			||||||
# TODO: add input to control forcing to pull from cloud or dist. 
 | 
					# TODO: add input to control forcing to pull from cloud or dist. 
 | 
				
			||||||
#       escape valve for someone having issues or needing the absolute latest which isn't cached yet
 | 
					#       escape valve for someone having issues or needing the absolute latest which isn't cached yet
 | 
				
			||||||
outputs:
 | 
					outputs:
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										21
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -73209,6 +73209,7 @@ const core = __importStar(__nccwpck_require__(2186));
 | 
				
			|||||||
const hc = __importStar(__nccwpck_require__(9925));
 | 
					const hc = __importStar(__nccwpck_require__(9925));
 | 
				
			||||||
const io = __importStar(__nccwpck_require__(7436));
 | 
					const io = __importStar(__nccwpck_require__(7436));
 | 
				
			||||||
const tc = __importStar(__nccwpck_require__(7784));
 | 
					const tc = __importStar(__nccwpck_require__(7784));
 | 
				
			||||||
 | 
					const exec = __importStar(__nccwpck_require__(1514));
 | 
				
			||||||
const path = __importStar(__nccwpck_require__(1017));
 | 
					const path = __importStar(__nccwpck_require__(1017));
 | 
				
			||||||
const semver = __importStar(__nccwpck_require__(5911));
 | 
					const semver = __importStar(__nccwpck_require__(5911));
 | 
				
			||||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
 | 
					const fs_1 = __importDefault(__nccwpck_require__(7147));
 | 
				
			||||||
@ -73653,6 +73654,24 @@ exports.parseNodeVersionFile = parseNodeVersionFile;
 | 
				
			|||||||
function isLatestSyntax(versionSpec) {
 | 
					function isLatestSyntax(versionSpec) {
 | 
				
			||||||
    return ['current', 'latest', 'node'].includes(versionSpec);
 | 
					    return ['current', 'latest', 'node'].includes(versionSpec);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					function enableCorepack(input) {
 | 
				
			||||||
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
 | 
					        let corepackArgs = ['enable'];
 | 
				
			||||||
 | 
					        if (input.length > 0 && input !== 'false') {
 | 
				
			||||||
 | 
					            if (input !== 'true') {
 | 
				
			||||||
 | 
					                const packageManagers = input.split(' ');
 | 
				
			||||||
 | 
					                if (!packageManagers.every(pm => ['npm', 'yarn', 'pnpm'].includes(pm))) {
 | 
				
			||||||
 | 
					                    throw new Error(`One or more of the specified package managers [ ${input} ] are not supported by corepack`);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                corepackArgs.push(...packageManagers);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            yield exec.getExecOutput('corepack', corepackArgs, {
 | 
				
			||||||
 | 
					                ignoreReturnCode: true
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.enableCorepack = enableCorepack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/***/ }),
 | 
					/***/ }),
 | 
				
			||||||
@ -73722,6 +73741,8 @@ function run() {
 | 
				
			|||||||
            if (registryUrl) {
 | 
					            if (registryUrl) {
 | 
				
			||||||
                auth.configAuthentication(registryUrl, alwaysAuth);
 | 
					                auth.configAuthentication(registryUrl, alwaysAuth);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            const corepack = core.getInput('corepack') || 'false';
 | 
				
			||||||
 | 
					            yield installer.enableCorepack(corepack);
 | 
				
			||||||
            if (cache && cache_utils_1.isCacheFeatureAvailable()) {
 | 
					            if (cache && cache_utils_1.isCacheFeatureAvailable()) {
 | 
				
			||||||
                const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
					                const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
				
			||||||
                yield cache_restore_1.restoreCache(cache, cacheDependencyPath);
 | 
					                yield cache_restore_1.restoreCache(cache, cacheDependencyPath);
 | 
				
			||||||
 | 
				
			|||||||
@ -358,3 +358,32 @@ NOTE: As per https://github.com/actions/setup-node/issues/49 you cannot use `sec
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### always-auth input
 | 
					### always-auth input
 | 
				
			||||||
The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries.
 | 
					The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Enabling Corepack
 | 
				
			||||||
 | 
					You can enable [Corepack](https://github.com/nodejs/corepack) by using the `corepack` input. This will enable Corepack. You can then use `pnpm` and `yarn` commands in your project.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					steps:
 | 
				
			||||||
 | 
					- uses: actions/checkout@v3
 | 
				
			||||||
 | 
					- uses: actions/setup-node@v3
 | 
				
			||||||
 | 
					  with:
 | 
				
			||||||
 | 
					    node-version: '16.x'
 | 
				
			||||||
 | 
					    corepack: true
 | 
				
			||||||
 | 
					- name: Install dependencies
 | 
				
			||||||
 | 
					  run: yarn install --immutable
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can also pass package manager names instead if you want to enable corepack for specific package managers only.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					steps:
 | 
				
			||||||
 | 
					- uses: actions/checkout@v3
 | 
				
			||||||
 | 
					- uses: actions/setup-node@v3
 | 
				
			||||||
 | 
					  with:
 | 
				
			||||||
 | 
					    node-version: '16.x'
 | 
				
			||||||
 | 
					    corepack: yarn pnpm
 | 
				
			||||||
 | 
					- name: Install dependencies
 | 
				
			||||||
 | 
					  run: yarn install --immutable
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					This option by default is `false` as Corepack is still in experimental phase.
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,7 @@ import * as core from '@actions/core';
 | 
				
			|||||||
import * as hc from '@actions/http-client';
 | 
					import * as hc from '@actions/http-client';
 | 
				
			||||||
import * as io from '@actions/io';
 | 
					import * as io from '@actions/io';
 | 
				
			||||||
import * as tc from '@actions/tool-cache';
 | 
					import * as tc from '@actions/tool-cache';
 | 
				
			||||||
 | 
					import * as exec from '@actions/exec';
 | 
				
			||||||
import * as path from 'path';
 | 
					import * as path from 'path';
 | 
				
			||||||
import * as semver from 'semver';
 | 
					import * as semver from 'semver';
 | 
				
			||||||
import fs from 'fs';
 | 
					import fs from 'fs';
 | 
				
			||||||
@ -604,3 +605,21 @@ export function parseNodeVersionFile(contents: string): string {
 | 
				
			|||||||
function isLatestSyntax(versionSpec): boolean {
 | 
					function isLatestSyntax(versionSpec): boolean {
 | 
				
			||||||
  return ['current', 'latest', 'node'].includes(versionSpec);
 | 
					  return ['current', 'latest', 'node'].includes(versionSpec);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export async function enableCorepack(input: string): Promise<void> {
 | 
				
			||||||
 | 
					  let corepackArgs = ['enable'];
 | 
				
			||||||
 | 
					  if (input.length > 0 && input !== 'false') {
 | 
				
			||||||
 | 
					    if (input !== 'true') {
 | 
				
			||||||
 | 
					      const packageManagers = input.split(' ');
 | 
				
			||||||
 | 
					      if (!packageManagers.every(pm => ['npm', 'yarn', 'pnpm'].includes(pm))) {
 | 
				
			||||||
 | 
					        throw new Error(
 | 
				
			||||||
 | 
					          `One or more of the specified package managers [ ${input} ] are not supported by corepack`
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      corepackArgs.push(...packageManagers);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    await exec.getExecOutput('corepack', corepackArgs, {
 | 
				
			||||||
 | 
					      ignoreReturnCode: true
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -49,6 +49,9 @@ export async function run() {
 | 
				
			|||||||
      auth.configAuthentication(registryUrl, alwaysAuth);
 | 
					      auth.configAuthentication(registryUrl, alwaysAuth);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const corepack = core.getInput('corepack') || 'false';
 | 
				
			||||||
 | 
					    await installer.enableCorepack(corepack);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (cache && isCacheFeatureAvailable()) {
 | 
					    if (cache && isCacheFeatureAvailable()) {
 | 
				
			||||||
      const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
					      const cacheDependencyPath = core.getInput('cache-dependency-path');
 | 
				
			||||||
      await restoreCache(cache, cacheDependencyPath);
 | 
					      await restoreCache(cache, cacheDependencyPath);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user