@atlaskit/codemod-cli 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/filepath.js +1 -1
  3. package/dist/cjs/main.js +1 -1
  4. package/dist/cjs/presets/index.js +2 -1
  5. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +79 -0
  6. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +27 -0
  7. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +51 -0
  8. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +37 -0
  9. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +40 -0
  10. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +40 -0
  11. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +48 -0
  12. package/dist/cjs/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +40 -0
  13. package/dist/cjs/transforms.js +3 -3
  14. package/dist/es2019/filepath.js +2 -2
  15. package/dist/es2019/presets/index.js +2 -1
  16. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +52 -0
  17. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +17 -0
  18. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +63 -0
  19. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +31 -0
  20. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +28 -0
  21. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +28 -0
  22. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +42 -0
  23. package/dist/es2019/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +19 -0
  24. package/dist/es2019/transforms.js +3 -3
  25. package/dist/esm/filepath.js +2 -2
  26. package/dist/esm/main.js +1 -1
  27. package/dist/esm/presets/index.js +2 -1
  28. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.js +73 -0
  29. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.js +21 -0
  30. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.js +44 -0
  31. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.js +31 -0
  32. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.js +34 -0
  33. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.js +34 -0
  34. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.js +42 -0
  35. package/dist/esm/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.js +33 -0
  36. package/dist/esm/transforms.js +3 -3
  37. package/dist/types/presets/index.d.ts +1 -0
  38. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.d.ts +2 -0
  39. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.d.ts +2 -0
  40. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.d.ts +3 -0
  41. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.d.ts +2 -0
  42. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.d.ts +2 -0
  43. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.d.ts +2 -0
  44. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.d.ts +2 -0
  45. package/dist/types/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +2 -0
  46. package/dist/types-ts4.5/presets/index.d.ts +1 -0
  47. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/auto-scroll.d.ts +2 -0
  48. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/element-adapter-types.d.ts +2 -0
  49. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/external-adapter.d.ts +3 -0
  50. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/move-to-react-drop-indicator.d.ts +2 -0
  51. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/pointer-outside-of-preview.d.ts +2 -0
  52. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/prevent-unhandled.d.ts +2 -0
  53. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/transformers/update-safe-imports.d.ts +2 -0
  54. package/dist/types-ts4.5/presets/upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable.d.ts +2 -0
  55. package/package.json +4 -4
