Skip to content

Commit 4264c8b

Browse files
tannevaledclaude
andcommitted
fix temporal-dead-zone on PKGX_MIN_VERSION
The previous commit placed `const PKGX_MIN_VERSION = new SemVer("2.4.0")` above pkgx_meets_minimum() near line ~540, but the top-level dispatch block (parsedArgs switch at lines 60–126) calls install() → get_pkgx() → pkgx_meets_minimum() at module-init time, which is BEFORE execution reaches line 540. `const` declarations are hoisted in name only (TDZ), unlike `function` declarations whose bodies are hoisted — so the reference threw `Cannot access 'PKGX_MIN_VERSION' before initialization` at runtime, causing every `pkgm install` to fail silently with exit 1. Neither `deno fmt`, `deno lint`, nor `deno check` detect this — it's a module-init ordering issue invisible to static analysis. Pushed CI on #86 caught it via the existing `./pkgm.ts i git` test. Move the constant up to module-scope right after the `hydrate` import, above any function that's reachable from top-level code. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e1104ea commit 4264c8b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

pkgm.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { ensureDir, existsSync, walk } from "jsr:@std/fs@^1";
1313
import { parseArgs } from "jsr:@std/cli@^1";
1414
const { hydrate } = plumbing;
1515

16+
// Module-scope SemVer literal: must be defined before any function that
17+
// reads it can be called from top-level code below. `const` declarations
18+
// are hoisted in name only (TDZ), so placing this further down the file
19+
// triggered "Cannot access 'PKGX_MIN_VERSION' before initialization" once
20+
// install()/get_pkgx() ran at module-init time.
21+
const PKGX_MIN_VERSION = new SemVer("2.4.0");
22+
1623
function standardPath() {
1724
let path = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
1825

@@ -535,8 +542,6 @@ function symlink_with_overwrite(src: string, dst: string) {
535542
Deno.symlinkSync(src, dst);
536543
}
537544

538-
const PKGX_MIN_VERSION = new SemVer("2.4.0");
539-
540545
function pkgx_meets_minimum(path: string): boolean {
541546
try {
542547
const out = new Deno.Command(path, { args: ["--version"] }).outputSync();

0 commit comments

Comments
 (0)