Skip to content

Commit 7ad248d

Browse files
authored
fix(cli: export-maps codemod): refactor base pkg reexports correctly (#7846)
1 parent 3d32205 commit 7ad248d

File tree

1 file changed

+27
-8
lines changed
  • packages/cli/src/scripts/codemod/transforms/export-maps

1 file changed

+27
-8
lines changed

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ const aiPackageName = '@ui5/webcomponents-ai-react';
99
const compatPackageName = '@ui5/webcomponents-react-compat';
1010
const packageNames = [mainPackageName, basePackageName, chartsPackageName, aiPackageName, compatPackageName];
1111

12+
const mainPackageReExports = [
13+
'CommonProps',
14+
'Ui5CustomEvent',
15+
'Ui5DomRef',
16+
'UI5WCSlotsNode',
17+
'withWebComponent',
18+
'WithWebComponentPropTypes',
19+
];
20+
1221
function getFileNames(dir: string) {
1322
let fileNames: string[] = [];
1423
try {
@@ -161,25 +170,35 @@ export default function transform(file: FileInfo, api: API): string | undefined
161170
root.find(j.ImportDeclaration, { source: { value: pkg } }).forEach((importPath) => {
162171
const specifiers = importPath.node.specifiers || [];
163172
specifiers.forEach((spec) => {
164-
if (spec.type !== 'ImportSpecifier') return;
173+
if (spec.type !== 'ImportSpecifier') {
174+
return;
175+
}
165176
const importedName = spec.imported.name as string;
166177
let componentName = importedName;
167178
if (importedName.endsWith('PropTypes')) {
168179
componentName = importedName.replace(/PropTypes$/, '');
169-
} else if (importedName.endsWith('Props')) {
180+
} else if (importedName.endsWith('Props') && !mainPackageReExports.includes(importedName)) {
170181
componentName = componentName.replace(/Props$/, '');
171182
} else if (importedName.endsWith('DomRef')) {
172183
componentName = componentName.replace(/DomRef$/, '');
173184
}
174185

175186
let newSource: string;
176187
if (pkg === mainPackageName) {
177-
newSource =
178-
componentName !== importedName
179-
? `${mainPackageName}/${componentName}`
180-
: enumNames.has(importedName)
181-
? `${mainPackageName}/enums/${importedName}`
182-
: `${mainPackageName}/${importedName}`;
188+
if (mainPackageReExports.includes(importedName)) {
189+
if (importedName.toLowerCase().startsWith('withwebcomponent')) {
190+
newSource = `${basePackageName}/withWebComponent`;
191+
} else {
192+
newSource = `${basePackageName}/internal/types`;
193+
}
194+
} else {
195+
newSource =
196+
componentName !== importedName
197+
? `${mainPackageName}/${componentName}`
198+
: enumNames.has(importedName)
199+
? `${mainPackageName}/enums/${importedName}`
200+
: `${mainPackageName}/${importedName}`;
201+
}
183202
} else if (pkg === basePackageName && importedName !== 'Device' && importedName !== 'hooks') {
184203
newSource = resolveBaseExport(importedName) || basePackageName;
185204
} else if (pkg === chartsPackageName) {

0 commit comments

Comments
 (0)