Skip to content

Commit

Permalink
fix: missing types in builder,console-stream and store (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodarove authored and Diego Ferreiro Val committed Jun 20, 2019
1 parent ea9adc0 commit 1359d13
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/@best/builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@best/builder/src/rollup-plugin-benchmark-import.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RollupOptions } from "rollup";
import {InputOption, RollupOptions} from "rollup";

const PRIMITIVES = [
'beforeAll',
Expand Down Expand Up @@ -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) {
Expand Down
34 changes: 10 additions & 24 deletions packages/@best/console-stream/src/runner-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,22 @@ 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',
RUNNING = 'RUNNING',
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<string, BenchmarkStatus>

interface RunnerConfig {
maxDuration: number;
minSampleCount: number,
iterations: number,
}

interface RunnerState {
executedTime: number,
executedIterations: number,
results: any[],
}
interface BenchmarkProgress {
executedIterations: number,
estimated: number,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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, " ");
Expand Down
3 changes: 2 additions & 1 deletion packages/@best/console-stream/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"outDir": "build",
},
"references": [
{ "path": "../utils" }
{ "path": "../utils" },
{ "path": "../types" },
]
}
3 changes: 1 addition & 2 deletions packages/@best/store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import path from 'path';
import { formatEnvironment } from './md-formatter';
import { stringify } from './pretty-json';
Expand All @@ -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;
}, {});
Expand Down
9 changes: 5 additions & 4 deletions packages/@best/store/src/md-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import json2md from 'json2md';
import {EnvironmentConfig} from "@best/types";

const ENV_TEXT = 'Benchmark Environment';

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 });
Expand All @@ -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)) {
Expand Down

0 comments on commit 1359d13

Please sign in to comment.