Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: unify TypeScript project #4404

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"lint-fix": "yarn lerna run --no-bail lint-fix",
"lint": "run-s --continue-on-error lint:*",
"lint:packages": "yarn lerna run --no-bail lint",
"lint:all-types": "yarn tsc --project tsconfig.build.json",
"test": "yarn lerna run --no-bail test",
"test:c8-all": "rm -rf coverage/tmp && C8_OPTIONS=\"--clean=false --temp-directory=$PWD/coverage/tmp\" lerna run test:c8",
"test:xs": "yarn workspaces run test:xs",
Expand Down
3 changes: 1 addition & 2 deletions packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"lint:eslint": "eslint ."
},
"devDependencies": {
"@types/better-sqlite3": "^7.5.0",
"@types/microtime": "^2.1.0",
"@types/tmp": "^0.2.0",
"@types/yargs-parser": "^21.0.0"
Expand Down Expand Up @@ -56,7 +55,7 @@
"@endo/zip": "^0.2.34",
"ansi-styles": "^6.2.1",
"anylogger": "^0.21.0",
"better-sqlite3": "^8.2.0",
"better-sqlite3": "^9.1.1",
Comment on lines -59 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see discussion of some pretty fine details about sqlite among kernel devs. @gibson042 are you confident that this upgrade is OK? Or should it get review by others?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The major version bump was just to drop Node.js 16, so I'd be surprised if this affects anything not covered by unit tests. @warner gets deeper on this than I do, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runtime change so pulled out to #8590

"import-meta-resolve": "^2.2.1",
"microtime": "^3.1.0",
"semver": "^6.3.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/agoric-cli/src/anylogger-agoric.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/* global process */
import anylogger from 'anylogger';
import chalk from 'chalk';
Expand All @@ -13,8 +14,9 @@ if (DEBUG === undefined) {
const defaultLevel = anylogger.levels[selectedLevel];

const oldExt = anylogger.ext;
anylogger.ext = (l, o) => {
l = oldExt(l, o);
/** @type {typeof anylogger.ext} */
anylogger.ext = l => {
l = oldExt(l);
l.enabledFor = lvl => defaultLevel >= anylogger.levels[lvl];

const prefix = l.name.replace(/:/g, ': ');
Expand Down
7 changes: 6 additions & 1 deletion packages/agoric-cli/src/chain-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import djson from 'deterministic-json';
import TOML from '@iarna/toml';
import * as Tokens from '@agoric/internal/src/tokens.js';
Expand Down Expand Up @@ -189,7 +190,11 @@ export function finishTendermintConfig({
return TOML.stringify(config);
}

// Rewrite/import the genesis.json.
/**
* Rewrite/import the genesis.json
*
* @param {genesisJson: string, exportedGenesisJson?: string} genesisjsons
*/
export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
const genesis = JSON.parse(genesisJson);
const exported = exportedGenesisJson ? JSON.parse(exportedGenesisJson) : {};
Expand Down
2 changes: 2 additions & 0 deletions packages/agoric-cli/src/cosmos.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import chalk from 'chalk';
import path from 'path';
import { makePspawn, getSDKBinaries } from './helpers.js';
Expand Down Expand Up @@ -50,6 +51,7 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
},
);
// Ensure the build doesn't mess up stdout.
assert(ps.childProcess.stdout);
ps.childProcess.stdout.pipe(process.stderr);
return ps;
}
Expand Down
12 changes: 4 additions & 8 deletions packages/agoric-cli/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getSDKBinaries = ({
* @param {Record<string, string | undefined>} [param0.env] the default environment
* @param {*} [param0.chalk] a colorizer
* @param {Console} [param0.log] a console object
* @param {(cmd: string, cargs: Array<string>, opts: any) => ChildProcess}param0.spawn the spawn function
* @param {import('child_process').spawn} param0.spawn the spawn function
*/
export const makePspawn = ({
env: defaultEnv = process.env,
Expand All @@ -38,13 +38,9 @@ export const makePspawn = ({
/**
* Promisified spawn.
*
* @param {string} cmd command name to run
* @param {Array<string>} cargs arguments to the command
* @param {object} param2
* @param {string} [param2.cwd]
* @param {string | [string, string, string]} [param2.stdio] standard IO
* specification
* @param {Record<string, string | undefined>} [param2.env] environment
* @param {Parameters<import('child_process').spawn>[0]} cmd command name to run
* @param {Parameters<import('child_process').spawn>[1]} cargs arguments to the command
* @param {Parameters<import('child_process').spawn>[2]} options
* @returns {Promise<number> & { childProcess: ChildProcess }}} promise for
* exit status. The return result has a `childProcess` property to obtain
* control over the running process
Expand Down
5 changes: 5 additions & 0 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/* global process AggregateError Buffer */
import path from 'path';
import chalk from 'chalk';
Expand Down Expand Up @@ -38,6 +39,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
stdio: ['inherit', 'pipe', 'inherit'],
});
const stdout = [];
assert(p.childProcess.stdout);
p.childProcess.stdout.on('data', out => stdout.push(out));
await p;
const d = JSON.parse(Buffer.concat(stdout).toString('utf-8'));
Expand Down Expand Up @@ -175,9 +177,11 @@ export default async function installMain(progname, rawArgs, powers, opts) {
);
if (failures.length) {
if (typeof AggregateError !== 'function') {
// @ts-expect-error Property 'reason' does not exist on type 'PromiseSettledResult'
throw failures[0].reason;
}
throw AggregateError(
// @ts-expect-error Property 'reason' does not exist on type 'PromiseSettledResult'
failures.map(({ reason }) => reason),
'Failed to prune',
);
Expand Down Expand Up @@ -268,6 +272,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
};
await Promise.all(subdirs.map(removeNodeModulesSymlinks));
} else {
// @ts-expect-error sdkPackageToPath is Map<string, string>
DEFAULT_SDK_PACKAGE_NAMES.forEach(name => sdkPackageToPath.set(name, null));
}

Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/src/run.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import makeScratchPad from '@agoric/internal/src/scratch.js';
import { makeScriptLoader } from './scripts.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const makeLookup =

/**
* @param {string[]} scripts
* @param {{ allowUnsafePlugins: boolean, progname: string, rawArgs: string[], endowments?: Record<string, any> }} opts
* @param {{ allowUnsafePlugins?: boolean, progname: string, rawArgs: string[], endowments?: Record<string, any> }} opts
* @param {{ fs: import('fs/promises'), console: Console }} powers
*/
export const makeScriptLoader =
Expand Down
22 changes: 12 additions & 10 deletions packages/agoric-cli/src/start.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/* eslint @typescript-eslint/no-floating-promises: "warn" */
/* global process setTimeout */
import chalk from 'chalk';
Expand Down Expand Up @@ -184,7 +185,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {

await null;
if (popts.reset) {
rmVerbose(serverDir);
void rmVerbose(serverDir);
}

if (!opts.dockerTag) {
Expand Down Expand Up @@ -274,16 +275,16 @@ export default async function startMain(progname, rawArgs, powers, opts) {

const serverDir = `${SERVERS_ROOT_DIR}/${profileName}-${portNum}`;
if (popts.reset) {
rmVerbose(serverDir);
void rmVerbose(serverDir);
}

let chainSpawn;
if (!popts.dockerTag) {
chainSpawn = (args, spawnOpts = undefined) => {
chainSpawn = (args, spawnOpts) => {
return pspawn(cosmosChain, [...args, `--home=${serverDir}`], spawnOpts);
};
} else {
chainSpawn = (args, spawnOpts = undefined, dockerArgs = []) =>
chainSpawn = (args, spawnOpts, dockerArgs = []) =>
pspawn(
'docker',
[
Expand Down Expand Up @@ -398,10 +399,12 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const newGenesisJson = finishCosmosGenesis({
genesisJson,
});
// @ts-expect-error typedef lacking optionality
const newConfigToml = finishTendermintConfig({
configToml,
portNum,
});
// @ts-expect-error typedef lacking optionality
const newAppToml = finishCosmosApp({
appToml,
portNum,
Expand Down Expand Up @@ -481,15 +484,14 @@ export default async function startMain(progname, rawArgs, powers, opts) {
}

if (popts.reset) {
rmVerbose(serverDir);
void rmVerbose(serverDir);
}

let soloSpawn;
if (!popts.dockerTag) {
soloSpawn = (args, spawnOpts = undefined) =>
pspawn(agSolo, args, spawnOpts);
soloSpawn = (args, spawnOpts) => pspawn(agSolo, args, spawnOpts);
} else {
soloSpawn = (args, spawnOpts = undefined, dockerArgs = []) =>
soloSpawn = (args, spawnOpts, dockerArgs = []) =>
pspawn(
'docker',
[
Expand Down Expand Up @@ -704,7 +706,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {
const serverDir = `${SERVERS_ROOT_DIR}/${profileName}-${port}`;

if (popts.reset) {
rmVerbose(serverDir);
void rmVerbose(serverDir);
}

const setupRun = (...bonusArgs) =>
Expand All @@ -731,7 +733,7 @@ export default async function startMain(progname, rawArgs, powers, opts) {

await null;
if (popts.reset) {
rmVerbose(serverDir);
void rmVerbose(serverDir);
}

const setupRun = (...bonusArgs) =>
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/test/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test('sanity', async t => {
const myMain = args => {
const oldConsole = console;
try {
// @ts-expect-error
globalThis.console = stubAnylogger();
return main('foo', args, {
anylogger: stubAnylogger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
import { E } from '@endo/far';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const helperEndowments = {
...endowments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const helperEndowments = {
...endowments,
Expand Down
8 changes: 6 additions & 2 deletions packages/agoric-cli/tools/getting-started.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global process setTimeout clearTimeout setInterval clearInterval */

// @ts-check
import fs from 'fs';
import path from 'path';
import tmp from 'tmp';
Expand Down Expand Up @@ -41,8 +41,10 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {
// Kill an entire process group.
const pkill = (cp, signal = 'SIGINT') => process.kill(-cp.pid, signal);

/** @type {typeof pspawn} */
function pspawnStdout(...args) {
const ps = pspawn(...args);
assert(ps.childProcess.stdout);
ps.childProcess.stdout.on('data', chunk => {
process.stdout.write(chunk);
});
Expand Down Expand Up @@ -170,6 +172,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {

if (opts.stdin) {
// Write the input to stdin.
assert(deployP.childProcess.stdin);
deployP.childProcess.stdin.write(opts.stdin);
deployP.childProcess.stdin.end();
}
Expand Down Expand Up @@ -200,6 +203,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {
urlReq.setTimeout(2000);
urlReq.on('error', err => urlResolve(`Cannot connect to ${url}: ${err}`));
urlReq.end();
// @ts-expect-error urlResolve could be undefined
const urlTimeout = setTimeout(urlResolve, 3000, 'timeout');
const urlDone = await urlP;
clearTimeout(urlTimeout);
Expand Down Expand Up @@ -235,7 +239,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {
});
req.setTimeout(2000);
req.on('error', err => {
if (err.code !== 'ECONNREFUSED') {
if ('code' in err && err.code !== 'ECONNREFUSED') {
resolve(`Cannot connect to UI server: ${err}`);
}
});
Expand Down
1 change: 1 addition & 0 deletions packages/builders/scripts/inter-protocol/add-STARS.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const starsOraclesProposalBuilder = async powers => {
});
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('add-STARS', starsVaultProposalBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/* global process */
import { makeHelpers } from '@agoric/deploy-script-support';

Expand Down Expand Up @@ -103,6 +104,7 @@ export const psmProposalBuilder = async (
});
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);

Expand All @@ -112,6 +114,7 @@ export default async (homeP, endowments) => {

await writeCoreProposal('gov-add-collateral', defaultProposalBuilder);
await writeCoreProposal('gov-start-psm', opts =>
// @ts-expect-error xxx wrapInstall generics
psmProposalBuilder({ ...opts, wrapInstall: tool.wrapInstall }),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const provideWhen = async (store, key, make) => {
await E(store).set(key, value);
return value;
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const home = await homeP;
const { zoe, scratch, board } = home;
Expand Down
5 changes: 4 additions & 1 deletion packages/builders/scripts/inter-protocol/init-core.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
/* global process */
/**
* @file can be run with `agoric deploy` after a chain is running (depends on
Expand Down Expand Up @@ -183,7 +184,7 @@ export const defaultProposalBuilder = async (
],
});
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);

Expand All @@ -192,9 +193,11 @@ export default async (homeP, endowments) => {
});
await Promise.all([
writeCoreProposal('gov-econ-committee', opts =>
// @ts-expect-error xxx InstallBundle/wrapInstall types
committeeProposalBuilder({ ...opts, wrapInstall: tool.wrapInstall }),
),
writeCoreProposal('gov-amm-vaults-etc', opts =>
// @ts-expect-error xxx InstallBundle/wrapInstall types
mainProposalBuilder({ ...opts, wrapInstall: tool.wrapInstall }),
),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const defaultProposalBuilder = async (
],
});
};

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('gov-invite-committee', defaultProposalBuilder);
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/scripts/pegasus/init-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
},
],
});

/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('gov-pegasus', defaultProposalBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const game1ProposalBuilder = async ({ publishRef, install }) => {
});
};

/** @type {DeployScriptFunction} */
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').DeployScriptFunction} */
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('start-game1', game1ProposalBuilder);
Expand Down
Loading
Loading