@atlaskit/codemod-utils 3.4.0 → 4.0.2

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 CHANGED
@@ -1,5 +1,55 @@
1
1
  # @atlaskit/codemod-utils
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`9358d42eeaa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9358d42eeaa) - NO-ISSUE: fixed codemod utils tryCreateImport() and addToImport() causing multiple insert in certain scenarios
8
+
9
+ ## 4.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`cb2392f6d33`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb2392f6d33) - Upgrade to TypeScript 4.2.4
14
+
15
+ ## 4.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - [`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
20
+
21
+ @atlaskit/adf-schema/schema-bitbucket for:
22
+
23
+ - bitbucketSchema
24
+
25
+ @atlaskit/adf-schema/schema-confluence for:
26
+
27
+ - confluenceSchema
28
+ - confluenceSchemaWithMediaSingle
29
+
30
+ @atlaskit/adf-schema/schema-jira for:
31
+
32
+ - default as createJIRASchema
33
+ - isSchemaWithLists
34
+ - isSchemaWithMentions
35
+ - isSchemaWithEmojis
36
+ - isSchemaWithLinks
37
+ - isSchemaWithAdvancedTextFormattingMarks
38
+ - isSchemaWithCodeBlock
39
+ - isSchemaWithBlockQuotes
40
+ - isSchemaWithMedia
41
+ - isSchemaWithSubSupMark
42
+ - isSchemaWithTextColor
43
+ - isSchemaWithTables
44
+
45
+ @atlaskit/adf-schema/schema-default for:
46
+
47
+ - defaultSchema
48
+ - getSchemaBasedOnStage
49
+ - defaultSchemaConfig
50
+
51
+ 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.
52
+
3
53
  ## 3.4.0
4
54
 
5
55
  ### Minor Changes
