Skip to content

Added option to enable corepack #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: removed extra corepack commands
  • Loading branch information
jrparish committed Mar 25, 2025
commit 108e90108c402eb6bc48f93e904bd444066cd438
17 changes: 0 additions & 17 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -305,23 +305,6 @@ describe('main tests', () => {
inputs['corepack'] = 'true';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith('npm i -g corepack');
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable');
});

it('should enable corepack with a single package manager', async () => {
inputs['corepack'] = 'npm';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith('npm i -g corepack');
expect(getCommandOutputSpy).toHaveBeenCalledWith('corepack enable npm');
});

it('should enable corepack with multiple package managers', async () => {
inputs['corepack'] = 'npm yarn';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith('npm i -g corepack');
expect(getCommandOutputSpy).toHaveBeenCalledWith(
'corepack enable npm yarn'
);
});
});
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ inputs:
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.'
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.'
description: 'Used to specify whether to enable Corepack.'
default: 'false'
# 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
6 changes: 0 additions & 6 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
@@ -88341,13 +88341,7 @@ exports.unique = unique;
function enableCorepack(input) {
return __awaiter(this, void 0, void 0, function* () {
if (input.length && input !== 'false') {
const corepackArgs = ['enable'];
if (input !== 'true') {
const packageManagers = input.split(' ');
corepackArgs.push(...packageManagers);
}
yield (0, cache_utils_1.getCommandOutput)('npm i -g corepack');
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
}
});
}
6 changes: 0 additions & 6 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
@@ -98019,13 +98019,7 @@ exports.unique = unique;
function enableCorepack(input) {
return __awaiter(this, void 0, void 0, function* () {
if (input.length && input !== 'false') {
const corepackArgs = ['enable'];
if (input !== 'true') {
const packageManagers = input.split(' ');
corepackArgs.push(...packageManagers);
}
yield (0, cache_utils_1.getCommandOutput)('npm i -g corepack');
yield (0, cache_utils_1.getCommandOutput)(`corepack ${corepackArgs.join(' ')}`);
}
});
}
15 changes: 1 addition & 14 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
@@ -427,21 +427,8 @@ steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
node-version: '22.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@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
corepack: yarn pnpm
- name: Install dependencies
run: yarn install --immutable
```
6 changes: 0 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -110,12 +110,6 @@ export const unique = () => {

export async function enableCorepack(input: string): Promise<void> {
if (input.length && input !== 'false') {
const corepackArgs = ['enable'];
if (input !== 'true') {
const packageManagers = input.split(' ');
corepackArgs.push(...packageManagers);
}
await getCommandOutput('npm i -g corepack');
await getCommandOutput(`corepack ${corepackArgs.join(' ')}`);
}
}