Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the lockfile hydration of the npm: protocol #9023

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ process.stdout.prependListener('error', err => {
throw err;
});

function findPackageManager(base: string): ?string {
function findPackageManager(base: string): string | null {
let prev = null;
let dir = base;

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

let data;
try {
data = JSON.parse(fs.readFileSync(p));
data = JSON.parse(fs.readFileSync(p, `utf8`));
} catch (err) {}

if (data && typeof data.packageManager === `string`) {
Expand Down Expand Up @@ -303,12 +303,14 @@ export async function main({
process.stderr.write(
`Presence of the ${chalk.gray(
`"packageManager"`,
// eslint-disable-next-line max-len
)} 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`,
);

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

Expand Down
19 changes: 9 additions & 10 deletions src/lockfile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,19 @@ export default class Lockfile {
invariant(remote, 'Package is missing a remote');

const remoteKey = keyForRemote(remote);
const seenPattern = remoteKey && seen.get(remoteKey);
const pkgName = getName(pattern);

const seenKey = remoteKey ? `${remoteKey}#${pkgName}` : null;
const seenPattern = seenKey ? seen.get(seenKey) : null;

if (seenPattern) {
// no point in duplicating it
lockfile[pattern] = seenPattern;

// if we're relying on our name being inferred and two of the patterns have
// different inferred names then we need to set it
if (!seenPattern.name && getName(pattern) !== pkg.name) {
seenPattern.name = pkg.name;
}
continue;
}

const obj = implodeEntry(pattern, {
name: pkg.name,
name: pkgName,
version: pkg.version,
uid: pkg._uid,
resolved: remote.resolved,
Expand All @@ -257,8 +256,8 @@ export default class Lockfile {

lockfile[pattern] = obj;

if (remoteKey) {
seen.set(remoteKey, obj);
if (seenKey) {
seen.set(seenKey, obj);
}
}

Expand Down