From 1359d13650413cb49a5f8a97b4bfe8ebcc4a4916 Mon Sep 17 00:00:00 2001 From: Jose David Rodriguez Velasco Date: Thu, 20 Jun 2019 16:48:04 -0700 Subject: [PATCH] fix: missing types in builder,console-stream and store (#163) --- packages/@best/builder/src/index.ts | 2 +- .../src/rollup-plugin-benchmark-import.ts | 4 +-- .../@best/console-stream/src/runner-stream.ts | 34 ++++++------------- packages/@best/console-stream/tsconfig.json | 3 +- packages/@best/store/src/index.ts | 3 +- packages/@best/store/src/md-formatter.ts | 9 ++--- 6 files changed, 21 insertions(+), 34 deletions(-) diff --git a/packages/@best/builder/src/index.ts b/packages/@best/builder/src/index.ts index 5c1a646d..5e3239bd 100644 --- a/packages/@best/builder/src/index.ts +++ b/packages/@best/builder/src/index.ts @@ -26,7 +26,7 @@ function addResolverPlugins(plugins: ProjectConfigPlugin[]): any[] { return []; } - return plugins.map((plugin: any) => { + return plugins.map((plugin: ProjectConfigPlugin) => { if (typeof plugin === 'string') { return req(plugin)(); } else if (Array.isArray(plugin)) { diff --git a/packages/@best/builder/src/rollup-plugin-benchmark-import.ts b/packages/@best/builder/src/rollup-plugin-benchmark-import.ts index 02e89e19..f72c9b4e 100644 --- a/packages/@best/builder/src/rollup-plugin-benchmark-import.ts +++ b/packages/@best/builder/src/rollup-plugin-benchmark-import.ts @@ -1,4 +1,4 @@ -import { RollupOptions } from "rollup"; +import {InputOption, RollupOptions} from "rollup"; const PRIMITIVES = [ 'beforeAll', @@ -27,7 +27,7 @@ const BENCHMARK_RUNTIME_MODULE = '@best/runtime'; const BENCHMARK_IMPORT = `import { ${PRIMITIVES.join(',')} } from "${BENCHMARK_RUNTIME_MODULE}" \n`; export default function () { - let input: any; + let input: InputOption | undefined; return { name: 'benchmark-import', options(rollupOpts: RollupOptions) { diff --git a/packages/@best/console-stream/src/runner-stream.ts b/packages/@best/console-stream/src/runner-stream.ts index 3840d916..cdfaa4e7 100644 --- a/packages/@best/console-stream/src/runner-stream.ts +++ b/packages/@best/console-stream/src/runner-stream.ts @@ -3,6 +3,11 @@ import { isInteractive as globaIsInteractive, clearLine } from "@best/utils"; import chalk from "chalk"; import trimPath from "./utils/trim-path"; import countEOL from "./utils/count-eod"; +import { + BenchmarkResultsState, + BenchmarkRuntimeConfig, + BuildConfig +} from "@best/types"; enum State { QUEUED = 'QUEUED', @@ -10,29 +15,10 @@ enum State { DONE = 'DONE', ERROR = 'ERROR', } -interface BuildConfig { - benchmarkName: string, - benchmarkFolder: string, - benchmarkSignature: string, - benchmarkEntry: string, - projectConfig: { projectName: string, rootDir: string }, - globalConfig: any, -} interface BenchmarkStatus { state: State; displayPath: string; projectName: string } type AllBencharkRunnerState = Map -interface RunnerConfig { - maxDuration: number; - minSampleCount: number, - iterations: number, -} - -interface RunnerState { - executedTime: number, - executedIterations: number, - results: any[], -} interface BenchmarkProgress { executedIterations: number, estimated: number, @@ -67,7 +53,7 @@ function printProjectName(projectName: string) { return ' ' + chalk.reset.cyan.dim(`(${projectName})`); } -function calculateBenchmarkProgress(progress: RunnerState, { iterations, maxDuration }: RunnerConfig): BenchmarkProgress { +function calculateBenchmarkProgress(progress: BenchmarkResultsState, { iterations, maxDuration }: BenchmarkRuntimeConfig): BenchmarkProgress { const { executedIterations, executedTime } = progress; const avgIteration = executedTime / executedIterations; const runtime = parseInt((executedTime / 1000) + '', 10); @@ -100,7 +86,7 @@ function printProgressBar(runTime: number, estimatedTime: number, width: number) return time; } -export default class BuildOutputStream { +export default class RunnerOutputStream { stdout: NodeJS.WriteStream; isInteractive: boolean; @@ -117,8 +103,8 @@ export default class BuildOutputStream { } initState(buildConfigs: BuildConfig[]): AllBencharkRunnerState { - return buildConfigs.reduce((state: AllBencharkRunnerState, build: any): AllBencharkRunnerState => { - buildConfigs.forEach(({ benchmarkEntry, projectConfig: { projectName, rootDir }}) => { + return buildConfigs.reduce((state: AllBencharkRunnerState): AllBencharkRunnerState => { + buildConfigs.forEach(({ benchmarkEntry, projectConfig: { projectName }}) => { state.set(benchmarkEntry, { projectName, state: State.QUEUED, @@ -260,7 +246,7 @@ export default class BuildOutputStream { this.updateRunnerState(benchmarkPath, State.ERROR); } - updateBenchmarkProgress(state: RunnerState, runtimeOpts: RunnerConfig) { + updateBenchmarkProgress(state: BenchmarkResultsState, runtimeOpts: BenchmarkRuntimeConfig) { const progress = this._progress = calculateBenchmarkProgress(state, runtimeOpts); const { executedIterations, avgIteration, estimated, runtime } = progress; const runIter = executedIterations.toString().padEnd(5, " "); diff --git a/packages/@best/console-stream/tsconfig.json b/packages/@best/console-stream/tsconfig.json index 121b2687..2d6c4f52 100644 --- a/packages/@best/console-stream/tsconfig.json +++ b/packages/@best/console-stream/tsconfig.json @@ -5,6 +5,7 @@ "outDir": "build", }, "references": [ - { "path": "../utils" } + { "path": "../utils" }, + { "path": "../types" }, ] } diff --git a/packages/@best/store/src/index.ts b/packages/@best/store/src/index.ts index 7fe48fd6..404c23ff 100644 --- a/packages/@best/store/src/index.ts +++ b/packages/@best/store/src/index.ts @@ -1,4 +1,3 @@ - import path from 'path'; import { formatEnvironment } from './md-formatter'; import { stringify } from './pretty-json'; @@ -17,7 +16,7 @@ function getStoredFileMapping(benchmarkFolder: string, artifactsFolder: string) const artifactFiles = fs.readdirSync(artifactsFolder).map(p => path.join('artifacts', p)); const files = [...currentFiles, ...artifactFiles].filter(p => WHITELIST.includes(path.extname(p))); - return files.reduce((map: any, file: string) => { + return files.reduce((map: { [key: string]: string }, file: string) => { map[file] = path.join(benchmarkFolder, file); return map; }, {}); diff --git a/packages/@best/store/src/md-formatter.ts b/packages/@best/store/src/md-formatter.ts index 421eecf7..1da57b04 100644 --- a/packages/@best/store/src/md-formatter.ts +++ b/packages/@best/store/src/md-formatter.ts @@ -1,4 +1,5 @@ import json2md from 'json2md'; +import {EnvironmentConfig} from "@best/types"; const ENV_TEXT = 'Benchmark Environment'; @@ -6,13 +7,13 @@ function capitalizeFirstLetter(string: string) { return string.charAt(0).toUpperCase() + string.slice(1); } -export function formatEnvironment(env: any) { +export function formatEnvironment(env: EnvironmentConfig) { const jsonMd = Object.keys(env) .sort() .reduce( - (md:any, k1) => { + (md:any, k1: string) => { const nKey = capitalizeFirstLetter(k1); - const value = env[k1]; + const value = env[k1 as keyof EnvironmentConfig]; md.push({ h2: nKey }); if (typeof value === 'string') { md.push({ p: value }); @@ -21,7 +22,7 @@ export function formatEnvironment(env: any) { } else { Object.keys(value).forEach(k2 => { const subKey = capitalizeFirstLetter(k2); - const subValue = value[k2]; + const subValue = value[k2 as keyof typeof value]; if (typeof subValue === 'string') { md.push({ h3: subKey }, { p: subValue }); } else if (Array.isArray(subValue)) {