refactor(core): improve dev perf, fine-grained site reloads - part 3 (#9975)

This commit is contained in:
Sébastien Lorber 2024-03-28 12:39:07 +01:00 committed by GitHub
parent 06e70a4f9a
commit efbe474e9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 359 additions and 286 deletions

View file

@ -6,7 +6,16 @@
*/
import path from 'path';
import shell from 'shelljs';
import fs from 'fs-extra';
import _ from 'lodash';
import shell from 'shelljs'; // TODO replace with async-first version
const realHasGitFn = () => !!shell.which('git');
// The hasGit call is synchronous IO so we memoize it
// The user won't install Git in the middle of a build anyway...
const hasGit =
process.env.NODE_ENV === 'test' ? realHasGitFn : _.memoize(realHasGitFn);
/** Custom error thrown when git is not found in `PATH`. */
export class GitNotFoundError extends Error {}
@ -86,13 +95,13 @@ export async function getFileCommitDate(
timestamp: number;
author?: string;
}> {
if (!shell.which('git')) {
if (!hasGit()) {
throw new GitNotFoundError(
`Failed to retrieve git history for "${file}" because git is not installed.`,
);
}
if (!shell.test('-f', file)) {
if (!(await fs.pathExists(file))) {
throw new Error(
`Failed to retrieve git history for "${file}" because the file does not exist.`,
);