@@ -0,0 +1,28 @@
1
+ const paths = {
2
+ current: '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer',
3
+ next: '@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview'
4
+ };
5
+ export function shiftToPointerOutsideOfPreview(file, api) {
6
+ const j = api.jscodeshift;
7
+ const root = j(file.source);
8
+ const isUsingImport = root.find(j.ImportDeclaration).some(path => path.node.source.value === paths.current);
9
+
10
+ // don't change the file if we don't need to
11
+ if (!isUsingImport) {
12
+ return file.source;
13
+ }
14
+
15
+ // replace old import path with new import path
16
+ root.find(j.ImportDeclaration).filter(path => path.node.source.value === paths.current)
17
+ // replace import
18
+ .map(path => {
19
+ path.node.source.value = paths.next;
20
+ return path;
21
+ });
22
+
23
+ // replace old named import and usages with new one
24
+ root.find(j.Identifier).filter(path => path.value.name === 'offsetFromPointer').replaceWith(j.identifier('pointerOutsideOfPreview'));
25
+ return root.toSource({
26
+ quote: 'single'
27
+ });
28
+ }
@@ -0,0 +1,28 @@
1
+ const paths = {
2
+ current: '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled',
3
+ next: '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled'
4
+ };
5
+ export function shiftToPreventUnhandled(file, api) {
6
+ const j = api.jscodeshift;
7
+ const root = j(file.source);
8
+ const isUsingImport = root.find(j.ImportDeclaration).some(path => path.node.source.value === paths.current);
9
+
10
+ // don't change the file if we don't need to
11
+ if (!isUsingImport) {
12
+ return file.source;
13
+ }
14
+
15
+ // replace old import path with new import path
16
+ root.find(j.ImportDeclaration).filter(path => path.node.source.value === paths.current)
17
+ // replace import
18
+ .map(path => {
19
+ path.node.source.value = paths.next;
20
+ return path;
21
+ });
22
+
23
+ // replace old named import and usages with new one
24
+ root.find(j.Identifier).filter(path => path.value.name === 'cancelUnhandled').replaceWith(j.identifier('preventUnhandled'));
25
+ return root.toSource({
26
+ quote: 'single'
27
+ });
28
+ }
@@ -0,0 +1,42 @@
1
+ const importMap = {
2
+ // core package
3
+ '@atlaskit/pragmatic-drag-and-drop/adapter/element': '@atlaskit/pragmatic-drag-and-drop/element/adapter',
4
+ '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview',
5
+ '@atlaskit/pragmatic-drag-and-drop/util/center-under-pointer': '@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer',
6
+ '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-on-source': '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source',
7
+ '@atlaskit/pragmatic-drag-and-drop/util/disable-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview',
8
+ '@atlaskit/pragmatic-drag-and-drop/util/scroll-just-enough-into-view': '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view',
9
+ '@atlaskit/pragmatic-drag-and-drop/util/combine': '@atlaskit/pragmatic-drag-and-drop/combine',
10
+ '@atlaskit/pragmatic-drag-and-drop/util/once': '@atlaskit/pragmatic-drag-and-drop/once',
11
+ '@atlaskit/pragmatic-drag-and-drop/util/reorder': '@atlaskit/pragmatic-drag-and-drop/reorder',
12
+ // hitbox package
13
+ '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge': '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'
14
+
15
+ // Doing cancel-unhandled in it's own transformer as the name is changing too
16
+ // '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled':
17
+ // '@atlaskit/pragmatic-drag-and-drop/cancel-unhandled',
18
+ // We are doing the name update in another transform
19
+ // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
20
+ // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
21
+ };
22
+
23
+ export function updateSafeImports(file, api) {
24
+ const j = api.jscodeshift;
25
+ const root = j(file.source);
26
+
27
+ // avoiding reformatting the file if we are not changing anything
28
+ let changed = false;
29
+ root.find(j.ImportDeclaration).forEach(path => {
30
+ const importPath = path.node.source.value;
31
+ if (typeof importPath === 'string' && importMap[importPath]) {
32
+ changed = true;
33
+ path.node.source.value = importMap[importPath];
34
+ }
35
+ });
36
+ if (!changed) {
37
+ return file.source;
38
+ }
39
+ return root.toSource({
40
+ quote: 'single'
41
+ });
42
+ }
@@ -0,0 +1,19 @@
1
+ import { updateSafeImports } from './transformers/update-safe-imports';
2
+ import { moveFromFileAdapterToExternalAdapter } from './transformers/external-adapter';
3
+ import { moveToReactDropIndicator } from './transformers/move-to-react-drop-indicator';
4
+ import { updateAutoScroll } from './transformers/auto-scroll';
5
+ import { shiftToPointerOutsideOfPreview } from './transformers/pointer-outside-of-preview';
6
+ import { shiftToPreventUnhandled } from './transformers/prevent-unhandled';
7
+ import { shiftCanMonitorArgType } from './transformers/element-adapter-types';
8
+ const transformers = [updateSafeImports, moveFromFileAdapterToExternalAdapter, moveToReactDropIndicator, updateAutoScroll, shiftToPointerOutsideOfPreview, shiftToPreventUnhandled, shiftCanMonitorArgType];
9
+ export default function transformer(file, api) {
10
+ let source = file.source;
11
+ for (const fn of transformers) {
12
+ const updated = {
13
+ ...file,
14
+ source
15
+ };
16
+ source = fn(updated, api);
17
+ }
18
+ return source;
19
+ }
@@ -1,12 +1,12 @@
1
1
  import path from 'path';
2
- import glob from 'glob';
2
+ import { globSync } from 'glob';
3
3
  import semver from 'semver';
4
4
  import presets from './presets';
5
5
  const basePath = packages => {
6
6
  const packageDirectory = packages && packages.length > 0 ? [`{${packages.map(pkg => pkg.name).join(',')},}`] : ['@{atlaskit,atlassian,atlassiansox}', '*'];
7
7
  return path.join(process.cwd(), 'node_modules', ...packageDirectory, 'codemods');
8
8
  };
9
- export const hasTransform = transformPath => glob.sync(transformPath).length > 0;
9
+ export const hasTransform = transformPath => globSync(transformPath).length > 0;
10
10
 
11
11
  /** Retrieves transforms for `packages` if provided, otherwise all transforms including presets */
