@atlaskit/checkbox 17.3.8 → 17.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/codemods/15.0.0-size-removal.tsx +2 -2
  3. package/codemods/migrations/remove-full-width.tsx +6 -0
  4. package/codemods/migrations/remove-imports.tsx +1 -1
  5. package/codemods/migrations/remove-overrides.tsx +15 -0
  6. package/codemods/migrations/remove-size.tsx +6 -0
  7. package/codemods/migrations/remove-theme.tsx +15 -0
  8. package/codemods/migrations/rename-checkbox-without-analytics-import.tsx +11 -0
  9. package/codemods/migrations/rename-deep-type-import.tsx +10 -0
  10. package/codemods/migrations/rename-input-ref-to-ref.tsx +1 -1
  11. package/codemods/migrations/rename-type-import.tsx +10 -0
  12. package/codemods/types.tsx +1 -0
  13. package/codemods/utils/add-comment-before.tsx +40 -0
  14. package/codemods/utils/add-comment-to-start-of-file.tsx +20 -0
  15. package/codemods/utils/add-to-import.tsx +32 -0
  16. package/codemods/utils/create-remove-func-for.tsx +33 -0
  17. package/codemods/utils/create-remove-imports-for.tsx +84 -0
  18. package/codemods/utils/create-rename-func-for.tsx +42 -0
  19. package/codemods/utils/create-rename-import-for.tsx +98 -0
  20. package/codemods/utils/create-transformer.tsx +23 -0
  21. package/codemods/utils/find-identifier-and-replace-attribute.tsx +27 -0
  22. package/codemods/utils/get-default-specifier.tsx +17 -0
  23. package/codemods/utils/get-jsx-attributes-by-name.tsx +18 -0
  24. package/codemods/utils/get-named-specifier.tsx +24 -0
  25. package/codemods/utils/has-import-declaration.tsx +12 -0
  26. package/codemods/utils/has-variable-assignment.tsx +18 -0
  27. package/codemods/utils/try-create-import.tsx +27 -0
  28. package/dist/cjs/internal/label.compiled.css +1 -1
  29. package/dist/cjs/internal/label.js +1 -1
  30. package/dist/es2019/internal/label.compiled.css +1 -1
  31. package/dist/es2019/internal/label.js +1 -1
  32. package/dist/esm/internal/label.compiled.css +1 -1
  33. package/dist/esm/internal/label.js +1 -1
  34. package/package.json +9 -1
  35. package/codemods/migrations/remove-props.tsx +0 -39
  36. package/codemods/migrations/rename-import.tsx +0 -33
  37. package/codemods/utils.tsx +0 -477
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/checkbox
2
2
 
