Skip to content

Commit

Permalink
feat: move all types to new package
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ferreiro Val committed Jun 18, 2019
1 parent ded739e commit 23a4cbf
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 94 deletions.
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/sql/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiDBAdapter, Project, TemporarySnapshot, Snapshot } from '../types'
import transformer from './transformer'
import { SQLDatabase } from './db'
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export class SQLAdapter extends ApiDBAdapter {
db: SQLDatabase
Expand Down Expand Up @@ -61,4 +61,4 @@ export class SQLAdapter extends ApiDBAdapter {

return true
}
}
}
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/sql/postgres/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pool } from 'pg'
import { SQLDatabase, SQLQueryResult } from '../db'
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export default class PostgresDatabase extends SQLDatabase {
pool: Pool
Expand All @@ -14,4 +14,4 @@ export default class PostgresDatabase extends SQLDatabase {
query(text: string, params: any[]): Promise<SQLQueryResult> {
return this.pool.query(text, params)
}
}
}
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/sql/postgres/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import PostgresDatabase from './db'
import { SQLAdapter } from '../adapter'
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export default class PostgresAdapter extends SQLAdapter {
constructor(config: ApiDatabaseConfig) {
super(config, new PostgresDatabase(config))
}
}
}
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/sql/sqlite/db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sqlite from 'sqlite'
import { SQLDatabase, SQLQueryResult } from '../db'
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export default class SQLiteDatabase extends SQLDatabase {
dbPromise: any
Expand All @@ -21,4 +21,4 @@ export default class SQLiteDatabase extends SQLDatabase {
transformQuery(original: string): string {
return original.replace(/(\$[\d]+)/g, '?')
}
}
}
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/sql/sqlite/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import SQLiteDatabase from './db'
import { SQLAdapter } from '../adapter'
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export default class SQLiteAdapter extends SQLAdapter {
constructor(config: ApiDatabaseConfig) {
super(config, new SQLiteDatabase(config))
}
}
}
8 changes: 4 additions & 4 deletions packages/@best/api-db/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from 'crypto';
import { loadDbFromConfig } from './utils';
import { TemporarySnapshot } from './types';
import { FrozenGlobalConfig } from '@best/config';
import { FrozenGlobalConfig } from '@best/types';

function md5(data: string) {
return crypto
Expand All @@ -27,7 +27,7 @@ export const saveBenchmarkSummaryInDB = (benchmarkResults: any, globalConfig: Fr
}

const environmentHash = md5(JSON.stringify(snapshotEnvironment));

const runSettings = {
similarityHash: benchmarkSignature,
commit: lastCommit.hash,
Expand All @@ -54,11 +54,11 @@ export const saveBenchmarkSummaryInDB = (benchmarkResults: any, globalConfig: Fr
metrics: metrics
}
snapshotsToSave.push(snapshot);

});
});

return db.saveSnapshots(snapshotsToSave, projectName);
}),
);
}
}
6 changes: 3 additions & 3 deletions packages/@best/api-db/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiDatabaseConfig } from '@best/config';
import { ApiDatabaseConfig } from '@best/types';

export interface Project {
id: number;
Expand Down Expand Up @@ -41,12 +41,12 @@ export class ApiDBAdapter {
fetchSnapshots(projectId: number, branch: string, since: string): Promise<Snapshot[]> {
throw new Error('ApiDB.fetchSnapshots() not implemented')
}

saveSnapshots(snapshots: TemporarySnapshot[], projectName: string): Promise<boolean> {
throw new Error('ApiDB.saveSnapshots() not implemented')
}

updateLastRelease(projectName: string, release: string | Date): Promise<boolean> {
throw new Error('ApiDB.updateLastRelease() not implemented')
}
}
}
4 changes: 2 additions & 2 deletions packages/@best/api-db/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { FrozenGlobalConfig } from '@best/config';
import { FrozenGlobalConfig } from '@best/types';
import { ApiDBAdapter } from './types';

const LOCAL_ADAPTERS = ['sql/postgres', 'sql/sqlite'];
Expand All @@ -23,4 +23,4 @@ export const loadDbFromConfig = (globalConfig: FrozenGlobalConfig): ApiDBAdapter

