Skip to content

Commit f6aafa0

Browse files
authored
Removes the protocol when it matches the default one (#6917)
## What's the problem this PR addresses? Yarn normalizes all ranges to prefix them by a unique registry string (ie `npm:^2.0.0`) but other package managers don't understand those explicit ranges (they expect `^2.0.0`). Fixes #6913 ## How did you fix it? Removes the protocol from the output before storing it in the package.json when operating on `catalog:` replacements. This follows the same logic as in `yarn add`. ## Checklist <!--- Don't worry if you miss something, chores are automatically tested. --> <!--- This checklist exists to help you remember doing the chores when you submit a PR. --> <!--- Put an `x` in all the boxes that apply. --> - [x] I have read the [Contributing Guide](https://yarnpkg.com/advanced/contributing). <!-- See https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released for more details. --> <!-- Check with `yarn version check` and fix with `yarn version check -i` --> - [x] I have set the packages that need to be released for my changes to be effective. <!-- The "Testing chores" workflow validates that your PR follows our guidelines. --> <!-- If it doesn't pass, click on it to see details as to what your PR might be missing. --> - [x] I will check that all automated PR checks pass before the PR gets reviewed.
1 parent a2973cc commit f6aafa0

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

.yarn/versions/b206e309.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-catalog": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-npm-cli"
14+
- "@yarnpkg/plugin-pack"
15+
- "@yarnpkg/plugin-patch"
16+
- "@yarnpkg/plugin-pnp"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"

packages/acceptance-tests/pkg-tests-specs/sources/features/catalogs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ describe(`Features`, () => {
181181

182182
const packedManifest = await xfs.readJsonPromise(`${path}/package/package.json` as PortablePath);
183183

184-
expect(packedManifest.dependencies[`no-deps`]).toBe(`npm:^2.0.0`);
185-
expect(packedManifest.devDependencies[`one-fixed-dep`]).toBe(`npm:~1.0.0`);
184+
expect(packedManifest.dependencies[`no-deps`]).toBe(`^2.0.0`);
185+
expect(packedManifest.devDependencies[`one-fixed-dep`]).toBe(`~1.0.0`);
186186
},
187187
),
188188
);

packages/plugin-catalog/sources/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ const plugin: Plugin<CoreHooks & PackHooks> = {
8585
// Resolve the catalog reference to get the actual version range
8686
const resolvedDescriptor = resolveDescriptorFromCatalog(project, descriptor, resolver, resolveOptions);
8787

88+
let {protocol, source, params, selector} = structUtils.parseRange(structUtils.convertToManifestRange(resolvedDescriptor.range));
89+
if (protocol === workspace.project.configuration.get(`defaultProtocol`))
90+
protocol = null;
91+
8892
// Replace the catalog reference with the resolved range
89-
dependencies[identStr] = resolvedDescriptor.range;
93+
dependencies[identStr] = structUtils.makeRange({protocol, source, params, selector});
9094
}
9195
}
9296
},

packages/plugin-catalog/sources/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const resolveDescriptorFromCatalog = (project: Project, dependency: Descr
4646
if (!resolvedRange)
4747
throw new ReportError(MessageName.RESOLUTION_FAILED, `${structUtils.prettyDescriptor(project.configuration, dependency)}: entry not found in ${getCatalogErrorDisplayName(catalogName)}`);
4848

49-
5049
// The range resolved from the catalog may need to be normalized (.i.e. ^2.4.0 -> npm:^2.4.0)
5150
// This process typically happens before the reduceDependency hook, but we need to do it here since
5251
// when it is first called the dependency range still refers to the catalog

0 commit comments

Comments
 (0)