fix(core): ignore missing modules.yaml during postinstall (#15660)

This commit is contained in:
Miroslav Jonaš 2023-03-14 16:20:41 +01:00 committed by GitHub
parent ebdb193f0e
commit 8a0398d744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,10 +92,12 @@ export function parseLockFile(
return parseNpmLockfile(content); return parseNpmLockfile(content);
} }
} catch (e) { } catch (e) {
if (!isPostInstallProcess()) {
output.error({ output.error({
title: `Failed to parse ${packageManager} lockfile`, title: `Failed to parse ${packageManager} lockfile`,
bodyLines: errorBodyLines(e), bodyLines: errorBodyLines(e),
}); });
}
return; return;
} }
throw new Error(`Unknown package manager: ${packageManager}`); throw new Error(`Unknown package manager: ${packageManager}`);
@ -153,6 +155,7 @@ export function createLockFile(
return stringifyNpmLockfile(prunedGraph, content, normalizedPackageJson); return stringifyNpmLockfile(prunedGraph, content, normalizedPackageJson);
} }
} catch (e) { } catch (e) {
if (!isPostInstallProcess()) {
const additionalInfo = [ const additionalInfo = [
'To prevent the build from breaking we are returning the root lock file.', 'To prevent the build from breaking we are returning the root lock file.',
]; ];
@ -165,6 +168,7 @@ export function createLockFile(
title: 'An error occured while creating pruned lockfile', title: 'An error occured while creating pruned lockfile',
bodyLines: errorBodyLines(e, additionalInfo), bodyLines: errorBodyLines(e, additionalInfo),
}); });
}
return content; return content;
} }
} }
@ -180,3 +184,10 @@ function errorBodyLines(originalError: Error, additionalInfo: string[] = []) {
originalError.stack, originalError.stack,
]; ];
} }
function isPostInstallProcess(): boolean {
return (
process.env.npm_command === 'install' &&
process.env.npm_lifecycle_event === 'postinstall'
);
}