return new remoteAdapter(config);
}
}
}
3 changes: 1 addition & 2 deletions packages/@best/api-db/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"outDir": "build",
},
"references": [
{ "path": "../config" }
{ "path": "../types" }
]
}

11 changes: 1 addition & 10 deletions packages/@best/builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import crypto from 'crypto';
import mkdirp from "mkdirp";
import benchmarkRollup from './rollup-plugin-benchmark-import';
import generateHtml from './html-templating';
import { FrozenGlobalConfig, FrozenProjectConfig, ProjectConfigPlugin } from '@best/config';
import { FrozenGlobalConfig, FrozenProjectConfig, ProjectConfigPlugin, BuildConfig } from '@best/types';
import { BuildOutputStream } from "@best/console-stream"

const BASE_ROLLUP_OUTPUT = { format: 'iife' as ModuleFormat };
Expand Down Expand Up @@ -37,15 +37,6 @@ function addResolverPlugins(plugins: ProjectConfigPlugin[]): any[] {
});
}

export interface BuildConfig {
benchmarkName: string,
benchmarkFolder: string,
benchmarkSignature: string,
benchmarkEntry: string,
projectConfig: FrozenProjectConfig,
globalConfig: FrozenGlobalConfig,
}

export async function buildBenchmark(entry: string, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, buildLogStream: BuildOutputStream): Promise<BuildConfig> {
buildLogStream.onBenchmarkBuildStart(entry);

Expand Down
4 changes: 2 additions & 2 deletions packages/@best/cli/src/cli/args.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Options } from "yargs";
import { BestCliOptions } from "@best/config";
import { CliConfig } from "@best/types";

export const check = () => {
// TODO: Implement checks
Expand Down Expand Up @@ -93,7 +93,7 @@ export const options: { [key: string]: Options } = {
}
};

