diff --git a/packages/rstack/src/setup/install.ts b/packages/rstack/src/setup/install.ts index bd0bb407..b67c0a92 100644 --- a/packages/rstack/src/setup/install.ts +++ b/packages/rstack/src/setup/install.ts @@ -7,6 +7,7 @@ import { writeFileSync, } from 'node:fs'; import path from 'node:path'; +import { types } from 'node:util'; import { displayPath, fail, @@ -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; @@ -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; } @@ -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}`); }