Skip to content

Commit debf044

Browse files
committed
type imports
1 parent 5e08ace commit debf044

File tree

1 file changed

+13
-10
lines changed
  • packages/cli/src/scripts/codemod/transforms/export-maps

1 file changed

+13
-10
lines changed

packages/cli/src/scripts/codemod/transforms/export-maps/main.cts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export default function transform(file: FileInfo, api: API): string | undefined
6767
const j: JSCodeshift = api.jscodeshift;
6868
const root: Collection = j(file.source);
6969

70+
if (file.path.includes('node_modules')) {
71+
return undefined;
72+
}
73+
7074
let isDirty = false;
7175

7276
packageNames.forEach((pkg) => {
@@ -76,20 +80,18 @@ export default function transform(file: FileInfo, api: API): string | undefined
7680
if (spec.type !== 'ImportSpecifier') return;
7781
const importedName = spec.imported.name as string;
7882
let componentName = importedName;
79-
if (importPath.node.importKind === 'type') {
80-
if (importedName.endsWith('PropTypes')) {
81-
componentName = importedName.replace(/PropTypes$/, '');
82-
} else if (importedName.endsWith('Props')) {
83-
componentName = importedName.replace(/Props$/, '');
84-
} else if (importedName.endsWith('DomRef')) {
85-
componentName = importedName.replace(/DomRef$/, '');
86-
}
83+
if (importedName.endsWith('PropTypes')) {
84+
componentName = importedName.replace(/PropTypes$/, '');
85+
} else if (importedName.endsWith('Props')) {
86+
componentName = importedName.replace(/Props$/, '');
87+
} else if (importedName.endsWith('DomRef')) {
88+
componentName = importedName.replace(/DomRef$/, '');
8789
}
8890

8991
let newSource: string;
9092
if (pkg === mainPackageName) {
9193
newSource =
92-
importPath.node.importKind === 'type'
94+
componentName !== importedName
9395
? `${mainPackageName}/${componentName}`
9496
: enumNames.has(importedName)
9597
? `${mainPackageName}/enums/${importedName}`
@@ -119,5 +121,6 @@ export default function transform(file: FileInfo, api: API): string | undefined
119121
});
120122
});
121123

122-
return isDirty ? root.toSource({ quote: 'single' }) : undefined;
124+
//todo: 'use client' and other string expressions will receive two semicolons. This can be fixed by running prettier - is there a better option?
125+
return isDirty ? root.toSource() : undefined;
123126
}

0 commit comments

Comments
 (0)