export function normalize(args: { [x: string]: any; _: string[]; $0: string }): BestCliOptions {
export function normalize(args: { [x: string]: any; _: string[]; $0: string }): CliConfig {
const { _, help, clearCache, clearResults, showConfigs, disableInteractive, gitIntegration, useHttp, externalStorage, runner, runnerConfig, config, projects, iterations, compareStats } = args;
return {
_,
Expand Down
12 changes: 6 additions & 6 deletions packages/@best/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { normalize, usage, options, docs, check } from './args';
import Output from './output';
import yargs from 'yargs';
import rimraf from 'rimraf';
import { getConfigs, BestCliOptions } from '@best/config';
import { OutputStream } from '@best/console-stream';
import { logError } from "@best/utils";
import { runBest } from '../run_best';
import { runCompare } from '../run_compare';
import { ProjectConfigs, FrozenProjectConfig } from '@best/config';
import { getConfigs } from "@best/config";
import { ProjectConfigs, FrozenProjectConfig, CliConfig } from '@best/types';

export function buildArgs(maybeArgv?: string[]): BestCliOptions {
export function buildArgs(maybeArgv?: string[]): CliConfig {
const parsedArgs = yargs(maybeArgv || process.argv.slice(2))
.usage(usage)
.alias('help', 'h')
Expand All @@ -21,7 +21,7 @@ export function buildArgs(maybeArgv?: string[]): BestCliOptions {
return normalize(parsedArgs);
}

function getProjectListFromCLIArgs(argsCLI: BestCliOptions, project?: string): string[] {
function getProjectListFromCLIArgs(argsCLI: CliConfig, project?: string): string[] {
const projects = argsCLI.projects;

if (project) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function run(maybeArgv?: string[], project?: string) {
}
}

export async function runCLI(argsCLI: BestCliOptions, projects: string[]) {
export async function runCLI(argsCLI: CliConfig, projects: string[]) {
const outputStream = new OutputStream(process.stdout);
let projectConfigs: ProjectConfigs;
let results;
Expand Down Expand Up @@ -106,4 +106,4 @@ export async function runCLI(argsCLI: BestCliOptions, projects: string[]) {
return true;
}

export { BestCliOptions };
export { CliConfig as BestCliOptions };
9 changes: 5 additions & 4 deletions packages/@best/cli/src/run_best.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import path from 'path';
import micromatch from 'micromatch';
import fg from 'fast-glob';
import { buildBenchmarks, BuildConfig } from '@best/builder';

import { buildBenchmarks } from '@best/builder';
import { runBenchmarks } from '@best/runner';
import { BuildOutputStream, RunnerOutputStream } from "@best/console-stream";
import { storeBenchmarkResults } from '@best/store';
import { saveBenchmarkSummaryInDB } from '@best/api-db';
import { analyzeBenchmarks } from '@best/analyzer';
import path from 'path';
import micromatch from 'micromatch';
import { FrozenGlobalConfig, FrozenProjectConfig } from '@best/config';
import { BuildConfig, FrozenGlobalConfig, FrozenProjectConfig} from "@best/types";

async function getBenchmarkPaths(config: FrozenProjectConfig): Promise<string[]> {
const { testMatch, testPathIgnorePatterns, rootDir: cwd } = config;
Expand Down
1 change: 1 addition & 0 deletions packages/@best/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{ "path": "../store" },
{ "path": "../store-fs" },
{ "path": "../utils" },
{ "path": "../types" },
],
"include": [
"../package.json",
Expand Down
12 changes: 5 additions & 7 deletions packages/@best/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

import { resolveConfigPath, readConfigAndSetRootDir, ensureNoDuplicateConfigs } from './utils/resolve-config';
import { getGitInfo, GitInfo } from './utils/git';
import { getGitInfo } from './utils/git';
import { normalizeConfig, normalizeRootDirPattern } from './utils/normalize';
import { BestCliOptions, NormalizedConfig, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs, ProjectConfigPlugin, ApiDatabaseConfig } from './internal-types';
export { BestCliOptions, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs, ProjectConfigPlugin, ApiDatabaseConfig };
import { GitConfig, CliConfig, NormalizedConfig, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs } from '@best/types';

function generateProjectConfigs(options: NormalizedConfig, isRoot: boolean, gitInfo?: GitInfo): { projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig | undefined } {
function generateProjectConfigs(options: NormalizedConfig, isRoot: boolean, gitInfo?: GitConfig): { projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig | undefined } {
let globalConfig: FrozenGlobalConfig | undefined;

if (isRoot) {
Expand Down Expand Up @@ -54,7 +52,7 @@ function generateProjectConfigs(options: NormalizedConfig, isRoot: boolean, gitI
return { globalConfig, projectConfig };
}

export async function readConfig(cliOptions: BestCliOptions, packageRoot: string, parentConfigPath?: string): Promise<{ configPath: string, globalConfig?: FrozenGlobalConfig, projectConfig: FrozenProjectConfig }> {
export async function readConfig(cliOptions: CliConfig, packageRoot: string, parentConfigPath?: string): Promise<{ configPath: string, globalConfig?: FrozenGlobalConfig, projectConfig: FrozenProjectConfig }> {
const configPath = resolveConfigPath(packageRoot, process.cwd());
const userConfig = readConfigAndSetRootDir(configPath);
const options = normalizeConfig(userConfig, cliOptions);
Expand All @@ -74,7 +72,7 @@ export async function readConfig(cliOptions: BestCliOptions, packageRoot: string
return { configPath, globalConfig, projectConfig };
}

export async function getConfigs(projectsFromCLIArgs: string[], cliOptions: BestCliOptions): Promise<ProjectConfigs> {
export async function getConfigs(projectsFromCLIArgs: string[], cliOptions: CliConfig): Promise<ProjectConfigs> {
let globalConfig: FrozenGlobalConfig | undefined;
let configs: FrozenProjectConfig[] = [];
let projects: string[] = [];
Expand Down
13 changes: 2 additions & 11 deletions packages/@best/config/src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SimpleGit from "simple-git/promise";
import { GitConfig } from "@best/types";

// TODO: Remove this once the library fixes its types
declare module 'simple-git/promise' {
Expand Down Expand Up @@ -34,17 +35,7 @@ async function getRepository(git: SimpleGit.SimpleGit): Promise<{ owner: string,
return { owner, repo};
}

export interface GitInfo {
lastCommit: { hash: string, date: string }
localChanges: boolean,
branch: string,
repo: {
owner: string,
repo: string
}
}

export async function getGitInfo(baseDir?: string): Promise<GitInfo | undefined> {
export async function getGitInfo(baseDir?: string): Promise<GitConfig | undefined> {
const git = SimpleGit(baseDir);
const isRepo = await git.checkIsRepo();

Expand Down
10 changes: 5 additions & 5 deletions packages/@best/config/src/utils/normalize.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import chalk from 'chalk';
import { BestCliOptions, UserBestConfig, NormalizedConfig, RunnerConfig } from '../internal-types';
import DEFAULT_CONFIG from './defaults';
import { replacePathSepForRegex } from '@best/regex-util';
import { CliConfig, UserConfig, NormalizedConfig, RunnerConfig } from '@best/types';

const TARGET_COMMIT = process.env.TARGET_COMMIT;
const BASE_COMMIT = process.env.BASE_COMMIT;
Expand Down Expand Up @@ -37,7 +37,7 @@ function normalizeRunner(runner: string, runners?: RunnerConfig[]) {
return selectedRunner.runner;
}

function setCliOptionOverrides(initialOptions: UserBestConfig, argsCLI: BestCliOptions): UserBestConfig {
function setCliOptionOverrides(initialOptions: UserConfig, argsCLI: CliConfig): UserConfig {
const argvToOptions = Object.keys(argsCLI)
.reduce((options: any, key: string) => {
switch (key) {
Expand Down Expand Up @@ -77,7 +77,7 @@ function normalizeObjectPathPatterns(options: { [key: string]: any }, rootDir: s
}, {});
}

function normalizePlugins(plugins: any, { rootDir }: UserBestConfig) {
function normalizePlugins(plugins: any, { rootDir }: UserConfig) {
return plugins.map((plugin: any) => {
if (typeof plugin === 'string') {
return normalizeRootDirPattern(plugin, rootDir);
Expand All @@ -88,7 +88,7 @@ function normalizePlugins(plugins: any, { rootDir }: UserBestConfig) {
});
}

function normalizeRootDir(options: UserBestConfig): UserBestConfig {
function normalizeRootDir(options: UserConfig): UserConfig {
// Assert that there *is* a rootDir
if (!options.hasOwnProperty('rootDir')) {
throw new Error(` Configuration option ${chalk.bold('rootDir')} must be specified.`);
Expand Down Expand Up @@ -127,7 +127,7 @@ export function normalizeRegexPattern(names: string | string[] | RegExp) {
return typeof names === 'string' ? new RegExp(names) : names;
}

export function normalizeConfig(userConfig: UserBestConfig, cliOptions: BestCliOptions): NormalizedConfig {
export function normalizeConfig(userConfig: UserConfig, cliOptions: CliConfig): NormalizedConfig {
const userCliMergedConfig = normalizeRootDir(setCliOptionOverrides(userConfig, cliOptions));
const normalizedConfig: NormalizedConfig = { ...DEFAULT_CONFIG, ...userCliMergedConfig };

Expand Down
4 changes: 2 additions & 2 deletions packages/@best/config/src/utils/resolve-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import { PACKAGE_JSON, BEST_CONFIG } from './constants';
import { UserBestConfig } from '../internal-types';
import { UserConfig } from '@best/types';

function isFile(filePath:string) {
return fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory();
Expand Down Expand Up @@ -35,7 +35,7 @@ export function resolveConfigPath(pathToResolve: string, cwd: string) {
return resolveConfigPathByTraversing(absolutePath, pathToResolve, cwd);
}

export function readConfigAndSetRootDir(configPath: string): UserBestConfig {
export function readConfigAndSetRootDir(configPath: string): UserConfig {
const isJSON = configPath.endsWith('.json');
let configObject;
try {
Expand Down
3 changes: 2 additions & 1 deletion packages/@best/config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"references": [
{ "path": "../utils" },
{ "path": "../regex-util" }
{ "path": "../regex-util" },
{ "path": "../types" }
]
}
2 changes: 1 addition & 1 deletion packages/@best/runner-abstract/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSystemInfo } from '@best/utils';
import { RunnerOutputStream } from "@best/console-stream";
import { FrozenGlobalConfig, FrozenProjectConfig } from '@best/config';
import { FrozenGlobalConfig, FrozenProjectConfig } from '@best/types';

export interface RunnerBundle {
benchmarkName: string,
Expand Down
Loading

0 comments on commit 23a4cbf

Please sign in to comment.