3
+ ## 17.3.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`02483200273ec`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/02483200273ec) -
8
+ Enrol all Design System UI packages into the React Compiler with platform gating via
9
+ isReactCompilerActivePlatform.
10
+ - Updated dependencies
11
+
12
+ ## 17.3.9
13
+
14
+ ### Patch Changes
15
+
16
+ - [`22bf79dbdcdca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/22bf79dbdcdca) -
17
+ Internal changes to remove unnecessary token fallbacks and imports from `@atlaskit/theme`
18
+
3
19
  ## 17.3.8
4
20
 
5
21
  ### Patch Changes
@@ -1,7 +1,7 @@
1
1
  import type { API, FileInfo, Options } from 'jscodeshift';
2
2
 
3
- import { removeSize } from './migrations/remove-props';
4
- import { createTransformer } from './utils';
3
+ import { removeSize } from './migrations/remove-size';
4
+ import { createTransformer } from './utils/create-transformer';
5
5
 
6
6
  const transformer: (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string =
7
7
  createTransformer('@atlaskit/checkbox', [removeSize]);
@@ -0,0 +1,6 @@
1
+ import { createRemoveFuncFor } from '../utils/create-remove-func-for';
2
+
3
+ export const removeFullWidth: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRemoveFuncFor('@atlaskit/checkbox', 'Checkbox', 'isFullWidth');
@@ -1,4 +1,4 @@
1
- import { createRemoveImportsFor } from '../utils';
1
+ import { createRemoveImportsFor } from '../utils/create-remove-imports-for';
2
2
 
3
3
  export const removeThemeImports: (
4
4
  j: import('jscodeshift/src/core').JSCodeshift,
@@ -0,0 +1,15 @@
1
+ import { createRemoveFuncFor } from '../utils/create-remove-func-for';
2
+
3
+ export const removeOverrides: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRemoveFuncFor(
7
+ '@atlaskit/checkbox',
8
+ 'Checkbox',
9
+ 'overrides',
10
+ `This file uses the @atlaskit/checkbox \`overrides\` prop
11
+ which has now been removed due to its poor performance characteristics. We have not
12
+ replaced overrides with an equivalent API and the overrides pattern exposes internal
13
+ implementation detail as public API and makes it harder for you to upgrade. The appearance
14
+ of Checkbox will have likely changed.`,
15
+ );
@@ -0,0 +1,6 @@
1
+ import { createRemoveFuncFor } from '../utils/create-remove-func-for';
2
+
3
+ export const removeSize: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRemoveFuncFor('@atlaskit/checkbox', 'Checkbox', 'size');
@@ -0,0 +1,15 @@
1
+ import { createRemoveFuncFor } from '../utils/create-remove-func-for';
2
+
3
+ export const removeTheme: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRemoveFuncFor(
7
+ '@atlaskit/checkbox',
8
+ 'Checkbox',
9
+ 'theme',
10
+ `This file uses the @atlaskit/checkbox \`theme\` prop which
11
+ has now been removed due to its poor performance characteristics. We have not replaced
12
+ theme with an equivalent API due to minimal usage of the \`theme\` prop. However if you
13
+ were using theme to customise the size of the checkbox there is now a \`size\` prop.
14
+ The appearance of Checkbox will have likely changed.`,
15
+ );
@@ -0,0 +1,11 @@
1
+ import { createRenameImportFor } from '../utils/create-rename-import-for';
2
+
3
+ export const renameCheckboxWithoutAnalyticsImport: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRenameImportFor({
7
+ componentName: 'CheckboxWithoutAnalytics',
8
+ newComponentName: 'Checkbox',
9
+ oldPackagePath: '@atlaskit/checkbox/Checkbox',
10
+ newPackagePath: '@atlaskit/checkbox',
11
+ });
@@ -0,0 +1,10 @@
1
+ import { createRenameImportFor } from '../utils/create-rename-import-for';
2
+
3
+ export const renameDeepTypeImport: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRenameImportFor({
7
+ componentName: 'CheckboxProps',
8
+ oldPackagePath: '@atlaskit/checkbox/dist/cjs/types',
9
+ newPackagePath: '@atlaskit/checkbox',
10
+ });
@@ -1,4 +1,4 @@
1
- import { createRenameFuncFor } from '../utils';
1
+ import { createRenameFuncFor } from '../utils/create-rename-func-for';
2
2
 
