@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.
- package/CHANGELOG.md +16 -0
- package/codemods/15.0.0-size-removal.tsx +2 -2
- package/codemods/migrations/remove-full-width.tsx +6 -0
- package/codemods/migrations/remove-imports.tsx +1 -1
- package/codemods/migrations/remove-overrides.tsx +15 -0
- package/codemods/migrations/remove-size.tsx +6 -0
- package/codemods/migrations/remove-theme.tsx +15 -0
- package/codemods/migrations/rename-checkbox-without-analytics-import.tsx +11 -0
- package/codemods/migrations/rename-deep-type-import.tsx +10 -0
- package/codemods/migrations/rename-input-ref-to-ref.tsx +1 -1
- package/codemods/migrations/rename-type-import.tsx +10 -0
- package/codemods/types.tsx +1 -0
- package/codemods/utils/add-comment-before.tsx +40 -0
- package/codemods/utils/add-comment-to-start-of-file.tsx +20 -0
- package/codemods/utils/add-to-import.tsx +32 -0
- package/codemods/utils/create-remove-func-for.tsx +33 -0
- package/codemods/utils/create-remove-imports-for.tsx +84 -0
- package/codemods/utils/create-rename-func-for.tsx +42 -0
- package/codemods/utils/create-rename-import-for.tsx +98 -0
- package/codemods/utils/create-transformer.tsx +23 -0
- package/codemods/utils/find-identifier-and-replace-attribute.tsx +27 -0
- package/codemods/utils/get-default-specifier.tsx +17 -0
- package/codemods/utils/get-jsx-attributes-by-name.tsx +18 -0
- package/codemods/utils/get-named-specifier.tsx +24 -0
- package/codemods/utils/has-import-declaration.tsx +12 -0
- package/codemods/utils/has-variable-assignment.tsx +18 -0
- package/codemods/utils/try-create-import.tsx +27 -0
- package/dist/cjs/internal/label.compiled.css +1 -1
- package/dist/cjs/internal/label.js +1 -1
- package/dist/es2019/internal/label.compiled.css +1 -1
- package/dist/es2019/internal/label.js +1 -1
- package/dist/esm/internal/label.compiled.css +1 -1
- package/dist/esm/internal/label.js +1 -1
- package/package.json +9 -1
- package/codemods/migrations/remove-props.tsx +0 -39
- package/codemods/migrations/rename-import.tsx +0 -33
- package/codemods/utils.tsx +0 -477
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
._f0grby5v{--checkbox-border-color:var(--ds-background-disabled,#17171708)}
|
|
16
16
|
._f0grjmqp{--checkbox-border-color:var(--ds-background-selected-bold,#1868db)}
|
|
17
17
|
._f0grrsbi{--checkbox-border-color:var(--ds-border-input,#8c8f97)}
|
|
18
|
-
.
|
|
18
|
+
._syaz1gmx{color:var(--ds-text-disabled,#080f214a)}
|
|
19
19
|
._syazi7uo{color:var(--ds-text,#292a2e)}
|
|
20
20
|
._umai184x{grid-auto-rows:min-content}
|
|
21
21
|
._yv0ey09t{grid-template-columns:min-content auto}
|
|
@@ -44,7 +44,7 @@ function Label(_ref) {
|
|
|
44
44
|
id = _ref.id,
|
|
45
45
|
xcss = _ref.xcss;
|
|
46
46
|
return /*#__PURE__*/React.createElement("label", {
|
|
47
|
-
className: (0, _runtime.ax)(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v
|
|
47
|
+
className: (0, _runtime.ax)(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v _syaz1gmx _80om13gf _1vj5by5v _q29qby5v _dh4gby5v _cz1uby5v _jom5wc43 _1s0718qt _106f18qt", isDisabled && (isChecked || isIndeterminate) && "_1e9d2sac _9js12sac _zoo92sac", xcss]),
|
|
48
48
|
"data-testid": testId,
|
|
49
49
|
"data-disabled": isDisabled || undefined,
|
|
50
50
|
id: id
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
._f0grby5v{--checkbox-border-color:var(--ds-background-disabled,#17171708)}
|
|
16
16
|
._f0grjmqp{--checkbox-border-color:var(--ds-background-selected-bold,#1868db)}
|
|
17
17
|
._f0grrsbi{--checkbox-border-color:var(--ds-border-input,#8c8f97)}
|
|
18
|
-
.
|
|
18
|
+
._syaz1gmx{color:var(--ds-text-disabled,#080f214a)}
|
|
19
19
|
._syazi7uo{color:var(--ds-text,#292a2e)}
|
|
20
20
|
._umai184x{grid-auto-rows:min-content}
|
|
21
21
|
._yv0ey09t{grid-template-columns:min-content auto}
|
|
@@ -37,7 +37,7 @@ export default function Label({
|
|
|
37
37
|
xcss
|
|
38
38
|
}) {
|
|
39
39
|
return /*#__PURE__*/React.createElement("label", {
|
|
40
|
-
className: ax(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v
|
|
40
|
+
className: ax(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v _syaz1gmx _80om13gf _1vj5by5v _q29qby5v _dh4gby5v _cz1uby5v _jom5wc43 _1s0718qt _106f18qt", isDisabled && (isChecked || isIndeterminate) && "_1e9d2sac _9js12sac _zoo92sac", xcss]),
|
|
41
41
|
"data-testid": testId,
|
|
42
42
|
"data-disabled": isDisabled || undefined,
|
|
43
43
|
id: id
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
._f0grby5v{--checkbox-border-color:var(--ds-background-disabled,#17171708)}
|
|
16
16
|
._f0grjmqp{--checkbox-border-color:var(--ds-background-selected-bold,#1868db)}
|
|
17
17
|
._f0grrsbi{--checkbox-border-color:var(--ds-border-input,#8c8f97)}
|
|
18
|
-
.
|
|
18
|
+
._syaz1gmx{color:var(--ds-text-disabled,#080f214a)}
|
|
19
19
|
._syazi7uo{color:var(--ds-text,#292a2e)}
|
|
20
20
|
._umai184x{grid-auto-rows:min-content}
|
|
21
21
|
._yv0ey09t{grid-template-columns:min-content auto}
|
|
@@ -36,7 +36,7 @@ export default function Label(_ref) {
|
|
|
36
36
|
id = _ref.id,
|
|
37
37
|
xcss = _ref.xcss;
|
|
38
38
|
return /*#__PURE__*/React.createElement("label", {
|
|
39
|
-
className: ax(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v
|
|
39
|
+
className: ax(["_11c8fhey _1e0c11p5 _1ejihkll _umai184x _1qwn1j9a _f0grrsbi _1c53glyw _1e9d1j28 _syazi7uo _80om73ad _ljcgdfik _1vj5l4ek _dh4gr01l _cz1u1l7x _jom5wc43 _1s071onz _106f1onz", label && "_zulp1nu5 _yv0ey09t", (isChecked || isIndeterminate) && "_1qwnjmqp _f0grjmqp _1e9d5w2r _1vj51q28 _q29q1q28 _dh4gr01l _cz1u1l7x _zoo95w2r _jom5wc43 _1s071onz _106f1onz", isInvalid && "_f0gr1bqt _q29q1bqt _cz1u1bqt _1s07gir2", isDisabled && "_1qwnby5v _f0grby5v _syaz1gmx _80om13gf _1vj5by5v _q29qby5v _dh4gby5v _cz1uby5v _jom5wc43 _1s0718qt _106f18qt", isDisabled && (isChecked || isIndeterminate) && "_1e9d2sac _9js12sac _zoo92sac", xcss]),
|
|
40
40
|
"data-testid": testId,
|
|
41
41
|
"data-disabled": isDisabled || undefined,
|
|
42
42
|
id: id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/checkbox",
|
|
3
|
-
"version": "17.3.
|
|
3
|
+
"version": "17.3.10",
|
|
4
4
|
"description": "A checkbox is an input control that allows a user to select one or more options from a number of choices.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
],
|
|
26
26
|
"atlaskit:src": "src/index.tsx",
|
|
27
27
|
"atlassian": {
|
|
28
|
+
"react-compiler": {
|
|
29
|
+
"enabled": true,
|
|
30
|
+
"gating": {
|
|
31
|
+
"source": "@atlassian/react-compiler-gating",
|
|
32
|
+
"importSpecifierName": "isReactCompilerActivePlatform"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
28
35
|
"team": "Design System Team",
|
|
29
36
|
"website": {
|
|
30
37
|
"name": "Checkbox",
|
|
@@ -53,6 +60,7 @@
|
|
|
53
60
|
"@atlaskit/link": "^3.3.0",
|
|
54
61
|
"@atlaskit/primitives": "^18.1.0",
|
|
55
62
|
"@atlaskit/section-message": "^8.12.0",
|
|
63
|
+
"@atlassian/react-compiler-gating": "workspace:^",
|
|
56
64
|
"@atlassian/ssr-tests": "workspace:^",
|
|
57
65
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
58
66
|
"@testing-library/react": "^16.3.0",
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createRemoveFuncFor } from '../utils';
|
|
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');
|
|
7
|
-
|
|
8
|
-
export const removeOverrides: (
|
|
9
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
10
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
11
|
-
) => void = createRemoveFuncFor(
|
|
12
|
-
'@atlaskit/checkbox',
|
|
13
|
-
'Checkbox',
|
|
14
|
-
'overrides',
|
|
15
|
-
`This file uses the @atlaskit/checkbox \`overrides\` prop
|
|
16
|
-
which has now been removed due to its poor performance characteristics. We have not
|
|
17
|
-
replaced overrides with an equivalent API and the overrides pattern exposes internal
|
|
18
|
-
implementation detail as public API and makes it harder for you to upgrade. The appearance
|
|
19
|
-
of Checkbox will have likely changed.`,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
export const removeTheme: (
|
|
23
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
24
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
25
|
-
) => void = createRemoveFuncFor(
|
|
26
|
-
'@atlaskit/checkbox',
|
|
27
|
-
'Checkbox',
|
|
28
|
-
'theme',
|
|
29
|
-
`This file uses the @atlaskit/checkbox \`theme\` prop which
|
|
30
|
-
has now been removed due to its poor performance characteristics. We have not replaced
|
|
31
|
-
theme with an equivalent API due to minimal usage of the \`theme\` prop. However if you
|
|
32
|
-
were using theme to customise the size of the checkbox there is now a \`size\` prop.
|
|
33
|
-
The appearance of Checkbox will have likely changed.`,
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export const removeSize: (
|
|
37
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
38
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
39
|
-
) => void = createRemoveFuncFor('@atlaskit/checkbox', 'Checkbox', 'size');
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createRenameImportFor } from '../utils';
|
|
2
|
-
|
|
3
|
-
// As you could access everything in Checkbox with the old entry points
|
|
4
|
-
// there are a lot of possible things to fix. Having searched on SourceTree
|
|
5
|
-
// these are the only things that need to be fixed
|
|
6
|
-
|
|
7
|
-
export const renameTypeImport: (
|
|
8
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
9
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
10
|
-
) => void = createRenameImportFor({
|
|
11
|
-
componentName: 'CheckboxProps',
|
|
12
|
-
oldPackagePath: '@atlaskit/checkbox/types',
|
|
13
|
-
newPackagePath: '@atlaskit/checkbox',
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const renameDeepTypeImport: (
|
|
17
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
18
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
19
|
-
) => void = createRenameImportFor({
|
|
20
|
-
componentName: 'CheckboxProps',
|
|
21
|
-
oldPackagePath: '@atlaskit/checkbox/dist/cjs/types',
|
|
22
|
-
newPackagePath: '@atlaskit/checkbox',
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const renameCheckboxWithoutAnalyticsImport: (
|
|
26
|
-
j: import('jscodeshift/src/core').JSCodeshift,
|
|
27
|
-
source: import('jscodeshift/src/Collection').Collection<Node>,
|
|
28
|
-
) => void = createRenameImportFor({
|
|
29
|
-
componentName: 'CheckboxWithoutAnalytics',
|
|
30
|
-
newComponentName: 'Checkbox',
|
|
31
|
-
oldPackagePath: '@atlaskit/checkbox/Checkbox',
|
|
32
|
-
newPackagePath: '@atlaskit/checkbox',
|
|
33
|
-
});
|
package/codemods/utils.tsx
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
API,
|
|
3
|
-
ASTPath,
|
|
4
|
-
default as core,
|
|
5
|
-
FileInfo,
|
|
6
|
-
ImportDeclaration,
|
|
7
|
-
ImportDefaultSpecifier,
|
|
8
|
-
ImportSpecifier,
|
|
9
|
-
JSXAttribute,
|
|
10
|
-
Options,
|
|
11
|
-
Program,
|
|
12
|
-
VariableDeclaration,
|
|
13
|
-
} from 'jscodeshift';
|
|
14
|
-
import { type Collection } from 'jscodeshift/src/Collection';
|
|
15
|
-
|
|
16
|
-
export type Nullable<T> = T | null;
|
|
17
|
-
|
|
18
|
-
export function getNamedSpecifier(
|
|
19
|
-
j: core.JSCodeshift,
|
|
20
|
-
source: any,
|
|
21
|
-
specifier: string,
|
|
22
|
-
importName: string,
|
|
23
|
-
): any {
|
|
24
|
-
const specifiers = source
|
|
25
|
-
.find(j.ImportDeclaration)
|
|
26
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
27
|
-
.find(j.ImportSpecifier)
|
|
28
|
-
.filter((path: ASTPath<ImportSpecifier>) => path.node.imported.name === importName);
|
|
29
|
-
|
|
30
|
-
if (!specifiers.length) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getDefaultSpecifier(j: core.JSCodeshift, source: ReturnType<typeof j>, specifier: string) {
|
|
37
|
-
const specifiers = source
|
|
38
|
-
.find(j.ImportDeclaration)
|
|
39
|
-
.filter((path: ASTPath<ImportDeclaration>) => path.node.source.value === specifier)
|
|
40
|
-
.find(j.ImportDefaultSpecifier);
|
|
41
|
-
|
|
42
|
-
if (!specifiers.length) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return specifiers.nodes()[0]!.local!.name;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function getJSXAttributesByName(
|
|
49
|
-
j: core.JSCodeshift,
|
|
50
|
-
element: ASTPath<any>,
|
|
51
|
-
attributeName: string,
|
|
52
|
-
): Collection<JSXAttribute> {
|
|
53
|
-
return j(element)
|
|
54
|
-
.find(j.JSXOpeningElement)
|
|
55
|
-
.find(j.JSXAttribute)
|
|
56
|
-
.filter((attribute) => {
|
|
57
|
-
const matches = j(attribute)
|
|
58
|
-
.find(j.JSXIdentifier)
|
|
59
|
-
.filter((identifier) => identifier.value.name === attributeName);
|
|
60
|
-
return Boolean(matches.length);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function hasImportDeclaration(
|
|
65
|
-
j: core.JSCodeshift,
|
|
66
|
-
source: any,
|
|
67
|
-
importPath: string,
|
|
68
|
-
): boolean {
|
|
69
|
-
const imports = source
|
|
70
|
-
.find(j.ImportDeclaration)
|
|
71
|
-
.filter(
|
|
72
|
-
(path: ASTPath<ImportDeclaration>) =>
|
|
73
|
-
typeof path.node.source.value === 'string' && path.node.source.value.startsWith(importPath),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
return Boolean(imports.length);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function findIdentifierAndReplaceAttribute(
|
|
80
|
-
j: core.JSCodeshift,
|
|
81
|
-
source: ReturnType<typeof j>,
|
|
82
|
-
identifierName: string,
|
|
83
|
-
searchAttr: string,
|
|
84
|
-
replaceWithAttr: string,
|
|
85
|
-
): void {
|
|
86
|
-
source
|
|
87
|
-
.find(j.JSXElement)
|
|
88
|
-
.find(j.JSXOpeningElement)
|
|
89
|
-
.filter((path) => {
|
|
90
|
-
return !!j(path.node)
|
|
91
|
-
.find(j.JSXIdentifier)
|
|
92
|
-
.filter((identifier) => identifier.value.name === identifierName);
|
|
93
|
-
})
|
|
94
|
-
.forEach((element) => {
|
|
95
|
-
j(element)
|
|
96
|
-
.find(j.JSXAttribute)
|
|
97
|
-
.find(j.JSXIdentifier)
|
|
98
|
-
.filter((attr) => attr.node.name === searchAttr)
|
|
99
|
-
.forEach((attribute) => {
|
|
100
|
-
j(attribute).replaceWith(j.jsxIdentifier(replaceWithAttr));
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function hasVariableAssignment(
|
|
106
|
-
j: core.JSCodeshift,
|
|
107
|
-
source: ReturnType<typeof j>,
|
|
108
|
-
identifierName: string,
|
|
109
|
-
): Collection<VariableDeclaration> | boolean {
|
|
110
|
-
const occurance = source.find(j.VariableDeclaration).filter((path) => {
|
|
111
|
-
return !!j(path.node)
|
|
112
|
-
.find(j.VariableDeclarator)
|
|
113
|
-
.find(j.Identifier)
|
|
114
|
-
.filter((identifier) => {
|
|
115
|
-
return identifier.node.name === identifierName;
|
|
116
|
-
}).length;
|
|
117
|
-
});
|
|
118
|
-
return !!occurance.length ? occurance : false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// not replacing newlines (which \s does)
|
|
122
|
-
const spacesAndTabs: RegExp = /[ \t]{2,}/g;
|
|
123
|
-
const lineStartWithSpaces: RegExp = /^[ \t]*/gm;
|
|
124
|
-
|
|
125
|
-
function clean(value: string): string {
|
|
126
|
-
return (
|
|
127
|
-
value
|
|
128
|
-
.replace(spacesAndTabs, ' ')
|
|
129
|
-
.replace(lineStartWithSpaces, '')
|
|
130
|
-
// using .trim() to clear the any newlines before the first text and after last text
|
|
131
|
-
.trim()
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function addCommentToStartOfFile({
|
|
136
|
-
j,
|
|
137
|
-
base,
|
|
138
|
-
message,
|
|
139
|
-
}: {
|
|
140
|
-
j: core.JSCodeshift;
|
|
141
|
-
base: Collection<Node>;
|
|
142
|
-
message: string;
|
|
143
|
-
}): void {
|
|
144
|
-
addCommentBefore({
|
|
145
|
-
j,
|
|
146
|
-
target: base.find(j.Program),
|
|
147
|
-
message,
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function addCommentBefore({
|
|
152
|
-
j,
|
|
153
|
-
target,
|
|
154
|
-
message,
|
|
155
|
-
}: {
|
|
156
|
-
j: core.JSCodeshift;
|
|
157
|
-
target: Collection<Program> | Collection<ImportDeclaration>;
|
|
158
|
-
message: string;
|
|
159
|
-
}): void {
|
|
160
|
-
const content: string = ` TODO: (from codemod) ${clean(message)} `;
|
|
161
|
-
target.forEach((path: ASTPath<Program | ImportDeclaration>) => {
|
|
162
|
-
path.value.comments = path.value.comments || [];
|
|
163
|
-
|
|
164
|
-
const exists = path.value.comments.find((comment) => comment.value === content);
|
|
165
|
-
|
|
166
|
-
// avoiding duplicates of the same comment
|
|
167
|
-
if (exists) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
path.value.comments.push(j.commentBlock(content));
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function tryCreateImport({
|
|
176
|
-
j,
|
|
177
|
-
base,
|
|
178
|
-
relativeToPackage,
|
|
179
|
-
packageName,
|
|
180
|
-
}: {
|
|
181
|
-
j: core.JSCodeshift;
|
|
182
|
-
base: Collection<any>;
|
|
183
|
-
relativeToPackage: string;
|
|
184
|
-
packageName: string;
|
|
185
|
-
}): void {
|
|
186
|
-
const exists: boolean =
|
|
187
|
-
base.find(j.ImportDeclaration).filter((path) => path.value.source.value === packageName)
|
|
188
|
-
.length > 0;
|
|
189
|
-
|
|
190
|
-
if (exists) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
base
|
|
195
|
-
.find(j.ImportDeclaration)
|
|
196
|
-
.filter((path) => path.value.source.value === relativeToPackage)
|
|
197
|
-
.insertBefore(j.importDeclaration([], j.literal(packageName)));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function addToImport({
|
|
201
|
-
j,
|
|
202
|
-
base,
|
|
203
|
-
importSpecifier,
|
|
204
|
-
packageName,
|
|
205
|
-
}: {
|
|
206
|
-
j: core.JSCodeshift;
|
|
207
|
-
base: Collection<any>;
|
|
208
|
-
importSpecifier: ImportSpecifier | ImportDefaultSpecifier;
|
|
209
|
-
packageName: string;
|
|
210
|
-
}): void {
|
|
211
|
-
base
|
|
212
|
-
.find(j.ImportDeclaration)
|
|
213
|
-
.filter((path) => path.value.source.value === packageName)
|
|
214
|
-
.replaceWith((declaration) => {
|
|
215
|
-
return j.importDeclaration(
|
|
216
|
-
[
|
|
217
|
-
// we are appending to the existing specifiers
|
|
218
|
-
// We are doing a filter hear because sometimes specifiers can be removed
|
|
219
|
-
// but they hand around in the declaration
|
|
220
|
-
...(declaration.value.specifiers || []).filter(
|
|
221
|
-
(item) => item.type === 'ImportSpecifier' && item.imported != null,
|
|
222
|
-
),
|
|
223
|
-
importSpecifier,
|
|
224
|
-
],
|
|
225
|
-
j.literal(packageName),
|
|
226
|
-
);
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export const createRenameFuncFor: (
|
|
231
|
-
component: string,
|
|
232
|
-
importName: string,
|
|
233
|
-
from: string,
|
|
234
|
-
to: string,
|
|
235
|
-
) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
236
|
-
(component: string, importName: string, from: string, to: string) =>
|
|
237
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
238
|
-
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
239
|
-
|
|
240
|
-
if (!specifier) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
245
|
-
getJSXAttributesByName(j, element, from).forEach((attribute) => {
|
|
246
|
-
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(to), attribute.node.value));
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
let variable = hasVariableAssignment(j, source, specifier);
|
|
251
|
-
if (variable) {
|
|
252
|
-
(variable as Collection<VariableDeclaration>)
|
|
253
|
-
.find(j.VariableDeclarator)
|
|
254
|
-
.forEach((declarator) => {
|
|
255
|
-
j(declarator)
|
|
256
|
-
.find(j.Identifier)
|
|
257
|
-
.filter((identifier) => identifier.name === 'id')
|
|
258
|
-
.forEach((ids) => {
|
|
259
|
-
findIdentifierAndReplaceAttribute(j, source, ids.node.name, from, to);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export const createRemoveFuncFor: (
|
|
266
|
-
component: string,
|
|
267
|
-
importName: string,
|
|
268
|
-
prop: string,
|
|
269
|
-
comment?: string,
|
|
270
|
-
) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
271
|
-
(component: string, importName: string, prop: string, comment?: string) =>
|
|
272
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
273
|
-
const specifier =
|
|
274
|
-
getNamedSpecifier(j, source, component, importName) ||
|
|
275
|
-
getDefaultSpecifier(j, source, component);
|
|
276
|
-
|
|
277
|
-
if (!specifier) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
source.findJSXElements(specifier).forEach((element) => {
|
|
282
|
-
getJSXAttributesByName(j, element, prop).forEach((attribute) => {
|
|
283
|
-
j(attribute).remove();
|
|
284
|
-
if (comment) {
|
|
285
|
-
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
export const createRenameImportFor: ({
|
|
292
|
-
componentName,
|
|
293
|
-
newComponentName,
|
|
294
|
-
oldPackagePath,
|
|
295
|
-
newPackagePath,
|
|
296
|
-
}: {
|
|
297
|
-
componentName: string;
|
|
298
|
-
newComponentName?: string;
|
|
299
|
-
oldPackagePath: string;
|
|
300
|
-
newPackagePath: string;
|
|
301
|
-
}) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
302
|
-
({
|
|
303
|
-
componentName,
|
|
304
|
-
newComponentName,
|
|
305
|
-
oldPackagePath,
|
|
306
|
-
newPackagePath,
|
|
307
|
-
}: {
|
|
308
|
-
componentName: string;
|
|
309
|
-
newComponentName?: string;
|
|
310
|
-
oldPackagePath: string;
|
|
311
|
-
newPackagePath: string;
|
|
312
|
-
}) =>
|
|
313
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
314
|
-
const isUsingName: boolean =
|
|
315
|
-
source
|
|
316
|
-
.find(j.ImportDeclaration)
|
|
317
|
-
.filter((path) => path.node.source.value === oldPackagePath)
|
|
318
|
-
.find(j.ImportSpecifier)
|
|
319
|
-
.nodes()
|
|
320
|
-
.filter((specifier) => specifier.imported && specifier.imported.name === componentName)
|
|
321
|
-
.length > 0;
|
|
322
|
-
if (!isUsingName) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
const existingAlias: Nullable<string> =
|
|
327
|
-
source
|
|
328
|
-
.find(j.ImportDeclaration)
|
|
329
|
-
.filter((path) => path.node.source.value === oldPackagePath)
|
|
330
|
-
.find(j.ImportSpecifier)
|
|
331
|
-
.nodes()
|
|
332
|
-
.map((specifier): Nullable<string> => {
|
|
333
|
-
if (specifier.imported && specifier.imported.name !== componentName) {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
// If aliased: return the alias
|
|
337
|
-
if (specifier.local && specifier.local.name !== componentName) {
|
|
338
|
-
return specifier.local.name;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return null;
|
|
342
|
-
})
|
|
343
|
-
.filter(Boolean)[0] || null;
|
|
344
|
-
|
|
345
|
-
// Check to see if need to create new package path
|
|
346
|
-
// Try create an import declaration just before the old import
|
|
347
|
-
tryCreateImport({
|
|
348
|
-
j,
|
|
349
|
-
base: source,
|
|
350
|
-
relativeToPackage: oldPackagePath,
|
|
351
|
-
packageName: newPackagePath,
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
const newSpecifier: ImportSpecifier | ImportDefaultSpecifier = (() => {
|
|
355
|
-
// If there's a new name use that
|
|
356
|
-
if (newComponentName) {
|
|
357
|
-
return j.importSpecifier(j.identifier(newComponentName), j.identifier(newComponentName));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (existingAlias) {
|
|
361
|
-
return j.importSpecifier(j.identifier(componentName), j.identifier(existingAlias));
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Add specifier
|
|
365
|
-
return j.importSpecifier(j.identifier(componentName), j.identifier(componentName));
|
|
366
|
-
})();
|
|
367
|
-
|
|
368
|
-
addToImport({
|
|
369
|
-
j,
|
|
370
|
-
base: source,
|
|
371
|
-
importSpecifier: newSpecifier,
|
|
372
|
-
packageName: newPackagePath,
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
// Remove old path
|
|
376
|
-
source
|
|
377
|
-
.find(j.ImportDeclaration)
|
|
378
|
-
.filter((path) => path.node.source.value === oldPackagePath)
|
|
379
|
-
.remove();
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
export const createRemoveImportsFor: ({
|
|
383
|
-
importsToRemove,
|
|
384
|
-
packagePath,
|
|
385
|
-
comment,
|
|
386
|
-
}: {
|
|
387
|
-
importsToRemove: string[];
|
|
388
|
-
packagePath: string;
|
|
389
|
-
comment: string;
|
|
390
|
-
}) => (j: core.JSCodeshift, source: Collection<Node>) => void =
|
|
391
|
-
({
|
|
392
|
-
importsToRemove,
|
|
393
|
-
packagePath,
|
|
394
|
-
comment,
|
|
395
|
-
}: {
|
|
396
|
-
importsToRemove: string[];
|
|
397
|
-
packagePath: string;
|
|
398
|
-
comment: string;
|
|
399
|
-
}) =>
|
|
400
|
-
(j: core.JSCodeshift, source: Collection<Node>) => {
|
|
401
|
-
const isUsingName: boolean =
|
|
402
|
-
source.find(j.ImportDeclaration).filter((path) => path.node.source.value === packagePath)
|
|
403
|
-
.length > 0;
|
|
404
|
-
if (!isUsingName) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const existingAlias: Nullable<string> =
|
|
409
|
-
source
|
|
410
|
-
.find(j.ImportDeclaration)
|
|
411
|
-
.filter((path) => path.node.source.value === packagePath)
|
|
412
|
-
.find(j.ImportSpecifier)
|
|
413
|
-
.nodes()
|
|
414
|
-
.map((specifier): Nullable<string> => {
|
|
415
|
-
if (!importsToRemove.includes(specifier.imported.name)) {
|
|
416
|
-
return null;
|
|
417
|
-
}
|
|
418
|
-
// If aliased: return the alias
|
|
419
|
-
if (specifier.local && !importsToRemove.includes(specifier.local.name)) {
|
|
420
|
-
return specifier.local.name;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return null;
|
|
424
|
-
})
|
|
425
|
-
.filter(Boolean)[0] || null;
|
|
426
|
-
|
|
427
|
-
// Remove imports
|
|
428
|
-
source
|
|
429
|
-
.find(j.ImportDeclaration)
|
|
430
|
-
.filter((path) => path.node.source.value === packagePath)
|
|
431
|
-
.find(j.ImportSpecifier)
|
|
432
|
-
.find(j.Identifier)
|
|
433
|
-
.filter((identifier) => {
|
|
434
|
-
if (
|
|
435
|
-
importsToRemove.includes(identifier.value.name) ||
|
|
436
|
-
identifier.value.name === existingAlias
|
|
437
|
-
) {
|
|
438
|
-
addCommentToStartOfFile({ j, base: source, message: comment });
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
return false;
|
|
442
|
-
})
|
|
443
|
-
.remove();
|
|
444
|
-
|
|
445
|
-
// Remove entire import if it is empty
|
|
446
|
-
const isEmptyImport =
|
|
447
|
-
source
|
|
448
|
-
.find(j.ImportDeclaration)
|
|
449
|
-
.filter((path) => path.node.source.value === packagePath)
|
|
450
|
-
.find(j.ImportSpecifier)
|
|
451
|
-
.find(j.Identifier).length === 0;
|
|
452
|
-
if (isEmptyImport) {
|
|
453
|
-
source
|
|
454
|
-
.find(j.ImportDeclaration)
|
|
455
|
-
.filter((path) => path.node.source.value === packagePath)
|
|
456
|
-
.remove();
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
export const createTransformer: (
|
|
461
|
-
component: string,
|
|
462
|
-
migrates: {
|
|
463
|
-
(j: core.JSCodeshift, source: Collection<Node>): void;
|
|
464
|
-
}[],
|
|
465
|
-
) => (fileInfo: FileInfo, { jscodeshift }: API, options: Options) => string =
|
|
466
|
-
(component: string, migrates: { (j: core.JSCodeshift, source: Collection<Node>): void }[]) =>
|
|
467
|
-
(fileInfo: FileInfo, { jscodeshift }: API, options: Options) => {
|
|
468
|
-
const source: Collection<Node> = jscodeshift(fileInfo.source);
|
|
469
|
-
|
|
470
|
-
if (!hasImportDeclaration(jscodeshift, source, component)) {
|
|
471
|
-
return fileInfo.source;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
migrates.forEach((tf) => tf(jscodeshift, source));
|
|
475
|
-
|
|
476
|
-
return source.toSource(options.printOptions || { quote: 'single' });
|
|
477
|
-
};
|