Skip to content

Commit

Permalink
Fixes the lockfile hydration of the npm: protocol (#9023)
Browse files Browse the repository at this point in the history
* Fixes npm: aliases lockfile hydration

* Tweaks

* Tweaks
  • Loading branch information
arcanis committed Mar 9, 2024
1 parent 655707d commit 88d5e44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/cli/index.js
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
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

0 comments on commit 88d5e44

Please sign in to comment.