File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @codeshift/test-utils ' : minor
3
+ ---
4
+
5
+ Allows to use an FileInfo in the applyTransform test util
Original file line number Diff line number Diff line change 1
- import jscodeshift from 'jscodeshift' ;
1
+ import jscodeshift , { FileInfo } from 'jscodeshift' ;
2
2
3
3
type Parser = 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx' ;
4
4
@@ -8,15 +8,18 @@ interface Options {
8
8
9
9
export default async function applyTransform (
10
10
transform : any ,
11
- input : string ,
11
+ input : string | FileInfo ,
12
12
options : Options = {
13
13
parser : 'babel' ,
14
14
} ,
15
15
) {
16
16
// Handle ES6 modules using default export for the transform
17
17
const transformer = transform . default ? transform . default : transform ;
18
+
19
+ const file = typeof input === 'string' ? { source : input } : input ;
20
+
18
21
const output = await transformer (
19
- { source : input } ,
22
+ file ,
20
23
{
21
24
jscodeshift : jscodeshift . withParser ( options . parser as string ) ,
22
25
// eslint-disable-next-line @typescript-eslint/no-empty-function
You can’t perform that action at this time.
0 commit comments