endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
762 stars 68 forks source link

build: automatically build types in prepack #2258

Closed turadg closed 1 month ago

turadg commented 2 months ago

refs: #1488

Description

Simplify build by using NPM lifecycle hooks. Adds a CI test for the package graph sensitivity that the extant method was checking.

Part of making it work was adding "typescript" to devDependencies of packages that need it. The root build:types was running with the root tsc but when building in each package separately they wouldn't get the root's typescript version and fall back to the global one, which didn't know the @import syntax.

Security Considerations

None

Scaling Considerations

None

Documentation Considerations

Less to document

Testing Considerations

I tried the "publish" commands in CONTRIBUTING.md.

integration PR in agoric-sdk: https://github.com/Agoric/agoric-sdk/pull/9385

Compatibility Considerations

Removes a necessary accommodation on agoric-sdk

Upgrade Considerations

None

mhofman commented 1 month ago

FYI, running prepack in topo order vs reverse topo order (to simulate deps not being built before) yields in the following diff. From what I can tell the differences while not obvious, are benign. This should confirm that building the types of packages independently is now working.

diff --git topo/packages/marshal/src/encodeToSmallcaps.d.ts rev-topo/packages/marshal/src/encodeToSmallcaps.d.ts
index ebb499146..ede8c1d13 100644
--- topo/packages/marshal/src/encodeToSmallcaps.d.ts
+++ rev-topo/packages/marshal/src/encodeToSmallcaps.d.ts
@@ -3,15 +3,14 @@ export function makeDecodeFromSmallcaps(decodeOptions?: DecodeFromSmallcapsOptio
 export type SmallcapsEncoding = any;
 export type SmallcapsEncodingUnion = any;
 export type EncodeToSmallcapsOptions = {
-    encodeRemotableToSmallcaps?: ((remotable: typeof Remotable, encodeRecur: (p: Passable) => SmallcapsEncoding) => SmallcapsEncoding) | undefined;
+    encodeRemotableToSmallcaps?: ((remotable: <T extends {}, I extends string>(iface?: I | undefined, props?: undefined, remotable?: T | undefined) => T & import("@endo/pass-style").RemotableObject<I> & import("@endo/eventual-send").RemotableBrand<{}, T>, encodeRecur: (p: Passable) => SmallcapsEncoding) => SmallcapsEncoding) | undefined;
     encodePromiseToSmallcaps?: ((promise: Promise<any>, encodeRecur: (p: Passable) => SmallcapsEncoding) => SmallcapsEncoding) | undefined;
     encodeErrorToSmallcaps?: ((error: Error, encodeRecur: (p: Passable) => SmallcapsEncoding) => SmallcapsEncoding) | undefined;
 };
 export type DecodeFromSmallcapsOptions = {
-    decodeRemotableFromSmallcaps?: ((encodedRemotable: SmallcapsEncoding, decodeRecur: (e: SmallcapsEncoding) => Passable) => typeof Remotable) | undefined;
+    decodeRemotableFromSmallcaps?: ((encodedRemotable: SmallcapsEncoding, decodeRecur: (e: SmallcapsEncoding) => Passable) => <T extends {}, I extends string>(iface?: I | undefined, props?: undefined, remotable?: T | undefined) => T & import("@endo/pass-style").RemotableObject<I> & import("@endo/eventual-send").RemotableBrand<{}, T>) | undefined;
     decodePromiseFromSmallcaps?: ((encodedPromise: SmallcapsEncoding, decodeRecur: (e: SmallcapsEncoding) => Passable) => Promise<any>) | undefined;
     decodeErrorFromSmallcaps?: ((encodedError: SmallcapsEncoding, decodeRecur: (e: SmallcapsEncoding) => Passable) => Error) | undefined;
 };
 import type { Passable } from '@endo/pass-style';
-import type { Remotable } from '@endo/pass-style';
 //# sourceMappingURL=encodeToSmallcaps.d.ts.map
\ No newline at end of file
diff --git topo/packages/marshal/src/encodeToSmallcaps.d.ts.map rev-topo/packages/marshal/src/encodeToSmallcaps.d.ts.map
index 541c3835e..bab18f46f 100644
--- topo/packages/marshal/src/encodeToSmallcaps.d.ts.map
+++ rev-topo/packages/marshal/src/encodeToSmallcaps.d.ts.map
@@ -1 +1 @@
-{"version":3,"file":"encodeToSmallcaps.d.ts","sourceRoot":"","sources":["encodeToSmallcaps.js"],"names":[],"mappings":"AAsHO,qHAF8B,iBAAiB,CAgLrD;AA8BM,2GAFgB,iBAAiB,cAqJvC;gCA9ba,GAAG;qCACH,GAAG;;8FAmEkB,iBAAiB,KAC5C,iBAAiB;sFAGU,iBAAiB,KAC5C,iBAAiB;sCAEb,KAAK,gCACkB,iBAAiB,KAC5C,iBAAiB;;;uDAsMF,iBAAiB,mBAClB,iBAAiB;mDAGlB,iBAAiB,mBAChB,iBAAiB;+CAGpB,iBAAiB,mBACd,iBAAiB,kBAC/B,KAAK;;8BA/R0B,kBAAkB;+BAAlB,kBAAkB"}
\ No newline at end of file
+{"version":3,"file":"encodeToSmallcaps.d.ts","sourceRoot":"","sources":["encodeToSmallcaps.js"],"names":[],"mappings":"AAsHO,qHAF8B,iBAAiB,CAgLrD;AA8BM,2GAFgB,iBAAiB,cAqJvC;gCA9ba,GAAG;qCACH,GAAG;;8RAmEkB,iBAAiB,KAC5C,iBAAiB;sFAGU,iBAAiB,KAC5C,iBAAiB;sCAEb,KAAK,gCACkB,iBAAiB,KAC5C,iBAAiB;;;uDAsMF,iBAAiB,mBAClB,iBAAiB;mDAGlB,iBAAiB,mBAChB,iBAAiB;+CAGpB,iBAAiB,mBACd,iBAAiB,kBAC/B,KAAK;;8BA/R0B,kBAAkB"}
\ No newline at end of file
diff --git topo/packages/marshal/src/rankOrder.d.ts rev-topo/packages/marshal/src/rankOrder.d.ts
index 9ce047e6a..0ae719af4 100644
--- topo/packages/marshal/src/rankOrder.d.ts
+++ rev-topo/packages/marshal/src/rankOrder.d.ts
@@ -1,4 +1,4 @@
-export function trivialComparator(left: any, right: any): 1 | -1 | 0;
+export function trivialComparator(left: any, right: any): 0 | 1 | -1;
 export function getPassStyleCover(passStyle: PassStyle): RankCover;
 export function makeComparatorKit(compareRemotables?: RankCompare | undefined): RankComparatorKit;
 export function comparatorMirrorImage(comparator: RankCompare): RankCompare | undefined;
@@ -48,27 +48,27 @@ export type PassStyleRanksRecord = {
         index: number;
         cover: RankCover;
     };
-    tagged: {
+    null: {
         index: number;
         cover: RankCover;
     };
-    remotable: {
+    error: {
         index: number;
         cover: RankCover;
     };
-    null: {
+    copyRecord: {
         index: number;
         cover: RankCover;
     };
-    copyRecord: {
+    copyArray: {
         index: number;
         cover: RankCover;
     };
-    copyArray: {
+    tagged: {
         index: number;
         cover: RankCover;
     };
-    error: {
+    remotable: {
         index: number;
         cover: RankCover;
     };
diff --git topo/packages/pass-style/src/passStyleOf.d.ts rev-topo/packages/pass-style/src/passStyleOf.d.ts
index 6f0658fd6..5fd3dce02 100644
--- topo/packages/pass-style/src/passStyleOf.d.ts
+++ rev-topo/packages/pass-style/src/passStyleOf.d.ts
@@ -19,7 +19,7 @@ export function assertPassable(val: any): void;
 export function isPassable(specimen: any): specimen is Passable;
 export function toPassableError(err: Error): Error;
 export function toThrowable(specimen: unknown): Passable<never, Error>;
-export type HelperPassStyle = "copyRecord" | "copyArray" | "tagged" | "remotable" | "error";
+export type HelperPassStyle = "error" | "copyRecord" | "copyArray" | "tagged" | "remotable";
 import type { PassStyleOf } from './types.js';
 import type { Passable } from './types.js';
 //# sourceMappingURL=passStyleOf.d.ts.map
\ No newline at end of file
diff --git topo/packages/patterns/src/types.d.ts rev-topo/packages/patterns/src/types.d.ts
index 2ab291977..cf22322d9 100644
--- topo/packages/patterns/src/types.d.ts
+++ rev-topo/packages/patterns/src/types.d.ts
@@ -173,7 +173,7 @@ export type Limits = Partial<AllLimits>;
  * PassStyle is 'tagged', then the `getTag` value for tags that are
  * recognized at the
  */
-export type Kind = "remotable" | import("@endo/pass-style").PrimitiveStyle | "copyRecord" | "copyArray" | "error" | "promise" | "copySet" | "copyBag" | "copyMap" | `match:${any}` | `guard:${any}`;
+export type Kind = "error" | import("@endo/pass-style").PrimitiveStyle | "copyRecord" | "copyArray" | "remotable" | "promise" | "copySet" | "copyBag" | "copyMap" | `match:${any}` | `guard:${any}`;
 export type PatternMatchers = {
     /**
      * Matches any Passable.

For reference, the commands used:

yarn lerna ls --all --toposort | cut -d' ' -f1 | tac | xargs -I % yarn lerna run --scope % prepack
git add . && git stash -m "reverse toposort"
yarn lerna run --reject-cycles --concurrency 1 prepack
git add . && git stash -m "run prepack"
git diff --src-prefix=topo/ --dst-prefix=rev-topo/ stash@{0}^2..stash@{1}^2
kriskowal commented 1 month ago

Wow, brilliant experiment.