Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(helpers): get moveSpecifiers to handle cjs/dynamic imports correctly #784

Merged
Show file tree
Hide file tree
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 @@ -40,15 +40,20 @@ export function moveSpecifiers(
// expecting @patternfly/{package} or
// @patternfly/{package}/{designator} where designator is deprecated
const toParts = toPackage.split('/');
const parentSourceValue = firstSpecifier?.parent?.source?.value;
const modulePaths = ['esm', 'js', 'dynamic'].map((path) => `dist/${path}`);
const isDistImport = modulePaths.some((path) =>
parentSourceValue?.includes(path)
);

if (
!firstSpecifier?.parent?.source?.value?.includes('dist/esm') ||
!isDistImport ||
toParts[0] !== '@patternfly'
) {
return;
}

const fromParts = firstSpecifier.parent.source.value.split('/');
const fromParts = parentSourceValue.split('/');
//expecting @patternfly/{package}/dist/esm/components/{Component}/index.js
//needing toPath to look like fromPath with the designator before /components
if (toParts.length === 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/dist/js/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/dist/dynamic/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
Expand All @@ -97,14 +97,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/dist/js/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/dist/dynamic/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
Expand All @@ -92,14 +92,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/dist/js/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`import {\n\t${specifier}\n} from '@patternfly/react-core/dist/dynamic/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
Expand All @@ -99,14 +99,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/dist/js/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/deprecated';`,
`export {\n\t${specifier}\n} from '@patternfly/react-core/dist/dynamic/deprecated/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`import { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`import {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
[{ message: errorMessage, type: "ImportDeclaration" }]
)
);
Expand All @@ -85,14 +85,14 @@ specifiersToMove.forEach((specifier) => {
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/js/next/components/Modal/index.js';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/js/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
invalidTests.push(
createInvalidTest(
`export { ${specifier} } from '@patternfly/react-core/dist/dynamic/next/components/Modal/index.js';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core';`,
`export {\n\t${specifier} /* data-codemods */\n} from '@patternfly/react-core/dist/dynamic/components/Modal/index.js';`,
[{ message: errorMessage, type: "ExportNamedDeclaration" }]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ruleTester.run('tile-deprecated', rule, {
},
{
code: `import { Tile } from '@patternfly/react-core/dist/js/components/Tile/index.js';`,
output: `import {\n\tTile\n} from '@patternfly/react-core/deprecated';`,
output: `import {\n\tTile\n} from '@patternfly/react-core/dist/js/deprecated/components/Tile/index.js';`,
errors: [
{
message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`,
Expand All @@ -50,7 +50,7 @@ ruleTester.run('tile-deprecated', rule, {
},
{
code: `import { Tile } from '@patternfly/react-core/dist/dynamic/components/Tile/index.js';`,
output: `import {\n\tTile\n} from '@patternfly/react-core/deprecated';`,
output: `import {\n\tTile\n} from '@patternfly/react-core/dist/dynamic/deprecated/components/Tile/index.js';`,
errors: [
{
message: `Tile has been deprecated. Running the fix flag will update your imports to our deprecated package, but we suggest using Card instead.`,
Expand Down
Loading