Skip to content

Commit

Permalink
refactor: optimize type usage (#8947)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Mar 2, 2021
1 parent b9c8ffd commit 74d7691
Show file tree
Hide file tree
Showing 364 changed files with 695 additions and 716 deletions.
4 changes: 3 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ const config: InitialOptionsTsJest = {
'lib/**/*.{js,ts}',
'!lib/**/*.{d,spec}.ts',
'!lib/**/{__fixtures__,__mocks__,__testutil__}/**/*.{js,ts}',
'!lib/**/types.ts',
],
coverageReporters: ci
? ['html', 'json', 'text-summary']
: ['html', 'text-summary'],
coverageThreshold: {
global: {
branches: 94.19,
branches: 94.15,
functions: 100,
lines: 100,
statements: 100,
Expand All @@ -31,6 +32,7 @@ const config: InitialOptionsTsJest = {
globals: {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/config-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import equal from 'fast-deep-equal';
import { readFileSync } from 'fs-extra';
import JSON5 from 'json5';
import { configFileNames } from './config/app-strings';
import { RenovateConfig } from './config/common';
import { getConfig as getFileConfig } from './config/file';
import { massageConfig } from './config/massage';
import { migrateConfig } from './config/migration';
import type { RenovateConfig } from './config/types';
import { validateConfig } from './config/validation';
import { logger } from './logger';

Expand Down
2 changes: 1 addition & 1 deletion lib/config/admin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RenovateConfig, RepoAdminConfig } from './common';
import type { RenovateConfig, RepoAdminConfig } from './types';

let adminConfig: RepoAdminConfig = {};

Expand Down
2 changes: 1 addition & 1 deletion lib/config/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as datasourceDocker from '../datasource/docker';
import * as cli from './cli';
import getArgv from './config/__fixtures__/argv';
import { RenovateOptions } from './definitions';
import type { RenovateOptions } from './types';

describe('config/cli', () => {
let argv: string[];
Expand Down
4 changes: 2 additions & 2 deletions lib/config/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import { version } from '../../package.json';
import { GlobalConfig } from './common';
import { RenovateOptions, getOptions } from './definitions';
import { getOptions } from './definitions';
import type { GlobalConfig, RenovateOptions } from './types';

export function getCliName(option: Partial<RenovateOptions>): string {
if (option.cli === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/decrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logger } from '../logger';
import { maskToken } from '../util/mask';
import { add } from '../util/sanitize';
import { getAdminConfig } from './admin';
import { RenovateConfig } from './common';
import type { RenovateConfig } from './types';

export function decryptConfig(config: RenovateConfig): RenovateConfig {
logger.trace({ config }, 'decryptConfig()');
Expand Down
4 changes: 2 additions & 2 deletions lib/config/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GlobalConfig } from './common';
import { RenovateOptions, getOptions } from './definitions';
import { getOptions } from './definitions';
import type { GlobalConfig, RenovateOptions } from './types';

const defaultValues = {
boolean: true,
Expand Down
86 changes: 1 addition & 85 deletions lib/config/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,91 +5,7 @@ import { getVersioningList } from '../versioning';
import * as dockerVersioning from '../versioning/docker';
import * as pep440Versioning from '../versioning/pep440';
import * as semverVersioning from '../versioning/semver';

import { RenovateConfigStage } from './common';

export interface RenovateOptionBase {
admin?: boolean;

allowedValues?: string[];

allowString?: boolean;

cli?: boolean;

description: string;

env?: false | string;

freeChoice?: boolean;
mergeable?: boolean;

autogenerated?: boolean;

name: string;

parent?: 'hostRules' | 'packageRules' | 'postUpgradeTasks' | 'regexManagers';

// used by tests
relatedOptions?: string[];

releaseStatus?: 'alpha' | 'beta' | 'unpublished';

stage?: RenovateConfigStage;
}

export interface RenovateArrayOption<
T extends string | number | Record<string, unknown> = Record<string, unknown>
> extends RenovateOptionBase {
default?: T[];
mergeable?: boolean;
type: 'array';
subType?: 'string' | 'object' | 'number';
}

export interface RenovateStringArrayOption extends RenovateArrayOption<string> {
format?: 'regex';
subType: 'string';
}

export interface RenovateNumberArrayOption extends RenovateArrayOption<number> {
subType: 'number';
}

export interface RenovateBooleanOption extends RenovateOptionBase {
default?: boolean;
type: 'boolean';
}

export interface RenovateIntegerOption extends RenovateOptionBase {
default?: number;
type: 'integer';
}

export interface RenovateStringOption extends RenovateOptionBase {
default?: string;
format?: 'regex';

// Not used
replaceLineReturns?: boolean;
type: 'string';
}

export interface RenovateObjectOption extends RenovateOptionBase {
default?: any;
additionalProperties?: Record<string, unknown> | boolean;
mergeable?: boolean;
type: 'object';
}

export type RenovateOptions =
| RenovateStringOption
| RenovateNumberArrayOption
| RenovateStringArrayOption
| RenovateIntegerOption
| RenovateBooleanOption
| RenovateArrayOption
| RenovateObjectOption;
import type { RenovateOptions } from './types';

const options: RenovateOptions[] = [
{
Expand Down
2 changes: 1 addition & 1 deletion lib/config/env.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {
PLATFORM_TYPE_BITBUCKET,
PLATFORM_TYPE_GITLAB,
} from '../constants/platforms';
import { RenovateOptions } from './definitions';
import * as env from './env';
import type { RenovateOptions } from './types';

describe('config/env', () => {
describe('.getConfig(env)', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import is from '@sindresorhus/is';
import { PLATFORM_TYPE_GITHUB } from '../constants/platforms';
import * as datasourceDocker from '../datasource/docker';
import { logger } from '../logger';
import { GlobalConfig } from './common';
import { RenovateOptions, getOptions } from './definitions';
import { getOptions } from './definitions';
import type { GlobalConfig, RenovateOptions } from './types';

export function getEnvName(option: Partial<RenovateOptions>): string {
if (option.env === false) {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import upath from 'upath';
import { logger } from '../logger';
import { GlobalConfig } from './common';
import { migrateConfig } from './migration';
import type { GlobalConfig } from './types';

export function getConfig(env: NodeJS.ProcessEnv): GlobalConfig {
let configFile = env.RENOVATE_CONFIG_FILE || 'config';
Expand Down
8 changes: 6 additions & 2 deletions lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import { get, getLanguageList, getManagerList } from '../manager';
import { readFile } from '../util/fs';
import { ensureTrailingSlash } from '../util/url';
import * as cliParser from './cli';
import { GlobalConfig, RenovateConfig, RenovateConfigStage } from './common';
import * as defaultsParser from './defaults';
import * as definitions from './definitions';
import * as envParser from './env';
import * as fileParser from './file';
import { resolveConfigPresets } from './presets';
import type {
GlobalConfig,
RenovateConfig,
RenovateConfigStage,
} from './types';
import { mergeChildConfig } from './utils';

export * from './common';
export * from './types';
export { mergeChildConfig };

export interface ManagerConfig extends RenovateConfig {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/massage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from '@sindresorhus/is';
import { clone } from '../util/clone';
import { PackageRule, RenovateConfig, UpdateType } from './common';
import { getOptions } from './definitions';
import type { PackageRule, RenovateConfig, UpdateType } from './types';

const options = getOptions();

Expand Down
2 changes: 1 addition & 1 deletion lib/config/migrate-validate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import is from '@sindresorhus/is';
import { logger } from '../logger';
import { RenovateConfig, ValidationMessage } from './common';
import * as configMassage from './massage';
import * as configMigration from './migration';
import type { RenovateConfig, ValidationMessage } from './types';
import * as configValidation from './validation';

export async function migrateAndValidate(
Expand Down
6 changes: 3 additions & 3 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import later from '@breejs/later';
import is from '@sindresorhus/is';
import equal from 'fast-deep-equal';
import { logger } from '../logger';
import { HostRule } from '../types';
import type { HostRule } from '../types';
import { clone } from '../util/clone';
import { PackageRule, RenovateConfig } from './common';
import { RenovateOptions, getOptions } from './definitions';
import { getOptions } from './definitions';
import type { PackageRule, RenovateConfig, RenovateOptions } from './types';

const options = getOptions();

Expand Down
4 changes: 2 additions & 2 deletions lib/config/presets/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { FileData } from '../../../types/platform/bitbucket-server';
import type { FileData } from '../../../types/platform/bitbucket-server';
import {
BitbucketServerHttp,
setBaseUrl,
} from '../../../util/http/bitbucket-server';
import { Preset } from '../common';
import type { Preset } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util';

const http = new BitbucketServerHttp();
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getRepoContents,
} from '../../../platform/gitea/gitea-helper';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { Preset, PresetConfig } from '../common';
import type { Preset, PresetConfig } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util';

export const Endpoint = 'https://gitea.com/api/v1/';
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import { GithubHttp } from '../../../util/http/github';
import { Preset, PresetConfig } from '../common';
import type { Preset, PresetConfig } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util';

export const Endpoint = 'https://api.github.com/';
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from '../../../logger';
import { ExternalHostError } from '../../../types/errors/external-host-error';
import type { GitLabBranch } from '../../../types/platform/gitlab';
import { GitlabHttp } from '../../../util/http/gitlab';
import { Preset, PresetConfig } from '../common';
import type { Preset, PresetConfig } from '../types';
import { PRESET_DEP_NOT_FOUND, fetchPreset } from '../util';

const gitlabApi = new GitlabHttp();
Expand Down
4 changes: 2 additions & 2 deletions lib/config/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import {
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import { regEx } from '../../util/regex';
import { GlobalConfig, RenovateConfig } from '../common';
import * as massage from '../massage';
import * as migration from '../migration';
import type { GlobalConfig, RenovateConfig } from '../types';
import { mergeChildConfig } from '../utils';
import { PresetApi } from './common';
import * as gitea from './gitea';
import * as github from './github';
import * as gitlab from './gitlab';
import * as internal from './internal';
import * as local from './local';
import * as npm from './npm';
import type { PresetApi } from './types';
import { PRESET_DEP_NOT_FOUND } from './util';

const presetSources: Record<string, PresetApi> = {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
base: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/default.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
enableRenovate: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/docker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
disable: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';
import * as monorepos from './monorepo';

const staticGroups = {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
disableTypesNodeMajor: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset, PresetConfig } from '../common';
import type { Preset, PresetConfig } from '../types';
import * as configPreset from './config';
import * as defaultPreset from './default';
import * as dockerPreset from './docker';
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/monorepo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import is from '@sindresorhus/is';
import { Preset } from '../common';
import type { Preset } from '../types';

const repoGroups = {
'ag-grid': 'https://github.com/ag-grid/ag-grid',
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/npm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
unpublishSafe: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/packages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
angularJs: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
dockerCompose: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/regex-managers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
dockerfileVersions: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
earlyMondays: {
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/workarounds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Preset } from '../common';
import type { Preset } from '../types';

export const presets: Record<string, Preset> = {
all: {
Expand Down
Loading

0 comments on commit 74d7691

Please sign in to comment.