package/dist/cjs/index.js CHANGED
@@ -3,142 +3,148 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "createRenameFuncFor", {
6
+ Object.defineProperty(exports, "addCommentBefore", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _utils.createRenameFuncFor;
9
+ return _support.addCommentBefore;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "createConvertFuncFor", {
12
+ Object.defineProperty(exports, "addCommentToStartOfFile", {
13
13
  enumerable: true,
14
14
  get: function get() {
15
- return _utils.createConvertFuncFor;
15
+ return _support.addCommentToStartOfFile;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "createRenameImportFor", {
18
+ Object.defineProperty(exports, "addDynamicImport", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _utils.createRenameImportFor;
21
+ return _support.addDynamicImport;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "createRemoveFuncFor", {
24
+ Object.defineProperty(exports, "addToImport", {
25
25
  enumerable: true,
26
26
  get: function get() {
27
- return _utils.createRemoveFuncFor;
27
+ return _support.addToImport;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "replaceImportStatementFor", {
30
+ Object.defineProperty(exports, "callExpressionArgMatchesString", {
31
31
  enumerable: true,
32
32
  get: function get() {
33
- return _utils.replaceImportStatementFor;
33
+ return _support.callExpressionArgMatchesString;
34
34
  }
35
35
  });
36
- Object.defineProperty(exports, "elevateComponentToNewEntryPoint", {
36
+ Object.defineProperty(exports, "changeImportEntryPoint", {
37
37
  enumerable: true,
38
38
  get: function get() {
39
- return _utils.elevateComponentToNewEntryPoint;
39
+ return _utils.changeImportEntryPoint;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "createTransformer", {
42
+ Object.defineProperty(exports, "createConvertFuncFor", {
43
43
  enumerable: true,
44
44
  get: function get() {
45
- return _utils.createTransformer;
45
+ return _utils.createConvertFuncFor;
46
46
  }
47
47
  });
48
- Object.defineProperty(exports, "renameNamedImportWithAliasName", {
48
+ Object.defineProperty(exports, "createRemoveFuncAddCommentFor", {
49
49
  enumerable: true,
50
50
  get: function get() {
51
- return _utils.renameNamedImportWithAliasName;
51
+ return _utils.createRemoveFuncAddCommentFor;
52
52
  }
53
53
  });
54
- Object.defineProperty(exports, "flattenCertainChildPropsAsProp", {
54
+ Object.defineProperty(exports, "createRemoveFuncFor", {
55
55
  enumerable: true,
56
56
  get: function get() {
57
- return _utils.flattenCertainChildPropsAsProp;
57
+ return _utils.createRemoveFuncFor;
58
58
  }
59
59
  });
60
- Object.defineProperty(exports, "createRenameJSXFunc", {
60
+ Object.defineProperty(exports, "createRenameFuncFor", {
61
61
  enumerable: true,
62
62
  get: function get() {
63
- return _utils.createRenameJSXFunc;
63
+ return _utils.createRenameFuncFor;
64
64
  }
65
65
  });
66
- Object.defineProperty(exports, "createRemoveFuncAddCommentFor", {
66
+ Object.defineProperty(exports, "createRenameImportFor", {
67
67
  enumerable: true,
68
68
  get: function get() {
69
- return _utils.createRemoveFuncAddCommentFor;
69
+ return _utils.createRenameImportFor;
70
70
  }
71
71
  });
72
- Object.defineProperty(exports, "getDefaultSpecifier", {
72
+ Object.defineProperty(exports, "createRenameJSXFunc", {
73
73
  enumerable: true,
74
74
  get: function get() {
75
- return _support.getDefaultSpecifier;
75
+ return _utils.createRenameJSXFunc;
76
76
  }
77
77
  });
78
- Object.defineProperty(exports, "getNamedSpecifier", {
78
+ Object.defineProperty(exports, "createTransformer", {
79
79
  enumerable: true,
80
80
  get: function get() {
81
- return _support.getNamedSpecifier;
81
+ return _utils.createTransformer;
82
82
  }
83
83
  });
84
- Object.defineProperty(exports, "getJSXAttributesByName", {
84
+ Object.defineProperty(exports, "doesIdentifierExist", {
85
85
  enumerable: true,
86
86
  get: function get() {
87
- return _support.getJSXAttributesByName;
87
+ return _support.doesIdentifierExist;
88
88
  }
89
89
  });
90
- Object.defineProperty(exports, "hasJSXAttributesByName", {
90
+ Object.defineProperty(exports, "elevateComponentToNewEntryPoint", {
91
91
  enumerable: true,
92
92
  get: function get() {
93
- return _support.hasJSXAttributesByName;
93
+ return _utils.elevateComponentToNewEntryPoint;
94
94
  }
95
95
  });
96
- Object.defineProperty(exports, "doesIdentifierExist", {
96
+ Object.defineProperty(exports, "flattenCertainChildPropsAsProp", {
97
97
  enumerable: true,
98
98
  get: function get() {
99
- return _support.doesIdentifierExist;
99
+ return _utils.flattenCertainChildPropsAsProp;
100
100
  }
101
101
  });
102
- Object.defineProperty(exports, "hasImportDeclaration", {
102
+ Object.defineProperty(exports, "getDefaultSpecifier", {
103
103
  enumerable: true,
104
104
  get: function get() {
105
- return _support.hasImportDeclaration;
105
+ return _support.getDefaultSpecifier;
106
106
  }
107
107
  });
108
- Object.defineProperty(exports, "hasImportDeclarationFromAnyPackageEntrypoint", {
108
+ Object.defineProperty(exports, "getDynamicImportName", {
109
109
  enumerable: true,
110
110
  get: function get() {
111
- return _support.hasImportDeclarationFromAnyPackageEntrypoint;
111
+ return _support.getDynamicImportName;
112
112
  }
113
113
  });
114
- Object.defineProperty(exports, "addCommentBefore", {
114
+ Object.defineProperty(exports, "getJSXAttributesByName", {
115
115
  enumerable: true,
116
116
  get: function get() {
117
- return _support.addCommentBefore;
117
+ return _support.getJSXAttributesByName;
118
118
  }
119
119
  });
120
- Object.defineProperty(exports, "addCommentToStartOfFile", {
120
+ Object.defineProperty(exports, "getNamedSpecifier", {
121
121
  enumerable: true,
122
122
  get: function get() {
123
- return _support.addCommentToStartOfFile;
123
+ return _support.getNamedSpecifier;
124
124
  }
125
125
  });
126
- Object.defineProperty(exports, "callExpressionArgMatchesString", {
126
+ Object.defineProperty(exports, "getSafeImportName", {
127
127
  enumerable: true,
128
128
  get: function get() {
129
- return _support.callExpressionArgMatchesString;
129
+ return _support.getSafeImportName;
130
130
  }
131
131
  });
132
- Object.defineProperty(exports, "testMethodVariantEach", {
132
+ Object.defineProperty(exports, "hasImportDeclaration", {
133
133
  enumerable: true,
134
134
  get: function get() {
135
- return _support.testMethodVariantEach;
135
+ return _support.hasImportDeclaration;
136
136
  }
137
137
  });
138
- Object.defineProperty(exports, "getSafeImportName", {
138
+ Object.defineProperty(exports, "hasImportDeclarationFromAnyPackageEntrypoint", {
139
139
  enumerable: true,
140
140
  get: function get() {
141
- return _support.getSafeImportName;
141
+ return _support.hasImportDeclarationFromAnyPackageEntrypoint;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, "hasJSXAttributesByName", {
145
+ enumerable: true,
146
+ get: function get() {
147
+ return _support.hasJSXAttributesByName;
142
148
  }
143
149
  });
144
150
  Object.defineProperty(exports, "removeImport", {
@@ -147,28 +153,28 @@ Object.defineProperty(exports, "removeImport", {
147
153
  return _support.removeImport;
148
154
  }
149
155
  });
150
- Object.defineProperty(exports, "getDynamicImportName", {
156
+ Object.defineProperty(exports, "renameNamedImportWithAliasName", {
151
157
  enumerable: true,
152
158
  get: function get() {
153
- return _support.getDynamicImportName;
159
+ return _utils.renameNamedImportWithAliasName;
154
160
  }
155
161
  });
156
- Object.defineProperty(exports, "addDynamicImport", {
162
+ Object.defineProperty(exports, "replaceImportStatementFor", {
157
163
  enumerable: true,
158
164
  get: function get() {
159
- return _support.addDynamicImport;
165
+ return _utils.replaceImportStatementFor;
160
166
  }
161
167
  });
162
- Object.defineProperty(exports, "tryCreateImport", {
168
+ Object.defineProperty(exports, "testMethodVariantEach", {
163
169
  enumerable: true,
164
170
  get: function get() {
165
- return _support.tryCreateImport;
171
+ return _support.testMethodVariantEach;
166
172
  }
167
173
  });
168
- Object.defineProperty(exports, "addToImport", {
174
+ Object.defineProperty(exports, "tryCreateImport", {
169
175
  enumerable: true,
170
176
  get: function get() {
171
- return _support.addToImport;
177
+ return _support.tryCreateImport;
172
178
  }
173
179
  });
174
180
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createRemoveFuncAddCommentFor = exports.createRenameJSXFunc = exports.flattenCertainChildPropsAsProp = exports.renameNamedImportWithAliasName = exports.createTransformer = exports.elevateComponentToNewEntryPoint = exports.replaceImportStatementFor = exports.createRemoveFuncFor = exports.createRenameImportFor = exports.createConvertFuncFor = exports.createRenameFuncFor = void 0;
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.removeImport = removeImport;
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.addDynamicImport = exports.getDynamicImportName = exports.testMethodVariantEach = exports.callExpressionArgMatchesString = exports.debug = exports.isEmpty = exports.shiftDefaultImport = exports.doesIdentifierExist = exports.addCommentToStartOfFile = exports.hasImportDeclarationFromAnyPackageEntrypoint = exports.hasImportDeclaration = exports.hasJSXAttributesByName = exports.getJSXAttributesByName = exports.getDefaultSpecifier = void 0;
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
 
@@ -293,13 +297,13 @@ function tryCreateImport(j, base, relativeToPackage, packageName) {
293
297
 
294
298
  base.find(j.ImportDeclaration).filter(function (path) {
295
299
  return path.value.source.value === relativeToPackage;
296
- }).insertBefore(j.importDeclaration([], j.literal(packageName)));
300
+ }).at(0).insertBefore(j.importDeclaration([], j.literal(packageName)));
297
301
  }
298
302
 
299
303
  function addToImport(j, base, importSpecifier, packageName) {
300
304
  base.find(j.ImportDeclaration).filter(function (path) {
301
305
  return path.value.source.value === packageName;
302
- }).replaceWith(function (declaration) {
306
+ }).at(0).replaceWith(function (declaration) {
303
307
  return j.importDeclaration([].concat((0, _toConsumableArray2.default)((declaration.value.specifiers || []).filter(function (item) {
304
308
  return item.type === 'ImportSpecifier' && item.imported != null;
305
309
  })), [importSpecifier]), j.literal(packageName));
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-utils",
3
- "version": "3.4.0",
3
+ "version": "4.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,2 +1,2 @@
1
- export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor } from './utils';
1
+ export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint } from './utils';
2
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
- export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor };
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 };
@@ -222,11 +222,11 @@ function tryCreateImport(j, base, relativeToPackage, packageName) {
222
222
  return;
223
223
  }
224
224
 
225
- base.find(j.ImportDeclaration).filter(path => path.value.source.value === relativeToPackage).insertBefore(j.importDeclaration([], j.literal(packageName)));
225
+ base.find(j.ImportDeclaration).filter(path => path.value.source.value === relativeToPackage).at(0).insertBefore(j.importDeclaration([], j.literal(packageName)));
226
226
  }
227
227
 
228
228
  function addToImport(j, base, importSpecifier, packageName) {
229
- base.find(j.ImportDeclaration).filter(path => path.value.source.value === packageName).replaceWith(declaration => {
229
+ base.find(j.ImportDeclaration).filter(path => path.value.source.value === packageName).at(0).replaceWith(declaration => {
230
230
  return j.importDeclaration([// we are appending to the existing specifiers
231
231
  // We are doing a filter hear because sometimes specifiers can be removed
232
232
  // but they hand around in the declaration
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-utils",
3
- "version": "3.4.0",
3
+ "version": "4.0.2",
4
4
  "sideEffects": false
5
5
  }
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';
1
+ export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint } from './utils';
2
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
  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
- export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor };
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 };
@@ -252,13 +252,13 @@ function tryCreateImport(j, base, relativeToPackage, packageName) {
252
252
 
253
253
  base.find(j.ImportDeclaration).filter(function (path) {
254
254
  return path.value.source.value === relativeToPackage;
255
- }).insertBefore(j.importDeclaration([], j.literal(packageName)));
255
+ }).at(0).insertBefore(j.importDeclaration([], j.literal(packageName)));
256
256
  }
257
257
 
258
258
  function addToImport(j, base, importSpecifier, packageName) {
259
259
  base.find(j.ImportDeclaration).filter(function (path) {
260
260
  return path.value.source.value === packageName;
261
- }).replaceWith(function (declaration) {
261
+ }).at(0).replaceWith(function (declaration) {
262
262
  return j.importDeclaration([].concat(_toConsumableArray((declaration.value.specifiers || []).filter(function (item) {
263
263
  return item.type === 'ImportSpecifier' && item.imported != null;
264
264
  })), [importSpecifier]), j.literal(packageName));
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-utils",
3
- "version": "3.4.0",
3
+ "version": "4.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,2 +1,2 @@
1
- export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, } from './utils';
1
+ export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, changeImportEntryPoint, } from './utils';
2
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
- export { createRenameFuncFor, createConvertFuncFor, createRenameImportFor, createRemoveFuncFor, replaceImportStatementFor, elevateComponentToNewEntryPoint, createTransformer, renameNamedImportWithAliasName, flattenCertainChildPropsAsProp, createRenameJSXFunc, createRemoveFuncAddCommentFor, };
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, };
@@ -9,7 +9,7 @@ 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
14
  declare const getJSXAttributesByName: (j: core.JSCodeshift, element: ASTPath<any>, attributeName: string) => Collection<JSXAttribute>;
15
15
  declare const isEmpty: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/codemod-utils",
3
- "version": "3.4.0",
3
+ "version": "4.0.2",
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": "AFP: Monorepo",
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.6"
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
- "new-theming-api"
49
+ "react-context"
50
50
  ],
51
51
  "ui-components": [
52
52
  "lite-mode"