Skip to content

Commit 1f2ec8b

Browse files
authored
Check for target component in Text migrations before modifying file (#7632)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? The `Text` component import was being added to every file regardless if it was needed. <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Only modify a file in the `replace-text-components` migration if the targeted deprecated components exist.
1 parent 20c8cad commit 1f2ec8b

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

.changeset/rare-pandas-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris-migrator': patch
3+
---
4+
5+
Check for targeted component import before modifying in Text component migration

polaris-migrator/src/migrations/replace-text-component/steps/replace-display-text.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '../../../utilities/jsx';
99
import {
1010
getImportSpecifierName,
11+
hasImportSpecifier,
1112
normalizeImportSourcePaths,
1213
updateImports,
1314
} from '../../../utilities/imports';
@@ -35,6 +36,7 @@ export function replaceDisplayText<NodeType = ASTNode>(
3536
});
3637

3738
if (!sourcePaths) return;
39+
if (!hasImportSpecifier(j, source, 'DisplayText', sourcePaths.from)) return;
3840

3941
const localElementName =
4042
getImportSpecifierName(j, source, 'DisplayText', sourcePaths.from) ||

polaris-migrator/src/migrations/replace-text-component/steps/replace-other.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
insertJSXAttribute,
88
} from '../../../utilities/jsx';
99
import {
10+
hasImportSpecifier,
1011
getImportSpecifierName,
1112
normalizeImportSourcePaths,
1213
updateImports,
@@ -50,6 +51,7 @@ export function replaceOther<NodeType = ASTNode>(
5051
});
5152

5253
if (!sourcePaths) return;
54+
if (!hasImportSpecifier(j, source, componentName, sourcePaths.from)) return;
5355

5456
const localElementName =
5557
getImportSpecifierName(j, source, componentName, sourcePaths.from) ||

polaris-migrator/src/migrations/replace-text-component/steps/replace-text-style.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function replaceTextStyle<NodeType = ASTNode>(
4242
});
4343

4444
if (!sourcePaths) return;
45+
if (!hasImportSpecifier(j, source, 'TextStyle', sourcePaths.from)) return;
4546

4647
const localElementName =
4748
getImportSpecifierName(j, source, 'TextStyle', sourcePaths.from) ||

0 commit comments

Comments
 (0)