@atlaskit/codemod-cli 0.19.0 → 0.20.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/cli/package.json +1 -1
  3. package/dist/cjs/main.js +1 -1
  4. package/dist/cjs/presets/index.js +2 -1
  5. package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
  6. package/dist/cjs/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  7. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +79 -0
  8. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +27 -0
  9. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +51 -0
  10. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +37 -0
  11. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +40 -0
  12. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +40 -0
  13. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +47 -0
  14. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +40 -0
  15. package/dist/cjs/types.js +1 -1
  16. package/dist/es2019/main.js +0 -1
  17. package/dist/es2019/presets/index.js +2 -1
  18. package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +8 -0
  19. package/dist/es2019/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  20. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +52 -0
  21. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +17 -0
  22. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +63 -0
  23. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +31 -0
  24. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +28 -0
  25. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +28 -0
  26. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +41 -0
  27. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +19 -0
  28. package/dist/esm/main.js +1 -1
  29. package/dist/esm/presets/index.js +2 -1
  30. package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +12 -0
  31. package/dist/esm/presets/migrate-to-new-buttons/utils/import-types-from-new-entry-point.js +0 -1
  32. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +73 -0
  33. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +21 -0
  34. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +44 -0
  35. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +31 -0
  36. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +34 -0
  37. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +34 -0
  38. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +41 -0
  39. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +33 -0
  40. package/dist/esm/types.js +1 -1
  41. package/dist/types/presets/index.d.ts +1 -0
  42. package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  43. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.d.ts +2 -0
  44. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.d.ts +2 -0
  45. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.d.ts +3 -0
  46. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.d.ts +2 -0
  47. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.d.ts +2 -0
  48. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.d.ts +2 -0
  49. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.d.ts +2 -0
  50. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +2 -0
  51. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  52. package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +1 -1
  53. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.d.ts +2 -0
  54. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.d.ts +2 -0
  55. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.d.ts +3 -0
  56. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.d.ts +2 -0
  57. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.d.ts +2 -0
  58. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.d.ts +2 -0
  59. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.d.ts +2 -0
  60. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +2 -0
  61. package/filepath/package.json +1 -1
  62. package/main/package.json +1 -1
  63. package/package.json +5 -4
  64. package/sinceRef/package.json +1 -1
  65. package/transforms/package.json +1 -1
  66. package/types/package.json +1 -1
  67. package/utils/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.20.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#83116](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83116) [`8d4e99057fe0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8d4e99057fe0) - Upgrade Typescript from `4.9.5` to `5.4.2`
8
+
9
+ ## 0.20.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#70616](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70616) [`533c86673290`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/533c86673290) - Adding a new pattern for upgrading Pragmatic drag and drop consumers to `1.0`
14
+
15
+ Pattern name: `"upgrade-pragmatic-drag-and-drop-to-stable"`
16
+
3
17
  ## 0.19.0
4
18
 
5
19
  ### Minor Changes
package/cli/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "module:es2019": "../dist/es2019/cli.js",
6
6
  "types": "../dist/types/cli.d.ts",
7
7
  "typesVersions": {
8
- ">=4.5 <4.9": {
8
+ ">=4.5 <5.4": {
9
9
  "*": [
10
10
  "../dist/types-ts4.5/cli.d.ts"
11
11
  ]
package/dist/cjs/main.js CHANGED
@@ -305,7 +305,7 @@ function _main() {
305
305
  case 4:
306
306
  _yield$parseArgs = _context5.sent;
307
307
  packages = _yield$parseArgs.packages;
308
- _process$env$_PACKAGE = "0.19.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
308
+ _process$env$_PACKAGE = "0.20.1", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
309
309
  logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
310
310
  if (packages && packages.length > 0) {
311
311
  logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -9,12 +9,13 @@ var _path = _interopRequireDefault(require("path"));
9
9
  require("./styled-to-emotion/styled-to-emotion");
10
10
  require("./theme-remove-deprecated-mixins/theme-remove-deprecated-mixins");
11
11
  require("./migrate-to-new-buttons/migrate-to-new-buttons");
12
+ require("./upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable");
12
13
  /**
13
14
  * Manually import presets to make sure typescript includes them
14
15
  * in the final bundle.
15
16
  */
16
17
 
17
- var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons'].map(function (preset) {
18
+ var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable'].map(function (preset) {
18
19
  return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
19
20
  });
20
21
  var _default = exports.default = presets;
@@ -74,6 +74,18 @@ var generateNewElement = exports.generateNewElement = function generateNewElemen
74
74
 
75
75
  // rename iconBefore/iconAfter to icon
76
76
  iconAttrs[0].name.name = 'icon';
77
+ var ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(function (attribute) {
78
+ return attribute.node.name.name === 'aria-label';
79
+ });
80
+ if (ariaLabelAttr.length) {
81
+ var hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(function (attribute) {
82
+ return attribute.type === 'JSXAttribute' && attribute.name.name === 'label';
83
+ }));
84
+ if (hasNoLabelProp && attributes) {
85
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
86
+ }
87
+ ariaLabelAttr.remove();
88
+ }
77
89
  }
78
90
  return j.jsxElement(
79
91
  // self closing if it's an icon button or icon link button
@@ -37,6 +37,5 @@ var importTypesFromNewEntryPoint = exports.importTypesFromNewEntryPoint = functi
37
37
  j(specifier).remove(); // remove old one
38
38
  });