12
12
  export const getTransforms = packages => {
@@ -14,7 +14,7 @@ export const getTransforms = packages => {
14
14
  if (!packages) {
15
15
  transforms.unshift(...presets);
16
16
  }
17
- return transforms.map(transform => glob.sync(transform)).reduce((acc, val) => acc.concat(val), []).map(transform => parseTransformPath(transform)).filter(filterTransforms(packages)).sort();
17
+ return transforms.map(transform => globSync(transform)).reduce((acc, val) => acc.concat(val), []).map(transform => parseTransformPath(transform)).filter(filterTransforms(packages)).sort();
18
18
  };
19
19
  export const parseTransformPath = transformPath => path.parse(transformPath);
20
20
  export const getTransformPath = ({
@@ -1,6 +1,6 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { glob } from 'glob';
3
+ import { globSync } from 'glob';
4
4
  import { promises } from 'fs';
5
5
  var readFile = promises.readFile;
6
6
 
@@ -20,7 +20,7 @@ function _findDependentPackagePaths() {
20
20
  return "".concat(crawlPath.replace(/^\.\//, ''), "/**/package.json");
21
21
  }); // Convert array into glob string
22
22
  globString = searchStrings.length > 1 ? "{".concat(searchStrings.join(','), "}") : searchStrings[0];
23
- packageJsonPaths = glob.sync(globString, {
23
+ packageJsonPaths = globSync(globString, {
24
24
  ignore: '**/node_modules/**',
25
25
  nodir: true
26
26
  });
package/dist/esm/main.js CHANGED
@@ -298,7 +298,7 @@ function _main() {
298
298
  case 4:
299
299
  _yield$parseArgs = _context5.sent;
300
300
  packages = _yield$parseArgs.packages;
301
- _process$env$_PACKAGE = "0.18.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
301
+ _process$env$_PACKAGE = "0.20.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
302
302
  logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
303
303
  if (packages && packages.length > 0) {
304
304
  logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
@@ -7,7 +7,8 @@ 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
- var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons'].map(function (preset) {
10
+ import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
11
+ var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable'].map(function (preset) {
11
12
  return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
12
13
  });
13
14
  export default presets;
@@ -0,0 +1,73 @@
1
+ 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; } } }; }
2
+ 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); }
3
+ 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; }
4
+ var scenarios = [{
5
+ existing: {
6
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/file',
7
+ namedImport: 'autoScrollForFiles'
8
+ },
9
+ updated: {
10
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/external',
11
+ namedImport: 'autoScrollForExternal'
12
+ }
13
+ }, {
14
+ existing: {
15
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/file',
16
+ namedImport: 'unsafeOverflowAutoScrollForFiles'
17
+ },
18
+ updated: {
19
+ importPath: '@atlaskit/pragmatic-drag-and-drop-auto-scroll/unsafe-overflow/external',
20
+ namedImport: 'unsafeOverflowAutoScrollForExternal'
21
+ }
22
+ }];
23
+ export function updateAutoScroll(file, api) {
24
+ var j = api.jscodeshift;
25
+ var root = j(file.source);
26
+ var changed = false;
27
+ var _iterator = _createForOfIteratorHelper(scenarios),
28
+ _step;
29
+ try {
30
+ var _loop = function _loop() {
31
+ var scenario = _step.value;
32
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
33
+ return path.node.source.value === scenario.existing.importPath;
34
+ });
35
+
36
+ // move on to the next scenario
37
+ if (!isUsingImport) {
38
+ return 1; // continue
39
+ }
40
+ changed = true;
41
+
42
+ // replace old import path with new import path
43
+ root.find(j.ImportDeclaration).filter(function (path) {
44
+ return path.node.source.value === scenario.existing.importPath;
45
+ })
46
+ // replace import
47
+ .map(function (path) {
48
+ path.node.source.value = scenario.updated.importPath;
49
+ return path;
50
+ });
51
+
52
+ // replace old named import and usages with new one
53
+ root.find(j.Identifier).filter(function (path) {
54
+ return path.value.name === scenario.existing.namedImport;
55
+ }).replaceWith(j.identifier(scenario.updated.namedImport));
56
+ };
57
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
58
+ if (_loop()) continue;
59
+ }
60
+
61
+ // Don't format the file if we are not changing anything
62
+ } catch (err) {
63
+ _iterator.e(err);
64
+ } finally {
65
+ _iterator.f();
66
+ }
67
+ if (!changed) {
68
+ return file.source;
69
+ }
70
+ return root.toSource({
71
+ quote: 'single'
72
+ });
73
+ }
@@ -0,0 +1,21 @@
1
+ var newImport = '@atlaskit/pragmatic-drag-and-drop/element/adapter';
2
+ export function shiftCanMonitorArgType(file, api) {
3
+ var j = api.jscodeshift;
4
+ var root = j(file.source);
5
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
6
+ return path.node.source.value === newImport;
7
+ });
8
+
9
+ // don't change the file if we don't need to
10
+ if (!isUsingImport) {
11
+ return file.source;
12
+ }
13
+
14
+ // replace old named import and usages with new one
15
+ root.find(j.Identifier).filter(function (path) {
16
+ return path.value.name === 'ElementMonitorCanMonitorArgs';
17
+ }).replaceWith(j.identifier('ElementMonitorGetFeedbackArgs'));
18
+ return root.toSource({
19
+ quote: 'single'
20
+ });
21
+ }
@@ -0,0 +1,44 @@
1
+ import { addCommentToStartOfFile } from '@atlaskit/codemod-utils';
2
+ export var 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";
3
+ var oldImportPath = '@atlaskit/pragmatic-drag-and-drop/adapter/file';
4
+ var newImportPath = '@atlaskit/pragmatic-drag-and-drop/external/adapter';
5
+ export function moveFromFileAdapterToExternalAdapter(file, api) {
6
+ var j = api.jscodeshift;
7
+ var root = j(file.source);
8
+ var isUsingFileAdapter = root.find(j.ImportDeclaration).some(function (path) {
9
+ return path.node.source.value === oldImportPath;
10
+ });
11
+ if (!isUsingFileAdapter) {
12
+ return file.source;
13
+ }
14
+
15
+ // replace old import path with new import path
16
+ root.find(j.ImportDeclaration).filter(function (path) {
17
+ return path.node.source.value === oldImportPath;
18
+ })
19
+ // replace import
20
+ .map(function (path) {
21
+ path.node.source.value = newImportPath;
22
+ return path;
23
+ })
24
+ // Add an import for 'containsFiles()' and `getFiles()` as likely this file will need it
25
+ .insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('containsFiles')), j.importSpecifier(j.identifier('getFiles'))], j.literal('@atlaskit/pragmatic-drag-and-drop/external/file')));
26
+
27
+ // update usages of `monitorForFiles` and `dropTargetForFiles`
28
+ root.find(j.Identifier).filter(function (path) {
29
+ return path.value.name === 'monitorForFiles';
30
+ }).replaceWith(j.identifier('monitorForExternal'));
31
+ root.find(j.Identifier).filter(function (path) {
32
+ return path.value.name === 'dropTargetForFiles';
33
+ }).replaceWith(j.identifier('dropTargetForExternal'));
34
+
35
+ // add comment to the start of the file
36
+ addCommentToStartOfFile({
37
+ j: j,
38
+ base: root,
39
+ message: pleaseMigrateMessage
40
+ });
41
+ return root.toSource({
42
+ quote: 'single'
43
+ });
44
+ }
@@ -0,0 +1,31 @@
1
+ var oldPackagePath = '@atlaskit/pragmatic-drag-and-drop-react-indicator';
2
+ var newPackagePath = '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator';
3
+ function isString(value) {
4
+ return typeof value === 'string';
5
+ }
6
+ function isOldPackagePath(value) {
7
+ return isString(value) && value.startsWith(oldPackagePath);
8
+ }
9
+ export function moveToReactDropIndicator(file, api) {
10
+ var j = api.jscodeshift;
11
+ var root = j(file.source);
12
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
13
+ return isOldPackagePath(path.node.source.value);
14
+ });
15
+
16
+ // Don't format the file if we are not changing anything
17
+ if (!isUsingImport) {
18
+ return file.source;
19
+ }
20
+
21
+ // replace imports
22
+ root.find(j.ImportDeclaration).forEach(function (path) {
23
+ var value = path.node.source.value;
24
+ if (isString(value) && isOldPackagePath(path.node.source.value)) {
25
+ path.node.source.value = value.replace(oldPackagePath, newPackagePath);
26
+ }
27
+ });
28
+ return root.toSource({
29
+ quote: 'single'
30
+ });
31
+ }
@@ -0,0 +1,34 @@
1
+ var paths = {
2
+ current: '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer',
3
+ next: '@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview'
4
+ };
5
+ export function shiftToPointerOutsideOfPreview(file, api) {
6
+ var j = api.jscodeshift;
7
+ var root = j(file.source);
8
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
9
+ return path.node.source.value === paths.current;
10
+ });
11
+
12
+ // don't change the file if we don't need to
13
+ if (!isUsingImport) {
14
+ return file.source;
15
+ }
16
+
17
+ // replace old import path with new import path
18
+ root.find(j.ImportDeclaration).filter(function (path) {
19
+ return path.node.source.value === paths.current;
20
+ })
21
+ // replace import
22
+ .map(function (path) {
23
+ path.node.source.value = paths.next;
24
+ return path;
25
+ });
26
+
27
+ // replace old named import and usages with new one
28
+ root.find(j.Identifier).filter(function (path) {
29
+ return path.value.name === 'offsetFromPointer';
30
+ }).replaceWith(j.identifier('pointerOutsideOfPreview'));
31
+ return root.toSource({
32
+ quote: 'single'
33
+ });
34
+ }
@@ -0,0 +1,34 @@
1
+ var paths = {
2
+ current: '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled',
3
+ next: '@atlaskit/pragmatic-drag-and-drop/prevent-unhandled'
4
+ };
5
+ export function shiftToPreventUnhandled(file, api) {
6
+ var j = api.jscodeshift;
7
+ var root = j(file.source);
8
+ var isUsingImport = root.find(j.ImportDeclaration).some(function (path) {
9
+ return path.node.source.value === paths.current;
10
+ });
11
+
12
+ // don't change the file if we don't need to
13
+ if (!isUsingImport) {
14
+ return file.source;
15
+ }
16
+
17
+ // replace old import path with new import path
18
+ root.find(j.ImportDeclaration).filter(function (path) {
19
+ return path.node.source.value === paths.current;
20
+ })
21
+ // replace import
22
+ .map(function (path) {
23
+ path.node.source.value = paths.next;
24
+ return path;
25
+ });
26
+
27
+ // replace old named import and usages with new one
28
+ root.find(j.Identifier).filter(function (path) {
29
+ return path.value.name === 'cancelUnhandled';
30
+ }).replaceWith(j.identifier('preventUnhandled'));
31
+ return root.toSource({
32
+ quote: 'single'
33
+ });
34
+ }
@@ -0,0 +1,42 @@
1
+ var importMap = {
2
+ // core package
3
+ '@atlaskit/pragmatic-drag-and-drop/adapter/element': '@atlaskit/pragmatic-drag-and-drop/element/adapter',
4
+ '@atlaskit/pragmatic-drag-and-drop/util/set-custom-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview',
5
+ '@atlaskit/pragmatic-drag-and-drop/util/center-under-pointer': '@atlaskit/pragmatic-drag-and-drop/element/center-under-pointer',
6
+ '@atlaskit/pragmatic-drag-and-drop/util/preserve-offset-on-source': '@atlaskit/pragmatic-drag-and-drop/element/preserve-offset-on-source',
7
+ '@atlaskit/pragmatic-drag-and-drop/util/disable-native-drag-preview': '@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview',
8
+ '@atlaskit/pragmatic-drag-and-drop/util/scroll-just-enough-into-view': '@atlaskit/pragmatic-drag-and-drop/element/scroll-just-enough-into-view',
9
+ '@atlaskit/pragmatic-drag-and-drop/util/combine': '@atlaskit/pragmatic-drag-and-drop/combine',
10
+ '@atlaskit/pragmatic-drag-and-drop/util/once': '@atlaskit/pragmatic-drag-and-drop/once',
11
+ '@atlaskit/pragmatic-drag-and-drop/util/reorder': '@atlaskit/pragmatic-drag-and-drop/reorder',
12
+ // hitbox package
13
+ '@atlaskit/pragmatic-drag-and-drop-hitbox/addon/closest-edge': '@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge'
14
+
15
+ // Doing cancel-unhandled in it's own transformer as the name is changing too
16
+ // '@atlaskit/pragmatic-drag-and-drop/addon/cancel-unhandled':
17
+ // '@atlaskit/pragmatic-drag-and-drop/cancel-unhandled',
18
+ // We are doing the name update in another transform
19
+ // '@atlaskit/pragmatic-drag-and-drop/util/offset-from-pointer':
20
+ // '@atlaskit/pragmatic-drag-and-drop/element/offset-from-pointer',
21
+ };
22
+
23
+ export function updateSafeImports(file, api) {
24
+ var j = api.jscodeshift;
25
+ var root = j(file.source);
26
+
27
+ // avoiding reformatting the file if we are not changing anything
28
+ var changed = false;
29
+ root.find(j.ImportDeclaration).forEach(function (path) {
30
+ var importPath = path.node.source.value;
31
+ if (typeof importPath === 'string' && importMap[importPath]) {
32
+ changed = true;
33
+ path.node.source.value = importMap[importPath];
34
+ }
35
+ });
36
+ if (!changed) {
37
+ return file.source;
38
+ }
39
+ return root.toSource({
40
+ quote: 'single'
41
+ });
42
+ }
@@ -0,0 +1,33 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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) { _defineProperty(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; }
4
+ 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; } } }; }
5
+ 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); }
6
+ 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; }
7
+ import { updateSafeImports } from './transformers/update-safe-imports';
8
+ import { moveFromFileAdapterToExternalAdapter } from './transformers/external-adapter';
9
+ import { moveToReactDropIndicator } from './transformers/move-to-react-drop-indicator';
10
+ import { updateAutoScroll } from './transformers/auto-scroll';
11
+ import { shiftToPointerOutsideOfPreview } from './transformers/pointer-outside-of-preview';
12
+ import { shiftToPreventUnhandled } from './transformers/prevent-unhandled';
13
+ import { shiftCanMonitorArgType } from './transformers/element-adapter-types';
14
+ var transformers = [updateSafeImports, moveFromFileAdapterToExternalAdapter, moveToReactDropIndicator, updateAutoScroll, shiftToPointerOutsideOfPreview, shiftToPreventUnhandled, shiftCanMonitorArgType];
15
+ export default function transformer(file, api) {
16
+ var source = file.source;
17
+ var _iterator = _createForOfIteratorHelper(transformers),
18
+ _step;
19
+ try {
20
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
21
+ var fn = _step.value;
22
+ var updated = _objectSpread(_objectSpread({}, file), {}, {
23
+ source: source
24
+ });
25
+ source = fn(updated, api);
26
+ }
27
+ } catch (err) {
28
+ _iterator.e(err);
29
+ } finally {
30
+ _iterator.f();
31
+ }
32
+ return source;
33
+ }
@@ -1,6 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import path from 'path';
3
- import glob from 'glob';
3
+ import { globSync } from 'glob';
4
4
  import semver from 'semver';
