Skip to content

Commit ea20de1

Browse files
author
Daniel Del Core
committed
rename CodeshiftConfig type to Config
1 parent 7510eec commit ea20de1

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

.changeset/stupid-mice-lay.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@hypermod/validator': patch
3+
'@hypermod/fetcher': patch
4+
'@hypermod/types': patch
5+
'@hypermod/cli': patch
6+
---
7+
8+
Renames type `CodeshiftConfig` to `Config` (with backwards compatible alias)

packages/cli/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PluginManager, PluginManagerOptions } from 'live-plugin-manager';
88
import { installPackage } from '@antfu/install-pkg';
99

1010
import * as core from '@hypermod/core';
11-
import { CodeshiftConfig } from '@hypermod/types';
11+
import { Config } from '@hypermod/types';
1212
import { fetchConfigAtPath, fetchConfigs } from '@hypermod/fetcher';
1313

1414
import { InvalidUserInputError } from './errors';
@@ -78,7 +78,7 @@ export default async function main(
7878

7979
if (rootPackageJson && rootPackageJson.workspaces) {
8080
const configs = await (rootPackageJson.workspaces as string[]).reduce<
81-
Promise<{ filePath: string; config: CodeshiftConfig }[]>
81+
Promise<{ filePath: string; config: Config }[]>
8282
>(async (accum, filePath) => {
8383
const configs = await fetchConfigs(filePath);
8484
if (!configs.length) return accum;

packages/cli/src/prompt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import inquirer from 'inquirer';
22

3-
import { CodeshiftConfig } from '@hypermod/types';
3+
import { Config } from '@hypermod/types';
44

5-
export const getConfigPrompt = (config: CodeshiftConfig) => {
5+
export const getConfigPrompt = (config: Config) => {
66
const transforms = Object.keys(config.transforms || {});
77
const presets = Object.keys(config.presets || {});
88

@@ -22,7 +22,7 @@ export const getConfigPrompt = (config: CodeshiftConfig) => {
2222
};
2323

2424
export const getMultiConfigPrompt = (
25-
configs: { filePath: string; config: CodeshiftConfig }[],
25+
configs: { filePath: string; config: Config }[],
2626
) => {
2727
const choices = configs.reduce<any[]>((accum, { filePath, config }) => {
2828
function mapToConfig(codemods: Record<string, string> = {}) {

packages/fetcher/src/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import path from 'path';
33
import globby from 'globby';
44
import { PluginManager } from 'live-plugin-manager';
55

6-
import { CodeshiftConfig } from '@hypermod/types';
6+
import { Config } from '@hypermod/types';
77

88
export interface ConfigMeta {
99
filePath: string;
10-
config: CodeshiftConfig;
10+
config: Config;
1111
}
1212

13-
function resolveConfigExport(pkg: any): CodeshiftConfig {
13+
function resolveConfigExport(pkg: any): Config {
1414
return pkg.default ? pkg.default : pkg;
1515
}
1616

@@ -62,9 +62,7 @@ export async function fetchConfigs(filePath: string): Promise<ConfigMeta[]> {
6262
return configs;
6363
}
6464

65-
export async function fetchConfigAtPath(
66-
filePath: string,
67-
): Promise<CodeshiftConfig> {
65+
export async function fetchConfigAtPath(filePath: string): Promise<Config> {
6866
const resolvedFilePath = path.resolve(filePath);
6967
const exists = fs.existsSync(resolvedFilePath);
7068

packages/types/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
export interface CodeshiftConfig {
1+
export interface Config {
22
targets?: string[];
33
maintainers?: string[];
44
description?: string;
55
transforms?: Record<string, string>;
66
presets?: Record<string, string>;
77
}
8+
9+
export type CodeshiftConfig = Config;

packages/validator/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import semver from 'semver';
22

3-
import { CodeshiftConfig } from '@hypermod/types';
3+
import { Config } from '@hypermod/types';
44
import { fetchConfig } from '@hypermod/fetcher';
55

6-
function hasValidTransforms(config: CodeshiftConfig) {
6+
function hasValidTransforms(config: Config) {
77
if (!config.transforms) return true;
88

99
return Object.entries(config.transforms).every(([key]) => semver.valid(key));
1010
}
1111

12-
function hasValidPresets(config: CodeshiftConfig): boolean {
12+
function hasValidPresets(config: Config): boolean {
1313
if (!config.presets) return true;
1414

1515
return Object.entries(config.presets).every(([key]) =>
1616
key.match(/^[0-9a-zA-Z\-]+$/),
1717
);
1818
}
1919

20-
function getInvalidProperties(config: CodeshiftConfig) {
20+
function getInvalidProperties(config: Config) {
2121
const validProperties = [
2222
'maintainers',
2323
'description',
@@ -33,7 +33,7 @@ export function isValidPackageName(dir: string): boolean {
3333
return !!dir.match(/^(@[a-z0-9-~][a-z0-9-._~]*__)?[a-z0-9-~][a-z0-9-._~]*$/);
3434
}
3535

36-
export function isValidConfig(config: CodeshiftConfig) {
36+
export function isValidConfig(config: Config) {
3737
return hasValidTransforms(config) && hasValidPresets(config);
3838
}
3939

@@ -44,10 +44,10 @@ export async function isValidConfigAtPath(filePath: string) {
4444
throw new Error(`Unable to locate config file at path: ${filePath}`);
4545
}
4646

47-
const invalidProperites = getInvalidProperties(configMeta.config);
48-
if (invalidProperites.length) {
47+
const invalidProperties = getInvalidProperties(configMeta.config);
48+
if (invalidProperties.length) {
4949
throw new Error(
50-
`Invalid transform ids found: ${invalidProperites.join(', ')}`,
50+
`Invalid transform ids found: ${invalidProperties.join(', ')}`,
5151
);
5252
}
5353

0 commit comments

Comments
 (0)