@compiled/react 0.6.12 → 0.9.0
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 +26 -0
- package/dist/browser/class-names/index.d.ts +2 -2
- package/dist/browser/class-names/index.js.flow +45 -0
- package/dist/browser/css/index.d.ts +17 -3
- package/dist/browser/css/index.js +4 -12
- package/dist/browser/css/index.js.flow +35 -0
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +4 -1
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.flow +40 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/keyframes/__fixtures__/index.d.ts +3 -0
- package/dist/browser/keyframes/__fixtures__/index.js +12 -0
- package/dist/browser/keyframes/__fixtures__/index.js.map +1 -0
- package/dist/browser/keyframes/index.d.ts +47 -0
- package/dist/browser/keyframes/index.js +9 -0
- package/dist/browser/keyframes/index.js.flow +54 -0
- package/dist/browser/keyframes/index.js.map +1 -0
- package/dist/browser/runtime/ax.js.flow +27 -0
- package/dist/browser/runtime/css-custom-property.js.flow +19 -0
- package/dist/browser/runtime/dev-warnings.d.ts +0 -1
- package/dist/browser/runtime/dev-warnings.js +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +7 -0
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +10 -0
- package/dist/browser/runtime/is-node.js.flow +19 -0
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js.flow +36 -0
- package/dist/browser/runtime/style-cache.d.ts +1 -1
- package/dist/browser/runtime/style-cache.js.flow +19 -0
- package/dist/browser/runtime/style.d.ts +1 -1
- package/dist/browser/runtime/style.js.flow +17 -0
- package/dist/browser/runtime/types.js.flow +23 -0
- package/dist/browser/runtime.js.flow +7 -0
- package/dist/browser/styled/index.d.ts +6 -9
- package/dist/browser/styled/index.js.flow +69 -0
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +6 -3
- package/dist/browser/types.js.flow +29 -0
- package/dist/browser/utils/error.js.flow +7 -0
- package/dist/cjs/class-names/index.d.ts +2 -2
- package/dist/cjs/class-names/index.js.flow +45 -0
- package/dist/cjs/css/index.d.ts +17 -3
- package/dist/cjs/css/index.js +4 -12
- package/dist/cjs/css/index.js.flow +35 -0
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.flow +40 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/keyframes/__fixtures__/index.d.ts +3 -0
- package/dist/cjs/keyframes/__fixtures__/index.js +15 -0
- package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -0
- package/dist/cjs/keyframes/index.d.ts +47 -0
- package/dist/cjs/keyframes/index.js +13 -0
- package/dist/cjs/keyframes/index.js.flow +54 -0
- package/dist/cjs/keyframes/index.js.map +1 -0
- package/dist/cjs/runtime/ax.js.flow +27 -0
- package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
- package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
- package/dist/cjs/runtime/dev-warnings.js +2 -3
- package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +10 -0
- package/dist/cjs/runtime/is-node.js.flow +19 -0
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +36 -0
- package/dist/cjs/runtime/style-cache.d.ts +1 -1
- package/dist/cjs/runtime/style-cache.js.flow +19 -0
- package/dist/cjs/runtime/style.d.ts +1 -1
- package/dist/cjs/runtime/style.js.flow +17 -0
- package/dist/cjs/runtime/types.js.flow +23 -0
- package/dist/cjs/runtime.js.flow +7 -0
- package/dist/cjs/styled/index.d.ts +6 -9
- package/dist/cjs/styled/index.js.flow +69 -0
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -3
- package/dist/cjs/types.js.flow +29 -0
- package/dist/cjs/utils/error.js.flow +7 -0
- package/dist/esm/class-names/index.d.ts +2 -2
- package/dist/esm/class-names/index.js.flow +45 -0
- package/dist/esm/css/index.d.ts +17 -3
- package/dist/esm/css/index.js +4 -12
- package/dist/esm/css/index.js.flow +35 -0
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.flow +40 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/keyframes/__fixtures__/index.d.ts +3 -0
- package/dist/esm/keyframes/__fixtures__/index.js +12 -0
- package/dist/esm/keyframes/__fixtures__/index.js.map +1 -0
- package/dist/esm/keyframes/index.d.ts +47 -0
- package/dist/esm/keyframes/index.js +9 -0
- package/dist/esm/keyframes/index.js.flow +54 -0
- package/dist/esm/keyframes/index.js.map +1 -0
- package/dist/esm/runtime/ax.js.flow +27 -0
- package/dist/esm/runtime/css-custom-property.js.flow +19 -0
- package/dist/esm/runtime/dev-warnings.d.ts +0 -1
- package/dist/esm/runtime/dev-warnings.js +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +7 -0
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +10 -0
- package/dist/esm/runtime/is-node.js.flow +19 -0
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js.flow +36 -0
- package/dist/esm/runtime/style-cache.d.ts +1 -1
- package/dist/esm/runtime/style-cache.js.flow +19 -0
- package/dist/esm/runtime/style.d.ts +1 -1
- package/dist/esm/runtime/style.js.flow +17 -0
- package/dist/esm/runtime/types.js.flow +23 -0
- package/dist/esm/runtime.js.flow +7 -0
- package/dist/esm/styled/index.d.ts +6 -9
- package/dist/esm/styled/index.js.flow +69 -0
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +6 -3
- package/dist/esm/types.js.flow +29 -0
- package/dist/esm/utils/error.js.flow +7 -0
- package/package.json +18 -20
- package/src/class-names/__tests__/types.test.js.flow +28 -0
- package/src/class-names/index.js.flow +45 -0
- package/src/class-names/index.tsx +2 -2
- package/src/css/__tests__/index.test.tsx +41 -0
- package/src/css/__tests__/types.test.js.flow +17 -0
- package/src/css/index.js.flow +35 -0
- package/src/css/index.tsx +26 -3
- package/src/index.js.flow +40 -0
- package/src/index.tsx +5 -2
- package/src/keyframes/__fixtures__/index.tsx +14 -0
- package/src/keyframes/__tests__/index.test.tsx +324 -0
- package/src/keyframes/__tests__/types.test.js.flow +31 -0
- package/src/keyframes/index.js.flow +54 -0
- package/src/keyframes/index.tsx +61 -0
- package/src/runtime/__tests__/style.test.tsx +91 -57
- package/src/runtime/ax.js.flow +27 -0
- package/src/runtime/css-custom-property.js.flow +19 -0
- package/src/runtime/dev-warnings.js.flow +7 -0
- package/src/runtime/dev-warnings.tsx +1 -1
- package/src/runtime/index.js.flow +10 -0
- package/src/runtime/is-node.js.flow +19 -0
- package/src/runtime/sheet.js.flow +36 -0
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.js.flow +19 -0
- package/src/runtime/style-cache.tsx +1 -1
- package/src/runtime/style.js.flow +17 -0
- package/src/runtime/style.tsx +1 -1
- package/src/runtime/types.js.flow +23 -0
- package/src/runtime.js.flow +7 -0
- package/src/styled/__tests__/types.test.js.flow +30 -0
- package/src/styled/index.js.flow +69 -0
- package/src/styled/index.tsx +6 -10
- package/src/types.js.flow +29 -0
- package/src/types.tsx +7 -3
- package/src/utils/error.js.flow +7 -0
- package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
- package/dist/browser/codemods/codemods-helpers.js +0 -201
- package/dist/browser/codemods/codemods-helpers.js.map +0 -1
- package/dist/browser/codemods/constants.d.ts +0 -3
- package/dist/browser/codemods/constants.js +0 -4
- package/dist/browser/codemods/constants.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
- package/dist/cjs/codemods/codemods-helpers.js +0 -217
- package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
- package/dist/cjs/codemods/constants.d.ts +0 -3
- package/dist/cjs/codemods/constants.js +0 -7
- package/dist/cjs/codemods/constants.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
- package/dist/esm/codemods/codemods-helpers.js +0 -201
- package/dist/esm/codemods/codemods-helpers.js.map +0 -1
- package/dist/esm/codemods/constants.d.ts +0 -3
- package/dist/esm/codemods/constants.js +0 -4
- package/dist/esm/codemods/constants.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/src/codemods/README.md +0 -8
- package/src/codemods/codemods-helpers.tsx +0 -369
- package/src/codemods/constants.tsx +0 -3
- package/src/codemods/emotion-to-compiled/README.md +0 -71
- package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
- package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
- package/src/codemods/emotion-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/README.md +0 -37
- package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
- package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
import core, {
|
|
2
|
-
FileInfo,
|
|
3
|
-
API,
|
|
4
|
-
Options,
|
|
5
|
-
Collection,
|
|
6
|
-
ASTPath,
|
|
7
|
-
CommentBlock,
|
|
8
|
-
ObjectPattern,
|
|
9
|
-
} from 'jscodeshift';
|
|
10
|
-
|
|
11
|
-
import { COMPILED_IMPORT_PATH } from '../constants';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
hasImportDeclaration,
|
|
15
|
-
getImportDeclarationCollection,
|
|
16
|
-
findImportSpecifierName,
|
|
17
|
-
addCommentForUnresolvedImportSpecifiers,
|
|
18
|
-
addReactIdentifier,
|
|
19
|
-
convertDefaultImportToNamedImport,
|
|
20
|
-
replaceImportDeclaration,
|
|
21
|
-
mergeImportSpecifiersAlongWithTheirComments,
|
|
22
|
-
addCommentBefore,
|
|
23
|
-
} from '../codemods-helpers';
|
|
24
|
-
|
|
25
|
-
const imports = {
|
|
26
|
-
compiledStyledImportName: 'styled',
|
|
27
|
-
emotionStyledPackageName: '@emotion/styled',
|
|
28
|
-
emotionCoreJSXPragma: '@jsx jsx',
|
|
29
|
-
emotionCoreImportNames: { jsx: 'jsx', css: 'css', ClassNames: 'ClassNames' },
|
|
30
|
-
emotionCorePackageName: '@emotion/core',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const removeEmotionCoreJSXPragma = (j: core.JSCodeshift, collection: Collection) => {
|
|
34
|
-
const commentCollection = collection.find(j.Comment);
|
|
35
|
-
|
|
36
|
-
commentCollection.forEach((commentPath) => {
|
|
37
|
-
const commentBlockCollection = j(
|
|
38
|
-
(commentPath as unknown) as ASTPath<CommentBlock>
|
|
39
|
-
).filter((commentBlockPath) =>
|
|
40
|
-
commentBlockPath.value.value.includes(imports.emotionCoreJSXPragma)
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
commentBlockCollection.forEach((commentBlockPath) => {
|
|
44
|
-
j(commentBlockPath).remove();
|
|
45
|
-
|
|
46
|
-
addReactIdentifier({ j, collection });
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const replaceEmotionCoreCSSTaggedTemplateExpression = (
|
|
52
|
-
j: core.JSCodeshift,
|
|
53
|
-
collection: Collection
|
|
54
|
-
) => {
|
|
55
|
-
const importDeclarationCollection = getImportDeclarationCollection({
|
|
56
|
-
j,
|
|
57
|
-
collection,
|
|
58
|
-
importPath: imports.emotionCorePackageName,
|
|
59
|
-
});
|
|
60
|
-
const name = findImportSpecifierName({
|
|
61
|
-
j,
|
|
62
|
-
importDeclarationCollection,
|
|
63
|
-
importName: imports.emotionCoreImportNames.css,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (name == null) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
collection
|
|
71
|
-
.find(j.TaggedTemplateExpression)
|
|
72
|
-
.filter((taggedTemplateExpressionPath) =>
|
|
73
|
-
j(taggedTemplateExpressionPath)
|
|
74
|
-
.find(j.Identifier)
|
|
75
|
-
.some((identifierPath) => identifierPath.node.name === name)
|
|
76
|
-
)
|
|
77
|
-
.forEach((taggedTemplateExpressionPath) => {
|
|
78
|
-
const { quasi } = taggedTemplateExpressionPath.node;
|
|
79
|
-
|
|
80
|
-
if (quasi) {
|
|
81
|
-
j(taggedTemplateExpressionPath).replaceWith([quasi]);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const handleClassNamesCXBehavior = (j: core.JSCodeshift, objectPattern: ObjectPattern) => {
|
|
87
|
-
const cxIdentifierName = 'cx';
|
|
88
|
-
const axIdentifierName = 'ax';
|
|
89
|
-
const compiledRuntimePackageName = `${COMPILED_IMPORT_PATH}/runtime`;
|
|
90
|
-
|
|
91
|
-
const cxObjectPropertyCollection = j(objectPattern)
|
|
92
|
-
.find(j.ObjectProperty)
|
|
93
|
-
.filter(
|
|
94
|
-
(objectPropertyPath) =>
|
|
95
|
-
objectPropertyPath.node.key.type === 'Identifier' &&
|
|
96
|
-
objectPropertyPath.node.key.name === cxIdentifierName
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
cxObjectPropertyCollection.forEach((cxObjectPropertyPath) => {
|
|
100
|
-
addCommentBefore({
|
|
101
|
-
j,
|
|
102
|
-
collection: j(cxObjectPropertyPath.node),
|
|
103
|
-
message: `Please replace "${cxIdentifierName}" with "${axIdentifierName}" from "${compiledRuntimePackageName}".
|
|
104
|
-
Usage: import { ${axIdentifierName} } from '${compiledRuntimePackageName}';
|
|
105
|
-
|
|
106
|
-
NOTE: Both "${cxIdentifierName}" and "${axIdentifierName}" have some differences, so we have not replaced its usage.
|
|
107
|
-
Please check the docs for "${axIdentifierName}" usage.
|
|
108
|
-
|
|
109
|
-
In future, we will expose "${axIdentifierName}" directly from "${imports.emotionCoreImportNames.ClassNames}" props.
|
|
110
|
-
|
|
111
|
-
Issue tracked on Github: https://github.com/atlassian-labs/compiled/issues/373`,
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const handleClassNamesStyleBehavior = (j: core.JSCodeshift, objectPattern: ObjectPattern) => {
|
|
117
|
-
const styleIdentifierName = 'style';
|
|
118
|
-
|
|
119
|
-
const hasStyleObjectProperty = j(objectPattern)
|
|
120
|
-
.find(j.ObjectProperty)
|
|
121
|
-
.some(
|
|
122
|
-
(objectPropertyPath) =>
|
|
123
|
-
objectPropertyPath.node.key.type === 'Identifier' &&
|
|
124
|
-
objectPropertyPath.node.key.name === styleIdentifierName
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
if (!hasStyleObjectProperty) {
|
|
128
|
-
const styleObjectProperty = j.objectProperty(
|
|
129
|
-
j.identifier(styleIdentifierName),
|
|
130
|
-
j.identifier(styleIdentifierName)
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
objectPattern.properties.push(styleObjectProperty);
|
|
134
|
-
|
|
135
|
-
addCommentBefore({
|
|
136
|
-
j,
|
|
137
|
-
collection: j(styleObjectProperty),
|
|
138
|
-
message: `We have exported "${styleIdentifierName}" from "${imports.emotionCoreImportNames.ClassNames}" props.
|
|
139
|
-
If you are using dynamic declarations, make sure to set the "${styleIdentifierName}"
|
|
140
|
-
prop otherwise remove it.`,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const handleClassNamesBehavior = (j: core.JSCodeshift, collection: Collection) => {
|
|
146
|
-
const importDeclarationCollection = getImportDeclarationCollection({
|
|
147
|
-
j,
|
|
148
|
-
collection,
|
|
149
|
-
importPath: imports.emotionCorePackageName,
|
|
150
|
-
});
|
|
151
|
-
const name = findImportSpecifierName({
|
|
152
|
-
j,
|
|
153
|
-
importDeclarationCollection,
|
|
154
|
-
importName: imports.emotionCoreImportNames.ClassNames,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
if (name == null) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
collection
|
|
162
|
-
.find(j.JSXElement)
|
|
163
|
-
.filter((jsxElementPath) =>
|
|
164
|
-
j(jsxElementPath)
|
|
165
|
-
.find(j.JSXIdentifier)
|
|
166
|
-
.some((jsxIdentifierPath) => jsxIdentifierPath.node.name === name)
|
|
167
|
-
)
|
|
168
|
-
.find(j.JSXExpressionContainer)
|
|
169
|
-
.forEach((jsxExpressionContainer) => {
|
|
170
|
-
const { expression } = jsxExpressionContainer.node;
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
expression.type === 'FunctionExpression' ||
|
|
174
|
-
expression.type === 'ArrowFunctionExpression'
|
|
175
|
-
) {
|
|
176
|
-
if (expression.params.length && expression.params[0].type === 'ObjectPattern') {
|
|
177
|
-
const objectPattern = expression.params[0];
|
|
178
|
-
|
|
179
|
-
handleClassNamesStyleBehavior(j, objectPattern);
|
|
180
|
-
|
|
181
|
-
handleClassNamesCXBehavior(j, objectPattern);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
const mergeCompiledImportSpecifiers = (j: core.JSCodeshift, collection: Collection) => {
|
|
188
|
-
const allowedCompiledNames = [
|
|
189
|
-
imports.compiledStyledImportName,
|
|
190
|
-
...Object.values(imports.emotionCoreImportNames),
|
|
191
|
-
].filter(
|
|
192
|
-
(name) =>
|
|
193
|
-
![imports.emotionCoreImportNames.jsx, imports.emotionCoreImportNames.css].includes(name)
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
mergeImportSpecifiersAlongWithTheirComments({
|
|
197
|
-
j,
|
|
198
|
-
collection,
|
|
199
|
-
filter: (name) => !!(name && allowedCompiledNames.includes(name)),
|
|
200
|
-
});
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const transformer = (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options): string => {
|
|
204
|
-
const { source } = fileInfo;
|
|
205
|
-
const collection = j(source);
|
|
206
|
-
|
|
207
|
-
const hasEmotionCoreImportDeclaration = hasImportDeclaration({
|
|
208
|
-
j,
|
|
209
|
-
collection,
|
|
210
|
-
importPath: imports.emotionCorePackageName,
|
|
211
|
-
});
|
|
212
|
-
const hasEmotionStyledImportDeclaration = hasImportDeclaration({
|
|
213
|
-
j,
|
|
214
|
-
collection,
|
|
215
|
-
importPath: imports.emotionStyledPackageName,
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
if (!hasEmotionCoreImportDeclaration && !hasEmotionStyledImportDeclaration) {
|
|
219
|
-
return source;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (hasEmotionStyledImportDeclaration) {
|
|
223
|
-
convertDefaultImportToNamedImport({
|
|
224
|
-
j,
|
|
225
|
-
collection,
|
|
226
|
-
importPath: imports.emotionStyledPackageName,
|
|
227
|
-
namedImport: imports.compiledStyledImportName,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (hasEmotionCoreImportDeclaration) {
|
|
232
|
-
removeEmotionCoreJSXPragma(j, collection);
|
|
233
|
-
addCommentForUnresolvedImportSpecifiers({
|
|
234
|
-
j,
|
|
235
|
-
collection,
|
|
236
|
-
importPath: imports.emotionCorePackageName,
|
|
237
|
-
allowedImportSpecifierNames: Object.values(imports.emotionCoreImportNames),
|
|
238
|
-
});
|
|
239
|
-
replaceEmotionCoreCSSTaggedTemplateExpression(j, collection);
|
|
240
|
-
handleClassNamesBehavior(j, collection);
|
|
241
|
-
replaceImportDeclaration({ j, collection, importPath: imports.emotionCorePackageName });
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
mergeCompiledImportSpecifiers(j, collection);
|
|
245
|
-
|
|
246
|
-
return collection.toSource(options.printOptions || { quote: 'single' });
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
export default transformer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './emotion-to-compiled';
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# styled-components-to-compiled
|
|
2
|
-
|
|
3
|
-
> Codemod for easy migration from styled components.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npx @compiled/cli --preset codemods
|
|
9
|
-
# and follow the instructions
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
**Will modify files in place, so make sure you can recover if it goes wrong!**
|
|
13
|
-
|
|
14
|
-
## Examples
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
import styled from 'styled-components';
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Is transformed to:
|
|
21
|
-
|
|
22
|
-
```javascript
|
|
23
|
-
import { styled } from '@compiled/react';
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Updating Instructions
|
|
27
|
-
|
|
28
|
-
When wanting to update to a later version make sure `@compiled/cli` is being ran with the same version.
|
|
29
|
-
|
|
30
|
-
> Watch out for it being cached!
|
|
31
|
-
|
|
32
|
-
For example when upgrading `@compiled/react` to `v0.6.0` where you've already used the CLI,
|
|
33
|
-
on your next run explicitly set the version number:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npx @compiled/cli@0.6.0 --preset codemods
|
|
37
|
-
```
|
package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
jest.disableAutomock();
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
-
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
5
|
-
|
|
6
|
-
import transformer from '../styled-components-to-compiled';
|
|
7
|
-
|
|
8
|
-
describe('styled-components-to-compiled transformer', () => {
|
|
9
|
-
defineInlineTest(
|
|
10
|
-
{ default: transformer, parser: 'tsx' },
|
|
11
|
-
{},
|
|
12
|
-
"import styled from 'styled-components';",
|
|
13
|
-
"import { styled } from '@compiled/react';",
|
|
14
|
-
'it transforms default styled-components imports'
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
defineInlineTest(
|
|
18
|
-
{ default: transformer, parser: 'tsx' },
|
|
19
|
-
{},
|
|
20
|
-
"import sc from 'styled-components';",
|
|
21
|
-
"import { styled as sc } from '@compiled/react';",
|
|
22
|
-
'it transforms default with different name than "styled" styled-components imports'
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
defineInlineTest(
|
|
26
|
-
{ default: transformer, parser: 'tsx' },
|
|
27
|
-
{},
|
|
28
|
-
`
|
|
29
|
-
import styled from 'styled-components';
|
|
30
|
-
import * as React from 'react';
|
|
31
|
-
`,
|
|
32
|
-
`
|
|
33
|
-
import { styled } from '@compiled/react';
|
|
34
|
-
import * as React from 'react';
|
|
35
|
-
`,
|
|
36
|
-
'it ignores other imports'
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
defineInlineTest(
|
|
40
|
-
{ default: transformer, parser: 'tsx' },
|
|
41
|
-
{},
|
|
42
|
-
`
|
|
43
|
-
// @top-level comment
|
|
44
|
-
|
|
45
|
-
// comment 1
|
|
46
|
-
import styled from 'styled-components';
|
|
47
|
-
// comment 2
|
|
48
|
-
import * as React from 'react';
|
|
49
|
-
`,
|
|
50
|
-
`
|
|
51
|
-
// @top-level comment
|
|
52
|
-
|
|
53
|
-
// comment 1
|
|
54
|
-
import { styled } from '@compiled/react';
|
|
55
|
-
// comment 2
|
|
56
|
-
import * as React from 'react';
|
|
57
|
-
`,
|
|
58
|
-
'it should not remove top level comments when transformed'
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
defineInlineTest(
|
|
62
|
-
{ default: transformer, parser: 'tsx' },
|
|
63
|
-
{},
|
|
64
|
-
`
|
|
65
|
-
// @top-level comment
|
|
66
|
-
|
|
67
|
-
// comment 1
|
|
68
|
-
import * as React from 'react';
|
|
69
|
-
// comment 2
|
|
70
|
-
import styled from 'styled-components';
|
|
71
|
-
`,
|
|
72
|
-
`
|
|
73
|
-
// @top-level comment
|
|
74
|
-
|
|
75
|
-
// comment 1
|
|
76
|
-
import * as React from 'react';
|
|
77
|
-
// comment 2
|
|
78
|
-
import { styled } from '@compiled/react';
|
|
79
|
-
`,
|
|
80
|
-
'it should not remove comments before transformed statement when not on top'
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
defineInlineTest(
|
|
84
|
-
{ default: transformer, parser: 'tsx' },
|
|
85
|
-
{},
|
|
86
|
-
`
|
|
87
|
-
import styled, { css, keyframes, createGlobalStyle, ThemeProvider, withTheme } from 'styled-components';
|
|
88
|
-
import * as React from 'react';
|
|
89
|
-
`,
|
|
90
|
-
`
|
|
91
|
-
/* TODO(@compiled/react codemod): "css" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
|
|
92
|
-
/* TODO(@compiled/react codemod): "keyframes" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
|
|
93
|
-
/* TODO(@compiled/react codemod): "createGlobalStyle" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
|
|
94
|
-
/* TODO(@compiled/react codemod): "ThemeProvider" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
|
|
95
|
-
/* TODO(@compiled/react codemod): "withTheme" is not exported from "@compiled/react" at the moment. Please find an alternative for it. */
|
|
96
|
-
import { styled } from '@compiled/react';
|
|
97
|
-
import * as React from 'react';
|
|
98
|
-
`,
|
|
99
|
-
'it adds TODO comment for imports which are not resolved'
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
defineInlineTest(
|
|
103
|
-
{ default: transformer, parser: 'tsx' },
|
|
104
|
-
{},
|
|
105
|
-
"import * as React from 'react';",
|
|
106
|
-
"import * as React from 'react';",
|
|
107
|
-
'it should not transform when styled-components imports are not present'
|
|
108
|
-
);
|
|
109
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './styled-components-to-compiled';
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { FileInfo, API, Options } from 'jscodeshift';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
hasImportDeclaration,
|
|
5
|
-
convertDefaultImportToNamedImport,
|
|
6
|
-
addCommentForUnresolvedImportSpecifiers,
|
|
7
|
-
} from '../codemods-helpers';
|
|
8
|
-
|
|
9
|
-
const imports = {
|
|
10
|
-
compiledStyledImportName: 'styled',
|
|
11
|
-
styledComponentsPackageName: 'styled-components',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const transformer = (fileInfo: FileInfo, { jscodeshift: j }: API, options: Options): string => {
|
|
15
|
-
const { source } = fileInfo;
|
|
16
|
-
const collection = j(source);
|
|
17
|
-
|
|
18
|
-
const hasStyledComponentsImportDeclaration = hasImportDeclaration({
|
|
19
|
-
j,
|
|
20
|
-
collection,
|
|
21
|
-
importPath: imports.styledComponentsPackageName,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (!hasStyledComponentsImportDeclaration) {
|
|
25
|
-
return source;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
addCommentForUnresolvedImportSpecifiers({
|
|
29
|
-
j,
|
|
30
|
-
collection,
|
|
31
|
-
importPath: imports.styledComponentsPackageName,
|
|
32
|
-
allowedImportSpecifierNames: [],
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
convertDefaultImportToNamedImport({
|
|
36
|
-
j,
|
|
37
|
-
collection,
|
|
38
|
-
importPath: imports.styledComponentsPackageName,
|
|
39
|
-
namedImport: imports.compiledStyledImportName,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return collection.toSource(options.printOptions || { quote: 'single' });
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default transformer;
|