@atlaskit/codemod-utils 3.2.2 → 4.0.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 +50 -0
- package/dist/cjs/index.js +74 -32
- package/dist/cjs/utils/index.js +54 -2
- package/dist/cjs/utils/support.js +69 -6
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +2 -2
- package/dist/es2019/utils/index.js +48 -2
- package/dist/es2019/utils/support.js +58 -3
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/utils/index.js +52 -2
- package/dist/esm/utils/support.js +57 -3
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/support.d.ts +7 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @atlaskit/codemod-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`b29ce16dad8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b29ce16dad8) - [ED-14606] Move bitbucket schema, confluence schema, jira schema, and default schema from @atlaskit/adf-schema to their own entry points. These new entry points are as follows
|
|
8
|
+
|
|
9
|
+
@atlaskit/adf-schema/schema-bitbucket for:
|
|
10
|
+
|
|
11
|
+
- bitbucketSchema
|
|
12
|
+
|
|
13
|
+
@atlaskit/adf-schema/schema-confluence for:
|
|
14
|
+
|
|
15
|
+
- confluenceSchema
|
|
16
|
+
- confluenceSchemaWithMediaSingle
|
|
17
|
+
|
|
18
|
+
@atlaskit/adf-schema/schema-jira for:
|
|
19
|
+
|
|
20
|
+
- default as createJIRASchema
|
|
21
|
+
- isSchemaWithLists
|
|
22
|
+
- isSchemaWithMentions
|
|
23
|
+
- isSchemaWithEmojis
|
|
24
|
+
- isSchemaWithLinks
|
|
25
|
+
- isSchemaWithAdvancedTextFormattingMarks
|
|
26
|
+
- isSchemaWithCodeBlock
|
|
27
|
+
- isSchemaWithBlockQuotes
|
|
28
|
+
- isSchemaWithMedia
|
|
29
|
+
- isSchemaWithSubSupMark
|
|
30
|
+
- isSchemaWithTextColor
|
|
31
|
+
- isSchemaWithTables
|
|
32
|
+
|
|
33
|
+
@atlaskit/adf-schema/schema-default for:
|
|
34
|
+
|
|
35
|
+
- defaultSchema
|
|
36
|
+
- getSchemaBasedOnStage
|
|
37
|
+
- defaultSchemaConfig
|
|
38
|
+
|
|
39
|
+
This change also includes codemods in @atlaskit/adf-schema to update these entry points. It also introduces a new util function "changeImportEntryPoint" to @atlaskit/codemod-utils to handle this scenario.
|
|
40
|
+
|
|
41
|
+
## 3.4.0
|
|
42
|
+
|
|
43
|
+
### Minor Changes
|
|
44
|
+
|
|
45
|
+
- [`cf853e39278`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cf853e39278) - Adds new util `hasImportDeclarationFromAnyPackageEntrypoint`. It works just like `hasImportDeclaration`, but instead of searching for an import declaration that has strict equality with a supplied import path (e.g. `@atlaskit/theme`), it looks for an import declaration that _starts with_ the supplied import path. With that same example, it will match both `@atlaskit/theme` and `@atlaskit/theme/typography` — making it easy to choose to run a codemod on a usage regardless of the way in which it was imported.
|
|
46
|
+
|
|
47
|
+
## 3.3.0
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- [`9729143f07b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9729143f07b) - Add support functions `getDynamicImportName`, `isCallExpressionCalleeImportType`, `isCallExpressionArgumentStringLiteralType`, `isCallExpressionArgumentValueMatches` and `addDynamicImport`.
|
|
52
|
+
|
|
3
53
|
## 3.2.2
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,10 +3,40 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "addCommentBefore", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return
|
|
9
|
+
return _support.addCommentBefore;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "addCommentToStartOfFile", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _support.addCommentToStartOfFile;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "addDynamicImport", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _support.addDynamicImport;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "addToImport", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _support.addToImport;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "callExpressionArgMatchesString", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _support.callExpressionArgMatchesString;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "changeImportEntryPoint", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return _utils.changeImportEntryPoint;
|
|
10
40
|
}
|
|
11
41
|
});
|
|
12
42
|
Object.defineProperty(exports, "createConvertFuncFor", {
|
|
@@ -15,10 +45,10 @@ Object.defineProperty(exports, "createConvertFuncFor", {
|
|
|
15
45
|
return _utils.createConvertFuncFor;
|
|
16
46
|
}
|
|
17
47
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "createRemoveFuncAddCommentFor", {
|
|
19
49
|
enumerable: true,
|
|
20
50
|
get: function get() {
|
|
21
|
-
return _utils.
|
|
51
|
+
return _utils.createRemoveFuncAddCommentFor;
|
|
22
52
|
}
|
|
23
53
|
});
|
|
24
54
|
Object.defineProperty(exports, "createRemoveFuncFor", {
|
|
@@ -27,46 +57,46 @@ Object.defineProperty(exports, "createRemoveFuncFor", {
|
|
|
27
57
|
return _utils.createRemoveFuncFor;
|
|
28
58
|
}
|
|
29
59
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "createRenameFuncFor", {
|
|
31
61
|
enumerable: true,
|
|
32
62
|
get: function get() {
|
|
33
|
-
return _utils.
|
|
63
|
+
return _utils.createRenameFuncFor;
|
|
34
64
|
}
|
|
35
65
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
66
|
+
Object.defineProperty(exports, "createRenameImportFor", {
|
|
37
67
|
enumerable: true,
|
|
38
68
|
get: function get() {
|
|
39
|
-
return _utils.
|
|
69
|
+
return _utils.createRenameImportFor;
|
|
40
70
|
}
|
|
41
71
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
72
|
+
Object.defineProperty(exports, "createRenameJSXFunc", {
|
|
43
73
|
enumerable: true,
|
|
44
74
|
get: function get() {
|
|
45
|
-
return _utils.
|
|
75
|
+
return _utils.createRenameJSXFunc;
|
|
46
76
|
}
|
|
47
77
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
78
|
+
Object.defineProperty(exports, "createTransformer", {
|
|
49
79
|
enumerable: true,
|
|
50
80
|
get: function get() {
|
|
51
|
-
return _utils.
|
|
81
|
+
return _utils.createTransformer;
|
|
52
82
|
}
|
|
53
83
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
84
|
+
Object.defineProperty(exports, "doesIdentifierExist", {
|
|
55
85
|
enumerable: true,
|
|
56
86
|
get: function get() {
|
|
57
|
-
return
|
|
87
|
+
return _support.doesIdentifierExist;
|
|
58
88
|
}
|
|
59
89
|
});
|
|
60
|
-
Object.defineProperty(exports, "
|
|
90
|
+
Object.defineProperty(exports, "elevateComponentToNewEntryPoint", {
|
|
61
91
|
enumerable: true,
|
|
62
92
|
get: function get() {
|
|
63
|
-
return _utils.
|
|
93
|
+
return _utils.elevateComponentToNewEntryPoint;
|
|
64
94
|
}
|
|
65
95
|
});
|
|
66
|
-
Object.defineProperty(exports, "
|
|
96
|
+
Object.defineProperty(exports, "flattenCertainChildPropsAsProp", {
|
|
67
97
|
enumerable: true,
|
|
68
98
|
get: function get() {
|
|
69
|
-
return _utils.
|
|
99
|
+
return _utils.flattenCertainChildPropsAsProp;
|
|
70
100
|
}
|
|
71
101
|
});
|
|
72
102
|
Object.defineProperty(exports, "getDefaultSpecifier", {
|
|
@@ -75,10 +105,10 @@ Object.defineProperty(exports, "getDefaultSpecifier", {
|
|
|
75
105
|
return _support.getDefaultSpecifier;
|
|
76
106
|
}
|
|
77
107
|
});
|
|
78
|
-
Object.defineProperty(exports, "
|
|
108
|
+
Object.defineProperty(exports, "getDynamicImportName", {
|
|
79
109
|
enumerable: true,
|
|
80
110
|
get: function get() {
|
|
81
|
-
return _support.
|
|
111
|
+
return _support.getDynamicImportName;
|
|
82
112
|
}
|
|
83
113
|
});
|
|
84
114
|
Object.defineProperty(exports, "getJSXAttributesByName", {
|
|
@@ -87,16 +117,16 @@ Object.defineProperty(exports, "getJSXAttributesByName", {
|
|
|
87
117
|
return _support.getJSXAttributesByName;
|
|
88
118
|
}
|
|
89
119
|
});
|
|
90
|
-
Object.defineProperty(exports, "
|
|
120
|
+
Object.defineProperty(exports, "getNamedSpecifier", {
|
|
91
121
|
enumerable: true,
|
|
92
122
|
get: function get() {
|
|
93
|
-
return _support.
|
|
123
|
+
return _support.getNamedSpecifier;
|
|
94
124
|
}
|
|
95
125
|
});
|
|
96
|
-
Object.defineProperty(exports, "
|
|
126
|
+
Object.defineProperty(exports, "getSafeImportName", {
|
|
97
127
|
enumerable: true,
|
|
98
128
|
get: function get() {
|
|
99
|
-
return _support.
|
|
129
|
+
return _support.getSafeImportName;
|
|
100
130
|
}
|
|
101
131
|
});
|
|
102
132
|
Object.defineProperty(exports, "hasImportDeclaration", {
|
|
@@ -105,22 +135,34 @@ Object.defineProperty(exports, "hasImportDeclaration", {
|
|
|
105
135
|
return _support.hasImportDeclaration;
|
|
106
136
|
}
|
|
107
137
|
});
|
|
108
|
-
Object.defineProperty(exports, "
|
|
138
|
+
Object.defineProperty(exports, "hasImportDeclarationFromAnyPackageEntrypoint", {
|
|
109
139
|
enumerable: true,
|
|
110
140
|
get: function get() {
|
|
111
|
-
return _support.
|
|
141
|
+
return _support.hasImportDeclarationFromAnyPackageEntrypoint;
|
|
112
142
|
}
|
|
113
143
|
});
|
|
114
|
-
Object.defineProperty(exports, "
|
|
144
|
+
Object.defineProperty(exports, "hasJSXAttributesByName", {
|
|
115
145
|
enumerable: true,
|
|
116
146
|
get: function get() {
|
|
117
|
-
return _support.
|
|
147
|
+
return _support.hasJSXAttributesByName;
|
|
118
148
|
}
|
|
119
149
|
});
|
|
120
|
-
Object.defineProperty(exports, "
|
|
150
|
+
Object.defineProperty(exports, "removeImport", {
|
|
121
151
|
enumerable: true,
|
|
122
152
|
get: function get() {
|
|
123
|
-
return _support.
|
|
153
|
+
return _support.removeImport;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(exports, "renameNamedImportWithAliasName", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function get() {
|
|
159
|
+
return _utils.renameNamedImportWithAliasName;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(exports, "replaceImportStatementFor", {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function get() {
|
|
165
|
+
return _utils.replaceImportStatementFor;
|
|
124
166
|
}
|
|
125
167
|
});
|
|
126
168
|
Object.defineProperty(exports, "testMethodVariantEach", {
|
|
@@ -129,10 +171,10 @@ Object.defineProperty(exports, "testMethodVariantEach", {
|
|
|
129
171
|
return _support.testMethodVariantEach;
|
|
130
172
|
}
|
|
131
173
|
});
|
|
132
|
-
Object.defineProperty(exports, "
|
|
174
|
+
Object.defineProperty(exports, "tryCreateImport", {
|
|
133
175
|
enumerable: true,
|
|
134
176
|
get: function get() {
|
|
135
|
-
return _support.
|
|
177
|
+
return _support.tryCreateImport;
|
|
136
178
|
}
|
|
137
179
|
});
|
|
138
180
|
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.replaceImportStatementFor = exports.renameNamedImportWithAliasName = exports.flattenCertainChildPropsAsProp = exports.elevateComponentToNewEntryPoint = exports.createTransformer = exports.createRenameJSXFunc = exports.createRenameImportFor = exports.createRenameFuncFor = exports.createRemoveFuncFor = exports.createRemoveFuncAddCommentFor = exports.createConvertFuncFor = exports.changeImportEntryPoint = void 0;
|
|
7
7
|
|
|
8
8
|
var _support = require("./support");
|
|
9
9
|
|
|
@@ -273,4 +273,56 @@ var renameNamedImportWithAliasName = function renameNamedImportWithAliasName(com
|
|
|
273
273
|
};
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
-
exports.renameNamedImportWithAliasName = renameNamedImportWithAliasName;
|
|
276
|
+
exports.renameNamedImportWithAliasName = renameNamedImportWithAliasName;
|
|
277
|
+
|
|
278
|
+
var changeImportEntryPoint = function changeImportEntryPoint(oldPackageName, importToConvert, newPackageName) {
|
|
279
|
+
return function (j, root) {
|
|
280
|
+
root.find(j.ImportDeclaration, {
|
|
281
|
+
source: {
|
|
282
|
+
value: oldPackageName
|
|
283
|
+
}
|
|
284
|
+
}).forEach(function (path) {
|
|
285
|
+
var _currentImportSpecifi;
|
|
286
|
+
|
|
287
|
+
var currentImportSpecifier = (path.value.specifiers || []).find(function (specifier) {
|
|
288
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
289
|
+
return specifier.imported.name === importToConvert;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return false;
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
if (!currentImportSpecifier) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
var importedSpecifierName = currentImportSpecifier.imported.name;
|
|
300
|
+
var localSpecifierName = (_currentImportSpecifi = currentImportSpecifier.local) === null || _currentImportSpecifi === void 0 ? void 0 : _currentImportSpecifi.name;
|
|
301
|
+
var newIdentifier = j.importSpecifier(j.identifier(importedSpecifierName), localSpecifierName ? j.identifier(localSpecifierName) : undefined); // check if new import exists, if not create it
|
|
302
|
+
|
|
303
|
+
(0, _support.tryCreateImport)(j, root, oldPackageName, newPackageName); // remove the old import specifier, but NOT the whole package
|
|
304
|
+
|
|
305
|
+
root.find(j.ImportDeclaration, {
|
|
306
|
+
source: {
|
|
307
|
+
value: oldPackageName
|
|
308
|
+
}
|
|
309
|
+
}).find(j.ImportSpecifier).filter(function (path) {
|
|
310
|
+
return path.value.imported.name === importToConvert;
|
|
311
|
+
}).remove(); // adds import specifier to new import
|
|
312
|
+
|
|
313
|
+
(0, _support.addToImport)(j, root, newIdentifier, newPackageName); // if there are any imports with no specifiers, remove the whole import
|
|
314
|
+
|
|
315
|
+
root.find(j.ImportDeclaration, {
|
|
316
|
+
source: {
|
|
317
|
+
value: oldPackageName
|
|
318
|
+
}
|
|
319
|
+
}).filter(function (path) {
|
|
320
|
+
var _path$value$specifier;
|
|
321
|
+
|
|
322
|
+
return !((_path$value$specifier = path.value.specifiers) !== null && _path$value$specifier !== void 0 && _path$value$specifier.length);
|
|
323
|
+
}).remove();
|
|
324
|
+
});
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
exports.changeImportEntryPoint = changeImportEntryPoint;
|
|
@@ -5,14 +5,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.getNamedSpecifier = getNamedSpecifier;
|
|
9
8
|
exports.addCommentBefore = addCommentBefore;
|
|
10
|
-
exports.
|
|
11
|
-
exports.tryCreateImport = tryCreateImport;
|
|
9
|
+
exports.addDynamicImport = exports.addCommentToStartOfFile = void 0;
|
|
12
10
|
exports.addToImport = addToImport;
|
|
11
|
+
exports.callExpressionArgMatchesString = void 0;
|
|
13
12
|
exports.clean = clean;
|
|
13
|
+
exports.getJSXAttributesByName = exports.getDynamicImportName = exports.getDefaultSpecifier = exports.doesIdentifierExist = exports.debug = void 0;
|
|
14
|
+
exports.getNamedSpecifier = getNamedSpecifier;
|
|
14
15
|
exports.getSafeImportName = getSafeImportName;
|
|
15
|
-
exports.
|
|
16
|
+
exports.isEmpty = exports.hasJSXAttributesByName = exports.hasImportDeclarationFromAnyPackageEntrypoint = exports.hasImportDeclaration = void 0;
|
|
17
|
+
exports.removeImport = removeImport;
|
|
18
|
+
exports.testMethodVariantEach = exports.shiftDefaultImport = void 0;
|
|
19
|
+
exports.tryCreateImport = tryCreateImport;
|
|
16
20
|
|
|
17
21
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
22
|
|
|
@@ -28,9 +32,55 @@ function getNamedSpecifier(j, source, specifier, importName) {
|
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
return specifiers.nodes()[0].local.name;
|
|
31
|
-
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var getDynamicImportName = function getDynamicImportName(j, source, importPath) {
|
|
38
|
+
var dynamicImports = source.find(j.VariableDeclarator).filter(function (variableDeclaratorPath) {
|
|
39
|
+
return j(variableDeclaratorPath).find(j.CallExpression).filter(function (callExpressionPath) {
|
|
40
|
+
var _callExpressionPath$n = callExpressionPath.node,
|
|
41
|
+
callee = _callExpressionPath$n.callee,
|
|
42
|
+
callExpressionArguments = _callExpressionPath$n.arguments;
|
|
43
|
+
return !!(isCallExpressionCalleeImportType(callee) && isCallExpressionArgumentStringLiteralType(callExpressionArguments) && isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath));
|
|
44
|
+
}).length > 0;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!dynamicImports.length) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var id = dynamicImports.nodes()[0].id;
|
|
52
|
+
|
|
53
|
+
if (id.type !== 'Identifier') {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return id.name;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.getDynamicImportName = getDynamicImportName;
|
|
61
|
+
|
|
62
|
+
var isCallExpressionCalleeImportType = function isCallExpressionCalleeImportType(callee) {
|
|
63
|
+
return callee && callee.type === 'Import';
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var isCallExpressionArgumentStringLiteralType = function isCallExpressionArgumentStringLiteralType(callExpressionArguments) {
|
|
67
|
+
return callExpressionArguments && callExpressionArguments.length && callExpressionArguments[0].type === 'StringLiteral';
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
var isCallExpressionArgumentValueMatches = function isCallExpressionArgumentValueMatches(callExpressionArgument, j, value) {
|
|
71
|
+
return j(callExpressionArgument).some(function (path) {
|
|
72
|
+
return path.node.value === value;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
32
75
|
|
|
76
|
+
var addDynamicImport = function addDynamicImport(j, target, name, packageEndpoint) {
|
|
77
|
+
var node = j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), j.callExpression(j.memberExpression(j.identifier('React'), j.identifier('lazy')), [j.arrowFunctionExpression([], j.callExpression(j.import(), [j.stringLiteral(packageEndpoint)]))]))]);
|
|
78
|
+
target.insertAfter(node);
|
|
79
|
+
addCommentBefore(j, j(node), 'We have added "React.lazy" here. Feel free to change it to "lazy" or other named import depending upon how you imported.');
|
|
80
|
+
}; // not replacing newlines (which \s does)
|
|
33
81
|
|
|
82
|
+
|
|
83
|
+
exports.addDynamicImport = addDynamicImport;
|
|
34
84
|
var spacesAndTabs = /[ \t]{2,}/g;
|
|
35
85
|
var lineStartWithSpaces = /^[ \t]*/gm;
|
|
36
86
|
|
|
@@ -86,7 +136,7 @@ var getDefaultSpecifier = function getDefaultSpecifier(j, source, specifier) {
|
|
|
86
136
|
exports.getDefaultSpecifier = getDefaultSpecifier;
|
|
87
137
|
|
|
88
138
|
var getJSXAttributesByName = function getJSXAttributesByName(j, element, attributeName) {
|
|
89
|
-
return j(element).find(j.JSXOpeningElement).find(j.JSXAttribute).filter(function (attribute) {
|
|
139
|
+
return j(element).find(j.JSXOpeningElement).at(0).find(j.JSXAttribute).filter(function (attribute) {
|
|
90
140
|
var matches = j(attribute).find(j.JSXIdentifier).filter(function (identifier) {
|
|
91
141
|
return identifier.value.name === attributeName;
|
|
92
142
|
});
|
|
@@ -111,6 +161,19 @@ var hasImportDeclaration = function hasImportDeclaration(j, source, importPath)
|
|
|
111
161
|
|
|
112
162
|
exports.hasImportDeclaration = hasImportDeclaration;
|
|
113
163
|
|
|
164
|
+
var hasImportDeclarationFromAnyPackageEntrypoint = function hasImportDeclarationFromAnyPackageEntrypoint(j, source, packageName) {
|
|
165
|
+
var imports = source.find(j.ImportDeclaration).filter(function (path) {
|
|
166
|
+
var _path$node, _path$node$source;
|
|
167
|
+
|
|
168
|
+
return (// @ts-ignore
|
|
169
|
+
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName)
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
return Boolean(imports.length);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
exports.hasImportDeclarationFromAnyPackageEntrypoint = hasImportDeclarationFromAnyPackageEntrypoint;
|
|
176
|
+
|
|
114
177
|
var debug = function debug(component) {
|
|
115
178
|
return function (j, source) {
|
|
116
179
|
var defaultSpecifier = getDefaultSpecifier(j, source, component);
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor } from './utils';
|
|
2
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName } from './utils/support';
|
|
1
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint } from './utils';
|
|
2
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addCommentToStartOfFile, getDefaultSpecifier, getJSXAttributesByName, getNamedSpecifier, getSafeImportName } from './support';
|
|
1
|
+
import { addCommentToStartOfFile, addToImport, getDefaultSpecifier, getJSXAttributesByName, getNamedSpecifier, getSafeImportName, tryCreateImport } from './support';
|
|
2
2
|
|
|
3
3
|
const createRemoveFuncFor = (component, importName, prop, predicate = () => true, comment) => (j, source) => {
|
|
4
4
|
const specifier = getNamedSpecifier(j, source, component, importName);
|
|
@@ -200,4 +200,50 @@ const renameNamedImportWithAliasName = (component, from, to) => (j, source) => {
|
|
|
200
200
|
});
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
const changeImportEntryPoint = (oldPackageName, importToConvert, newPackageName) => (j, root) => {
|
|
204
|
+
root.find(j.ImportDeclaration, {
|
|
205
|
+
source: {
|
|
206
|
+
value: oldPackageName
|
|
207
|
+
}
|
|
208
|
+
}).forEach(path => {
|
|
209
|
+
var _currentImportSpecifi;
|
|
210
|
+
|
|
211
|
+
const currentImportSpecifier = (path.value.specifiers || []).find(specifier => {
|
|
212
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
213
|
+
return specifier.imported.name === importToConvert;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return false;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
if (!currentImportSpecifier) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const importedSpecifierName = currentImportSpecifier.imported.name;
|
|
224
|
+
const localSpecifierName = (_currentImportSpecifi = currentImportSpecifier.local) === null || _currentImportSpecifi === void 0 ? void 0 : _currentImportSpecifi.name;
|
|
225
|
+
const newIdentifier = j.importSpecifier(j.identifier(importedSpecifierName), localSpecifierName ? j.identifier(localSpecifierName) : undefined); // check if new import exists, if not create it
|
|
226
|
+
|
|
227
|
+
tryCreateImport(j, root, oldPackageName, newPackageName); // remove the old import specifier, but NOT the whole package
|
|
228
|
+
|
|
229
|
+
root.find(j.ImportDeclaration, {
|
|
230
|
+
source: {
|
|
231
|
+
value: oldPackageName
|
|
232
|
+
}
|
|
233
|
+
}).find(j.ImportSpecifier).filter(path => path.value.imported.name === importToConvert).remove(); // adds import specifier to new import
|
|
234
|
+
|
|
235
|
+
addToImport(j, root, newIdentifier, newPackageName); // if there are any imports with no specifiers, remove the whole import
|
|
236
|
+
|
|
237
|
+
root.find(j.ImportDeclaration, {
|
|
238
|
+
source: {
|
|
239
|
+
value: oldPackageName
|
|
240
|
+
}
|
|
241
|
+
}).filter(path => {
|
|
242
|
+
var _path$value$specifier;
|
|
243
|
+
|
|
244
|
+
return !((_path$value$specifier = path.value.specifiers) !== null && _path$value$specifier !== void 0 && _path$value$specifier.length);
|
|
245
|
+
}).remove();
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint };
|
|
@@ -6,7 +6,51 @@ function getNamedSpecifier(j, source, specifier, importName) {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
return specifiers.nodes()[0].local.name;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getDynamicImportName = (j, source, importPath) => {
|
|
12
|
+
const dynamicImports = source.find(j.VariableDeclarator).filter(variableDeclaratorPath => {
|
|
13
|
+
return j(variableDeclaratorPath).find(j.CallExpression).filter(callExpressionPath => {
|
|
14
|
+
const {
|
|
15
|
+
callee,
|
|
16
|
+
arguments: callExpressionArguments
|
|
17
|
+
} = callExpressionPath.node;
|
|
18
|
+
return !!(isCallExpressionCalleeImportType(callee) && isCallExpressionArgumentStringLiteralType(callExpressionArguments) && isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath));
|
|
19
|
+
}).length > 0;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (!dynamicImports.length) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
id
|
|
28
|
+
} = dynamicImports.nodes()[0];
|
|
29
|
+
|
|
30
|
+
if (id.type !== 'Identifier') {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return id.name;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const isCallExpressionCalleeImportType = callee => {
|
|
38
|
+
return callee && callee.type === 'Import';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isCallExpressionArgumentStringLiteralType = callExpressionArguments => {
|
|
42
|
+
return callExpressionArguments && callExpressionArguments.length && callExpressionArguments[0].type === 'StringLiteral';
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const isCallExpressionArgumentValueMatches = (callExpressionArgument, j, value) => {
|
|
46
|
+
return j(callExpressionArgument).some(path => path.node.value === value);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const addDynamicImport = (j, target, name, packageEndpoint) => {
|
|
50
|
+
const node = j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), j.callExpression(j.memberExpression(j.identifier('React'), j.identifier('lazy')), [j.arrowFunctionExpression([], j.callExpression(j.import(), [j.stringLiteral(packageEndpoint)]))]))]);
|
|
51
|
+
target.insertAfter(node);
|
|
52
|
+
addCommentBefore(j, j(node), 'We have added "React.lazy" here. Feel free to change it to "lazy" or other named import depending upon how you imported.');
|
|
53
|
+
}; // not replacing newlines (which \s does)
|
|
10
54
|
|
|
11
55
|
|
|
12
56
|
const spacesAndTabs = /[ \t]{2,}/g;
|
|
@@ -55,7 +99,7 @@ const getDefaultSpecifier = (j, source, specifier) => {
|
|
|
55
99
|
|
|
56
100
|
|
|
57
101
|
const getJSXAttributesByName = (j, element, attributeName) => {
|
|
58
|
-
return j(element).find(j.JSXOpeningElement).find(j.JSXAttribute).filter(attribute => {
|
|
102
|
+
return j(element).find(j.JSXOpeningElement).at(0).find(j.JSXAttribute).filter(attribute => {
|
|
59
103
|
const matches = j(attribute).find(j.JSXIdentifier).filter(identifier => identifier.value.name === attributeName);
|
|
60
104
|
return Boolean(matches.length);
|
|
61
105
|
});
|
|
@@ -68,6 +112,17 @@ const hasImportDeclaration = (j, source, importPath) => {
|
|
|
68
112
|
return Boolean(imports.length);
|
|
69
113
|
};
|
|
70
114
|
|
|
115
|
+
const hasImportDeclarationFromAnyPackageEntrypoint = (j, source, packageName) => {
|
|
116
|
+
const imports = source.find(j.ImportDeclaration).filter(path => {
|
|
117
|
+
var _path$node, _path$node$source;
|
|
118
|
+
|
|
119
|
+
return (// @ts-ignore
|
|
120
|
+
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName)
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
return Boolean(imports.length);
|
|
124
|
+
};
|
|
125
|
+
|
|
71
126
|
const debug = component => (j, source) => {
|
|
72
127
|
const defaultSpecifier = getDefaultSpecifier(j, source, component);
|
|
73
128
|
|
|
@@ -201,4 +256,4 @@ function getSafeImportName({
|
|
|
201
256
|
return isUsed ? fallbackName : desiredName;
|
|
202
257
|
}
|
|
203
258
|
|
|
204
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName };
|
|
259
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport };
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor } from './utils';
|
|
2
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName } from './utils/support';
|
|
1
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint } from './utils';
|
|
2
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } from './utils/support';
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addCommentToStartOfFile, getDefaultSpecifier, getJSXAttributesByName, getNamedSpecifier, getSafeImportName } from './support';
|
|
1
|
+
import { addCommentToStartOfFile, addToImport, getDefaultSpecifier, getJSXAttributesByName, getNamedSpecifier, getSafeImportName, tryCreateImport } from './support';
|
|
2
2
|
|
|
3
3
|
var createRemoveFuncFor = function createRemoveFuncFor(component, importName, prop) {
|
|
4
4
|
var predicate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
|
|
@@ -246,4 +246,54 @@ var renameNamedImportWithAliasName = function renameNamedImportWithAliasName(com
|
|
|
246
246
|
};
|
|
247
247
|
};
|
|
248
248
|
|
|
249
|
-
|
|
249
|
+
var changeImportEntryPoint = function changeImportEntryPoint(oldPackageName, importToConvert, newPackageName) {
|
|
250
|
+
return function (j, root) {
|
|
251
|
+
root.find(j.ImportDeclaration, {
|
|
252
|
+
source: {
|
|
253
|
+
value: oldPackageName
|
|
254
|
+
}
|
|
255
|
+
}).forEach(function (path) {
|
|
256
|
+
var _currentImportSpecifi;
|
|
257
|
+
|
|
258
|
+
var currentImportSpecifier = (path.value.specifiers || []).find(function (specifier) {
|
|
259
|
+
if (specifier.type === 'ImportSpecifier') {
|
|
260
|
+
return specifier.imported.name === importToConvert;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return false;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
if (!currentImportSpecifier) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
var importedSpecifierName = currentImportSpecifier.imported.name;
|
|
271
|
+
var localSpecifierName = (_currentImportSpecifi = currentImportSpecifier.local) === null || _currentImportSpecifi === void 0 ? void 0 : _currentImportSpecifi.name;
|
|
272
|
+
var newIdentifier = j.importSpecifier(j.identifier(importedSpecifierName), localSpecifierName ? j.identifier(localSpecifierName) : undefined); // check if new import exists, if not create it
|
|
273
|
+
|
|
274
|
+
tryCreateImport(j, root, oldPackageName, newPackageName); // remove the old import specifier, but NOT the whole package
|
|
275
|
+
|
|
276
|
+
root.find(j.ImportDeclaration, {
|
|
277
|
+
source: {
|
|
278
|
+
value: oldPackageName
|
|
279
|
+
}
|
|
280
|
+
}).find(j.ImportSpecifier).filter(function (path) {
|
|
281
|
+
return path.value.imported.name === importToConvert;
|
|
282
|
+
}).remove(); // adds import specifier to new import
|
|
283
|
+
|
|
284
|
+
addToImport(j, root, newIdentifier, newPackageName); // if there are any imports with no specifiers, remove the whole import
|
|
285
|
+
|
|
286
|
+
root.find(j.ImportDeclaration, {
|
|
287
|
+
source: {
|
|
288
|
+
value: oldPackageName
|
|
289
|
+
}
|
|
290
|
+
}).filter(function (path) {
|
|
291
|
+
var _path$value$specifier;
|
|
292
|
+
|
|
293
|
+
return !((_path$value$specifier = path.value.specifiers) !== null && _path$value$specifier !== void 0 && _path$value$specifier.length);
|
|
294
|
+
}).remove();
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint };
|
|
@@ -12,7 +12,50 @@ function getNamedSpecifier(j, source, specifier, importName) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
return specifiers.nodes()[0].local.name;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var getDynamicImportName = function getDynamicImportName(j, source, importPath) {
|
|
18
|
+
var dynamicImports = source.find(j.VariableDeclarator).filter(function (variableDeclaratorPath) {
|
|
19
|
+
return j(variableDeclaratorPath).find(j.CallExpression).filter(function (callExpressionPath) {
|
|
20
|
+
var _callExpressionPath$n = callExpressionPath.node,
|
|
21
|
+
callee = _callExpressionPath$n.callee,
|
|
22
|
+
callExpressionArguments = _callExpressionPath$n.arguments;
|
|
23
|
+
return !!(isCallExpressionCalleeImportType(callee) && isCallExpressionArgumentStringLiteralType(callExpressionArguments) && isCallExpressionArgumentValueMatches(callExpressionArguments[0], j, importPath));
|
|
24
|
+
}).length > 0;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (!dynamicImports.length) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var id = dynamicImports.nodes()[0].id;
|
|
32
|
+
|
|
33
|
+
if (id.type !== 'Identifier') {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return id.name;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var isCallExpressionCalleeImportType = function isCallExpressionCalleeImportType(callee) {
|
|
41
|
+
return callee && callee.type === 'Import';
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var isCallExpressionArgumentStringLiteralType = function isCallExpressionArgumentStringLiteralType(callExpressionArguments) {
|
|
45
|
+
return callExpressionArguments && callExpressionArguments.length && callExpressionArguments[0].type === 'StringLiteral';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var isCallExpressionArgumentValueMatches = function isCallExpressionArgumentValueMatches(callExpressionArgument, j, value) {
|
|
49
|
+
return j(callExpressionArgument).some(function (path) {
|
|
50
|
+
return path.node.value === value;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var addDynamicImport = function addDynamicImport(j, target, name, packageEndpoint) {
|
|
55
|
+
var node = j.variableDeclaration('const', [j.variableDeclarator(j.identifier(name), j.callExpression(j.memberExpression(j.identifier('React'), j.identifier('lazy')), [j.arrowFunctionExpression([], j.callExpression(j.import(), [j.stringLiteral(packageEndpoint)]))]))]);
|
|
56
|
+
target.insertAfter(node);
|
|
57
|
+
addCommentBefore(j, j(node), 'We have added "React.lazy" here. Feel free to change it to "lazy" or other named import depending upon how you imported.');
|
|
58
|
+
}; // not replacing newlines (which \s does)
|
|
16
59
|
|
|
17
60
|
|
|
18
61
|
var spacesAndTabs = /[ \t]{2,}/g;
|
|
@@ -66,7 +109,7 @@ var getDefaultSpecifier = function getDefaultSpecifier(j, source, specifier) {
|
|
|
66
109
|
|
|
67
110
|
|
|
68
111
|
var getJSXAttributesByName = function getJSXAttributesByName(j, element, attributeName) {
|
|
69
|
-
return j(element).find(j.JSXOpeningElement).find(j.JSXAttribute).filter(function (attribute) {
|
|
112
|
+
return j(element).find(j.JSXOpeningElement).at(0).find(j.JSXAttribute).filter(function (attribute) {
|
|
70
113
|
var matches = j(attribute).find(j.JSXIdentifier).filter(function (identifier) {
|
|
71
114
|
return identifier.value.name === attributeName;
|
|
72
115
|
});
|
|
@@ -85,6 +128,17 @@ var hasImportDeclaration = function hasImportDeclaration(j, source, importPath)
|
|
|
85
128
|
return Boolean(imports.length);
|
|
86
129
|
};
|
|
87
130
|
|
|
131
|
+
var hasImportDeclarationFromAnyPackageEntrypoint = function hasImportDeclarationFromAnyPackageEntrypoint(j, source, packageName) {
|
|
132
|
+
var imports = source.find(j.ImportDeclaration).filter(function (path) {
|
|
133
|
+
var _path$node, _path$node$source;
|
|
134
|
+
|
|
135
|
+
return (// @ts-ignore
|
|
136
|
+
path === null || path === void 0 ? void 0 : (_path$node = path.node) === null || _path$node === void 0 ? void 0 : (_path$node$source = _path$node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value.toString().startsWith(packageName)
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
return Boolean(imports.length);
|
|
140
|
+
};
|
|
141
|
+
|
|
88
142
|
var debug = function debug(component) {
|
|
89
143
|
return function (j, source) {
|
|
90
144
|
var defaultSpecifier = getDefaultSpecifier(j, source, component);
|
|
@@ -235,4 +289,4 @@ function getSafeImportName(_ref2) {
|
|
|
235
289
|
return isUsed ? fallbackName : desiredName;
|
|
236
290
|
}
|
|
237
291
|
|
|
238
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName };
|
|
292
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport };
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, } from './utils';
|
|
2
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, } from './utils/support';
|
|
1
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint, } from './utils';
|
|
2
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, doesIdentifierExist, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport, } from './utils/support';
|
|
@@ -11,4 +11,5 @@ declare const flattenCertainChildPropsAsProp: (component: string, propName: stri
|
|
|
11
11
|
declare const createRenameJSXFunc: (packagePath: string, from: string, to: string, fallback?: string | undefined) => (j: core.JSCodeshift, source: any) => void;
|
|
12
12
|
declare const createRemoveFuncAddCommentFor: (component: string, prop: string, comment?: string | undefined) => (j: core.JSCodeshift, source: Collection<Node>) => void;
|
|
13
13
|
declare const renameNamedImportWithAliasName: (component: string, from: string, to: string) => (j: core.JSCodeshift, source: Collection<Node>) => void;
|
|
14
|
-
|
|
14
|
+
declare const changeImportEntryPoint: (oldPackageName: string, importToConvert: string, newPackageName: string) => (j: core.JSCodeshift, root: Collection<Node>) => void;
|
|
15
|
+
export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint, };
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import core, { ASTPath, CallExpression, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXElement, Program, VariableDeclarator } from 'jscodeshift';
|
|
1
|
+
import core, { ASTPath, CallExpression, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXAttribute, JSXElement, Program, VariableDeclaration, VariableDeclarator } from 'jscodeshift';
|
|
2
2
|
import { Collection } from 'jscodeshift/src/Collection';
|
|
3
3
|
declare function getNamedSpecifier(j: core.JSCodeshift, source: Collection<Node>, specifier: string, importName: string): string | null;
|
|
4
|
+
declare const getDynamicImportName: (j: core.JSCodeshift, source: Collection<any>, importPath: string) => string | null;
|
|
5
|
+
declare const addDynamicImport: (j: core.JSCodeshift, target: Collection<VariableDeclaration>, name: string, packageEndpoint: string) => void;
|
|
4
6
|
declare function clean(value: string): string;
|
|
5
7
|
declare const addCommentToStartOfFile: ({ j, base, message, }: {
|
|
6
8
|
j: core.JSCodeshift;
|
|
7
9
|
base: Collection<Node>;
|
|
8
10
|
message: string;
|
|
9
11
|
}) => void;
|
|
10
|
-
declare function addCommentBefore(j: core.JSCodeshift, target: Collection<Program> | Collection<ImportDeclaration> | Collection<JSXElement> | Collection<CallExpression> | Collection<VariableDeclarator>, message: string, commentType?: 'block' | 'line', messagePrefix?: string): void;
|
|
12
|
+
declare function addCommentBefore(j: core.JSCodeshift, target: Collection<Program> | Collection<ImportDeclaration> | Collection<JSXElement> | Collection<JSXAttribute> | Collection<CallExpression> | Collection<VariableDeclarator>, message: string, commentType?: 'block' | 'line', messagePrefix?: string): void;
|
|
11
13
|
declare const getDefaultSpecifier: (j: core.JSCodeshift, source: Collection<Node>, specifier: string) => string | null;
|
|
12
|
-
declare const getJSXAttributesByName: any
|
|
14
|
+
declare const getJSXAttributesByName: (j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) => Collection<JSXAttribute>;
|
|
13
15
|
declare const isEmpty: any;
|
|
14
16
|
declare const hasImportDeclaration: (j: core.JSCodeshift, source: Collection<Node>, importPath: string) => boolean;
|
|
17
|
+
declare const hasImportDeclarationFromAnyPackageEntrypoint: (j: core.JSCodeshift, source: Collection<Node>, packageName: string) => boolean;
|
|
15
18
|
declare const debug: (component: string) => (j: core.JSCodeshift, source: Collection<Node>) => void;
|
|
16
19
|
declare const callExpressionArgMatchesString: (arg: CallExpression['arguments'][number], str: string) => boolean;
|
|
17
20
|
declare const testMethodVariantEach: (path: ASTPath<CallExpression>, testMethods: Set<string>) => boolean;
|
|
@@ -28,4 +31,4 @@ declare function getSafeImportName({ j, base, currentDefaultSpecifierName, desir
|
|
|
28
31
|
desiredName: string;
|
|
29
32
|
fallbackName: string;
|
|
30
33
|
}): string;
|
|
31
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, };
|
|
34
|
+
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, hasImportDeclarationFromAnyPackageEntrypoint, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/codemod-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": " jscodeshift-compatible codemod utilities",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"registry": "https://registry.npmjs.org/"
|
|
9
9
|
},
|
|
10
10
|
"atlassian": {
|
|
11
|
-
"team": "
|
|
11
|
+
"team": "UIP: Monorepo",
|
|
12
12
|
"inPublicMirror": false,
|
|
13
13
|
"releaseModel": "continuous"
|
|
14
14
|
},
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
31
31
|
"@types/jscodeshift": "^0.11.0",
|
|
32
32
|
"jscodeshift": "^0.13.0",
|
|
33
|
-
"typescript": "3.9.
|
|
33
|
+
"typescript": "3.9.10"
|
|
34
34
|
},
|
|
35
35
|
"techstack": {
|
|
36
36
|
"@atlassian/frontend": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"analytics-next"
|
|
47
47
|
],
|
|
48
48
|
"theming": [
|
|
49
|
-
"
|
|
49
|
+
"react-context"
|
|
50
50
|
],
|
|
51
51
|
"ui-components": [
|
|
52
52
|
"lite-mode"
|