Skip to content

Commit

Permalink
chore(agoric-cli): Type-check *.js files (#10481)
Browse files Browse the repository at this point in the history
## Description
Includes agoric-cli *.js files in type checking.

### Security Considerations
n/a

### Scaling Considerations
n/a

### Documentation Considerations
n/a

### Testing Considerations
n/a

### Upgrade Considerations
None known.
  • Loading branch information
mergify[bot] authored Nov 15, 2024
2 parents 40ad937 + 7a783fa commit be80150
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 27 deletions.
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/anylogger-agoric.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const selectedCode = anylogger.levels[selectedLevel];
const globalCode = selectedCode === undefined ? -Infinity : selectedCode;

const oldExt = anylogger.ext;
anylogger.ext = (l, o) => {
l = oldExt(l, o);
anylogger.ext = (l, ...rest) => {
l = oldExt(l, ...rest);
l.enabledFor = lvl => globalCode >= anylogger.levels[lvl];

const prefix = l.name.replace(/:/g, ': ');
Expand Down
25 changes: 22 additions & 3 deletions packages/agoric-cli/src/chain-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ export const DEFAULT_RPC_PORT = 26657;
export const DEFAULT_PROM_PORT = 26660;
export const DEFAULT_API_PORT = 1317;

// Rewrite the app.toml.
/**
* Rewrite the app.toml.
*
* @param {{ appToml: string, enableCors?: boolean, exportMetrics?: boolean, portNum?: string, chainId?: string, enableRosetta?: boolean, rosettaPort?: string }} input
* @returns {string} toml
*/
export function finishCosmosApp({
appToml,
enableCors,
Expand All @@ -92,6 +97,8 @@ export function finishCosmosApp({
rosettaPort = `${DEFAULT_ROSETTA_PORT}`,
}) {
const rpcPort = Number(portNum);
// TODO: Use an accurate narrow type.
/** @type {Record<string, any>} */
const app = TOML.parse(appToml);

if (enableCors) {
Expand Down Expand Up @@ -138,7 +145,12 @@ export function finishCosmosApp({
return TOML.stringify(app);
}

// Rewrite the config.toml.
/**
* Rewrite the config.toml.
*
* @param {{ configToml: string, enableCors?: boolean, exportMetrics?: boolean, portNum?: string, persistentPeers?: string, seeds?: string, unconditionalPeerIds?: string }} input
* @returns {string} toml
*/
export function finishTendermintConfig({
configToml,
enableCors,
Expand All @@ -151,6 +163,8 @@ export function finishTendermintConfig({
const rpcPort = Number(portNum);

// Adjust the config.toml.
// TODO: Use an accurate narrow type.
/** @type {Record<string, any>} */
const config = TOML.parse(configToml);

config.proxy_app = 'kvstore';
Expand Down Expand Up @@ -189,7 +203,12 @@ export function finishTendermintConfig({
return TOML.stringify(config);
}

// Rewrite/import the genesis.json.
/**
* Rewrite/import the genesis.json.
*
* @param {{ genesisJson: string, exportedGenesisJson?: string }} input
* @returns {string} json
*/
export function finishCosmosGenesis({ genesisJson, exportedGenesisJson }) {
const genesis = JSON.parse(genesisJson);
const exported = exportedGenesisJson ? JSON.parse(exportedGenesisJson) : {};
Expand Down
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export const makeWalletCommand = async command => {
keyring: { home, backend },
from,
gas:
gas === 'auto' ? ['auto', parseFiniteNumber(gasAdjustment)] : gas,
gas === 'auto'
? ['auto', parseFiniteNumber(gasAdjustment)]
: parseFiniteNumber(gas),
dryRun,
verbose,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default async function cosmosMain(progname, rawArgs, powers, opts) {
},
);
// Ensure the build doesn't mess up stdout.
ps.childProcess.stdout.pipe(process.stderr);
ps.childProcess.stdout?.pipe(process.stderr);
return ps;
}
throw e;
Expand Down
10 changes: 5 additions & 5 deletions packages/agoric-cli/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export const makePspawn = ({
*
* @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
* @param {object} [opts]
* @param {string} [opts.cwd]
* @param {string | [string, string, string]} [opts.stdio] standard IO
* specification
* @param {Record<string, string | undefined>} [param2.env] environment
* @param {boolean} [param2.detached] whether the child process should be detached
* @param {Record<string, string | undefined>} [opts.env] environment
* @param {boolean} [opts.detached] whether the child process should be detached
* @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
12 changes: 8 additions & 4 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
stdio: ['inherit', 'pipe', 'inherit'],
});
const stdout = [];
p.childProcess.stdout.on('data', out => stdout.push(out));
p.childProcess.stdout?.on('data', out => stdout.push(out));
await p;
const d = JSON.parse(Buffer.concat(stdout).toString('utf-8'));
for (const [name, { location }] of Object.entries(d)) {
Expand All @@ -49,7 +49,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
let subdirs;
const workTrees = ['.'];
let sdkWorktree;
/** @type {Map<string, string>} */
/** @type {Map<string, string | null>} */
const sdkPackageToPath = new Map();
const linkFolder = path.resolve(`_agstate/yarn-links`);
const linkFlags = [];
Expand Down Expand Up @@ -170,7 +170,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
.then(results => {
// After all have settled, throw any errors.
const failures = results.filter(
({ status }) => status !== 'fulfilled',
result => result.status !== 'fulfilled',
);
if (failures.length) {
throw AggregateError(
Expand Down Expand Up @@ -284,6 +284,10 @@ export default async function installMain(progname, rawArgs, powers, opts) {
// Create symlinks to the SDK packages.
await Promise.all(
[...sdkPackageToPath.entries()].map(async ([pjName, dir]) => {
if (typeof dir !== 'string') {
throw Error(`unexpected incomplete package mapping: ${pjName}`);
}

const SUBOPTIMAL = false;
await null;
if (SUBOPTIMAL) {
Expand All @@ -301,7 +305,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
log('linking', linkName);
return fs
.mkdir(linkDir, { recursive: true })
.then(_ => fs.symlink(path.relative(linkDir, dir), linkName));
.then(() => fs.symlink(path.relative(linkDir, dir), linkName));
}),
);

Expand Down
4 changes: 4 additions & 0 deletions packages/agoric-cli/src/lib/network-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { NonNullish } from '@agoric/internal';

/**
* @import {MinimalNetworkConfig} from '@agoric/client-utils';
*/

export const networkConfigUrl = agoricNetSubdomain =>
`https://${agoricNetSubdomain}.agoric.net/network-config`;
export const rpcUrl = agoricNetSubdomain =>
Expand Down
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ const main = async (progname, rawArgs, powers) => {
'verbosity that can be increased',
(_value, _previous) => (cmdOpts.verbose += 1),
);
const baseCmd = (...args) => addCmdOpts(program.command(...args));
/** @type {typeof program.command} */
const baseCmd = (nameAndParams, ...rest) =>
addCmdOpts(program.command(nameAndParams, ...rest));

addCmdOpts(
program
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
14 changes: 7 additions & 7 deletions packages/agoric-cli/src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ export default async function startMain(progname, rawArgs, powers, opts) {
await rmVerbose(serverDir);
}

/** @type {(args: string[], spawnOpts?: Parameters<typeof pspawn>[2], dockerArgs?: string[]) => ReturnType<pspawn>} */
let chainSpawn;
if (!popts.dockerTag) {
chainSpawn = (args, spawnOpts = undefined) => {
return pspawn(cosmosChain, [...args, `--home=${serverDir}`], spawnOpts);
};
chainSpawn = (args, spawnOpts) =>
pspawn(cosmosChain, [...args, `--home=${serverDir}`], spawnOpts);
} else {
chainSpawn = (args, spawnOpts = undefined, dockerArgs = []) =>
chainSpawn = (args, spawnOpts, dockerArgs = []) =>
pspawn(
'docker',
[
Expand Down Expand Up @@ -482,12 +482,12 @@ export default async function startMain(progname, rawArgs, powers, opts) {
await rmVerbose(serverDir);
}

/** @type {(args: string[], spawnOpts?: Parameters<typeof pspawn>[2], dockerArgs?: string[]) => ReturnType<pspawn>} */
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
1 change: 1 addition & 0 deletions packages/agoric-cli/test/bundles-regExp.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import test from 'ava';
import { PACKAGE_NAME_RE } from '../src/lib/bundles.js';

/** @type {Array<[name: string, spec?: string]>} */
const goodPatterns = [
['@agoric/assert-v0.6.0'],
['@agoric/base-zone-v0.1.0/', '@agoric/base-zone-v0.1.0'],
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
2 changes: 1 addition & 1 deletion packages/agoric-cli/test/upgrade-contract/init-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { E } from '@endo/far';
/**
* Initialize contractRef the first time.
*
* @param {BootstrapSpace} param0
* @param {{ [K in keyof BootstrapSpace]: object }} promiseSpace
*/
export const initContract = async ({
consume: { zoe, myStatus },
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"checkJs": false,
"checkJs": true,
},
"include": [
"*.js",
Expand Down

0 comments on commit be80150

Please sign in to comment.