Skip to content

One cleanup pass over the three generator fetch scripts #241

Description

@thecodedrift

Collected from the review of #239 and deliberately kept out of it, so a rename did not become a cleanup. Worth actually doing — this is the tracking issue so it does not evaporate.

Scripts in scope: packages/cli/scripts/fetch-api-schema.ts, fetch-rule-hash-vectors.ts, fetch-ast-grep-schema.ts.

1. fetch-api-schema.ts resolves the origin one tier short

getApiBaseUrl (packages/cli/src/api/config.ts:25) has three tiers:

TASKLESS_API_URL  >  config.json apiUrl  >  default

The script checks two:

process.env.TASKLESS_API_URL ?? "https://app.taskless.io/cli"

The realistic failure is narrow but real: a developer pointed at staging purely through config.json silently vendors production instead, and the diff looks like a legitimate API change.

Fix the comment, not the code — the script is hand-run and the gap is worth stating rather than closing. Deliberately do NOT import getApiBaseUrl: that drags CLI runtime code into a build script for a case a sentence covers.

2. Three copies of escapeRegExp

In src/rules/verify.ts, test/recipe-cross-references.test.ts, and test/ast-grep-vendor-contract.test.ts.

3. Repeated boilerplate across the three scripts

Dirname and output-path resolution, duplicated in each.

4. A hand-rolled directory walker

Duplicating what readdir(..., { recursive: true }) already does.

5. Worth considering: the scripts do not format their own output

fetch-api-schema.ts writes JSON.stringify(…, 2) while the committed file is prettier-formatted, so git diff right after a refresh shows ~1700 lines of array-collapsing churn until lint-staged normalises it at commit.

Self-correcting, and pre-existing across all three scripts, but it means "run the script, see an empty diff" is not literally true yet — which is the property fetch-api-schema.ts's own docstring claims. Closing it needs prettier declared as a dependency of packages/cli (it currently resolves only by walking up to the root), so weigh that against the benefit.

Why one pass rather than five commits

These are all the same shape and all in the same three files. Fixing them together is one review; fixing them separately is five diffs that each look too small to think about.

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