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) {
output.error({ if (!isPostInstallProcess()) {
title: `Failed to parse ${packageManager} lockfile`, output.error({
bodyLines: errorBodyLines(e), title: `Failed to parse ${packageManager} lockfile`,
}); bodyLines: errorBodyLines(e),
});
}
return; return;
} }
throw new Error(`Unknown package manager: ${packageManager}`); throw new Error(`Unknown package manager: ${packageManager}`);
@ -153,18 +155,20 @@ export function createLockFile(
return stringifyNpmLockfile(prunedGraph, content, normalizedPackageJson); return stringifyNpmLockfile(prunedGraph, content, normalizedPackageJson);
} }
} catch (e) { } catch (e) {
const additionalInfo = [ if (!isPostInstallProcess()) {
'To prevent the build from breaking we are returning the root lock file.', const additionalInfo = [
]; 'To prevent the build from breaking we are returning the root lock file.',
if (packageManager === 'npm') { ];
additionalInfo.push( if (packageManager === 'npm') {
'If you run `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.' 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; 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'
);
}