fix(compartment-mapper): policy, parser type fixes#3247
Conversation
|
Warning This PR is part of a stack and targets branch 📚 Pull Request Stack
Managed by gh-stack |
🦋 Changeset detectedLatest commit: 4c88284 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
cc633e8 to
58609c1
Compare
00302f9 to
1c80621
Compare
58609c1 to
9725c9a
Compare
1c80621 to
7289aa0
Compare
9725c9a to
82706e8
Compare
7289aa0 to
ecf9587
Compare
82706e8 to
933188b
Compare
ecf9587 to
2cea83c
Compare
933188b to
6f77dc7
Compare
2cea83c to
aa54f8d
Compare
6f77dc7 to
1d7eeb4
Compare
aa54f8d to
a220677
Compare
1d7eeb4 to
2df8ad0
Compare
a220677 to
c824b83
Compare
2df8ad0 to
0ac5359
Compare
c824b83 to
1d75de4
Compare
0ac5359 to
ba8cedb
Compare
1d75de4 to
326f653
Compare
ba8cedb to
b66011e
Compare
326f653 to
3bd323b
Compare
b66011e to
3b71436
Compare
3bd323b to
06842be
Compare
3b71436 to
25002f8
Compare
06842be to
621dfcf
Compare
25002f8 to
a0b6ba7
Compare
621dfcf to
56238e6
Compare
a0b6ba7 to
868963d
Compare
6cfd746 to
c275156
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates @endo/compartment-mapper’s public TypeScript types to better model policy generics and parser hooks, improving the accuracy of external parser/plugin type-checking.
Changes:
- Make
CompartmentDescriptorgeneric over the compartmentPackagePolicy, enabling externally-definedParseFns to “see” custom policy shapes. - Introduce
ParseSourceMapHook(distinct fromSourceMapHook) and thread a genericTCompartmentDescriptorthrough parser types. - Fix
PolicyItemtyping soanyno longer collapses the “custom policy item” branch into thevoidbranch.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Updates lockfile to reflect dependency changes (adds @types/node, removes babel-eslint). |
| packages/module-source/package.json | Adjusts devDependencies (adds @types/node, removes babel-eslint). |
| packages/compartment-mapper/src/types/typescript.ts | Adds IsAny<T> helper for distinguishing wide any in conditional types. |
| packages/compartment-mapper/src/types/policy-schema.ts | Refines PolicyItem typing and updates policy generic parameter naming and “any policy” aliases. |
| packages/compartment-mapper/src/types/external.ts | Adds ParseSourceMapHook, factors parse options, and makes parser types generic over compartment descriptor type. |
| packages/compartment-mapper/src/types/compartment-map-schema.ts | Extends CompartmentDescriptor generics to include policy type; adds “any descriptor” helper types. |
| packages/compartment-mapper/src/parse-mjs.js | Adds a temporary @ts-expect-error for sourceMapHook typing pending a follow-up change. |
| packages/compartment-mapper/src/parse-archive-mjs.js | Same temporary @ts-expect-error for sourceMapHook typing. |
| .changeset/huge-mammals-give.md | Adds a changeset entry documenting the type-level fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * `PackagePolicy<any, any, any, any> = AnyPackagePolicy` was not a supertype of | ||
| * policies with extra string literals (for example, LavaMoat's {@code "root"} on | ||
| * package imports). A separate branch for a wide | ||
| * `any` type parameter yields | ||
| * `PolicyItem<any> = WildcardPolicy | PropertyPolicy | any` so | ||
| * `AnyPackagePolicy` correctly accepts all package policy item shapes. |
| import type { CanonicalName } from './canonical-name.js'; | ||
| import type { FileUrlString } from './external.js'; | ||
| import type { SomePackagePolicy } from './policy-schema.js'; | ||
| import type { PackagePolicy, SomePackagePolicy } from './policy-schema.js'; |
| /** | ||
| * An asynchronous module parsing function. | ||
| */ | ||
| export type AsyncParseFn = { isSyncParser?: false } & (( | ||
| ...args: ParseArguments | ||
| ) => Promise<ParseResult>); | ||
|
|
||
| /** | ||
| * Mapping of `Language` to synchronous {@link ParserImplementation}s only. | ||
| * |
868963d to
ce5b1cc
Compare
c275156 to
ec8ff8e
Compare
- Fixes `CompartmentDescriptor` so that it is generic on the `PackagePolicy`; externally-defined `ParseFn`s can now refer to the specific contents of a custom `PackagePolicy` present in a `CompartmentDescriptor`. - Introduces `ParseSourceMapHook`; differentiated from `@endo/module-source`'s `SourceMapHook`. - Fixes type of `PolicyItem`; eliminates confusion between `void` (no extra union members) and `any` (`SomePackagePolicy`).
ec8ff8e to
4c88284
Compare
naugtur
left a comment
There was a problem hiding this comment.
machines are complaining, but I don't care. up to you
CompartmentDescriptorso that it is generic on thePackagePolicy; externally-definedParseFns can now refer to the specific contents of a customPackagePolicypresent in aCompartmentDescriptor.ParseSourceMapHook; differentiated from@endo/module-source'sSourceMapHook.PolicyItem; eliminates confusion betweenvoid(no extra union members) andany(SomePackagePolicy).