@atlaskit/codemod-utils 3.3.0 → 4.0.1
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 +62 -50
- package/dist/cjs/utils/index.js +54 -2
- package/dist/cjs/utils/support.js +21 -4
- 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 +12 -1
- 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 +12 -1
- 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 +5 -4
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @atlaskit/codemod-utils
|
|
2
2
|
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`cb2392f6d33`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb2392f6d33) - Upgrade to TypeScript 4.2.4
|
|
8
|
+
|
|
9
|
+
## 4.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- [`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
|
|
14
|
+
|
|
15
|
+
@atlaskit/adf-schema/schema-bitbucket for:
|
|
16
|
+
|
|
17
|
+
- bitbucketSchema
|
|
18
|
+
|
|
19
|
+
@atlaskit/adf-schema/schema-confluence for:
|
|
20
|
+
|
|
21
|
+
- confluenceSchema
|
|
22
|
+
- confluenceSchemaWithMediaSingle
|
|
23
|
+
|
|
24
|
+
@atlaskit/adf-schema/schema-jira for:
|
|
25
|
+
|
|
26
|
+
- default as createJIRASchema
|
|
27
|
+
- isSchemaWithLists
|
|
28
|
+
- isSchemaWithMentions
|
|
29
|
+
- isSchemaWithEmojis
|
|
30
|
+
- isSchemaWithLinks
|
|
31
|
+
- isSchemaWithAdvancedTextFormattingMarks
|
|
32
|
+
- isSchemaWithCodeBlock
|
|
33
|
+
- isSchemaWithBlockQuotes
|
|
34
|
+
- isSchemaWithMedia
|
|
35
|
+
- isSchemaWithSubSupMark
|
|
36
|
+
- isSchemaWithTextColor
|
|
37
|
+
- isSchemaWithTables
|
|
38
|
+
|
|
39
|
+
@atlaskit/adf-schema/schema-default for:
|
|
40
|
+
|
|
41
|
+
- defaultSchema
|
|
42
|
+
- getSchemaBasedOnStage
|
|
43
|
+
- defaultSchemaConfig
|
|
44
|
+
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
## 3.4.0
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- [`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.
|
|
52
|
+
|
|
3
53
|
## 3.3.0
|
|
4
54
|
|
|
5
55
|
### Minor Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,58 +3,70 @@
|
|
|
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
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "addCommentToStartOfFile", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return
|
|
15
|
+
return _support.addCommentToStartOfFile;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "addDynamicImport", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return
|
|
21
|
+
return _support.addDynamicImport;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "addToImport", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function get() {
|
|
27
|
-
return
|
|
27
|
+
return _support.addToImport;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(exports, "
|
|
30
|
+
Object.defineProperty(exports, "callExpressionArgMatchesString", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function get() {
|
|
33
|
-
return
|
|
33
|
+
return _support.callExpressionArgMatchesString;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "changeImportEntryPoint", {
|
|
37
37
|
enumerable: true,
|
|
38
38
|
get: function get() {
|
|
39
|
-
return _utils.
|
|
39
|
+
return _utils.changeImportEntryPoint;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "createConvertFuncFor", {
|
|
43
43
|
enumerable: true,
|
|
44
44
|
get: function get() {
|
|
45
|
-
return _utils.
|
|
45
|
+
return _utils.createConvertFuncFor;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "createRemoveFuncAddCommentFor", {
|
|
49
49
|
enumerable: true,
|
|
50
50
|
get: function get() {
|
|
51
|
-
return _utils.
|
|
51
|
+
return _utils.createRemoveFuncAddCommentFor;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "createRemoveFuncFor", {
|
|
55
55
|
enumerable: true,
|
|
56
56
|
get: function get() {
|
|
57
|
-
return _utils.
|
|
57
|
+
return _utils.createRemoveFuncFor;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "createRenameFuncFor", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function get() {
|
|
63
|
+
return _utils.createRenameFuncFor;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "createRenameImportFor", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function get() {
|
|
69
|
+
return _utils.createRenameImportFor;
|
|
58
70
|
}
|
|
59
71
|
});
|
|
60
72
|
Object.defineProperty(exports, "createRenameJSXFunc", {
|
|
@@ -63,76 +75,76 @@ Object.defineProperty(exports, "createRenameJSXFunc", {
|
|
|
63
75
|
return _utils.createRenameJSXFunc;
|
|
64
76
|
}
|
|
65
77
|
});
|
|
66
|
-
Object.defineProperty(exports, "
|
|
78
|
+
Object.defineProperty(exports, "createTransformer", {
|
|
67
79
|
enumerable: true,
|
|
68
80
|
get: function get() {
|
|
69
|
-
return _utils.
|
|
81
|
+
return _utils.createTransformer;
|
|
70
82
|
}
|
|
71
83
|
});
|
|
72
|
-
Object.defineProperty(exports, "
|
|
84
|
+
Object.defineProperty(exports, "doesIdentifierExist", {
|
|
73
85
|
enumerable: true,
|
|
74
86
|
get: function get() {
|
|
75
|
-
return _support.
|
|
87
|
+
return _support.doesIdentifierExist;
|
|
76
88
|
}
|
|
77
89
|
});
|
|
78
|
-
Object.defineProperty(exports, "
|
|
90
|
+
Object.defineProperty(exports, "elevateComponentToNewEntryPoint", {
|
|
79
91
|
enumerable: true,
|
|
80
92
|
get: function get() {
|
|
81
|
-
return
|
|
93
|
+
return _utils.elevateComponentToNewEntryPoint;
|
|
82
94
|
}
|
|
83
95
|
});
|
|
84
|
-
Object.defineProperty(exports, "
|
|
96
|
+
Object.defineProperty(exports, "flattenCertainChildPropsAsProp", {
|
|
85
97
|
enumerable: true,
|
|
86
98
|
get: function get() {
|
|
87
|
-
return
|
|
99
|
+
return _utils.flattenCertainChildPropsAsProp;
|
|
88
100
|
}
|
|
89
101
|
});
|
|
90
|
-
Object.defineProperty(exports, "
|
|
102
|
+
Object.defineProperty(exports, "getDefaultSpecifier", {
|
|
91
103
|
enumerable: true,
|
|
92
104
|
get: function get() {
|
|
93
|
-
return _support.
|
|
105
|
+
return _support.getDefaultSpecifier;
|
|
94
106
|
}
|
|
95
107
|
});
|
|
96
|
-
Object.defineProperty(exports, "
|
|
108
|
+
Object.defineProperty(exports, "getDynamicImportName", {
|
|
97
109
|
enumerable: true,
|
|
98
110
|
get: function get() {
|
|
99
|
-
return _support.
|
|
111
|
+
return _support.getDynamicImportName;
|
|
100
112
|
}
|
|
101
113
|
});
|
|
102
|
-
Object.defineProperty(exports, "
|
|
114
|
+
Object.defineProperty(exports, "getJSXAttributesByName", {
|
|
103
115
|
enumerable: true,
|
|
104
116
|
get: function get() {
|
|
105
|
-
return _support.
|
|
117
|
+
return _support.getJSXAttributesByName;
|
|
106
118
|
}
|
|
107
119
|
});
|
|
108
|
-
Object.defineProperty(exports, "
|
|
120
|
+
Object.defineProperty(exports, "getNamedSpecifier", {
|
|
109
121
|
enumerable: true,
|
|
110
122
|
get: function get() {
|
|
111
|
-
return _support.
|
|
123
|
+
return _support.getNamedSpecifier;
|
|
112
124
|
}
|
|
113
125
|
});
|
|
114
|
-
Object.defineProperty(exports, "
|
|
126
|
+
Object.defineProperty(exports, "getSafeImportName", {
|
|
115
127
|
enumerable: true,
|
|
116
128
|
get: function get() {
|
|
117
|
-
return _support.
|
|
129
|
+
return _support.getSafeImportName;
|
|
118
130
|
}
|
|
119
131
|
});
|
|
120
|
-
Object.defineProperty(exports, "
|
|
132
|
+
Object.defineProperty(exports, "hasImportDeclaration", {
|
|
121
133
|
enumerable: true,
|
|
122
134
|
get: function get() {
|
|
123
|
-
return _support.
|
|
135
|
+
return _support.hasImportDeclaration;
|
|
124
136
|
}
|
|
125
137
|
});
|
|
126
|
-
Object.defineProperty(exports, "
|
|
138
|
+
Object.defineProperty(exports, "hasImportDeclarationFromAnyPackageEntrypoint", {
|
|
127
139
|
enumerable: true,
|
|
128
140
|
get: function get() {
|
|
129
|
-
return _support.
|
|
141
|
+
return _support.hasImportDeclarationFromAnyPackageEntrypoint;
|
|
130
142
|
}
|
|
131
143
|
});
|
|
132
|
-
Object.defineProperty(exports, "
|
|
144
|
+
Object.defineProperty(exports, "hasJSXAttributesByName", {
|
|
133
145
|
enumerable: true,
|
|
134
146
|
get: function get() {
|
|
135
|
-
return _support.
|
|
147
|
+
return _support.hasJSXAttributesByName;
|
|
136
148
|
}
|
|
137
149
|
});
|
|
138
150
|
Object.defineProperty(exports, "removeImport", {
|
|
@@ -141,28 +153,28 @@ Object.defineProperty(exports, "removeImport", {
|
|
|
141
153
|
return _support.removeImport;
|
|
142
154
|
}
|
|
143
155
|
});
|
|
144
|
-
Object.defineProperty(exports, "
|
|
156
|
+
Object.defineProperty(exports, "renameNamedImportWithAliasName", {
|
|
145
157
|
enumerable: true,
|
|
146
158
|
get: function get() {
|
|
147
|
-
return
|
|
159
|
+
return _utils.renameNamedImportWithAliasName;
|
|
148
160
|
}
|
|
149
161
|
});
|
|
150
|
-
Object.defineProperty(exports, "
|
|
162
|
+
Object.defineProperty(exports, "replaceImportStatementFor", {
|
|
151
163
|
enumerable: true,
|
|
152
164
|
get: function get() {
|
|
153
|
-
return
|
|
165
|
+
return _utils.replaceImportStatementFor;
|
|
154
166
|
}
|
|
155
167
|
});
|
|
156
|
-
Object.defineProperty(exports, "
|
|
168
|
+
Object.defineProperty(exports, "testMethodVariantEach", {
|
|
157
169
|
enumerable: true,
|
|
158
170
|
get: function get() {
|
|
159
|
-
return _support.
|
|
171
|
+
return _support.testMethodVariantEach;
|
|
160
172
|
}
|
|
161
173
|
});
|
|
162
|
-
Object.defineProperty(exports, "
|
|
174
|
+
Object.defineProperty(exports, "tryCreateImport", {
|
|
163
175
|
enumerable: true,
|
|
164
176
|
get: function get() {
|
|
165
|
-
return _support.
|
|
177
|
+
return _support.tryCreateImport;
|
|
166
178
|
}
|
|
167
179
|
});
|
|
168
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
|
|
|
@@ -157,6 +161,19 @@ var hasImportDeclaration = function hasImportDeclaration(j, source, importPath)
|
|
|
157
161
|
|
|
158
162
|
exports.hasImportDeclaration = hasImportDeclaration;
|
|
159
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
|
+
|
|
160
177
|
var debug = function debug(component) {
|
|
161
178
|
return function (j, source) {
|
|
162
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, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } 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 };
|
|
@@ -112,6 +112,17 @@ const hasImportDeclaration = (j, source, importPath) => {
|
|
|
112
112
|
return Boolean(imports.length);
|
|
113
113
|
};
|
|
114
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
|
+
|
|
115
126
|
const debug = component => (j, source) => {
|
|
116
127
|
const defaultSpecifier = getDefaultSpecifier(j, source, component);
|
|
117
128
|
|
|
@@ -245,4 +256,4 @@ function getSafeImportName({
|
|
|
245
256
|
return isUsed ? fallbackName : desiredName;
|
|
246
257
|
}
|
|
247
258
|
|
|
248
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport };
|
|
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, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport } 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 };
|
|
@@ -128,6 +128,17 @@ var hasImportDeclaration = function hasImportDeclaration(j, source, importPath)
|
|
|
128
128
|
return Boolean(imports.length);
|
|
129
129
|
};
|
|
130
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
|
+
|
|
131
142
|
var debug = function debug(component) {
|
|
132
143
|
return function (j, source) {
|
|
133
144
|
var defaultSpecifier = getDefaultSpecifier(j, source, component);
|
|
@@ -278,4 +289,4 @@ function getSafeImportName(_ref2) {
|
|
|
278
289
|
return isUsed ? fallbackName : desiredName;
|
|
279
290
|
}
|
|
280
291
|
|
|
281
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport };
|
|
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, removeImport, getDynamicImportName, addDynamicImport, tryCreateImport, addToImport, } 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,4 +1,4 @@
|
|
|
1
|
-
import core, { ASTPath, CallExpression, ImportDeclaration, ImportDefaultSpecifier, ImportSpecifier, JSXElement, Program, VariableDeclaration, 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
4
|
declare const getDynamicImportName: (j: core.JSCodeshift, source: Collection<any>, importPath: string) => string | null;
|
|
@@ -9,11 +9,12 @@ declare const addCommentToStartOfFile: ({ j, base, message, }: {
|
|
|
9
9
|
base: Collection<Node>;
|
|
10
10
|
message: string;
|
|
11
11
|
}) => void;
|
|
12
|
-
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;
|
|
13
13
|
declare const getDefaultSpecifier: (j: core.JSCodeshift, source: Collection<Node>, specifier: string) => string | null;
|
|
14
|
-
declare const getJSXAttributesByName: any
|
|
14
|
+
declare const getJSXAttributesByName: (j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) => Collection<JSXAttribute>;
|
|
15
15
|
declare const isEmpty: any;
|
|
16
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;
|
|
17
18
|
declare const debug: (component: string) => (j: core.JSCodeshift, source: Collection<Node>) => void;
|
|
18
19
|
declare const callExpressionArgMatchesString: (arg: CallExpression['arguments'][number], str: string) => boolean;
|
|
19
20
|
declare const testMethodVariantEach: (path: ASTPath<CallExpression>, testMethods: Set<string>) => boolean;
|
|
@@ -30,4 +31,4 @@ declare function getSafeImportName({ j, base, currentDefaultSpecifierName, desir
|
|
|
30
31
|
desiredName: string;
|
|
31
32
|
fallbackName: string;
|
|
32
33
|
}): string;
|
|
33
|
-
export { getDefaultSpecifier, getNamedSpecifier, getJSXAttributesByName, hasJSXAttributesByName, hasImportDeclaration, addCommentBefore, addCommentToStartOfFile, doesIdentifierExist, removeImport, tryCreateImport, addToImport, shiftDefaultImport, isEmpty, clean, debug, callExpressionArgMatchesString, testMethodVariantEach, getSafeImportName, getDynamicImportName, addDynamicImport, };
|
|
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.1",
|
|
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": "
|
|
33
|
+
"typescript": "4.2.4"
|
|
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"
|