Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/rstack/src/setup/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
writeFileSync,
} from 'node:fs';
import path from 'node:path';
import { types } from 'node:util';
import {
displayPath,
fail,
Expand All @@ -25,6 +26,8 @@ import { createHookFiles, hookNames } from './hooks.ts';

const defaultHooksDir = '.rstack/hooks';
const gitignore = '*\n';
const isError = (value: unknown): value is Error =>
Error.isError?.(value) ?? types.isNativeError(value);

type InstallHooksOptions = {
cwd?: string;
Expand Down Expand Up @@ -155,8 +158,7 @@ const claimOwner = (
// Exclusive creation makes concurrent prepare scripts agree on one owner.
writeFileSync(ownerPath, `${project}\n`, { flag: 'wx' });
} catch (error) {
const code =
error instanceof Error && 'code' in error ? error.code : undefined;
const code = isError(error) && 'code' in error ? error.code : undefined;
if (code !== 'EEXIST') {
throw error;
}
Expand Down Expand Up @@ -285,7 +287,7 @@ export const installHooks = ({
chmodSync(filePath, 0o755);
}
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
const message = isError(error) ? error.message : String(error);
return fail('write-failed', `Failed to write Git hook files: ${message}`);
}

Expand Down
Loading