Skip to content

Commit 7992d19

Browse files
committed
fix(scripts): add the git-env declaration mirror the spec TS lane needs
CI red on 6b398c3: `packages/spec` `pnpm run typecheck` exited 2 with TS7016 at both converted fixtures -- "Could not find a declaration file for module '../../../scripts/git-env.mjs'". Reproduced locally against `check:scripts-typecheck`, the lane that owns it: `tsconfig.scripts.json` includes `scripts/**/*`, inherits `strict` from the root config and sets no `allowJs`, so an untyped `.mjs` import from `packages/spec/scripts/` is TS7016. The mechanical difference from the live precedent: `scripts/js-comment-mask.mjs` and `scripts/check-regen-pending.mjs` each ship a hand-written `.d.mts` sibling (#5475, #10398) -- nine of them existed before this commit -- and `scripts/git-env.mjs` did not. That is also why the pre-existing `check-regen-pending.mjs` import in the very same test file type-checks. So this copies that shape and nothing else: one sibling declaration, PARTIAL on purpose per `invoked-as.d.mts`, declaring only the export TypeScript consumes. `check:declaration-mirrors` discovers the corpus rather than listing it and now reports "OK: 10 hand-written declaration(s) agree with their modules on name, kind and required arity" -- `gitFreeEnv`'s `Function.length` is 0 and the declaration's required arity is 0. ⚠️ This is one file beyond the declared surface, and it is declared as such: it is the mandatory accompaniment of the import triage ordered, and the two remedies that avoid a new file are the two the dispatch refuses. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ef78bLdybu3AffehKkhfk
1 parent 6b398c3 commit 7992d19

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎scripts/git-env.d.mts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Types for the git-environment strip `git-env.mjs` publishes to the gates and
2+
// fixtures that import it (#16644).
3+
//
4+
// The module itself stays `.mjs`, for the reason its three sibling mirrors
5+
// state: `pre-commit`, the merge driver and every `check:*` gate invoke these
6+
// root scripts with bare `node`, and every root script here is authored that
7+
// way. What needed the declaration is the other direction — two TypeScript
8+
// fixtures under `packages/spec/scripts/` now import the strip
9+
// (`build-schemas-check-mode.test.ts`, `sharded-artifacts.test.ts`), and since
10+
// #5475 that directory is inside a tsc program (`tsconfig.scripts.json`), where
11+
// an untyped `.mjs` import is TS7016. Left untyped, `gitFreeEnv` silently
12+
// becomes `any`, and the mistake that costs the most here — `env: gitFreeEnv`
13+
// instead of `env: gitFreeEnv()`, which hands the child a FUNCTION where an
14+
// environment belongs — type-checks clean.
15+
//
16+
// Declared rather than inferred (no `allowJs`) because the module sits at the
17+
// repo root, outside the consuming program's `rootDir`.
18+
//
19+
// PARTIAL on purpose, the `check-regen-pending.d.mts` / `invoked-as.d.mts`
20+
// shape: the module also exports `withoutGitEnv`, `gitEnvKeys`,
21+
// `sharedGitConfigVerdict`, `formatSharedGitConfigAlarm`, `selfTest` and two
22+
// string constants, and omitting them cannot fail green — a consumer importing
23+
// an undeclared name gets TS2305, which is loud and immediate. Every one of
24+
// those is reached today from `.mjs` callers, which need no declaration at all,
25+
// so declaring them would grow a hand-maintained surface nothing is asking for.
26+
// Keep this file in step with the module by hand; `check:declaration-mirrors`
27+
// asserts the name, kind and required arity of each entry — never the types,
28+
// which stay yours.
29+
30+
/**
31+
* A copy of `base` with every `GIT_`-prefixed key removed.
32+
*
33+
* Returns a NEW object; `process.env` is not mutated. Pass the result as the
34+
* `env` option of every `git` child that must operate on the repository its
35+
* `cwd` and arguments name ALONE.
36+
*
37+
* ⛔ Not for a child that talks to a remote: `GIT_CONFIG_*` and `GIT_SSL_*`
38+
* carry the transport configuration, and the module's header carries the
39+
* measurement behind that boundary.
40+
*
41+
* @param base Defaults to `process.env`.
42+
*/
43+
export function gitFreeEnv(base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;

0 commit comments

Comments
 (0)