feat: allow specifying a version

This commit is contained in:
Jacob Parish 2025-03-25 11:13:23 -05:00
parent 4478bd4702
commit aa9724272b
6 changed files with 40 additions and 6 deletions

View File

@ -301,10 +301,28 @@ describe('main tests', () => {
);
});
it('should enable corepack when input is "true"', async () => {
it('should install latest corepack when input is "true"', async () => {
inputs['corepack'] = 'true';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith('npm i -g corepack');
expect(getCommandOutputSpy).toHaveBeenCalledWith(
'npm i -g corepack@latest'
);
});
it('should install latest corepack when input is "latest"', async () => {
inputs['corepack'] = 'latest';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith(
'npm i -g corepack@latest'
);
});
it('should install a specific version of corepack when specified', async () => {
inputs['corepack'] = '0.32.0';
await main.run();
expect(getCommandOutputSpy).toHaveBeenCalledWith(
'npm i -g corepack@0.32.0'
);
});
});
});

View File

@ -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: 'Enables Corepack which allows the use of other package managers.'
description: 'Enables Corepack which allows the use of other package managers. Can provide a version string to install a specific version.'
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

View File

@ -88341,7 +88341,8 @@ exports.unique = unique;
function enableCorepack(input) {
return __awaiter(this, void 0, void 0, function* () {
if (input.length && input !== 'false') {
yield (0, cache_utils_1.getCommandOutput)('npm i -g corepack');
const version = input === 'true' ? 'latest' : input;
yield (0, cache_utils_1.getCommandOutput)(`npm i -g corepack@${version}`);
}
});
}

3
dist/setup/index.js vendored
View File

@ -98019,7 +98019,8 @@ exports.unique = unique;
function enableCorepack(input) {
return __awaiter(this, void 0, void 0, function* () {
if (input.length && input !== 'false') {
yield (0, cache_utils_1.getCommandOutput)('npm i -g corepack');
const version = input === 'true' ? 'latest' : input;
yield (0, cache_utils_1.getCommandOutput)(`npm i -g corepack@${version}`);
}
});
}

View File

@ -432,3 +432,16 @@ steps:
- name: Install dependencies
run: yarn install --immutable
```
You can also pass a version string to install a specific version of corepack.
```yaml
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
corepack: '0.32.0'
- name: Install dependencies
run: yarn install --immutable
```

View File

@ -110,6 +110,7 @@ export const unique = () => {
export async function enableCorepack(input: string): Promise<void> {
if (input.length && input !== 'false') {
await getCommandOutput('npm i -g corepack');
const version = input === 'true' ? 'latest' : input;
await getCommandOutput(`npm i -g corepack@${version}`);
}
}