Add read-only Prebuild RPC to rewrite-javascript#7935
Draft
knutwannheden wants to merge 1 commit into
Draft
Conversation
`Prebuild` is the JavaScript analog of "invoke the build tool": given a repository (or partition) root it returns the independent, workspace-aware projects with their source sets, config-input watch-set, and parser settings — the build descriptor a consumer uses to drive JS/TS builds and incremental re-parsing. It produces only the descriptor; it does not parse sources. v1 is read-only (no dependency install). The TS handler mirrors `ParseProject`; workspace/source-set/config-input discovery lives in a new `workspace-discovery` module. The Java client adds a `prebuild(...)` method plus `PrebuildResult`/`ProjectDescriptor`/ `SourceSetDescriptor`/`ParserSettings` types, with `packageManager` carried as the canonical `NodeResolutionResult.PackageManager` enum so yarn Classic vs Berry stays distinct.
5c06cf3 to
738bb67
Compare
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.
Motivation
A long-running session can keep parsed state current for hours while an agent edits files, re-parsing changed files incrementally. For JVM languages, a consumer gets the repository's shape (projects, source sets, classpaths, config inputs) by invoking the build tool during a prebuild step. JavaScript/TypeScript has no equivalent: JS prebuild is a no-op today, so there is no workspace-aware notion of "what are the projects, which files are tests, and which config files should force a full re-parse when they change."
Prebuildis the JavaScript analog of "invoke the build tool". Given a repository (or partition) root it returns the independent, workspace-aware projects with their source sets, config-input watch-set, and parser settings — the build descriptor a consumer uses to drive JS/TS builds and incremental re-parsing. It produces only the descriptor; it does not parse sources (that stays withparseProject). v1 is read-only — no dependency install.It mirrors the
ParseProjectRPC patterns but shares none of its code, so the two are independent.Examples
For a non-workspace repo it returns a single project; for an npm/yarn/bun (
package.json#workspaces) or pnpm (pnpm-workspace.yaml) workspace it returns one project per member.Summary
src/rpc/request/prebuild.ts(Prebuild+PrebuildResult), registered inrewrite-rpc.tsnext toParseProject.handle.src/javascript/workspace-discovery.ts— workspace-aware project roots, main/test source-set split by convention globs, config-input watch-set (package.json, nearest lock file, localtsconfigextendschain +references, prettier/jest/vitest config), parser settings (nearesttsconfig).!negationexclusions, trailing-slash and brace globs.packageManagerdetected from the nearest lock file (yarn Classic vs Berry content-sniffed), falling back to the corepackpackageManagerfield, elseNpm.prebuild(...)onJavaScriptRewriteRpcplusPrebuildResult/ProjectDescriptor/SourceSetDescriptor/ParserSettings.packageManageris the canonicalNodeResolutionResult.PackageManagerenum so yarn Classic vs Berry stays distinct.resolutionis present but alwaysnullin v1;parseProjectis untouched.Deliberately not in this PR (additive follow-ups): install ownership,
NodeResolutionResulton returned CUs, the per-file prod/test marker at parse time, and the stateful warm-session lifecycle. Source sets are modeled as a list with per-setparserSettingsso divergent prod/test config is additive later.Test plan
test/javascript/workspace-discovery.test.ts(15): standalone project, main/test split, configInputs extends chain + references (incl. directory-style reference, npm-package extends skipped), npm + pnpm workspace fan-out, yarn Berry vs Classic, nested-package.json pruning,!negation/ trailing-slash / brace workspace globs, corepackpackageManagerfallback.npm run typecheckclean; no regressions intest/rpc/(57 passed).JavaScriptRewriteRpcTest.prebuildover a fixture repo (npm workspace +tsconfigextends chain + main/test files), run against the rebuilt TS server.licenseFormatclean.