5
5
  import presets from './presets';
6
6
  var basePath = function basePath(packages) {
@@ -10,7 +10,7 @@ var basePath = function basePath(packages) {
10
10
  return path.join.apply(path, [process.cwd(), 'node_modules'].concat(packageDirectory, ['codemods']));
11
11
  };
12
12
  export var hasTransform = function hasTransform(transformPath) {
13
- return glob.sync(transformPath).length > 0;
13
+ return globSync(transformPath).length > 0;
14
14
  };
15
15
 
16
16
  /** Retrieves transforms for `packages` if provided, otherwise all transforms including presets */
@@ -20,7 +20,7 @@ export var getTransforms = function getTransforms(packages) {
20
20
  transforms.unshift.apply(transforms, _toConsumableArray(presets));
21
21
  }
22
22
  return transforms.map(function (transform) {
23
- return glob.sync(transform);
23
+ return globSync(transform);
24
24
  }).reduce(function (acc, val) {
25
25
  return acc.concat(val);
26
26
  }, []).map(function (transform) {
@@ -5,5 +5,6 @@
5
5
  import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
7
7
  import './migrate-to-new-buttons/migrate-to-new-buttons';
8
+ import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
8
9
  declare const presets: string[];
9
10
  export default presets;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function updateAutoScroll(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftCanMonitorArgType(file: FileInfo, api: API): string;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare const 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";
3
+ export declare function moveFromFileAdapterToExternalAdapter(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function moveToReactDropIndicator(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftToPointerOutsideOfPreview(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftToPreventUnhandled(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function updateSafeImports(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import { FileInfo, API } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;
@@ -5,5 +5,6 @@
5
5
  import './styled-to-emotion/styled-to-emotion';
6
6
  import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
7
7
  import './migrate-to-new-buttons/migrate-to-new-buttons';
8
+ import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
8
9
  declare const presets: string[];
9
10
  export default presets;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function updateAutoScroll(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftCanMonitorArgType(file: FileInfo, api: API): string;
@@ -0,0 +1,3 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare const 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";
3
+ export declare function moveFromFileAdapterToExternalAdapter(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function moveToReactDropIndicator(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftToPointerOutsideOfPreview(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function shiftToPreventUnhandled(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import type { API, FileInfo } from 'jscodeshift';
2
+ export declare function updateSafeImports(file: FileInfo, api: API): string;
@@ -0,0 +1,2 @@
1
+ import { FileInfo, API } from 'jscodeshift';
2
+ export default function transformer(file: FileInfo, api: API): string;