Skip to content

Commit

Permalink
fix(core): ignore missing modules.yaml during postinstall (#15660)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8a0398d)
  • Loading branch information
meeroslav authored and FrozenPandaz committed Mar 15, 2023
1 parent 4dd0d97 commit cd35a0c
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions packages/nx/src/lock-file/lock-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ export function parseLockFile(
return parseNpmLockfile(content);
}
} catch (e) {
output.error({
title: `Failed to parse ${packageManager} lockfile`,
bodyLines: errorBodyLines(e),
});
if (!isPostInstallProcess()) {
output.error({
title: `Failed to parse ${packageManager} lockfile`,
bodyLines: errorBodyLines(e),
});
}
return;
}
throw new Error(`Unknown package manager: ${packageManager}`);
Expand Down Expand Up @@ -153,18 +155,20 @@ export function createLockFile(
return stringifyNpmLockfile(prunedGraph, content, normalizedPackageJson);
}
} catch (e) {
const additionalInfo = [
'To prevent the build from breaking we are returning the root lock file.',
];
if (packageManager === 'npm') {
additionalInfo.push(
'If you run `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.'
);
if (!isPostInstallProcess()) {
const additionalInfo = [
'To prevent the build from breaking we are returning the root lock file.',
];
if (packageManager === 'npm') {
additionalInfo.push(
'If you run `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.'
);
}
output.error({
title: 'An error occured while creating pruned lockfile',
bodyLines: errorBodyLines(e, additionalInfo),
});
}
output.error({
title: 'An error occured while creating pruned lockfile',
bodyLines: errorBodyLines(e, additionalInfo),
});
return content;
}
}
Expand All @@ -180,3 +184,10 @@ function errorBodyLines(originalError: Error, additionalInfo: string[] = []) {
originalError.stack,
];
}

function isPostInstallProcess(): boolean {
return (
process.env.npm_command === 'install' &&
process.env.npm_lifecycle_event === 'postinstall'
);
}

0 comments on commit cd35a0c

Please sign in to comment.