mirror of
https://github.com/actions/setup-node.git
synced 2024-11-26 19:39:25 +08:00
Added option to enable corepack (#1)
Co-authored-by: Steven <steven@ceriously.com> Co-authored-by: Sayak Mukhopadhyay <mukhopadhyaysayak@gmail.com> Co-authored-by: Jacob Parish <jacob.parish.1@gmail.com>
This commit is contained in:
parent
5ef044f9d0
commit
2936fe8cda
23
README.md
23
README.md
@ -26,22 +26,22 @@ See [action.yml](action.yml)
|
|||||||
node-version: ''
|
node-version: ''
|
||||||
|
|
||||||
# File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.
|
# File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions.
|
||||||
# If node-version and node-version-file are both provided the action will use version from node-version.
|
# If node-version and node-version-file are both provided the action will use version from node-version.
|
||||||
node-version-file: ''
|
node-version-file: ''
|
||||||
|
|
||||||
# Set this option if you want the action to check for the latest available version
|
# Set this option if you want the action to check for the latest available version
|
||||||
# that satisfies the version spec.
|
# that satisfies the version spec.
|
||||||
# It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen).
|
# It will only get affect for lts Nodejs versions (12.x, >=10.15.0, lts/Hydrogen).
|
||||||
# Default: false
|
# Default: false
|
||||||
check-latest: false
|
check-latest: false
|
||||||
|
|
||||||
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
# Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.
|
||||||
# Default: ''. The action use system architecture by default
|
# Default: ''. The action use system architecture by default
|
||||||
architecture: ''
|
architecture: ''
|
||||||
|
|
||||||
# Used to pull node distributions from https://github.com/actions/node-versions.
|
# Used to pull node distributions from https://github.com/actions/node-versions.
|
||||||
# Since there's a default, this is typically not supplied by the user.
|
# Since there's a default, this is typically not supplied by the user.
|
||||||
# When running this action on github.com, the default value is sufficient.
|
# When running this action on github.com, the default value is sufficient.
|
||||||
# When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
# When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||||
#
|
#
|
||||||
# We recommend using a service account with the least permissions necessary. Also
|
# We recommend using a service account with the least permissions necessary. Also
|
||||||
@ -57,18 +57,18 @@ See [action.yml](action.yml)
|
|||||||
# Default: ''
|
# Default: ''
|
||||||
cache: ''
|
cache: ''
|
||||||
|
|
||||||
# Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc.
|
# Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc.
|
||||||
# It will generate hash from the target file for primary key. It works only If cache is specified.
|
# It will generate hash from the target file for primary key. It works only If cache is specified.
|
||||||
# Supports wildcards or a list of file names for caching multiple dependencies.
|
# Supports wildcards or a list of file names for caching multiple dependencies.
|
||||||
# Default: ''
|
# Default: ''
|
||||||
cache-dependency-path: ''
|
cache-dependency-path: ''
|
||||||
|
|
||||||
# Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
|
# Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file,
|
||||||
# and set up auth to read in from env.NODE_AUTH_TOKEN.
|
# and set up auth to read in from env.NODE_AUTH_TOKEN.
|
||||||
# Default: ''
|
# Default: ''
|
||||||
registry-url: ''
|
registry-url: ''
|
||||||
|
|
||||||
# Optional scope for authenticating against scoped registries.
|
# Optional scope for authenticating against scoped registries.
|
||||||
# Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
|
# Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).
|
||||||
# Default: ''
|
# Default: ''
|
||||||
scope: ''
|
scope: ''
|
||||||
@ -203,6 +203,7 @@ If the runner is not able to access github.com, any Nodejs versions requested du
|
|||||||
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
|
||||||
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
|
||||||
- [Using private packages](docs/advanced-usage.md#use-private-packages)
|
- [Using private packages](docs/advanced-usage.md#use-private-packages)
|
||||||
|
- [Enabling Corepack](docs/advanced-usage.md#enabling-corepack)
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -825,4 +825,36 @@ 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()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,10 +25,13 @@ 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 separated 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:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit.'
|
description: 'A boolean value to indicate if a cache was hit.'
|
||||||
node-version:
|
node-version:
|
||||||
description: 'The installed node version.'
|
description: 'The installed node version.'
|
||||||
|
17
dist/cache-save/index.js
vendored
17
dist/cache-save/index.js
vendored
@ -83321,7 +83321,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
exports.enableCorepack = exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
function parseNodeVersionFile(contents) {
|
function parseNodeVersionFile(contents) {
|
||||||
@ -83393,6 +83393,21 @@ const unique = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
exports.unique = unique;
|
exports.unique = unique;
|
||||||
|
function enableCorepack(input) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input.length > 0 && input !== 'false') {
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
yield exec.getExecOutput('corepack', corepackArgs, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.enableCorepack = enableCorepack;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
19
dist/setup/index.js
vendored
19
dist/setup/index.js
vendored
@ -93698,6 +93698,8 @@ function run() {
|
|||||||
if (registryUrl) {
|
if (registryUrl) {
|
||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
const corepack = core.getInput('corepack') || 'false';
|
||||||
|
yield (0, util_1.enableCorepack)(corepack);
|
||||||
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) {
|
if (cache && (0, cache_utils_1.isCacheFeatureAvailable)()) {
|
||||||
core.saveState(constants_1.State.CachePackageManager, cache);
|
core.saveState(constants_1.State.CachePackageManager, cache);
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
@ -93775,7 +93777,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
exports.enableCorepack = exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const exec = __importStar(__nccwpck_require__(1514));
|
const exec = __importStar(__nccwpck_require__(1514));
|
||||||
function parseNodeVersionFile(contents) {
|
function parseNodeVersionFile(contents) {
|
||||||
@ -93847,6 +93849,21 @@ const unique = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
exports.unique = unique;
|
exports.unique = unique;
|
||||||
|
function enableCorepack(input) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input.length > 0 && input !== 'false') {
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
yield exec.getExecOutput('corepack', corepackArgs, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.enableCorepack = enableCorepack;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -416,3 +416,32 @@ Please refer to the [Ensuring workflow access to your package - Configuring a pa
|
|||||||
|
|
||||||
### 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. 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 separated by a space 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.
|
||||||
|
@ -8,7 +8,11 @@ import * as path from 'path';
|
|||||||
import {restoreCache} from './cache-restore';
|
import {restoreCache} from './cache-restore';
|
||||||
import {isCacheFeatureAvailable} from './cache-utils';
|
import {isCacheFeatureAvailable} from './cache-utils';
|
||||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||||
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
|
import {
|
||||||
|
parseNodeVersionFile,
|
||||||
|
printEnvDetailsAndSetOutput,
|
||||||
|
enableCorepack
|
||||||
|
} from './util';
|
||||||
import {State} from './constants';
|
import {State} from './constants';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
@ -60,6 +64,9 @@ export async function run() {
|
|||||||
auth.configAuthentication(registryUrl, alwaysAuth);
|
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const corepack = core.getInput('corepack') || 'false';
|
||||||
|
await enableCorepack(corepack);
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
if (cache && isCacheFeatureAvailable()) {
|
||||||
core.saveState(State.CachePackageManager, cache);
|
core.saveState(State.CachePackageManager, cache);
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||||
|
13
src/util.ts
13
src/util.ts
@ -70,3 +70,16 @@ export const unique = () => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function enableCorepack(input: string): Promise<void> {
|
||||||
|
const corepackArgs = ['enable'];
|
||||||
|
if (input.length > 0 && input !== 'false') {
|
||||||
|
if (input !== 'true') {
|
||||||
|
const packageManagers = input.split(' ');
|
||||||
|
corepackArgs.push(...packageManagers);
|
||||||
|
}
|
||||||
|
await exec.getExecOutput('corepack', corepackArgs, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user