39
39
  }
40
-
41
40
  return specifiers;
42
41
  };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateAutoScroll = updateAutoScroll;
7
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ var scenarios = [{
11
+ existing: {
12
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/file',
13
+ namedImport: 'autoScrollForFiles'
14
+ },
15
+ updated: {
16
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/external',
17
+ namedImport: 'autoScrollForExternal'
18
+ }
19
+ }, {
20
+ existing: {
21
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/file',
22
+ namedImport: 'unsafeOverflowAutoScrollForFiles'
23
+ },
24
+ updated: {
25
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/external',
26
+ namedImport: 'unsafeOverflowAutoScrollForExternal'
27
+ }
28
+ }];
29
+ function updateAutoScroll(file, api) {
30
+ var j = api.jscodeshift;
31
+ var root = j(file.source);
32
+ var changed = false;
33
+ var _iterator = _createForOfIteratorHelper(scenarios),
34
+ _step;
35
+ try {
36
+ var _loop = function _loop() {
37
+ var scenario = _step.value;
38
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
39
+ return path.node.source.value === scenario.existing.importPath;
40
+ });
41
+
42
+ // move on to the next scenario
43
+ if (!isUsingImport) {
44
+ return 1; // continue
45
+ }
46
+ changed = true;
47
+
48
+ // replace old import path with new import path
49
+ root.find(j.ImportDeclaration).filter(function (path) {
50
+ return path.node.source.value === scenario.existing.importPath;
51
+ })
52
+ // replace import
53
+ .map(function (path) {
54
+ path.node.source.value = scenario.updated.importPath;
55
+ return path;
56
+ });
57
+
58
+ // replace old named import and usages with new one
59
+ root.find(j.Identifier).filter(function (path) {
60
+ return path.value.name === scenario.existing.namedImport;
61
+ }).replaceWith(j.identifier(scenario.updated.namedImport));
62
+ };
63
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
64
+ if (_loop()) continue;
65
+ }
66
+
67
+ // Don't format the file if we are not changing anything
68
+ } catch (err) {
69
+ _iterator.e(err);
70
+ } finally {
71
+ _iterator.f();
72
+ }
73
+ if (!changed) {
74
+ return file.source;
75
+ }
76
+ return root.toSource({
77
+ quote: 'single'
78
+ });
79
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shiftCanMonitorArgType = shiftCanMonitorArgType;
7
+ var newImport = '@atlaskit/pragmatic-drag-and-drop/element/adapter';
8
+ function shiftCanMonitorArgType(file, api) {
9
+ var j = api.jscodeshift;
10
+ var root = j(file.source);
11
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
12
+ return path.node.source.value === newImport;
13
+ });
14
+
15
+ // don't change the file if we don't need to
16
+ if (!isUsingImport) {
17
+ return file.source;
18
+ }
19
+
20
+ // replace old named import and usages with new one
21
+ root.find(j.Identifier).filter(function (path) {
22
+ return path.value.name === 'ElementMonitorCanMonitorArgs';
23
+ }).replaceWith(j.identifier('ElementMonitorGetFeedbackArgs'));
24
+ return root.toSource({
25
+ quote: 'single'
26
+ });
27
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.moveFromFileAdapterToExternalAdapter = moveFromFileAdapterToExternalAdapter;
7
+ exports.pleaseMigrateMessage = void 0;
8
+ var _codemodUtils = require("@atlaskit/codemod-utils");
9
+ var pleaseMigrateMessage = exports.pleaseMigrateMessage = "\n The file adapter has been replaced by a new (more powerful) external adapter.\n Please see our external adapter documentation on how to migrate your file adapter usage.\n\n We have also included \"containsFiles()\" as an import in this file as it is helpful to\n restrict your monitors and drop targets to only be for files.\n\n We have also included \"getFiles()\" as an import as it is a helpful way to extract the files\n from a drag operation\n\n dropTargetForExternal({\n canDrop: containsFiles,\n onDrop({source}) {\n const files = getFiles({source});\n }\n });\n\n monitorForExternal({\n canMonitor: containsFiles,\n onDrop({source}) {\n const files = getFiles({source});\n }\n });\n\n - [1.0 upgrade documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/changelog)\n - [external adapter documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/external)\n - [file usage documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/external/files)\n";
10
+ var oldImportPath = '@atlaskit/pragmatic-drag-and-drop/adapter/file';
11
+ var newImportPath = '@atlaskit/pragmatic-drag-and-drop/external/adapter';
12
+ function moveFromFileAdapterToExternalAdapter(file, api) {
13
+ var j = api.jscodeshift;
14
+ var root = j(file.source);
15
+ var isUsingFileAdapter = root.find(j.ImportDeclaration).some(function (path) {
16
+ return path.node.source.value === oldImportPath;
17
+ });
18
+ if (!isUsingFileAdapter) {
19
+ return file.source;
20
+ }
21
+
22
+ // replace old import path with new import path
23
+ root.find(j.ImportDeclaration).filter(function (path) {
24
+ return path.node.source.value === oldImportPath;
25
+ })
26
+ // replace import
27
+ .map(function (path) {
28
+ path.node.source.value = newImportPath;
29
+ return path;
30
+ })
31
+ // Add an import for 'containsFiles()' and `getFiles()` as likely this file will need it
32
+ .insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('containsFiles')), j.importSpecifier(j.identifier('getFiles'))], j.literal('@atlaskit/pragmatic-drag-and-drop/external/file')));
33
+
34
+ // update usages of `monitorForFiles` and `dropTargetForFiles`
35
+ root.find(j.Identifier).filter(function (path) {
36
+ return path.value.name === 'monitorForFiles';
37
+ }).replaceWith(j.identifier('monitorForExternal'));
38
+ root.find(j.Identifier).filter(function (path) {
39
+ return path.value.name === 'dropTargetForFiles';
40
+ }).replaceWith(j.identifier('dropTargetForExternal'));
41
+
42
+ // add comment to the start of the file
43
+ (0, _codemodUtils.addCommentToStartOfFile)({
44
+ j: j,
45
+ base: root,
46
+ message: pleaseMigrateMessage
47
+ });
48
+ return root.toSource({
49
+ quote: 'single'
50
+ });
51
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.moveToReactDropIndicator = moveToReactDropIndicator;
7
+ var oldPackagePath = '@atlaskit/pragmatic-drag-and-drop-react-indicator';
8
+ var newPackagePath = '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator';
9
+ function isString(value) {
10
+ return typeof value === 'string';
11
+ }
12
+ function isOldPackagePath(value) {
13
+ return isString(value) && value.startsWith(oldPackagePath);
14
+ }
15
+ function moveToReactDropIndicator(file, api) {
16
+ var j = api.jscodeshift;
17
+ var root = j(file.source);
18
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
19
+ return isOldPackagePath(path.node.source.value);
20
+ });
21
+
22
+ // Don't format the file if we are not changing anything
23
+ if (!isUsingImport) {
24
+ return file.source;
25
+ }
26
+
27
+ // replace imports
28
+ root.find(j.ImportDeclaration).forEach(function (path) {
29
+ var value = path.node.source.value;
30
+ if (isString(value) && isOldPackagePath(path.node.source.value)) {
31
+ path.node.source.value = value.replace(oldPackagePath, newPackagePath);
32
+ }
33
+ });
34
+ return root.toSource({
35
+ quote: 'single'
36
+ });
37
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shiftToPointerOutsideOfPreview = shiftToPointerOutsideOfPreview;
7
+ var paths = {
8
+ current: '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer',
9
+ next: '@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview'
10
+ };
11
+ function shiftToPointerOutsideOfPreview(file, api) {
12
+ var j = api.jscodeshift;
13
+ var root = j(file.source);
14
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
15
+ return path.node.source.value === paths.current;
16
+ });
17
+
18
+ // don't change the file if we don't need to
19
+ if (!isUsingImport) {
20
+ return file.source;
21
+ }
22
+
23
+ // replace old import path with new import path
24
+ root.find(j.ImportDeclaration).filter(function (path) {
25
+ return path.node.source.value === paths.current;
26
+ })
27
+ // replace import
28
+ .map(function (path) {
29
+ path.node.source.value = paths.next;
30
+ return path;
31
+ });
32
+
33
+ // replace old named import and usages with new one
34
+ root.find(j.Identifier).filter(function (path) {
35
+ return path.value.name === 'offsetFromPointer';
36
+ }).replaceWith(j.identifier('pointerOutsideOfPreview'));
37
+ return root.toSource({
38
+ quote: 'single'
39
+ });
40
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shiftToPreventUnhandled = shiftToPreventUnhandled;
7
+ var paths = {
8
+ current: '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled',
9
+ next: '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled'
10
+ };
11
+ function shiftToPreventUnhandled(file, api) {
12
+ var j = api.jscodeshift;
13
+ var root = j(file.source);
14
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
15
+ return path.node.source.value === paths.current;
16
+ });
17
+
18
+ // don't change the file if we don't need to
19
+ if (!isUsingImport) {
20
+ return file.source;
21
+ }
22
+
23
+ // replace old import path with new import path
24
+ root.find(j.ImportDeclaration).filter(function (path) {
25
+ return path.node.source.value === paths.current;
26
+ })
27
+ // replace import
28
+ .map(function (path) {
29
+ path.node.source.value = paths.next;
30
+ return path;
31
+ });
32
+
33
+ // replace old named import and usages with new one
34
+ root.find(j.Identifier).filter(function (path) {
35
+ return path.value.name === 'cancelUnhandled';
36
+ }).replaceWith(j.identifier('preventUnhandled'));
37
+ return root.toSource({
38
+ quote: 'single'
39
+ });
40
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.updateSafeImports = updateSafeImports;
7
+ var importMap = {
8
+ // core package
9
+ '@atlaskit/pragmatic-drag-and-drop/adapter/element': '@atlaskit/pragmatic-drag-and-drop/element/adapter',
10
+ '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview',
11
+ '@atlaskit/pragmatic-drag-and-drop/util/center-under-pointer': '@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer',
12
+ '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-on-source': '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source',
13
+ '@atlaskit/pragmatic-drag-and-drop/util/disable-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview',
14
+ '@atlaskit/pragmatic-drag-and-drop/util/scroll-just-enough-into-view': '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view',
15
+ '@atlaskit/pragmatic-drag-and-drop/util/combine': '@atlaskit/pragmatic-drag-and-drop/combine',
16
+ '@atlaskit/pragmatic-drag-and-drop/util/once': '@atlaskit/pragmatic-drag-and-drop/once',
17
+ '@atlaskit/pragmatic-drag-and-drop/util/reorder': '@atlaskit/pragmatic-drag-and-drop/reorder',
18
+ // hitbox package
19
+ '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge': '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'
20
+
21
+ // Doing cancel-unhandled in it's own transformer as the name is changing too
22
+ // '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled':
23
+ // '@atlaskit/pragmatic-drag-and-drop/cancel-unhandled',
24
+ // We are doing the name update in another transform
25
+ // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
26
+ // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
27
+ };
28
+ function updateSafeImports(file, api) {
29
+ var j = api.jscodeshift;
30
+ var root = j(file.source);
31
+
32
+ // avoiding reformatting the file if we are not changing anything
33
+ var changed = false;
34
+ root.find(j.ImportDeclaration).forEach(function (path) {
35
+ var importPath = path.node.source.value;
36
+ if (typeof importPath === 'string' && importMap[importPath]) {
37
+ changed = true;
38
+ path.node.source.value = importMap[importPath];
39
+ }
40
+ });
41
+ if (!changed) {
42
+ return file.source;
43
+ }
44
+ return root.toSource({
45
+ quote: 'single'
46
+ });
47
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = transformer;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _updateSafeImports = require("./transformers/update-safe-imports");
10
+ var _externalAdapter = require("./transformers/external-adapter");
11
+ var _moveToReactDropIndicator = require("./transformers/move-to-react-drop-indicator");
12
+ var _autoScroll = require("./transformers/auto-scroll");
13
+ var _pointerOutsideOfPreview = require("./transformers/pointer-outside-of-preview");
14
+ var _preventUnhandled = require("./transformers/prevent-unhandled");
15
+ var _elementAdapterTypes = require("./transformers/element-adapter-types");
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
19
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
21
+ var transformers = [_updateSafeImports.updateSafeImports, _externalAdapter.moveFromFileAdapterToExternalAdapter, _moveToReactDropIndicator.moveToReactDropIndicator, _autoScroll.updateAutoScroll, _pointerOutsideOfPreview.shiftToPointerOutsideOfPreview, _preventUnhandled.shiftToPreventUnhandled, _elementAdapterTypes.shiftCanMonitorArgType];
22
+ function transformer(file, api) {
23
+ var source = file.source;
24
+ var _iterator = _createForOfIteratorHelper(transformers),
25
+ _step;
26
+ try {
27
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
+ var fn = _step.value;
29
+ var updated = _objectSpread(_objectSpread({}, file), {}, {
30
+ source: source
31
+ });
32
+ source = fn(updated, api);
33
+ }
34
+ } catch (err) {
35
+ _iterator.e(err);
36
+ } finally {
37
+ _iterator.f();
38
+ }
39
+ return source;
40
+ }
package/dist/cjs/types.js CHANGED
@@ -12,7 +12,7 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
12
12
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
13
  var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
