Skip to content

Commit 2394026

Browse files
MLoughryarcanis
andauthored
Fixes the metadata file name to avoid ambiguities (#6762)
Fixes #6761 ## What's the problem this PR addresses? By using `-` to separate the scope and name in `slugifyident`, the code could result in a name collision between packages (eg., `@x-y/z` and `@x/y-z`). <!-- Describe the rationale of your PR. --> <!-- Link all issues that it closes. (Closes/Resolves #xxxx.) --> ... ## How did you fix it? This change uses `~` instead, which is valid in file names but not package names. ... ## 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. --------- Co-authored-by: Maël Nison <nison.mael@gmail.com>
1 parent 8ee9a3d commit 2394026

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

.yarn/versions/dd3b3646.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
releases:
2+
"@yarnpkg/core": patch
3+
"@yarnpkg/plugin-npm": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-jsr"
18+
- "@yarnpkg/plugin-link"
19+
- "@yarnpkg/plugin-nm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/cli"
31+
- "@yarnpkg/doctor"
32+
- "@yarnpkg/extensions"
33+
- "@yarnpkg/nm"
34+
- "@yarnpkg/pnpify"
35+
- "@yarnpkg/sdks"

packages/plugin-npm/sources/npmHttpUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ async function loadPackageMetadataInfoFromNetwork(identPath: PortablePath, ident
164164
});
165165
}
166166

167+
function generateMetadataFileName(ident: Ident) {
168+
if (ident.scope !== null) {
169+
return `@${ident.scope}-${ident.name}-${ident.scope.length}`;
170+
} else {
171+
return ident.name;
172+
}
173+
}
174+
167175
/**
168176
* Caches and returns the package metadata for the given ident.
169177
*
@@ -177,7 +185,7 @@ export async function getPackageMetadata(ident: Ident, {cache, project, registry
177185
registry = normalizeRegistry(configuration, {ident, registry});
178186

179187
const registryFolder = getRegistryFolder(configuration, registry);
180-
const identPath = ppath.join(registryFolder, `${structUtils.slugifyIdent(ident)}.json`);
188+
const identPath = ppath.join(registryFolder, `${generateMetadataFileName(ident)}.json`);
181189

182190
let cached: CachedMetadata | null = null;
183191

0 commit comments

Comments
 (0)