Skip to content

Commit

Permalink
support both v4 and v5-alpha, beta
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Oct 5, 2021
1 parent eb72833 commit 927f135
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/mui-codemod/src/v5.0.0/optimal-imports.js
Expand Up @@ -6,7 +6,11 @@ import getJSExports from '../util/getJSExports';
if (process.env.NODE_ENV === 'test') {
const resolve = require.resolve;
require.resolve = (source) =>
resolve(source.replace(/^@material-ui\/core\/es/, '../../../mui-material/src'));
resolve(
source
.replace(/^@material-ui\/core\/es/, '../../../mui-material/src')
.replace(/^@material-ui\/core\/modern/, '../../../mui-material/src'),
);
}

export default function transformer(fileInfo, api, options) {
Expand Down Expand Up @@ -47,11 +51,18 @@ export default function transformer(fileInfo, api, options) {
}
const targetImportPath = `${targetModule}/${subpath}`;

const whitelist = getJSExports(
require.resolve(`${importModule}/es/${subpath}`, {
let loader;
try {
loader = require.resolve(`${importModule}/modern/${subpath}`, {
paths: [dirname(fileInfo.path)],
}),
);
});
} catch (error) {
loader = require.resolve(`${importModule}/es/${subpath}`, {
paths: [dirname(fileInfo.path)],
});
}

const whitelist = getJSExports(loader);

path.node.specifiers.forEach((specifier, index) => {
if (!path.node.specifiers.length) {
Expand Down

0 comments on commit 927f135

Please sign in to comment.