Skip to content

Commit

Permalink
feat(npm): support corepack packageManager URLs
Browse files Browse the repository at this point in the history
Closes #27656
  • Loading branch information
rarkins committed Mar 11, 2024
1 parent d111a1e commit f86ce9b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/modules/manager/npm/post-update/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import semver from 'semver';
import upath from 'upath';
import { logger } from '../../../../logger';
import { readLocalFile } from '../../../../util/fs';
Expand Down Expand Up @@ -35,7 +36,10 @@ export function getPackageManagerVersion(
logger.debug(
`Found ${name} constraint in package.json packageManager: ${version}`,
);
return version;
if (semver.valid(version)) {
return version;
}
return null;
}
if (pkg.engines?.[name]) {
const version = pkg.engines[name];
Expand Down
47 changes: 47 additions & 0 deletions lib/modules/manager/npm/post-update/yarn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,53 @@ describe('modules/manager/npm/post-update/yarn', () => {
expect(res.lockFile).toBe('package-lock-contents');
});

it('supports packageManager url corepack', async () => {
process.env.CONTAINERBASE = 'true';
GlobalConfig.set({
localDir: '.',
binarySource: 'install',
cacheDir: '/tmp/cache',
});
const yarnLockContents = `__metadata:
version: 6
cacheKey: 8`;
Fixtures.mock(
{
'package.json':
'{ "packageManager": "yarn@https://nexus-proxy.repo.local.company.net/nexus/content/groups/npm-all/@yarnpkg/cli-dist/-/cli-dist-3.7.0.tgz#sha224.a06723957ae0292e21f598a453" }',
'yarn.lock': yarnLockContents,
},
'some-dir',
);
mockedFunction(getPkgReleases).mockResolvedValueOnce({
releases: [{ version: '0.10.0' }],
});
const execSnapshots = mockExecAll({
stdout: '2.1.0',
stderr: '',
});
const config = partial<PostUpdateConfig<NpmManagerData>>({
managerData: { hasPackageManager: true },
});
const res = await yarnHelper.generateLockFile('some-dir', {}, config);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool node 16.16.0', options: { cwd: 'some-dir' } },
{ cmd: 'install-tool corepack 0.10.0', options: { cwd: 'some-dir' } },
{
cmd: 'yarn install --mode=update-lockfile',
options: {
cwd: 'some-dir',
env: {
YARN_ENABLE_GLOBAL_CACHE: '1',
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false',
YARN_HTTP_TIMEOUT: '100000',
},
},
},
]);
expect(res.lockFile).toBe(yarnLockContents);
});

it('supports corepack on grouping', async () => {
process.env.CONTAINERBASE = 'true';
GlobalConfig.set({
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/npm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Json, LooseRecord } from '../../../util/schema-utils';
export const PackageManagerSchema = z
.string()
.transform((val) => val.split('@'))
.transform(([name, version]) => ({ name, version }));
.transform(([name, ...version]) => ({ name, version: version.join('@') }));

export const PackageJsonSchema = z.object({
engines: LooseRecord(z.string()).optional(),
Expand Down

0 comments on commit f86ce9b

Please sign in to comment.