Skip to content

Commit a293b75

Browse files
authored
refactor(jest-transform): rename TransformerConfig (#12708)
1 parent 625e0bc commit a293b75

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

docs/CodeTransformation.md

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,90 +33,91 @@ Remember to include the default `babel-jest` transformer explicitly, if you wish
3333
You can write your own transformer. The API of a transformer is as follows:
3434

3535
```ts
36-
interface TransformOptions<OptionType = unknown> {
36+
interface TransformOptions<TransformerConfig = unknown> {
3737
supportsDynamicImport: boolean;
3838
supportsExportNamespaceFrom: boolean;
3939
supportsStaticESM: boolean;
4040
supportsTopLevelAwait: boolean;
4141
instrument: boolean;
42-
/** a cached file system which is used in jest-runtime - useful to improve performance */
42+
/** Cached file system which is used by `jest-runtime` to improve performance. */
4343
cacheFS: Map<string, string>;
44-
config: Config.ProjectConfig;
45-
/** A stringified version of the configuration - useful in cache busting */
44+
/** Jest configuration of currently running project. */
45+
config: ProjectConfig;
46+
/** Stringified version of the `config` - useful in cache busting. */
4647
configString: string;
47-
/** the options passed through Jest's config by the user */
48-
transformerConfig: OptionType;
48+
/** Transformer configuration passed through `transform` option by the user. */
49+
transformerConfig: TransformerConfig;
4950
}
5051

5152
type TransformedSource = {
5253
code: string;
5354
map?: RawSourceMap | string | null;
5455
};
5556

56-
interface SyncTransformer<OptionType = unknown> {
57+
interface SyncTransformer<TransformerConfig = unknown> {
5758
canInstrument?: boolean;
5859

5960
getCacheKey?: (
6061
sourceText: string,
6162
sourcePath: string,
62-
options: TransformOptions<OptionType>,
63+
options: TransformOptions<TransformerConfig>,
6364
) => string;
6465

6566
getCacheKeyAsync?: (
6667
sourceText: string,
6768
sourcePath: string,
68-
options: TransformOptions<OptionType>,
69+
options: TransformOptions<TransformerConfig>,
6970
) => Promise<string>;
7071

7172
process: (
7273
sourceText: string,
7374
sourcePath: string,
74-
options: TransformOptions<OptionType>,
75+
options: TransformOptions<TransformerConfig>,
7576
) => TransformedSource;
7677

7778
processAsync?: (
7879
sourceText: string,
7980
sourcePath: string,
80-
options: TransformOptions<OptionType>,
81+
options: TransformOptions<TransformerConfig>,
8182
) => Promise<TransformedSource>;
8283
}
8384

84-
interface AsyncTransformer<OptionType = unknown> {
85+
interface AsyncTransformer<TransformerConfig = unknown> {
8586
canInstrument?: boolean;
8687

8788
getCacheKey?: (
8889
sourceText: string,
8990
sourcePath: string,
90-
options: TransformOptions<OptionType>,
91+
options: TransformOptions<TransformerConfig>,
9192
) => string;
9293

9394
getCacheKeyAsync?: (
9495
sourceText: string,
9596
sourcePath: string,
96-
options: TransformOptions<OptionType>,
97+
options: TransformOptions<TransformerConfig>,
9798
) => Promise<string>;
9899

99100
process?: (
100101
sourceText: string,
101102
sourcePath: string,
102-
options: TransformOptions<OptionType>,
103+
options: TransformOptions<TransformerConfig>,
103104
) => TransformedSource;
104105

105106
processAsync: (
106107
sourceText: string,
107108
sourcePath: string,
108-
options: TransformOptions<OptionType>,
109+
options: TransformOptions<TransformerConfig>,
109110
) => Promise<TransformedSource>;
110111
}
111112

112-
type Transformer<OptionType = unknown> =
113-
| SyncTransformer<OptionType>
114-
| AsyncTransformer<OptionType>;
113+
type Transformer<TransformerConfig = unknown> =
114+
| SyncTransformer<TransformerConfig>
115+
| AsyncTransformer<TransformerConfig>;
115116

116117
type TransformerCreator<
117-
X extends Transformer<OptionType>,
118-
OptionType = unknown,
119-
> = (options?: OptionType) => X;
118+
X extends Transformer<TransformerConfig>,
119+
TransformerConfig = unknown,
120+
> = (transformerConfig?: TransformerConfig) => X;
120121

121122
type TransformerFactory<X extends Transformer> = {
122123
createTransformer: TransformerCreator<X>;

packages/jest-transform/src/types.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,19 @@ export interface RequireAndTranspileModuleOptions
5757

5858
export type StringMap = Map<string, string>;
5959

60-
export interface TransformOptions<OptionType = unknown>
60+
export interface TransformOptions<TransformerConfig = unknown>
6161
extends ReducedTransformOptions {
62-
/** a cached file system which is used in jest-runtime - useful to improve performance */
62+
/** Cached file system which is used by `jest-runtime` to improve performance. */
6363
cacheFS: StringMap;
64+
/** Jest configuration of currently running project. */
6465
config: Config.ProjectConfig;
65-
/** A stringified version of the configuration - useful in cache busting */
66+
/** Stringified version of the `config` - useful in cache busting. */
6667
configString: string;
67-
/** the options passed through Jest's config by the user */
68-
transformerConfig: OptionType;
68+
/** Transformer configuration passed through `transform` option by the user. */
69+
transformerConfig: TransformerConfig;
6970
}
7071

71-
export interface SyncTransformer<OptionType = unknown> {
72+
export interface SyncTransformer<TransformerConfig = unknown> {
7273
/**
7374
* Indicates if the transformer is capable of instrumenting the code for code coverage.
7475
*
@@ -80,29 +81,29 @@ export interface SyncTransformer<OptionType = unknown> {
8081
getCacheKey?: (
8182
sourceText: string,
8283
sourcePath: string,
83-
options: TransformOptions<OptionType>,
84+
options: TransformOptions<TransformerConfig>,
8485
) => string;
8586

8687
getCacheKeyAsync?: (
8788
sourceText: string,
8889
sourcePath: string,
89-
options: TransformOptions<OptionType>,
90+
options: TransformOptions<TransformerConfig>,
9091
) => Promise<string>;
9192

9293
process: (
9394
sourceText: string,
9495
sourcePath: string,
95-
options: TransformOptions<OptionType>,
96+
options: TransformOptions<TransformerConfig>,
9697
) => TransformedSource;
9798

9899
processAsync?: (
99100
sourceText: string,
100101
sourcePath: string,
101-
options: TransformOptions<OptionType>,
102+
options: TransformOptions<TransformerConfig>,
102103
) => Promise<TransformedSource>;
103104
}
104105

105-
export interface AsyncTransformer<OptionType = unknown> {
106+
export interface AsyncTransformer<TransformerConfig = unknown> {
106107
/**
107108
* Indicates if the transformer is capable of instrumenting the code for code coverage.
108109
*
@@ -114,25 +115,25 @@ export interface AsyncTransformer<OptionType = unknown> {
114115
getCacheKey?: (
115116
sourceText: string,
116117
sourcePath: string,
117-
options: TransformOptions<OptionType>,
118+
options: TransformOptions<TransformerConfig>,
118119
) => string;
119120

120121
getCacheKeyAsync?: (
121122
sourceText: string,
122123
sourcePath: string,
123-
options: TransformOptions<OptionType>,
124+
options: TransformOptions<TransformerConfig>,
124125
) => Promise<string>;
125126

126127
process?: (
127128
sourceText: string,
128129
sourcePath: string,
129-
options: TransformOptions<OptionType>,
130+
options: TransformOptions<TransformerConfig>,
130131
) => TransformedSource;
131132

132133
processAsync: (
133134
sourceText: string,
134135
sourcePath: string,
135-
options: TransformOptions<OptionType>,
136+
options: TransformOptions<TransformerConfig>,
136137
) => Promise<TransformedSource>;
137138
}
138139

@@ -144,14 +145,14 @@ export interface AsyncTransformer<OptionType = unknown> {
144145
*
145146
* For more info on the sync vs async model, see https://jestjs.io/docs/code-transformation#writing-custom-transformers
146147
*/
147-
export type Transformer<OptionType = unknown> =
148-
| SyncTransformer<OptionType>
149-
| AsyncTransformer<OptionType>;
148+
export type Transformer<TransformerConfig = unknown> =
149+
| SyncTransformer<TransformerConfig>
150+
| AsyncTransformer<TransformerConfig>;
150151

151152
export type TransformerCreator<
152-
X extends Transformer<OptionType>,
153-
OptionType = unknown,
154-
> = (options?: OptionType) => X;
153+
X extends Transformer<TransformerConfig>,
154+
TransformerConfig = unknown,
155+
> = (transformerConfig?: TransformerConfig) => X;
155156

156157
/**
157158
* Instead of having your custom transformer implement the Transformer interface

0 commit comments

Comments
 (0)