Skip to content

Commit

Permalink
tsconfig moduleResolution: NodeNext (#2575)
Browse files Browse the repository at this point in the history
_incidental_

## Description

In an a3p test I tried disabling `skipLibCheck` and many errors were
from Endo packages's omission of module filename extensions.

That's because Endo was using the default
[moduleResolution](https://www.typescriptlang.org/tsconfig/#moduleResolution),
`node10`. This changes it to `NodeNext` and also the `module` option for
compatibility.

That resulted in new errors which I address mostly by switching to
explicit `@import`.

### Security Considerations

none

### Scaling Considerations

none

### Documentation Considerations

none

### Testing Considerations

- Agoric/agoric-sdk#9385

### Compatibility Considerations

This might affect consuming packages that depend on ambient types.
That's almost certainly only agoric-sdk which we can solve with
Agoric/agoric-sdk#9385

### Upgrade Considerations

If Agoric/agoric-sdk#9385 needs changes then
`NEWS.md` should indicate it. I don't think type changes live up to
`BREAKING` which would be a semver major bump.
  • Loading branch information
turadg authored Oct 18, 2024
2 parents 7a991aa + 713cc3a commit 20b9649
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 68 deletions.
4 changes: 2 additions & 2 deletions packages/bundle-source/src/bundle-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const SUPPORTED_FORMATS = [
'endoScript',
];

/** @type {import('./types').BundleSource} */
/** @type {import('./types.js').BundleSource} */
// @ts-ignore cast
const bundleSource = async (
startFilename,
Expand All @@ -18,7 +18,7 @@ const bundleSource = async (
if (typeof options === 'string') {
options = { format: options };
}
/** @type {{ format: import('./types').ModuleFormat }} */
/** @type {{ format: import('./types.js').ModuleFormat }} */
// @ts-expect-error cast (xxx params)
const { format: moduleFormat = DEFAULT_MODULE_FORMAT } = options;

Expand Down
2 changes: 0 additions & 2 deletions packages/captp/src/atomics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="ses"/>

import { X, Fail } from '@endo/errors';

// This is a pathological minimum, but exercised by the unit test.
Expand Down
2 changes: 0 additions & 2 deletions packages/captp/src/captp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="ses"/>

/** @import {RemoteKit, Settler} from '@endo/eventual-send' */
/** @import {CapTPSlot, TrapHost, TrapGuest, TrapImpl} from './types.js' */

Expand Down
1 change: 0 additions & 1 deletion packages/captp/test/traplib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global setTimeout */
/// <reference types="ses"/>

import { Far } from '@endo/marshal';
import { X, Fail } from '@endo/errors';
Expand Down
2 changes: 0 additions & 2 deletions packages/captp/test/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="ses"/>

import '@endo/init/pre-remoting.js';
import '@endo/init/debug.js';

Expand Down
2 changes: 0 additions & 2 deletions packages/compartment-mapper/src/compartment-map.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* Validates a compartment map against its schema. */

// @ts-check
/// <reference types="ses"/>

import { assertPackagePolicy } from './policy-format.js';

// TODO convert to the new `||` assert style.
Expand Down
2 changes: 0 additions & 2 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-check
/// <reference types="ses"/>

/* global setTimeout, clearTimeout */

import { makeExo } from '@endo/exo';
Expand Down
2 changes: 0 additions & 2 deletions packages/daemon/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* global globalThis */
// @ts-check
/// <reference types="ses"/>

import { E, Far } from '@endo/far';
import { makeExo } from '@endo/exo';
import { M } from '@endo/patterns';
Expand Down
2 changes: 0 additions & 2 deletions packages/errors/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global globalThis */
/// <reference types="ses"/>

// This module assumes the existence of a non-standard `assert` host object.
// SES version 0.11.0 introduces this global object and entangles it
// with the `console` host object in scope when it initializes,
Expand Down
3 changes: 2 additions & 1 deletion packages/evasive-transform/src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @module
*/

// @ts-ignore XXX no types defined
import babelGenerator from '@agoric/babel-generator';

// TODO The following is sufficient on Node.js, but for compatibility with
Expand Down Expand Up @@ -37,7 +38,7 @@ const generator = /** @type {typeof import('@babel/generator')['default']} */ (
* provided to the options.
*
* @template {string|undefined} [SourceUrl=undefined]
* @typedef {{code: string, map: SourceUrl extends string ? import('source-map').RawSourceMap : never}} TransformedResult
* @typedef {{code: string, map: SourceUrl extends string ? import('source-map-js').RawSourceMap : never}} TransformedResult
* @internal
*/

Expand Down
2 changes: 1 addition & 1 deletion packages/evasive-transform/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { generate } from './generate.js';
* Options for {@link evadeCensorSync}
*
* @typedef EvadeCensorOptions
* @property {string|import('source-map').RawSourceMap} [sourceMap] - Original source map in JSON string or object form
* @property {string|import('source-map-js').RawSourceMap} [sourceMap] - Original source map in JSON string or object form
* @property {string} [sourceUrl] - URL or filepath of the original source in `code`
* @property {boolean} [useLocationUnmap] - Enable location unmapping. Only applies if `sourceMap` was provided
* @property {boolean} [elideComments] - Replace comments with an ellipsis but preserve interior newlines.
Expand Down
1 change: 0 additions & 1 deletion packages/evasive-transform/src/transform-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { makeLocationUnmapper } from './location-unmapper.js';
// OR, upgrading to Babel 8 probably addresses this defect.
// const { default: traverse } = /** @type {any} */ (babelTraverse);
const traverse = /** @type {typeof import('@babel/traverse')['default']} */ (
// @ts-expect-error
babelTraverse.default || babelTraverse
);

Expand Down
48 changes: 26 additions & 22 deletions packages/eventual-send/src/E.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { makeMessageBreakpointTester } from './message-breakpoints.js';
const { details: X, quote: q, Fail, error: makeError } = assert;
const { assign, create } = Object;

/**
* @import { HandledPromiseConstructor } from './types.js';
*/

const onSend = makeMessageBreakpointTester('ENDO_SEND_BREAKPOINTS');

/** @type {ProxyHandler<any>} */
Expand Down Expand Up @@ -35,7 +39,7 @@ const baseFreezableProxyHandler = {
* A Proxy handler for E(x).
*
* @param {any} recipient Any value passed to E(x)
* @param {import('./types').HandledPromiseConstructor} HandledPromise
* @param {HandledPromiseConstructor} HandledPromise
* @returns {ProxyHandler<unknown>} the Proxy handler
*/
const makeEProxyHandler = (recipient, HandledPromise) =>
Expand Down Expand Up @@ -96,7 +100,7 @@ const makeEProxyHandler = (recipient, HandledPromise) =>
* It is a variant on the E(x) Proxy handler.
*
* @param {any} recipient Any value passed to E.sendOnly(x)
* @param {import('./types').HandledPromiseConstructor} HandledPromise
* @param {HandledPromiseConstructor} HandledPromise
* @returns {ProxyHandler<unknown>} the Proxy handler
*/
const makeESendOnlyProxyHandler = (recipient, HandledPromise) =>
Expand Down Expand Up @@ -153,7 +157,7 @@ const makeESendOnlyProxyHandler = (recipient, HandledPromise) =>
* It is a variant on the E(x) Proxy handler.
*
* @param {any} x Any value passed to E.get(x)
* @param {import('./types').HandledPromiseConstructor} HandledPromise
* @param {HandledPromiseConstructor} HandledPromise
* @returns {ProxyHandler<unknown>} the Proxy handler
*/
const makeEGetProxyHandler = (x, HandledPromise) =>
Expand All @@ -164,7 +168,7 @@ const makeEGetProxyHandler = (x, HandledPromise) =>
});

/**
* @param {import('./types').HandledPromiseConstructor} HandledPromise
* @param {HandledPromiseConstructor} HandledPromise
*/
const makeE = HandledPromise => {
return harden(
Expand Down Expand Up @@ -255,15 +259,15 @@ export default makeE;
*
* @template Primary The type of the primary reference.
* @template [Local=DataOnly<Primary>] The local properties of the object.
* @typedef {ERef<Local & import('./types').RemotableBrand<Local, Primary>>} FarRef
* @typedef {ERef<Local & import('./types.js').RemotableBrand<Local, Primary>>} FarRef
*/

/**
* `DataOnly<T>` means to return a record type `T2` consisting only of
* properties that are *not* functions.
*
* @template T The type to be filtered.
* @typedef {Omit<T, FilteredKeys<T, import('./types').Callable>>} DataOnly
* @typedef {Omit<T, FilteredKeys<T, import('./types.js').Callable>>} DataOnly
*/

/**
Expand All @@ -273,7 +277,7 @@ export default makeE;
*/

/**
* @template {import('./types').Callable} T
* @template {import('./types.js').Callable} T
* @typedef {(
* ReturnType<T> extends PromiseLike<infer U> // if function returns a promise
* ? T // return the function
Expand All @@ -284,7 +288,7 @@ export default makeE;
/**
* @template T
* @typedef {{
* readonly [P in keyof T]: T[P] extends import('./types').Callable
* readonly [P in keyof T]: T[P] extends import('./types.js').Callable
* ? ECallable<T[P]>
* : never;
* }} EMethods
Expand All @@ -300,14 +304,14 @@ export default makeE;
*/

/**
* @template {import('./types').Callable} T
* @template {import('./types.js').Callable} T
* @typedef {(...args: Parameters<T>) => Promise<void>} ESendOnlyCallable
*/

/**
* @template T
* @typedef {{
* readonly [P in keyof T]: T[P] extends import('./types').Callable
* readonly [P in keyof T]: T[P] extends import('./types.js').Callable
* ? ESendOnlyCallable<T[P]>
* : never;
* }} ESendOnlyMethods
Expand All @@ -316,7 +320,7 @@ export default makeE;
/**
* @template T
* @typedef {(
* T extends import('./types').Callable
* T extends import('./types.js').Callable
* ? ESendOnlyCallable<T> & ESendOnlyMethods<Required<T>>
* : ESendOnlyMethods<Required<T>>
* )} ESendOnlyCallableOrMethods
Expand All @@ -325,7 +329,7 @@ export default makeE;
/**
* @template T
* @typedef {(
* T extends import('./types').Callable
* T extends import('./types.js').Callable
* ? ECallable<T> & EMethods<Required<T>>
* : EMethods<Required<T>>
* )} ECallableOrMethods
Expand All @@ -352,9 +356,9 @@ export default makeE;
*
* @template T
* @typedef {(
* T extends import('./types').Callable
* T extends import('./types.js').Callable
* ? (...args: Parameters<T>) => ReturnType<T> // a root callable, no methods
* : Pick<T, FilteredKeys<T, import('./types').Callable>> // any callable methods
* : Pick<T, FilteredKeys<T, import('./types.js').Callable>> // any callable methods
* )} PickCallable
*/

Expand All @@ -363,9 +367,9 @@ export default makeE;
*
* @template T
* @typedef {(
* T extends import('./types').RemotableBrand<infer L, infer R> // if a given T is some remote interface R
* T extends import('./types.js').RemotableBrand<infer L, infer R> // if a given T is some remote interface R
* ? PickCallable<R> // then return the callable properties of R
* : Awaited<T> extends import('./types').RemotableBrand<infer L, infer R> // otherwise, if the final resolution of T is some remote interface R
* : Awaited<T> extends import('./types.js').RemotableBrand<infer L, infer R> // otherwise, if the final resolution of T is some remote interface R
* ? PickCallable<R> // then return the callable properties of R
* : T extends PromiseLike<infer U> // otherwise, if T is a promise
* ? Awaited<T> // then return resolved value T
Expand All @@ -376,9 +380,9 @@ export default makeE;
/**
* @template T
* @typedef {(
* T extends import('./types').RemotableBrand<infer L, infer R>
* T extends import('./types.js').RemotableBrand<infer L, infer R>
* ? L
* : Awaited<T> extends import('./types').RemotableBrand<infer L, infer R>
* : Awaited<T> extends import('./types.js').RemotableBrand<infer L, infer R>
* ? L
* : T extends PromiseLike<infer U>
* ? Awaited<T>
Expand All @@ -390,7 +394,7 @@ export default makeE;
* @template [R = unknown]
* @typedef {{
* promise: Promise<R>;
* settler: import('./types').Settler<R>;
* settler: import('./types.js').Settler<R>;
* }} EPromiseKit
*/

Expand All @@ -400,11 +404,11 @@ export default makeE;
*
* @template T
* @typedef {(
* T extends import('./types').Callable
* T extends import('./types.js').Callable
* ? (...args: Parameters<T>) => ERef<Awaited<EOnly<ReturnType<T>>>>
* : T extends Record<PropertyKey, import('./types').Callable>
* : T extends Record<PropertyKey, import('./types.js').Callable>
* ? {
* [K in keyof T]: T[K] extends import('./types').Callable
* [K in keyof T]: T[K] extends import('./types.js').Callable
* ? (...args: Parameters<T[K]>) => ERef<Awaited<EOnly<ReturnType<T[K]>>>>
* : T[K];
* }
Expand Down
6 changes: 3 additions & 3 deletions packages/eventual-send/src/postponed.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Create a simple postponedHandler that just postpones until donePostponing is
* called.
*
* @param {import('./types').HandledPromiseConstructor} HandledPromise
* @returns {[Required<import('./types').Handler<any>>, () => void]} postponedHandler and donePostponing callback.
* @param {import('./types.js').HandledPromiseConstructor} HandledPromise
* @returns {[Required<import('./types.js').Handler<any>>, () => void]} postponedHandler and donePostponing callback.
*/
export const makePostponedHandler = HandledPromise => {
/** @type {() => void} */
Expand All @@ -29,7 +29,7 @@ export const makePostponedHandler = HandledPromise => {
};
};

/** @type {Required<import('./types').Handler<any>>} */
/** @type {Required<import('./types.js').Handler<any>>} */
const postponedHandler = {
get: makePostponedOperation('get'),
getSendOnly: makePostponedOperation('getSendOnly'),
Expand Down
1 change: 0 additions & 1 deletion packages/exo/src/exo-makers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="ses"/>
import { objectMap } from '@endo/common/object-map.js';
import { environmentOptionsListHas } from '@endo/env-options';

Expand Down
2 changes: 0 additions & 2 deletions packages/lp32/reader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-check
/// <reference types="ses"/>

// We use a DataView to give users choice over endianness.
// But DataView does not default to host-byte-order like other typed arrays.

Expand Down
2 changes: 0 additions & 2 deletions packages/lp32/writer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-check
/// <reference types="ses"/>

import { Fail, q } from '@endo/errors';
import { hostIsLittleEndian } from './src/host-endian.js';

Expand Down
10 changes: 5 additions & 5 deletions packages/pass-style/src/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { expectAssignable, expectType, expectNotType } from 'tsd';
import { Far } from './make-far';
import { passStyleOf } from './passStyleOf';
import { makeTagged } from './makeTagged';
import { CopyTagged, Passable, PassStyle } from './types';
import { PASS_STYLE } from './passStyle-helpers';
import { Far } from './make-far.js';
import { passStyleOf } from './passStyleOf.js';
import { makeTagged } from './makeTagged.js';
import { CopyTagged, Passable, PassStyle } from './types.js';
import { PASS_STYLE } from './passStyle-helpers.js';

const remotable = Far('foo', {});

Expand Down
2 changes: 0 additions & 2 deletions packages/promise-kit/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* global globalThis */

/// <reference types="ses"/>

import { makeReleasingExecutorKit } from './src/promise-executor-kit.js';
import { memoRace } from './src/memo-race.js';

Expand Down
2 changes: 0 additions & 2 deletions packages/ses/src/compartment-shim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="ses"/>

import { globalThis } from './commons.js';
import { makeCompartmentConstructor } from './compartment.js';
import { tameFunctionToString } from './tame-function-tostring.js';
Expand Down
1 change: 1 addition & 0 deletions packages/ses/src/error/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { makeNoteLogArgsArrayKit } from './note-log-args.js';

/**
* @import {BaseAssert, Assert, AssertionFunctions, AssertionUtilities, StringablePayload, DetailsToken, MakeAssert} from '../../types.js'
* @import {LogArgs, NoteCallback, LoggedErrorHandler} from "./internal-types.js";
*/

// For our internal debugging purposes, uncomment
Expand Down
7 changes: 5 additions & 2 deletions packages/ses/src/error/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import {
weaksetAdd,
weaksetHas,
} from '../commons.js';
import './types.js';
import './internal-types.js';

/**
* @import {FilterConsole, LogSeverity, VirtualConsole} from './types.js'
* @import {ErrorInfo, ErrorInfoKind, LogRecord, NoteCallback, LoggedErrorHandler, MakeCausalConsole, MakeLoggingConsoleKit} from "./internal-types.js";
*/

// For our internal debugging purposes, uncomment
// const internalDebugConsole = console;
Expand Down
4 changes: 4 additions & 0 deletions packages/ses/src/error/internal-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// @ts-check

/**
* @import {VirtualConsole} from './types.js'
*/

/**
* @typedef {readonly any[]} LogArgs
*
Expand Down
5 changes: 4 additions & 1 deletion packages/ses/src/error/note-log-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
/* eslint-disable no-restricted-globals */

import { makeLRUCacheMap } from '../make-lru-cachemap.js';
import './internal-types.js';

/**
* @import {LogArgs} from './internal-types.js';
*/

const { freeze } = Object;
const { isSafeInteger } = Number;
Expand Down
Loading

0 comments on commit 20b9649

Please sign in to comment.