Skip to content

Commit 88d5e44

Browse files
authored
Fixes the lockfile hydration of the npm: protocol (#9023)
* Fixes npm: aliases lockfile hydration * Tweaks * Tweaks
1 parent 655707d commit 88d5e44

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/cli/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ process.stdout.prependListener('error', err => {
3636
throw err;
3737
});
3838

39-
function findPackageManager(base: string): ?string {
39+
function findPackageManager(base: string): string | null {
4040
let prev = null;
4141
let dir = base;
4242

@@ -45,7 +45,7 @@ function findPackageManager(base: string): ?string {
4545

4646
let data;
4747
try {
48-
data = JSON.parse(fs.readFileSync(p));
48+
data = JSON.parse(fs.readFileSync(p, `utf8`));
4949
} catch (err) {}
5050

5151
if (data && typeof data.packageManager === `string`) {
@@ -303,12 +303,14 @@ export async function main({
303303
process.stderr.write(
304304
`Presence of the ${chalk.gray(
305305
`"packageManager"`,
306+
// eslint-disable-next-line max-len
306307
)} field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.\n`,
307308
);
308309

309310
process.stderr.write(
310311
`Corepack must currently be enabled by running ${chalk.magenta(
311312
`corepack enable`,
313+
// $FlowIgnore
312314
)} in your terminal. For more information, check out ${chalk.blueBright(`https://yarnpkg.com/corepack`)}.\n`,
313315
);
314316

src/lockfile/index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,19 @@ export default class Lockfile {
229229
invariant(remote, 'Package is missing a remote');
230230

231231
const remoteKey = keyForRemote(remote);
232-
const seenPattern = remoteKey && seen.get(remoteKey);
232+
const pkgName = getName(pattern);
233+
234+
const seenKey = remoteKey ? `${remoteKey}#${pkgName}` : null;
235+
const seenPattern = seenKey ? seen.get(seenKey) : null;
236+
233237
if (seenPattern) {
234238
// no point in duplicating it
235239
lockfile[pattern] = seenPattern;
236-
237-
// if we're relying on our name being inferred and two of the patterns have
238-
// different inferred names then we need to set it
239-
if (!seenPattern.name && getName(pattern) !== pkg.name) {
240-
seenPattern.name = pkg.name;
241-
}
242240
continue;
243241
}
242+
244243
const obj = implodeEntry(pattern, {
245-
name: pkg.name,
244+
name: pkgName,
246245
version: pkg.version,
247246
uid: pkg._uid,
248247
resolved: remote.resolved,
@@ -257,8 +256,8 @@ export default class Lockfile {
257256

258257
lockfile[pattern] = obj;
259258

260-
if (remoteKey) {
261-
seen.set(remoteKey, obj);
259+
if (seenKey) {
260+
seen.set(seenKey, obj);
262261
}
263262
}
264263

0 commit comments

Comments
 (0)