feat(parser-pipeline): create @endo/parser-pipeline#3158
feat(parser-pipeline): create @endo/parser-pipeline#3158
Conversation
📚 Pull Request Stack
Managed by gh-stack |
|
d56e26d to
62012e4
Compare
62012e4 to
7fbfdd1
Compare
|
TODO: figure out why the docs build is failing |
7fbfdd1 to
f54da12
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new @endo/parser-pipeline workspace package to avoid redundant Babel AST parsing by composing multiple analyzer/transform visitor passes into a single parse→traverse→generate cycle, and adds an async worker-pool-backed parser option for parallel policy-generation workflows. It also updates @endo/compartment-mapper’s parser typing and mapping logic to support asynchronous parsers alongside synchronous ones.
Changes:
- Add
@endo/parser-pipelinewithcreateComposedParser(sync) andcreateWorkerParser(async worker pool), plus worker-siderunPipelineInWorker. - Refactor
@endo/compartment-mapperparser types andmakeMapParsersto support async parsers and async module transforms. - Add tests for composed parsing and worker-pool behavior.
Reviewed changes
Copilot reviewed 23 out of 25 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds new workspace package and Babel-related deps/types. |
| typedoc.json | Formatting tweaks and excludes the new package from typedoc output. |
| packages/parser-pipeline/package.json | Defines the new package, dependencies, and exports. |
| packages/parser-pipeline/index.js | Public entrypoint exporting types + parser constructors. |
| packages/parser-pipeline/src/composed-parser.js | Sync composed parser implementation. |
| packages/parser-pipeline/src/worker-parser.js | Async parser wrapper backed by worker pool. |
| packages/parser-pipeline/src/worker-pool.js | Worker thread pool and dispatch/queue/terminate logic. |
| packages/parser-pipeline/src/worker-runner.js | Worker-side message listener that runs the pipeline per task. |
| packages/parser-pipeline/src/types/external.ts | Public types for pipeline configuration and worker protocol. |
| packages/parser-pipeline/src/external.types.* | Type-export shim for JS consumers. |
| packages/parser-pipeline/test/* | AVA tests for composed parser, worker runner, and worker pool. |
| packages/parser-pipeline/README.md | New package documentation and usage examples. |
| packages/parser-pipeline/SECURITY.md | Package security policy doc. |
| packages/parser-pipeline/LICENSE | Apache-2.0 license file. |
| packages/parser-pipeline/tsconfig*.json | Typechecking/build config for the new package. |
| packages/compartment-mapper/src/types/external.ts | Splits sync vs async parser types and updates ParserForLanguage typing. |
| packages/compartment-mapper/src/types/internal.ts | Adjusts internal operator typings to accept ParseFn or AsyncParseFn. |
| packages/compartment-mapper/src/map-parser.js | Refactors parser selection/trampolines for sync+async support. |
| packages/compartment-mapper/src/import-hook.js | Adds a sync-parse type guard for importNow/dynamic-require constraints. |
| packages/compartment-mapper/src/link.js | Simplifies heuristicImports access with updated parser types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a9fdc61 to
9abf181
Compare
This updates the code and types to handle async parsers. Currently, there are no async parsers in `@endo/compartment-mapper`, which is a reasonable excuse for why they were not working. While this looks like a much was changed, it is mostly type-related. Some extra guards were added and code split out within `map-parser.js` to support both the async and sync parser use-cases, while maximizing logic reuse.
Babel AST parsing is expensive. When multiple consumers need to analyze or transform the same module source (`@endo/evasive-transform`, `@endo/module-source`, LavaMoat policy inspection), parsing each one independently wastes significant wall-clock time. This package composes Babel visitor passes from multiple packages into a single parse-traverse-generate cycle. It provides two `parserForLanguage`-compatible parsers: - `createComposedParser` -- synchronous, in-process; for the execution path where modules load on-demand - `createWorkerParser` -- async, worker-pool-backed; for policy generation where hundreds of modules can parse in parallel
- Check `ast.errors` after `errorRecovery: true` parsing in worker runner - Transfer `resultBytes.buffer` in `postMessage` to avoid copying - Fix JSDoc: return type says `removePipelineListener`, not `stop` - Wrap `worker.postMessage()` in try/catch to prevent leaked promises - Restore thenable check in sync parser wrapper (`map-parser.js`) - Remove duplicate JSDoc block on `createComposedParser` - Fix `runWorkerPipeline` → `runPipelineInWorker` in README example - Fix typo: "whichreceives" → "which receives" in README - Fix `homepage` and `repository.directory` pointing at `module-analyzer` - Fix JSDoc import path: `@endo/parser-pipeline/worker-runner.js`
9abf181 to
460895c
Compare
Babel AST parsing is expensive. When multiple consumers need to analyze or transform the same module source (
@endo/evasive-transform,@endo/module-source, LavaMoat policy inspection), parsing each one independently wastes significant wall-clock time.This package composes Babel visitor passes from multiple packages into a single parse-traverse-generate cycle. It provides two
parserForLanguage-compatible parsers:createComposedParser-- synchronous, in-process; for the execution path where modules load on-demandcreateWorkerParser-- async, worker-pool-backed; for policy generation where hundreds of modules can parse in parallel