fix(package): parse static imports with TypeScript - #652
Conversation
tangletools
left a comment
There was a problem hiding this comment.
✅ Auto-approved drewstone PR — 2d624e95
This PR was opened by the trusted drewstone account.
The full PR reviewer audit still runs separately and will publish findings if it detects issues.
tangletools · auto-approval · reason: drewstone_author · 2026-07-28T20:33:43Z
tangletools
left a comment
There was a problem hiding this comment.
🟢 Value Audit — sound
| Verdict | sound |
| Concerns | 0 (none) |
| Heuristic | 0.0s |
| Duplication | 0.0s |
| Interrogation | 75.6s (2 bridge agents) |
| Total | 75.6s |
💰 Value — sound
Replaces a fragile regex static-import scanner with a TypeScript-AST parser using an already-installed dependency, fixing real false positives/negatives and fronting a fast synthetic test before the expensive packed-package build.
- What it does: Adds
scripts/lib/static-imports.mjsexportingfindStaticPackageImports(source, packageNames), which parses JS withts.createSourceFileand walks the AST to collect ESM import/export specifiers and CommonJSrequire/module.requirestring-literal arguments, intentionally skipping dynamicimport().verify-package-exports.mjsdrops its hand-rolledhasStaticImportregex and `assertEdgeUn - Goals it achieves: Make the edge-unsafe-import release gate (Cloudflare rejects Workers that statically import
graceful-fs/proper-lockfile) actually correct: the old regex mis-classified commented-out code, string/template literals containing the wordimport, member-requirecalls, and inline-commented specifiers. The new gate catches real static imports the regex missed (require(\x`),module.require('x' - Assessment: Sound and in-grain.
typescriptis already a devDependency and already used identically inscripts/gen-primitive-catalog.mjs:51, so no new dependency. The chosen primitive (ts.createSourceFile, syntactic-only — nocreateProgram/type-checker) is the lightest correct tool. Placement inscripts/lib/matches the existingpacked-package-test.mjsreuse pattern. Returning the matching package - Better / existing approach: Searched
scripts/for existing equivalents (acorn, meriyah, espree, @babel/parse, any prior static-import scanner) — none found; onlygen-primitive-catalog.mjsuses the TS compiler, and it does full-program type-checker extraction for a different purpose (symbol/JSDoc cataloging), so it is not reusable here. The new file is the right factoring. none — this is the right approach. - Model: opencode/zai-coding-plan/glm-5.2
- Bridge attempts: 2
- Bridge warning: opencode/kimi-for-coding/k2p7: bridge stream ended without value-audit content
🎯 Usefulness — sound
Replaces a fragile regex static-import matcher with a TypeScript AST parse, fixing shipped false-positives on commented/string-embedded import text; fully wired into CI and publish.
- Integration: Fully reachable. findStaticPackageImports is consumed at scripts/verify-package-exports.mjs:651 inside assertNoEdgeUnsafeStaticImports (the Cloudflare-builtin-patch safety gate). The new standalone runner scripts/verify-static-imports.mjs is exposed as
pnpm run verify:static-imports(package.json:120) and prepended intoverify:package(package.json:124), which runs in .github/workflows/ci.yml: - Fit with existing patterns: Matches the codebase grain.
import ts from 'typescript'is already used the same way at scripts/gen-primitive-catalog.mjs:51 and tests/testing-fixture.test.ts:15; typescript is a catalog dependency (pnpm-workspace.yaml:28, package.json:146). The new code follows the existing scripts/lib/*.mjs factoring (cf. scripts/lib/packed-package-test.mjs). It replaces an inline regex (hasStaticImport) plus - Real-world viability: Holds up beyond the happy path. AST parsing is comment- and context-immune: the visitor catches ImportDeclaration/ExportDeclaration module specifiers, CommonJS require() and module.require(), package + subpath specifiers, and no-substitution template literals (isStringLiteralLike); it correctly skips dynamic import() (callee is
import, notrequire), non-string args, lookalike packages (proper- - Model: opencode/zai-coding-plan/glm-5.2
- Bridge attempts: 1
No concerns — sound change, no better or existing approach found. ✅
What this audit checks
It judges the change on its merits — not whether it was tasked out in an issue. Unticketed, fast-moving work is fine; the question is whether the change is good and whether a better or existing approach should be used instead.
| Pass | What it asks |
|---|---|
| Heuristic | Vague title? Whitespace-only or cruft-bearing diff? (content signals only) |
| Duplication | Do added function/class names already exist elsewhere in the repo? |
| Value Audit | What does it do? What goal does it achieve? Is it good? Better architecture or already-exists? |
| Usefulness Audit | Does it integrate and fit? Will it hold up in real use and actually get used? |
Findings are concerns, not blocks — the human reviewer decides what to do with them.
✅ No Blockers —
|
tangletools
left a comment
There was a problem hiding this comment.
✅ Approved — 4 non-blocking findings — 2d624e95
Full multi-shot audit completed 4/4 planned shots over 4 changed files. Global verifier still owns final merge decision.
Full immutable report for this review: trace
Summary comment for this run: full summary
tangletools · 2026-07-28T20:42:51Z · immutable trace
Summary
Checks
pnpm run verify:static-importspnpm run verify:packagepnpm test