Skip to content

Commit

Permalink
fix: config types
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ferreiro Val committed Jun 15, 2019
1 parent 097222d commit b21bfa3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
56 changes: 16 additions & 40 deletions packages/@best/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,47 @@
import { resolveConfigPath, readConfigAndSetRootDir, ensureNoDuplicateConfigs } from './utils/resolve-config';
import { getGitInfo, GitInfo } from './utils/git';
import { normalizeConfig, normalizeRegexPattern, normalizeRootDirPattern } from './utils/normalize';
import { BestCliOptions, DefaultProjectOptions, GlobalConfig, ProjectConfig } from './types';
import { BestCliOptions, DefaultProjectOptions, GlobalConfig, ProjectConfig, FrozenProjectConfig, FrozenGlobalConfig } from './types';
export { BestCliOptions };

function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean, gitInfo?: GitInfo): { projectConfig: ProjectConfig, globalConfig: GlobalConfig | undefined } {
let globalConfig: GlobalConfig | undefined = undefined;
let projectConfig: ProjectConfig;
function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean, gitInfo?: GitInfo): { projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig | undefined } {
let globalConfig: FrozenGlobalConfig | undefined;

if (isRoot) {
globalConfig = Object.freeze({
gitIntegration: options.gitIntegration,
detectLeaks: options.detectLeaks,
compareStats: options.compareStats,
outputFile: options.outputFile,
externalStorage: options.externalStorage,
apiDatabase: options.apiDatabase,
projects: options.projects,
rootDir: options.rootDir,
rootProjectName: options.projectName,
nonFlagArgs: options.nonFlagArgs,
testNamePattern: options.testNamePattern,
testPathPattern: options.testPathPattern,
verbose: options.verbose,
gitInfo: gitInfo,
gitCommit: options.gitCommit,
gitCommitDate: options.gitCommitDate,
gitLocalChanges: options.gitLocalChanges,
gitBranch: options.gitBranch,
gitRepository: options.gitRepository,
normalize: options.normalize,
outputMetricPattern: normalizeRegexPattern(options.outputMetricNames),
outputTotals: options.outputTotals,
outputHistograms: options.outputHistograms,
outputHistogramPattern: normalizeRegexPattern(options.outputHistogramNames),
histogramQuantileRange: options.histogramQuantileRange,
histogramMaxWidth: options.histogramMaxWidth,
openPages: options.openPages,
// outputMetricPattern: normalizeRegexPattern(options.outputMetricNames),
// outputTotals: options.outputTotals,
// outputHistograms: options.outputHistograms,
// outputHistogramPattern: normalizeRegexPattern(options.outputHistogramNames),
// histogramQuantileRange: options.histogramQuantileRange,
// histogramMaxWidth: options.histogramMaxWidth,
// normalize: options.normalize,
// openPages: options.openPages,
});
}

projectConfig = Object.freeze({
const projectConfig: ProjectConfig = Object.freeze({
cache: options.cache,
cacheDirectory: options.cacheDirectory,
useHttp: options.useHttp,
cwd: options.cwd,
detectLeaks: options.detectLeaks,
displayName: options.displayName,
globals: options.globals,
moduleDirectories: options.moduleDirectories,
moduleFileExtensions: options.moduleFileExtensions,
moduleLoader: options.moduleLoader,
moduleNameMapper: options.moduleNameMapper,
modulePathIgnorePatterns: options.modulePathIgnorePatterns,
modulePaths: options.modulePaths,
name: options.name,
plugins: options.plugins,
rootDir: options.rootDir,
roots: options.roots,

projectName: options.projectName,

benchmarkRunner: options.runnerConfig.runner || options.runner,
benchmarkRunnerConfig: options.runnerConfig.config || options.runnerConfig,
benchmarkEnvironment: options.benchmarkEnvironment,
Expand All @@ -73,12 +55,6 @@ function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean,

testMatch: options.testMatch,
testPathIgnorePatterns: options.testPathIgnorePatterns,
testRegex: options.testRegex,
testURL: options.testURL,
transform: options.transform,
transformIgnorePatterns: options.transformIgnorePatterns,

samplesQuantileThreshold: options.samplesQuantileThreshold,
});

return { globalConfig, projectConfig };
Expand All @@ -104,9 +80,9 @@ export async function readConfig(cliOptions: BestCliOptions, packageRoot: string
return { configPath, globalConfig, projectConfig };
}

export async function getConfigs(projectsFromCLIArgs: string[], cliOptions: BestCliOptions): Promise<{ globalConfig: GlobalConfig, configs: ProjectConfig[] }> {
let globalConfig: GlobalConfig | undefined;
let configs: ProjectConfig[] = [];
export async function getConfigs(projectsFromCLIArgs: string[], cliOptions: BestCliOptions): Promise<{ globalConfig: FrozenGlobalConfig, configs: FrozenProjectConfig[] }> {
let globalConfig: FrozenGlobalConfig | undefined;
let configs: FrozenProjectConfig[] = [];
let projects: string[] = [];
let configPath: string;

Expand Down
6 changes: 5 additions & 1 deletion packages/@best/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ export interface BestCliOptions {
projects: string[],
iterations: number,
compareStats: string[] | undefined
};
}


export interface GlobalConfig {
gitIntegration: boolean;
projects: string[];
detectLeaks: boolean;
}

export interface ProjectConfig {

}

export type FrozenGlobalConfig = Readonly<GlobalConfig>;
export type FrozenProjectConfig = Readonly<ProjectConfig>;
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11259,12 +11259,12 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
resolved "http://npm.lwcjs.org/signal-exit/-/signal-exit-3.0.2/b5fdc08f1287ea1178628e415e25132b73646c6d.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=

simple-git@~1.92.0:
version "1.92.0"
resolved "http://npm.lwcjs.org/simple-git/-/simple-git-1.92.0/6061468eb7d19f0141078fc742e62457e910f547.tgz#6061468eb7d19f0141078fc742e62457e910f547"
integrity sha1-YGFGjrfRnwFBB4/HQuYkV+kQ9Uc=
simple-git@~1.113.0:
version "1.113.0"
resolved "http://npm.lwcjs.org/simple-git/-/simple-git-1.113.0/668989728a1e9cf4ec6c72b69ea2eecc93489bea.tgz#668989728a1e9cf4ec6c72b69ea2eecc93489bea"
integrity sha512-i9WVsrK2u0G/cASI9nh7voxOk9mhanWY9eGtWBDSYql6m49Yk5/Fan6uZsDr/xmzv8n+eQ8ahKCoEr8cvU3h+g==
dependencies:
debug "^3.1.0"
debug "^4.0.1"

simple-statistics@^6.0.1:
version "6.1.1"
Expand Down

0 comments on commit b21bfa3

Please sign in to comment.