14
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
16
  /** Converts required args to optional if they have a default
17
17
  * Example: export type UserFlags = Default<Flags, keyof typeof defaultFlags>;
18
18
  */
@@ -60,7 +60,6 @@ const resolveTransform = async (flags, transforms) => {
60
60
  return transform; // Return only if transform found.
61
61
  }
62
62
  }
63
-
64
63
  if (flags.transform && hasTransform(flags.transform)) {
65
64
  return parseTransformPath(flags.transform);
66
65
  }
@@ -7,5 +7,6 @@ import path from 'path';
7
7
  import './styled-to-emotion/styled-to-emotion';
8
8
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
9
9
  import './migrate-to-new-buttons/migrate-to-new-buttons';
10
- const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
10
+ import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
11
+ const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
11
12
  export default presets;
@@ -65,6 +65,14 @@ export const generateNewElement = (variant, element, j) => {
65
65
 
66
66
  // rename iconBefore/iconAfter to icon
67
67
  iconAttrs[0].name.name = 'icon';
68
+ const ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(attribute => attribute.node.name.name === 'aria-label');
69
+ if (ariaLabelAttr.length) {
70
+ const hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label'));
71
+ if (hasNoLabelProp && attributes) {
72
+ attributes.push(j.jsxAttribute(j.jsxIdentifier('label'), ariaLabelAttr.get().node.value));
73
+ }
74
+ ariaLabelAttr.remove();
75
+ }
68
76
  }
