Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ const aiPackageName = '@ui5/webcomponents-ai-react';
const compatPackageName = '@ui5/webcomponents-react-compat';
const packageNames = [mainPackageName, basePackageName, chartsPackageName, aiPackageName, compatPackageName];

const mainPackageReExports = [
'CommonProps',
'Ui5CustomEvent',
'Ui5DomRef',
'UI5WCSlotsNode',
'withWebComponent',
'WithWebComponentPropTypes',
];

function getFileNames(dir: string) {
let fileNames: string[] = [];
try {
Expand Down Expand Up @@ -161,25 +170,35 @@ export default function transform(file: FileInfo, api: API): string | undefined
root.find(j.ImportDeclaration, { source: { value: pkg } }).forEach((importPath) => {
const specifiers = importPath.node.specifiers || [];
specifiers.forEach((spec) => {
if (spec.type !== 'ImportSpecifier') return;
if (spec.type !== 'ImportSpecifier') {
return;
}
const importedName = spec.imported.name as string;
let componentName = importedName;
if (importedName.endsWith('PropTypes')) {
componentName = importedName.replace(/PropTypes$/, '');
} else if (importedName.endsWith('Props')) {
} else if (importedName.endsWith('Props') && !mainPackageReExports.includes(importedName)) {
componentName = componentName.replace(/Props$/, '');
} else if (importedName.endsWith('DomRef')) {
componentName = componentName.replace(/DomRef$/, '');
}

let newSource: string;
if (pkg === mainPackageName) {
newSource =
componentName !== importedName
? `${mainPackageName}/${componentName}`
: enumNames.has(importedName)
? `${mainPackageName}/enums/${importedName}`
: `${mainPackageName}/${importedName}`;
if (mainPackageReExports.includes(importedName)) {
if (importedName.toLowerCase().startsWith('withwebcomponent')) {
newSource = `${basePackageName}/withWebComponent`;
} else {
newSource = `${basePackageName}/internal/types`;
}
} else {
newSource =
componentName !== importedName
? `${mainPackageName}/${componentName}`
: enumNames.has(importedName)
? `${mainPackageName}/enums/${importedName}`
: `${mainPackageName}/${importedName}`;
}
} else if (pkg === basePackageName && importedName !== 'Device' && importedName !== 'hooks') {
newSource = resolveBaseExport(importedName) || basePackageName;
} else if (pkg === chartsPackageName) {
Expand Down
Loading