3
3
  export const renameInputRef: (
4
4
  j: import('jscodeshift/src/core').JSCodeshift,
@@ -0,0 +1,10 @@
1
+ import { createRenameImportFor } from '../utils/create-rename-import-for';
2
+
3
+ export const renameTypeImport: (
4
+ j: import('jscodeshift/src/core').JSCodeshift,
5
+ source: import('jscodeshift/src/Collection').Collection<Node>,
6
+ ) => void = createRenameImportFor({
7
+ componentName: 'CheckboxProps',
8
+ oldPackagePath: '@atlaskit/checkbox/types',
9
+ newPackagePath: '@atlaskit/checkbox',
10
+ });
@@ -0,0 +1 @@
1
+ export type Nullable<T> = T | null;
@@ -0,0 +1,40 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift, type Program } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ // not replacing newlines (which \s does)
5
+ const spacesAndTabs: RegExp = /[ \t]{2,}/g;
6
+ const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
7
+
8
+ function clean(value: string): string {
9
+ return (
10
+ value
11
+ .replace(spacesAndTabs, ' ')
12
+ .replace(lineStartWithSpaces, '')
13
+ // using .trim() to clear the any newlines before the first text and after last text
14
+ .trim()
15
+ );
16
+ }
17
+
18
+ export function addCommentBefore({
19
+ j,
20
+ target,
21
+ message,
22
+ }: {
23
+ j: JSCodeshift;
24
+ target: Collection<Program> | Collection<ImportDeclaration>;
25
+ message: string;
26
+ }): void {
27
+ const content: string = ` TODO: (from codemod) ${clean(message)} `;
28
+ target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
29
+ path.value.comments = path.value.comments || [];
30
+
31
+ const exists = path.value.comments.find((comment) => comment.value === content);
32
+
33
+ // avoiding duplicates of the same comment
34
+ if (exists) {
35
+ return;
36
+ }
37
+
38
+ path.value.comments.push(j.commentBlock(content));
39
+ });
40
+ }
@@ -0,0 +1,20 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addCommentBefore } from './add-comment-before';
5
+
6
+ export function addCommentToStartOfFile({
7
+ j,
8
+ base,
9
+ message,
10
+ }: {
11
+ j: JSCodeshift;
12
+ base: Collection<Node>;
13
+ message: string;
14
+ }): void {
15
+ addCommentBefore({
16
+ j,
17
+ target: base.find(j.Program),
18
+ message,
19
+ });
20
+ }
@@ -0,0 +1,32 @@
1
+ import { type ImportDefaultSpecifier, type ImportSpecifier, type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function addToImport({
5
+ j,
6
+ base,
7
+ importSpecifier,
8
+ packageName,
9
+ }: {
10
+ j: JSCodeshift;
11
+ base: Collection<any>;
12
+ importSpecifier: ImportSpecifier | ImportDefaultSpecifier;
13
+ packageName: string;
14
+ }): void {
15
+ base
16
+ .find(j.ImportDeclaration)
17
+ .filter((path) => path.value.source.value === packageName)
18
+ .replaceWith((declaration) => {
19
+ return j.importDeclaration(
20
+ [
21
+ // we are appending to the existing specifiers
22
+ // We are doing a filter hear because sometimes specifiers can be removed
23
+ // but they hand around in the declaration
24
+ ...(declaration.value.specifiers || []).filter(
25
+ (item) => item.type === 'ImportSpecifier' && item.imported != null,
26
+ ),
27
+ importSpecifier,
28
+ ],
29
+ j.literal(packageName),
30
+ );
31
+ });
32
+ }
@@ -0,0 +1,33 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { addCommentToStartOfFile } from './add-comment-to-start-of-file';
5
+ import { getDefaultSpecifier } from './get-default-specifier';
6
+ import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
7
+ import { getNamedSpecifier } from './get-named-specifier';
8
+
9
+ export const createRemoveFuncFor: (
10
+ component: string,
11
+ importName: string,
12
+ prop: string,
13
+ comment?: string,
14
+ ) => (j: JSCodeshift, source: Collection<Node>) => void =
15
+ (component: string, importName: string, prop: string, comment?: string) =>
16
+ (j: JSCodeshift, source: Collection<Node>) => {
17
+ const specifier =
18
+ getNamedSpecifier(j, source, component, importName) ||
19
+ getDefaultSpecifier(j, source, component);
20
+
21
+ if (!specifier) {
22
+ return;
23
+ }
24
+
25
+ source.findJSXElements(specifier).forEach((element) => {
26
+ getJSXAttributesByName(j, element, prop).forEach((attribute) => {
27
+ j(attribute).remove();
28
+ if (comment) {
29
+ addCommentToStartOfFile({ j, base: source, message: comment });
30
+ }
31
+ });
32
+ });
33
+ };
@@ -0,0 +1,84 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { type Nullable } from '../types';
5
+
6
+ import { addCommentToStartOfFile } from './add-comment-to-start-of-file';
7
+
8
+ export const createRemoveImportsFor: ({
9
+ importsToRemove,
10
+ packagePath,
11
+ comment,
12
+ }: {
13
+ importsToRemove: string[];
14
+ packagePath: string;
15
+ comment: string;
16
+ }) => (j: JSCodeshift, source: Collection<Node>) => void =
17
+ ({
18
+ importsToRemove,
19
+ packagePath,
20
+ comment,
21
+ }: {
22
+ importsToRemove: string[];
23
+ packagePath: string;
24
+ comment: string;
25
+ }) =>
26
+ (j: JSCodeshift, source: Collection<Node>) => {
27
+ const isUsingName: boolean =
28
+ source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
29
+ .length > 0;
30
+ if (!isUsingName) {
31
+ return;
32
+ }
33
+
34
+ const existingAlias: Nullable<string> =
35
+ source
36
+ .find(j.ImportDeclaration)
37
+ .filter((path) => path.node.source.value === packagePath)
38
+ .find(j.ImportSpecifier)
39
+ .nodes()
40
+ .map((specifier): Nullable<string> => {
41
+ if (!importsToRemove.includes(specifier.imported.name)) {
42
+ return null;
43
+ }
44
+ // If aliased: return the alias
45
+ if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
46
+ return specifier.local.name;
47
+ }
48
+
49
+ return null;
50
+ })
51
+ .filter(Boolean)[0] || null;
52
+
53
+ // Remove imports
54
+ source
55
+ .find(j.ImportDeclaration)
56
+ .filter((path) => path.node.source.value === packagePath)
57
+ .find(j.ImportSpecifier)
58
+ .find(j.Identifier)
59
+ .filter((identifier) => {
60
+ if (
61
+ importsToRemove.includes(identifier.value.name) ||
62
+ identifier.value.name === existingAlias
63
+ ) {
64
+ addCommentToStartOfFile({ j, base: source, message: comment });
65
+ return true;
66
+ }
67
+ return false;
68
+ })
69
+ .remove();
70
+
71
+ // Remove entire import if it is empty
72
+ const isEmptyImport =
73
+ source
74
+ .find(j.ImportDeclaration)
75
+ .filter((path) => path.node.source.value === packagePath)
76
+ .find(j.ImportSpecifier)
77
+ .find(j.Identifier).length === 0;
78
+ if (isEmptyImport) {
79
+ source
80
+ .find(j.ImportDeclaration)
81
+ .filter((path) => path.node.source.value === packagePath)
82
+ .remove();
83
+ }
84
+ };
@@ -0,0 +1,42 @@
1
+ import { type JSCodeshift, type VariableDeclaration } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { findIdentifierAndReplaceAttribute } from './find-identifier-and-replace-attribute';
5
+ import { getJSXAttributesByName } from './get-jsx-attributes-by-name';
6
+ import { getNamedSpecifier } from './get-named-specifier';
7
+ import { hasVariableAssignment } from './has-variable-assignment';
8
+
9
+ export const createRenameFuncFor: (
10
+ component: string,
11
+ importName: string,
12
+ from: string,
13
+ to: string,
14
+ ) => (j: JSCodeshift, source: Collection<Node>) => void =
15
+ (component: string, importName: string, from: string, to: string) =>
16
+ (j: JSCodeshift, source: Collection<Node>) => {
17
+ const specifier = getNamedSpecifier(j, source, component, importName);
18
+
19
+ if (!specifier) {
20
+ return;
21
+ }
22
+
23
+ source.findJSXElements(specifier).forEach((element) => {
24
+ getJSXAttributesByName(j, element, from).forEach((attribute) => {
25
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
26
+ });
27
+ });
28
+
29
+ let variable = hasVariableAssignment(j, source, specifier);
30
+ if (variable) {
31
+ (variable as Collection<VariableDeclaration>)
32
+ .find(j.VariableDeclarator)
33
+ .forEach((declarator) => {
34
+ j(declarator)
35
+ .find(j.Identifier)
36
+ .filter((identifier) => identifier.name === 'id')
37
+ .forEach((ids) => {
38
+ findIdentifierAndReplaceAttribute(j, source, ids.node.name, from, to);
39
+ });
40
+ });
41
+ }
42
+ };
@@ -0,0 +1,98 @@
1
+ import { type ImportDefaultSpecifier, type ImportSpecifier, type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { type Nullable } from '../types';
5
+
6
+ import { addToImport } from './add-to-import';
7
+ import { tryCreateImport } from './try-create-import';
8
+
9
+ export const createRenameImportFor: ({
10
+ componentName,
11
+ newComponentName,
12
+ oldPackagePath,
13
+ newPackagePath,
14
+ }: {
15
+ componentName: string;
16
+ newComponentName?: string;
17
+ oldPackagePath: string;
18
+ newPackagePath: string;
19
+ }) => (j: JSCodeshift, source: Collection<Node>) => void =
20
+ ({
21
+ componentName,
22
+ newComponentName,
23
+ oldPackagePath,
24
+ newPackagePath,
25
+ }: {
26
+ componentName: string;
27
+ newComponentName?: string;
28
+ oldPackagePath: string;
29
+ newPackagePath: string;
30
+ }) =>
31
+ (j: JSCodeshift, source: Collection<Node>) => {
32
+ const isUsingName: boolean =
33
+ source
34
+ .find(j.ImportDeclaration)
35
+ .filter((path) => path.node.source.value === oldPackagePath)
36
+ .find(j.ImportSpecifier)
37
+ .nodes()
38
+ .filter((specifier) => specifier.imported && specifier.imported.name === componentName)
39
+ .length > 0;
40
+ if (!isUsingName) {
41
+ return;
42
+ }
43
+
44
+ const existingAlias: Nullable<string> =
45
+ source
46
+ .find(j.ImportDeclaration)
47
+ .filter((path) => path.node.source.value === oldPackagePath)
48
+ .find(j.ImportSpecifier)
49
+ .nodes()
50
+ .map((specifier): Nullable<string> => {
51
+ if (specifier.imported && specifier.imported.name !== componentName) {
52
+ return null;
53
+ }
54
+ // If aliased: return the alias
55
+ if (specifier.local && specifier.local.name !== componentName) {
56
+ return specifier.local.name;
57
+ }
58
+
59
+ return null;
60
+ })
61
+ .filter(Boolean)[0] || null;
62
+
63
+ // Check to see if need to create new package path
64
+ // Try create an import declaration just before the old import
65
+ tryCreateImport({
66
+ j,
67
+ base: source,
68
+ relativeToPackage: oldPackagePath,
69
+ packageName: newPackagePath,
70
+ });
71
+
72
+ const newSpecifier: ImportSpecifier | ImportDefaultSpecifier = (() => {
73
+ // If there's a new name use that
74
+ if (newComponentName) {
75
+ return j.importSpecifier(j.identifier(newComponentName), j.identifier(newComponentName));
76
+ }
77
+
78
+ if (existingAlias) {
79
+ return j.importSpecifier(j.identifier(componentName), j.identifier(existingAlias));
80
+ }
81
+
82
+ // Add specifier
83
+ return j.importSpecifier(j.identifier(componentName), j.identifier(componentName));
84
+ })();
85
+
86
+ addToImport({
87
+ j,
88
+ base: source,
89
+ importSpecifier: newSpecifier,
90
+ packageName: newPackagePath,
91
+ });
92
+
93
+ // Remove old path
94
+ source
95
+ .find(j.ImportDeclaration)
96
+ .filter((path) => path.node.source.value === oldPackagePath)
97
+ .remove();
98
+ };
@@ -0,0 +1,23 @@
1
+ import { type API, type FileInfo, type JSCodeshift, type Options } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ import { hasImportDeclaration } from './has-import-declaration';
5
+
6
+ export const createTransformer: (
7
+ component: string,
8
+ migrates: {
9
+ (j: JSCodeshift, source: Collection<Node>): void;
10
+ }[],
11
+ ) => (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string =
12
+ (component: string, migrates: { (j: JSCodeshift, source: Collection<Node>): void }[]) =>
13
+ (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => {
14
+ const source: Collection<Node> = jscodeshift(fileInfo.source);
15
+
16
+ if (!hasImportDeclaration(jscodeshift, source, component)) {
17
+ return fileInfo.source;
18
+ }
19
+
20
+ migrates.forEach((tf) => tf(jscodeshift, source));
21
+
22
+ return source.toSource(options.printOptions || { quote: 'single' });
23
+ };
@@ -0,0 +1,27 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function findIdentifierAndReplaceAttribute(
4
+ j: JSCodeshift,
5
+ source: ReturnType<typeof j>,
6
+ identifierName: string,
7
+ searchAttr: string,
8
+ replaceWithAttr: string,
9
+ ): void {
10
+ source
11
+ .find(j.JSXElement)
12
+ .find(j.JSXOpeningElement)
13
+ .filter((path) => {
14
+ return !!j(path.node)
15
+ .find(j.JSXIdentifier)
16
+ .filter((identifier) => identifier.value.name === identifierName);
17
+ })
18
+ .forEach((element) => {
19
+ j(element)
20
+ .find(j.JSXAttribute)
21
+ .find(j.JSXIdentifier)
22
+ .filter((attr) => attr.node.name === searchAttr)
23
+ .forEach((attribute) => {
24
+ j(attribute).replaceWith(j.jsxIdentifier(replaceWithAttr));
25
+ });
26
+ });
27
+ }
@@ -0,0 +1,17 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function getDefaultSpecifier(
4
+ j: JSCodeshift,
5
+ source: ReturnType<typeof j>,
6
+ specifier: string,
7
+ ): string | null {
8
+ const specifiers = source
9
+ .find(j.ImportDeclaration)
10
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
11
+ .find(j.ImportDefaultSpecifier);
12
+
13
+ if (!specifiers.length) {
14
+ return null;
15
+ }
16
+ return specifiers.nodes()[0]!.local!.name;
17
+ }
@@ -0,0 +1,18 @@
1
+ import { type ASTPath, type JSCodeshift, type JSXAttribute } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function getJSXAttributesByName(
5
+ j: JSCodeshift,
6
+ element: ASTPath<any>,
7
+ attributeName: string,
8
+ ): Collection<JSXAttribute> {
9
+ return j(element)
10
+ .find(j.JSXOpeningElement)
11
+ .find(j.JSXAttribute)
12
+ .filter((attribute) => {
13
+ const matches = j(attribute)
14
+ .find(j.JSXIdentifier)
15
+ .filter((identifier) => identifier.value.name === attributeName);
16
+ return Boolean(matches.length);
17
+ });
18
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ type ASTPath,
3
+ type ImportDeclaration,
4
+ type ImportSpecifier,
5
+ type JSCodeshift,
6
+ } from 'jscodeshift';
7
+
8
+ export function getNamedSpecifier(
9
+ j: JSCodeshift,
10
+ source: any,
11
+ specifier: string,
12
+ importName: string,
13
+ ): any {
14
+ const specifiers = source
15
+ .find(j.ImportDeclaration)
16
+ .filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
17
+ .find(j.ImportSpecifier)
18
+ .filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
19
+
20
+ if (!specifiers.length) {
21
+ return null;
22
+ }
23
+ return specifiers.nodes()[0]!.local!.name;
24
+ }
@@ -0,0 +1,12 @@
1
+ import { type ASTPath, type ImportDeclaration, type JSCodeshift } from 'jscodeshift';
2
+
3
+ export function hasImportDeclaration(j: JSCodeshift, source: any, importPath: string): boolean {
4
+ const imports = source
5
+ .find(j.ImportDeclaration)
6
+ .filter(
7
+ (path: ASTPath<ImportDeclaration>) =>
8
+ typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
9
+ );
10
+
11
+ return Boolean(imports.length);
12
+ }
@@ -0,0 +1,18 @@
1
+ import { type JSCodeshift, type VariableDeclaration } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function hasVariableAssignment(
5
+ j: JSCodeshift,
6
+ source: ReturnType<typeof j>,
7
+ identifierName: string,
8
+ ): Collection<VariableDeclaration> | boolean {
9
+ const occurance = source.find(j.VariableDeclaration).filter((path) => {
10
+ return !!j(path.node)
11
+ .find(j.VariableDeclarator)
12
+ .find(j.Identifier)
13
+ .filter((identifier) => {
14
+ return identifier.node.name === identifierName;
15
+ }).length;
16
+ });
17
+ return !!occurance.length ? occurance : false;
18
+ }
@@ -0,0 +1,27 @@
1
+ import { type JSCodeshift } from 'jscodeshift';
2
+ import { type Collection } from 'jscodeshift/src/Collection';
3
+
4
+ export function tryCreateImport({
5
+ j,
6
+ base,
7
+ relativeToPackage,
8
+ packageName,
9
+ }: {
10
+ j: JSCodeshift;
11
+ base: Collection<any>;
12
+ relativeToPackage: string;
13
+ packageName: string;
14
+ }): void {
15
+ const exists: boolean =
16
+ base.find(j.ImportDeclaration).filter((path) => path.value.source.value === packageName)
17
+ .length > 0;
18
+
19
+ if (exists) {
20
+ return;
21
+ }
22
+
23
+ base
24
+ .find(j.ImportDeclaration)
25
+ .filter((path) => path.value.source.value === relativeToPackage)
26
+ .insertBefore(j.importDeclaration([], j.literal(packageName)));
27
+ }