69
77
  return j.jsxElement(
70
78
  // self closing if it's an icon button or icon link button
@@ -25,6 +25,5 @@ export const importTypesFromNewEntryPoint = (buttonImports, specifiers, j, fileS
25
25
  j(specifier).remove(); // remove old one
26
26
  });
27
27
  }
28
-
29
28
  return specifiers;
30
29
  };
@@ -0,0 +1,52 @@
1
+ const scenarios = [{
2
+ existing: {
3
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/file',
4
+ namedImport: 'autoScrollForFiles'
5
+ },
6
+ updated: {
7
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/external',
8
+ namedImport: 'autoScrollForExternal'
9
+ }
10
+ }, {
11
+ existing: {
12
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/file',
13
+ namedImport: 'unsafeOverflowAutoScrollForFiles'
14
+ },
15
+ updated: {
16
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/external',
17
+ namedImport: 'unsafeOverflowAutoScrollForExternal'
18
+ }
19
+ }];
20
+ export function updateAutoScroll(file, api) {
21
+ const j = api.jscodeshift;
22
+ const root = j(file.source);
23
+ let changed = false;
24
+ for (const scenario of scenarios) {
25
+ const isUsingImport = root.find(j.ImportDeclaration).some(path => path.node.source.value === scenario.existing.importPath);
26
+
27
+ // move on to the next scenario
28
+ if (!isUsingImport) {
29
+ continue;
30
+ }
31
+ changed = true;
32
+
33
+ // replace old import path with new import path
34
+ root.find(j.ImportDeclaration).filter(path => path.node.source.value === scenario.existing.importPath)
35
+ // replace import
36
+ .map(path => {
37
+ path.node.source.value = scenario.updated.importPath;
38
+ return path;
39
+ });
40
+
41
+ // replace old named import and usages with new one
42
+ root.find(j.Identifier).filter(path => path.value.name === scenario.existing.namedImport).replaceWith(j.identifier(scenario.updated.namedImport));
43
+ }
44
+
45
+ // Don't format the file if we are not changing anything
46
+ if (!changed) {
47
+ return file.source;
48
+ }
49
+ return root.toSource({
50
+ quote: 'single'
51
+ });
52
+ }
@@ -0,0 +1,17 @@
1
+ const newImport = '@atlaskit/pragmatic-drag-and-drop/element/adapter';
2
+ export function shiftCanMonitorArgType(file, api) {
3
+ const j = api.jscodeshift;
4
+ const root = j(file.source);
5
+ const isUsingImport = root.find(j.ImportDeclaration).some(path => path.node.source.value === newImport);
6
+
7
+ // don't change the file if we don't need to
8
+ if (!isUsingImport) {
9
+ return file.source;
10
+ }
11
+
12
+ // replace old named import and usages with new one
13
+ root.find(j.Identifier).filter(path => path.value.name === 'ElementMonitorCanMonitorArgs').replaceWith(j.identifier('ElementMonitorGetFeedbackArgs'));
14
+ return root.toSource({
15
+ quote: 'single'
16
+ });
17
+ }
@@ -0,0 +1,63 @@
1
+ import { addCommentToStartOfFile } from '@atlaskit/codemod-utils';
2
+ export const pleaseMigrateMessage = `
3
+ The file adapter has been replaced by a new (more powerful) external adapter.
4
+ Please see our external adapter documentation on how to migrate your file adapter usage.
5
+
6
+ We have also included "containsFiles()" as an import in this file as it is helpful to
7
+ restrict your monitors and drop targets to only be for files.
8
+
9
+ We have also included "getFiles()" as an import as it is a helpful way to extract the files
10
+ from a drag operation
11
+
12
+ dropTargetForExternal({
13
+ canDrop: containsFiles,
14
+ onDrop({source}) {
15
+ const files = getFiles({source});
16
+ }
17
+ });
18
+
19
+ monitorForExternal({
20
+ canMonitor: containsFiles,
21
+ onDrop({source}) {
22
+ const files = getFiles({source});
23
+ }
24
+ });
25
+
26
+ - [1.0 upgrade documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/changelog)
27
+ - [external adapter documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/external)
28
+ - [file usage documentation](https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/external/files)
29
+ `;
30
+ const oldImportPath = '@atlaskit/pragmatic-drag-and-drop/adapter/file';
31
+ const newImportPath = '@atlaskit/pragmatic-drag-and-drop/external/adapter';
32
+ export function moveFromFileAdapterToExternalAdapter(file, api) {
33
+ const j = api.jscodeshift;
34
+ const root = j(file.source);
35
+ const isUsingFileAdapter = root.find(j.ImportDeclaration).some(path => path.node.source.value === oldImportPath);
36
+ if (!isUsingFileAdapter) {
37
+ return file.source;
38
+ }
39
+
40
+ // replace old import path with new import path
41
+ root.find(j.ImportDeclaration).filter(path => path.node.source.value === oldImportPath)
42
+ // replace import
43
+ .map(path => {
44
+ path.node.source.value = newImportPath;
45
+ return path;
46
+ })
47
+ // Add an import for 'containsFiles()' and `getFiles()` as likely this file will need it
48
+ .insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('containsFiles')), j.importSpecifier(j.identifier('getFiles'))], j.literal('@atlaskit/pragmatic-drag-and-drop/external/file')));
49
+
50
+ // update usages of `monitorForFiles` and `dropTargetForFiles`
51
+ root.find(j.Identifier).filter(path => path.value.name === 'monitorForFiles').replaceWith(j.identifier('monitorForExternal'));
52
+ root.find(j.Identifier).filter(path => path.value.name === 'dropTargetForFiles').replaceWith(j.identifier('dropTargetForExternal'));
53
+
54
+ // add comment to the start of the file
55
+ addCommentToStartOfFile({
56
+ j,
57
+ base: root,
58
+ message: pleaseMigrateMessage
59
+ });
60
+ return root.toSource({
61
+ quote: 'single'
62
+ });
63
+ }