Command Palette

Search for a command to run...

Back to skills
skill № 82497

hoc-dependency-defect

How to deal with a bug in code this project uses but does not own — a framework, an in-house package, anything inside `node_modules/`. Use when a package…

FreeNo executable scripts
openreachtechby openreachtech★ 17 GitHub stars

Install hoc-dependency-defect in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Dependency Defect

Never edit code this project uses but does not own. Work around it instead.

Code this project does not own means a framework, an in-house package, or anything inside node_modules/. This skill explains how to write that workaround and where to put it. It does not decide who approves the work, which branch it goes on, or what gets written down outside the code. The team's process decides those.

A bug in code this project owns is a different thing. Fix that code directly.

The steps

  1. Check whether the package already fixed it. Read the package's own history: the version in use, and every version after it. If the fix is already there, upgrade the package and stop.
  2. Add a class in this project that extends the broken class.
  3. Override only the member that is broken.
  4. Use the new class at every call site.
  5. Write a comment saying why the class exists, so someone can delete it later.

Step 0 is the one people skip. Then they write a subclass that repeats a fix the package already shipped. Reading the history takes a few minutes.

Why a subclass, and not something else

What people do instead What goes wrong
Edit the package inside node_modules/ The next install wipes the edit. Nothing shows that it was ever there, so the bug comes back and nobody knows why.
Fork the package Every future upgrade turns into a merge. Forever, for one bug.
Rewrite what the package does As much work as a fork, and now this project owns all of it. Fixes to the parts that were never broken stop arriving.
Replace the class's methods at runtime The call site looks normal, so a reader cannot tell that the behavior changed, and has no file to open. If two of these run in one process, whichever one loads last wins.
Copy the class into this project and fix the copy The same problems as a fork, in one file.

A small bug is not an excuse to pick one of these. The rule holds because the code belongs to someone else, and they will change it again.

Step 1 — add a subclass of the broken class

The subclass is normal code in this project. It follows the same rules as every other class here.

  • Put it where this project keeps its other classes of that kind. Never create a folder named after the package, and never put the file next to the package's own files.
  • Name it after what it does, as a singular UpperCamelCase noun, like any other class here. Do not use names like PatchedXxxx, FixedXxxx or XxxxWorkaround. Those names describe how the file was born, not what it does, and they become wrong if the class is kept for another reason. The reason belongs in the comment of step 4.
  • Import the broken class the way the package exports it (default or named). Put that import with the other package imports at the top of the file, as the import convention says.
  • This subclass does not need a property of its own. A class here normally has to hold state, but that rule does not apply once a class has extends. The parent holds the state, and the parent already decides the constructor arguments.

Step 2 — override one member, not the whole class

Override one member, and the subclass keeps getting every later improvement from the package. Rewrite the whole class, and it stops getting them the moment you write it. Nothing warns you.

  • Override the one method that behaves wrongly, and call super for everything else.
  • Override a getter when the parent computes a value wrongly.
  • Do not copy the parent's code into the child and change two lines.
  • Do not override a member that already works, just to keep the class tidy.
  • Mark every override with @override, in the form the JSDoc convention (/hoc-jsdoc) settles.

When the correct answer needs part of the parent's work, call the parent and correct its result. Do not rewrite what it does.

// NG: the parent's code is copied here, so the package's later fixes never reach this class
export default class SingleDayDateRangeFormatter extends DateRangeFormatter {
  /**
   * Format a date range.
   *
   * @param {{
   *   startedOn: string
   *   endedOn: string
   * }} params - Parameters.
   * @returns {string} Formatted range.
   * @override
   */
  formatRange ({
    startedOn,
    endedOn,
  }) {
    if (startedOn === endedOn) {
      return startedOn
    }

    return `${startedOn} - ${endedOn}` // copied out of the package, minus the bug
  }
}

// OK: only the broken case is handled here, and the rest stays with the parent
export default class SingleDayDateRangeFormatter extends DateRangeFormatter {
  /**
   * Format a date range.
   *
   * @param {{
   *   startedOn: string
   *   endedOn: string
   * }} params - Parameters.
   * @returns {string} Formatted range.
   * @override
   */
  formatRange ({
    startedOn,
    endedOn,
  }) {
    if (startedOn === endedOn) {
      return startedOn
    }

    return supe
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the hoc-dependency-defect skill do?

How to deal with a bug in code this project uses but does not own — a framework, an in-house package, anything inside `node_modules/`. Use when a package behaves wrongly and the correction has to live in this project. A bug in code this project owns is fixed directly instead.

How do I install the hoc-dependency-defect skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the hoc-dependency-defect skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare hoc-dependency-defect with