perf(lint): load Sucrase lazily in validateReactPages#2547
Merged
Conversation
@objectstack/lint sits on the kernel boot path, but the react syntax
gate (ADR-0081) only runs when a kind:'react' page is actually
validated. The top-level `import { transform } from 'sucrase'` made
every boot parse ~1.5 MB of transpiler (~16 ms cold require) — the same
boot-path problem as the TypeScript compiler in validateReactPageProps,
fixed in #2544.
Sucrase now loads on the first validated react-source page via the same
deferred createRequire (anchor chain import.meta.url → __filename →
cwd); the public API stays synchronous and unchanged, `sucrase` stays a
regular dependency, and a missing package at call time fails validation
with an actionable error instead of killing boot.
The guard test is generalized from lazy-typescript.test.ts to
lazy-deps.test.ts, covering both deps at all three levels (structural
no-eager-import scan over src, child-process probes of both dist
formats, in-process lazy-load behavior) — verified to go red for each
dep separately when its eager import is reintroduced. An in-worker
require.cache probe alone cannot catch it: vitest inlines static
imports through its transform.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📓 Docs Drift CheckNo hand-written docs reference the 1 changed package(s). ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@objectstack/lintsits on the kernel boot path, but the react syntax gate (ADR-0081) only runs when akind:'react'page is actually validated. The top-levelimport { transform } from 'sucrase'invalidate-react-pages.tsmade every boot parse ~1.5 MB of transpiler (~16 ms cold require) — the same boot-path problem as the TypeScript compiler invalidateReactPageProps, fixed in #2544.createRequirepattern (anchor chainimport.meta.url→__filename→ cwd); the public API stays synchronous and unchanged, andsucrasestays a regular dependency in package.json.tryso a missing package can't be swallowed as a syntax finding.lazy-typescript.test.tstolazy-deps.test.ts, parameterized overLAZY_DEPS = ['typescript', 'sucrase']at all three levels: structural no-eager-import scan over src, child-process probes of both built dist formats (also asserting per-gate independence — the syntax gate must not load typescript), and in-process lazy-load behavior. An in-worker require.cache probe alone cannot catch a reintroduced eager import: vitest inlines static imports through its transform.Red-check
Verified the guard goes red for each dep separately by reintroducing the eager imports (string-patched, then reverted):
sucrase was loaded eagerly, at import timeVerification
pnpm vitest runin packages/lint: 116/116 green, all 4 guard tests run un-skipped against built disteslint srccleanturbo build --filter=...@objectstack/lint: 61/61 tasks green@objectstack/lint🤖 Generated with Claude Code