Skip to content

Replace the three isPlainObject copies with the shared isRecord guard #421

Description

@theCodeDrift

The 0.12.0 stack (#411–#416) added packages/cli/src/util/is-record.ts and replaced six private copies of the same three-line object guard with it. Three older copies remain under another name, isPlainObject, with the identical body:

File Line
packages/cli/src/filesystem/manifest.ts 223
packages/cli/src/filesystem/migrations/0002-install.ts 8
packages/cli/src/filesystem/migrations/0003-drop-installed-at.ts 8
function isPlainObject(value: unknown): value is Record<string, unknown> {
  return typeof value === "object" && value !== null && !Array.isArray(value);
}

That's three copies, which is where we consolidate. They were left alone in the stack because they predate it and weren't in its diff.

Change

Delete the three functions and import isRecord from ../util/is-record (from ../../util/is-record in the migrations). There are 7 call sites. No other inline copy of the guard exists in packages/cli/src.

Migrations can share it

Migrations 0002 and 0003 can import the shared guard too. The migration run takes a project all the way to the latest schema before any command does its work, so sharing a helper with the rest of the CLI doesn't change what an old project sees.

Done when

  • The three functions are gone and every call site imports isRecord.
  • pnpm typecheck, pnpm lint, and the CLI suite pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions