@atlaskit/codemod-cli 0.26.3 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/index.js +2 -1
- package/dist/cjs/presets/migrate-to-link/codemods/migrate-to-link.js +139 -0
- package/dist/cjs/presets/migrate-to-link/migrate-to-link.js +44 -0
- package/dist/cjs/presets/migrate-to-link/utils/comments.js +18 -0
- package/dist/cjs/presets/migrate-to-link/utils/constants.js +12 -0
- package/dist/cjs/presets/migrate-to-link/utils/find-attribute-with-value.js +17 -0
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/migrate-to-link/codemods/migrate-to-link.js +136 -0
- package/dist/es2019/presets/migrate-to-link/migrate-to-link.js +18 -0
- package/dist/es2019/presets/migrate-to-link/utils/comments.js +11 -0
- package/dist/es2019/presets/migrate-to-link/utils/constants.js +6 -0
- package/dist/es2019/presets/migrate-to-link/utils/find-attribute-with-value.js +11 -0
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/index.js +2 -1
- package/dist/esm/presets/migrate-to-link/codemods/migrate-to-link.js +133 -0
- package/dist/esm/presets/migrate-to-link/migrate-to-link.js +37 -0
- package/dist/esm/presets/migrate-to-link/utils/comments.js +12 -0
- package/dist/esm/presets/migrate-to-link/utils/constants.js +6 -0
- package/dist/esm/presets/migrate-to-link/utils/find-attribute-with-value.js +11 -0
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/migrate-to-link/codemods/migrate-to-link.d.ts +2 -0
- package/dist/types/presets/migrate-to-link/migrate-to-link.d.ts +2 -0
- package/dist/types/presets/migrate-to-link/utils/comments.d.ts +6 -0
- package/dist/types/presets/migrate-to-link/utils/constants.d.ts +6 -0
- package/dist/types/presets/migrate-to-link/utils/find-attribute-with-value.d.ts +2 -0
- package/dist/types-ts4.5/presets/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-link/codemods/migrate-to-link.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-link/migrate-to-link.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-link/utils/comments.d.ts +6 -0
- package/dist/types-ts4.5/presets/migrate-to-link/utils/constants.d.ts +6 -0
- package/dist/types-ts4.5/presets/migrate-to-link/utils/find-attribute-with-value.d.ts +2 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#163865](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/163865)
|
|
8
|
+
[`e66453c2716df`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e66453c2716df) -
|
|
9
|
+
Added new codemod for migrating to Link component from `@atlaskit/link`.
|
|
10
|
+
|
|
3
11
|
## 0.26.3
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
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.
|
|
308
|
+
_process$env$_PACKAGE = "0.27.0", _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) {
|
|
@@ -8,6 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
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
|
+
require("./migrate-to-link/migrate-to-link");
|
|
11
12
|
require("./migrate-to-new-buttons/migrate-to-new-buttons");
|
|
12
13
|
require("./upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable");
|
|
13
14
|
require("./remove-dark-theme-vr-options/remove-dark-theme-vr-options");
|
|
@@ -16,7 +17,7 @@ require("./remove-dark-theme-vr-options/remove-dark-theme-vr-options");
|
|
|
16
17
|
* in the final bundle.
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(function (preset) {
|
|
20
|
+
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(function (preset) {
|
|
20
21
|
return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
|
|
21
22
|
});
|
|
22
23
|
var _default = exports.default = presets;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
var _codemodUtils = require("@atlaskit/codemod-utils");
|
|
8
|
+
var _utils = require("@hypermod/utils");
|
|
9
|
+
var _constants = require("../utils/constants");
|
|
10
|
+
var _comments = require("../utils/comments");
|
|
11
|
+
var _findAttributeWithValue = require("../utils/find-attribute-with-value");
|
|
12
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
13
|
+
|
|
14
|
+
function transformer(file, api) {
|
|
15
|
+
var j = api.jscodeshift;
|
|
16
|
+
var source = j(file.source);
|
|
17
|
+
|
|
18
|
+
// Find all native links
|
|
19
|
+
var nativeLinks = source.find(j.JSXElement).filter(function (path) {
|
|
20
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && /^[a-z]+$/.test(path.value.openingElement.name.name) && (path.value.openingElement.name.name === 'a' || (0, _findAttributeWithValue.findJSXAttributeWithValue)(path.value.openingElement, 'role', 'link'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// No native links are found, exit early
|
|
24
|
+
if (!nativeLinks.length) {
|
|
25
|
+
return file.source;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Links we can migrate
|
|
29
|
+
var nativeLinksSupportedForMigration = [];
|
|
30
|
+
|
|
31
|
+
// Links we can't migrate, but will leave a code comment as a suggestion for manual migration
|
|
32
|
+
var nativeLinksUnsupportedForMigration = [];
|
|
33
|
+
|
|
34
|
+
// Check for existing imports
|
|
35
|
+
var existingLinkImports = (0, _utils.getImportDeclaration)(j, source, _constants.LINK_ENTRY_POINT);
|
|
36
|
+
|
|
37
|
+
// Sets import name to be used. May be updated if an existing import is found with a different name
|
|
38
|
+
var linkImportName = _constants.LINK_EXPORT_NAME;
|
|
39
|
+
nativeLinks.forEach(function (path) {
|
|
40
|
+
var _path$value$openingEl;
|
|
41
|
+
var unsupportedMigrations = (_path$value$openingEl = path.value.openingElement) === null || _path$value$openingEl === void 0 || (_path$value$openingEl = _path$value$openingEl.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.reduce(function (acc, attribute) {
|
|
42
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
43
|
+
acc.push({
|
|
44
|
+
name: '',
|
|
45
|
+
reason: 'spreadProps'
|
|
46
|
+
});
|
|
47
|
+
} else if (_constants.UNSUPPORTED_STYLE_PROPS.includes(attribute.name.name.toString())) {
|
|
48
|
+
acc.push({
|
|
49
|
+
name: attribute.name.name.toString(),
|
|
50
|
+
reason: 'styleProp'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return acc;
|
|
54
|
+
}, []);
|
|
55
|
+
if (unsupportedMigrations !== null && unsupportedMigrations !== void 0 && unsupportedMigrations.length) {
|
|
56
|
+
nativeLinksUnsupportedForMigration.push({
|
|
57
|
+
path: path,
|
|
58
|
+
unsupportedMigrations: unsupportedMigrations
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
nativeLinksSupportedForMigration.push(path);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (nativeLinksSupportedForMigration.length) {
|
|
65
|
+
// Generate a unique import name if there is a different existing import named "Link"
|
|
66
|
+
var importNameSuffix = 1;
|
|
67
|
+
var uniqueLinkImportName = linkImportName;
|
|
68
|
+
while (source.find(j.ImportDeclaration).some(function (importDecl) {
|
|
69
|
+
var _importDecl$value$spe;
|
|
70
|
+
return Boolean((_importDecl$value$spe = importDecl.value.specifiers) === null || _importDecl$value$spe === void 0 ? void 0 : _importDecl$value$spe.some(function (specifier) {
|
|
71
|
+
var _specifier$local;
|
|
72
|
+
return ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) === uniqueLinkImportName;
|
|
73
|
+
}));
|
|
74
|
+
})) {
|
|
75
|
+
uniqueLinkImportName = "".concat(linkImportName).concat(importNameSuffix);
|
|
76
|
+
importNameSuffix++;
|
|
77
|
+
}
|
|
78
|
+
linkImportName = uniqueLinkImportName;
|
|
79
|
+
|
|
80
|
+
// Add link import
|
|
81
|
+
// If no existing link imports are found, add a new import
|
|
82
|
+
if (!existingLinkImports.length) {
|
|
83
|
+
var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(linkImportName))], j.stringLiteral(_constants.LINK_ENTRY_POINT));
|
|
84
|
+
var importDeclarations = source.find(j.ImportDeclaration);
|
|
85
|
+
if (importDeclarations.length) {
|
|
86
|
+
importDeclarations.at(importDeclarations.length - 1).get().insertAfter(linkImport);
|
|
87
|
+
} else {
|
|
88
|
+
source.get().node.program.body.unshift(linkImport);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// If an existing `@atlaskit/link import` is found, import Link if it's not already imported
|
|
92
|
+
else {
|
|
93
|
+
var hasExistingSpecifier = existingLinkImports.some(function (importDecl) {
|
|
94
|
+
var _importDecl$value$spe2;
|
|
95
|
+
return Boolean((_importDecl$value$spe2 = importDecl.value.specifiers) === null || _importDecl$value$spe2 === void 0 ? void 0 : _importDecl$value$spe2.some(function (specifier) {
|
|
96
|
+
var _specifier$local2;
|
|
97
|
+
var isDefaultImport = specifier.type === 'ImportDefaultSpecifier';
|
|
98
|
+
if (isDefaultImport && (_specifier$local2 = specifier.local) !== null && _specifier$local2 !== void 0 && _specifier$local2.name) {
|
|
99
|
+
var _specifier$local3;
|
|
100
|
+
linkImportName = (_specifier$local3 = specifier.local) === null || _specifier$local3 === void 0 ? void 0 : _specifier$local3.name;
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
});
|
|
105
|
+
if (!hasExistingSpecifier) {
|
|
106
|
+
existingLinkImports.at(0).get().node.specifiers.push(j.importDefaultSpecifier(j.identifier(linkImportName)));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
nativeLinksSupportedForMigration.forEach(function (link) {
|
|
110
|
+
var attributes = link.node.openingElement.attributes;
|
|
111
|
+
|
|
112
|
+
// Remove role="link" attributes
|
|
113
|
+
var filteredAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) {
|
|
114
|
+
var _attr$value;
|
|
115
|
+
return !(attr.type === 'JSXAttribute' && attr.name.name === 'role' && ((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral' && attr.value.value === 'link');
|
|
116
|
+
});
|
|
117
|
+
j(link).replaceWith(j.jsxElement.from({
|
|
118
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier(linkImportName), filteredAttributes, false),
|
|
119
|
+
closingElement: j.jsxClosingElement(j.jsxIdentifier(linkImportName)),
|
|
120
|
+
children: link.node.children
|
|
121
|
+
}));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
nativeLinksUnsupportedForMigration.forEach(function (link) {
|
|
125
|
+
(0, _codemodUtils.addCommentBefore)(j, j(link.path), "\n".concat(link.unsupportedMigrations.map(function (unsupported) {
|
|
126
|
+
switch (unsupported.reason) {
|
|
127
|
+
case 'styleProp':
|
|
128
|
+
return (0, _comments.stylePropComment)({
|
|
129
|
+
propName: unsupported.name
|
|
130
|
+
});
|
|
131
|
+
case 'spreadProps':
|
|
132
|
+
return _comments.spreadPropsComment;
|
|
133
|
+
default:
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}).join('\n'), "\n").concat((0, _comments.genericUnsupportedMigrationComment)(), "\n\n"));
|
|
137
|
+
});
|
|
138
|
+
return source.toSource(_constants.PRINT_SETTINGS);
|
|
139
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _migrateToLink = _interopRequireDefault(require("./codemods/migrate-to-link"));
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
function transformer(_x, _x2) {
|
|
15
|
+
return _transformer.apply(this, arguments);
|
|
16
|
+
}
|
|
17
|
+
function _transformer() {
|
|
18
|
+
_transformer = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file, api) {
|
|
19
|
+
var transformers, src;
|
|
20
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
transformers = [_migrateToLink.default];
|
|
24
|
+
src = file.source;
|
|
25
|
+
transformers.forEach(function (transformer) {
|
|
26
|
+
if (typeof src === 'undefined') {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
|
|
30
|
+
source: src
|
|
31
|
+
}), api);
|
|
32
|
+
if (nextSrc) {
|
|
33
|
+
src = nextSrc;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return _context.abrupt("return", src);
|
|
37
|
+
case 4:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee);
|
|
42
|
+
}));
|
|
43
|
+
return _transformer.apply(this, arguments);
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.stylePropComment = exports.spreadPropsComment = exports.genericUnsupportedMigrationComment = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
var stylePropComment = exports.stylePropComment = function stylePropComment(_ref) {
|
|
9
|
+
var propName = _ref.propName,
|
|
10
|
+
_ref$prefix = _ref.prefix,
|
|
11
|
+
prefix = _ref$prefix === void 0 ? '' : _ref$prefix;
|
|
12
|
+
return "".concat(prefix, "This link could not be migrated due to custom styles in `").concat(propName, "` prop.");
|
|
13
|
+
};
|
|
14
|
+
var spreadPropsComment = exports.spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
|
|
15
|
+
var genericUnsupportedMigrationComment = exports.genericUnsupportedMigrationComment = function genericUnsupportedMigrationComment() {
|
|
16
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
17
|
+
return "".concat(prefix, "- If this is a simple text-based link, replace with `").concat(_constants.LINK_ENTRY_POINT, "`.\n").concat(prefix, "- If this is a button-like link style, replace with a link button from `@atlaskit/button`.\n").concat(prefix, "- If this needs to retain custom styles, use the `Anchor` primitive from `@atlaskit/primitives`.");
|
|
18
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UNSUPPORTED_STYLE_PROPS = exports.PRINT_SETTINGS = exports.LINK_EXPORT_NAME = exports.LINK_ENTRY_POINT = void 0;
|
|
7
|
+
var PRINT_SETTINGS = exports.PRINT_SETTINGS = {
|
|
8
|
+
quote: 'single'
|
|
9
|
+
};
|
|
10
|
+
var LINK_ENTRY_POINT = exports.LINK_ENTRY_POINT = '@atlaskit/link';
|
|
11
|
+
var LINK_EXPORT_NAME = exports.LINK_EXPORT_NAME = 'Link';
|
|
12
|
+
var UNSUPPORTED_STYLE_PROPS = exports.UNSUPPORTED_STYLE_PROPS = ['css', 'style', 'className'];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findJSXAttributeWithValue = void 0;
|
|
7
|
+
var findJSXAttributeWithValue = exports.findJSXAttributeWithValue = function findJSXAttributeWithValue(path, attributeName, attributeValue) {
|
|
8
|
+
var _path$attributes;
|
|
9
|
+
if (!path || path.type === 'JSXSpreadAttribute') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
var attribute = path === null || path === void 0 || (_path$attributes = path.attributes) === null || _path$attributes === void 0 ? void 0 : _path$attributes.find(function (attribute) {
|
|
13
|
+
var _attribute$value;
|
|
14
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === attributeName && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && attribute.value.value === attributeValue;
|
|
15
|
+
});
|
|
16
|
+
return Boolean(attribute);
|
|
17
|
+
};
|
|
@@ -6,8 +6,9 @@ import path from 'path';
|
|
|
6
6
|
*/
|
|
7
7
|
import './styled-to-emotion/styled-to-emotion';
|
|
8
8
|
import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
|
|
9
|
+
import './migrate-to-link/migrate-to-link';
|
|
9
10
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
10
11
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
11
12
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
12
|
-
const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
|
|
13
|
+
const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
|
|
13
14
|
export default presets;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { getImportDeclaration } from '@hypermod/utils';
|
|
5
|
+
import { LINK_ENTRY_POINT, LINK_EXPORT_NAME, PRINT_SETTINGS, UNSUPPORTED_STYLE_PROPS } from '../utils/constants';
|
|
6
|
+
import { genericUnsupportedMigrationComment, spreadPropsComment, stylePropComment } from '../utils/comments';
|
|
7
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
8
|
+
export default function transformer(file, api) {
|
|
9
|
+
const j = api.jscodeshift;
|
|
10
|
+
const source = j(file.source);
|
|
11
|
+
|
|
12
|
+
// Find all native links
|
|
13
|
+
const nativeLinks = source.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && /^[a-z]+$/.test(path.value.openingElement.name.name) && (path.value.openingElement.name.name === 'a' || findJSXAttributeWithValue(path.value.openingElement, 'role', 'link')));
|
|
14
|
+
|
|
15
|
+
// No native links are found, exit early
|
|
16
|
+
if (!nativeLinks.length) {
|
|
17
|
+
return file.source;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Links we can migrate
|
|
21
|
+
const nativeLinksSupportedForMigration = [];
|
|
22
|
+
|
|
23
|
+
// Links we can't migrate, but will leave a code comment as a suggestion for manual migration
|
|
24
|
+
const nativeLinksUnsupportedForMigration = [];
|
|
25
|
+
|
|
26
|
+
// Check for existing imports
|
|
27
|
+
const existingLinkImports = getImportDeclaration(j, source, LINK_ENTRY_POINT);
|
|
28
|
+
|
|
29
|
+
// Sets import name to be used. May be updated if an existing import is found with a different name
|
|
30
|
+
let linkImportName = LINK_EXPORT_NAME;
|
|
31
|
+
nativeLinks.forEach(path => {
|
|
32
|
+
var _path$value$openingEl, _path$value$openingEl2;
|
|
33
|
+
const unsupportedMigrations = (_path$value$openingEl = path.value.openingElement) === null || _path$value$openingEl === void 0 ? void 0 : (_path$value$openingEl2 = _path$value$openingEl.attributes) === null || _path$value$openingEl2 === void 0 ? void 0 : _path$value$openingEl2.reduce((acc, attribute) => {
|
|
34
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
35
|
+
acc.push({
|
|
36
|
+
name: '',
|
|
37
|
+
reason: 'spreadProps'
|
|
38
|
+
});
|
|
39
|
+
} else if (UNSUPPORTED_STYLE_PROPS.includes(attribute.name.name.toString())) {
|
|
40
|
+
acc.push({
|
|
41
|
+
name: attribute.name.name.toString(),
|
|
42
|
+
reason: 'styleProp'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, []);
|
|
47
|
+
if (unsupportedMigrations !== null && unsupportedMigrations !== void 0 && unsupportedMigrations.length) {
|
|
48
|
+
nativeLinksUnsupportedForMigration.push({
|
|
49
|
+
path,
|
|
50
|
+
unsupportedMigrations
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
nativeLinksSupportedForMigration.push(path);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (nativeLinksSupportedForMigration.length) {
|
|
57
|
+
// Generate a unique import name if there is a different existing import named "Link"
|
|
58
|
+
let importNameSuffix = 1;
|
|
59
|
+
let uniqueLinkImportName = linkImportName;
|
|
60
|
+
while (source.find(j.ImportDeclaration).some(importDecl => {
|
|
61
|
+
var _importDecl$value$spe;
|
|
62
|
+
return Boolean((_importDecl$value$spe = importDecl.value.specifiers) === null || _importDecl$value$spe === void 0 ? void 0 : _importDecl$value$spe.some(specifier => {
|
|
63
|
+
var _specifier$local;
|
|
64
|
+
return ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) === uniqueLinkImportName;
|
|
65
|
+
}));
|
|
66
|
+
})) {
|
|
67
|
+
uniqueLinkImportName = `${linkImportName}${importNameSuffix}`;
|
|
68
|
+
importNameSuffix++;
|
|
69
|
+
}
|
|
70
|
+
linkImportName = uniqueLinkImportName;
|
|
71
|
+
|
|
72
|
+
// Add link import
|
|
73
|
+
// If no existing link imports are found, add a new import
|
|
74
|
+
if (!existingLinkImports.length) {
|
|
75
|
+
const linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(linkImportName))], j.stringLiteral(LINK_ENTRY_POINT));
|
|
76
|
+
const importDeclarations = source.find(j.ImportDeclaration);
|
|
77
|
+
if (importDeclarations.length) {
|
|
78
|
+
importDeclarations.at(importDeclarations.length - 1).get().insertAfter(linkImport);
|
|
79
|
+
} else {
|
|
80
|
+
source.get().node.program.body.unshift(linkImport);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// If an existing `@atlaskit/link import` is found, import Link if it's not already imported
|
|
84
|
+
else {
|
|
85
|
+
const hasExistingSpecifier = existingLinkImports.some(importDecl => {
|
|
86
|
+
var _importDecl$value$spe2;
|
|
87
|
+
return Boolean((_importDecl$value$spe2 = importDecl.value.specifiers) === null || _importDecl$value$spe2 === void 0 ? void 0 : _importDecl$value$spe2.some(specifier => {
|
|
88
|
+
var _specifier$local2;
|
|
89
|
+
const isDefaultImport = specifier.type === 'ImportDefaultSpecifier';
|
|
90
|
+
if (isDefaultImport && (_specifier$local2 = specifier.local) !== null && _specifier$local2 !== void 0 && _specifier$local2.name) {
|
|
91
|
+
var _specifier$local3;
|
|
92
|
+
linkImportName = (_specifier$local3 = specifier.local) === null || _specifier$local3 === void 0 ? void 0 : _specifier$local3.name;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
if (!hasExistingSpecifier) {
|
|
98
|
+
existingLinkImports.at(0).get().node.specifiers.push(j.importDefaultSpecifier(j.identifier(linkImportName)));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
nativeLinksSupportedForMigration.forEach(link => {
|
|
102
|
+
const {
|
|
103
|
+
attributes
|
|
104
|
+
} = link.node.openingElement;
|
|
105
|
+
|
|
106
|
+
// Remove role="link" attributes
|
|
107
|
+
const filteredAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attr => {
|
|
108
|
+
var _attr$value;
|
|
109
|
+
return !(attr.type === 'JSXAttribute' && attr.name.name === 'role' && ((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral' && attr.value.value === 'link');
|
|
110
|
+
});
|
|
111
|
+
j(link).replaceWith(j.jsxElement.from({
|
|
112
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier(linkImportName), filteredAttributes, false),
|
|
113
|
+
closingElement: j.jsxClosingElement(j.jsxIdentifier(linkImportName)),
|
|
114
|
+
children: link.node.children
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
nativeLinksUnsupportedForMigration.forEach(link => {
|
|
119
|
+
addCommentBefore(j, j(link.path), `
|
|
120
|
+
${link.unsupportedMigrations.map(unsupported => {
|
|
121
|
+
switch (unsupported.reason) {
|
|
122
|
+
case 'styleProp':
|
|
123
|
+
return stylePropComment({
|
|
124
|
+
propName: unsupported.name
|
|
125
|
+
});
|
|
126
|
+
case 'spreadProps':
|
|
127
|
+
return spreadPropsComment;
|
|
128
|
+
default:
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}).join('\n')}
|
|
132
|
+
${genericUnsupportedMigrationComment()}\n
|
|
133
|
+
`);
|
|
134
|
+
});
|
|
135
|
+
return source.toSource(PRINT_SETTINGS);
|
|
136
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import migrateToLinkTransformer from './codemods/migrate-to-link';
|
|
2
|
+
export default async function transformer(file, api) {
|
|
3
|
+
const transformers = [migrateToLinkTransformer];
|
|
4
|
+
let src = file.source;
|
|
5
|
+
transformers.forEach(transformer => {
|
|
6
|
+
if (typeof src === 'undefined') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const nextSrc = transformer({
|
|
10
|
+
...file,
|
|
11
|
+
source: src
|
|
12
|
+
}, api);
|
|
13
|
+
if (nextSrc) {
|
|
14
|
+
src = nextSrc;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return src;
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LINK_ENTRY_POINT } from './constants';
|
|
2
|
+
export const stylePropComment = ({
|
|
3
|
+
propName,
|
|
4
|
+
prefix = ''
|
|
5
|
+
}) => {
|
|
6
|
+
return `${prefix}This link could not be migrated due to custom styles in \`${propName}\` prop.`;
|
|
7
|
+
};
|
|
8
|
+
export const spreadPropsComment = `This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.`;
|
|
9
|
+
export const genericUnsupportedMigrationComment = (prefix = '') => `${prefix}- If this is a simple text-based link, replace with \`${LINK_ENTRY_POINT}\`.
|
|
10
|
+
${prefix}- If this is a button-like link style, replace with a link button from \`@atlaskit/button\`.
|
|
11
|
+
${prefix}- If this needs to retain custom styles, use the \`Anchor\` primitive from \`@atlaskit/primitives\`.`;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const findJSXAttributeWithValue = (path, attributeName, attributeValue) => {
|
|
2
|
+
var _path$attributes;
|
|
3
|
+
if (!path || path.type === 'JSXSpreadAttribute') {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const attribute = path === null || path === void 0 ? void 0 : (_path$attributes = path.attributes) === null || _path$attributes === void 0 ? void 0 : _path$attributes.find(attribute => {
|
|
7
|
+
var _attribute$value;
|
|
8
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === attributeName && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && attribute.value.value === attributeValue;
|
|
9
|
+
});
|
|
10
|
+
return Boolean(attribute);
|
|
11
|
+
};
|
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.
|
|
301
|
+
_process$env$_PACKAGE = "0.27.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) {
|
|
@@ -6,10 +6,11 @@ import path from 'path';
|
|
|
6
6
|
*/
|
|
7
7
|
import './styled-to-emotion/styled-to-emotion';
|
|
8
8
|
import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
|
|
9
|
+
import './migrate-to-link/migrate-to-link';
|
|
9
10
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
10
11
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
11
12
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
12
|
-
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(function (preset) {
|
|
13
|
+
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options'].map(function (preset) {
|
|
13
14
|
return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
|
|
14
15
|
});
|
|
15
16
|
export default presets;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
|
|
3
|
+
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
+
import { getImportDeclaration } from '@hypermod/utils';
|
|
5
|
+
import { LINK_ENTRY_POINT, LINK_EXPORT_NAME, PRINT_SETTINGS, UNSUPPORTED_STYLE_PROPS } from '../utils/constants';
|
|
6
|
+
import { genericUnsupportedMigrationComment, spreadPropsComment, stylePropComment } from '../utils/comments';
|
|
7
|
+
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
8
|
+
export default function transformer(file, api) {
|
|
9
|
+
var j = api.jscodeshift;
|
|
10
|
+
var source = j(file.source);
|
|
11
|
+
|
|
12
|
+
// Find all native links
|
|
13
|
+
var nativeLinks = source.find(j.JSXElement).filter(function (path) {
|
|
14
|
+
return path.value.openingElement.name.type === 'JSXIdentifier' && /^[a-z]+$/.test(path.value.openingElement.name.name) && (path.value.openingElement.name.name === 'a' || findJSXAttributeWithValue(path.value.openingElement, 'role', 'link'));
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// No native links are found, exit early
|
|
18
|
+
if (!nativeLinks.length) {
|
|
19
|
+
return file.source;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Links we can migrate
|
|
23
|
+
var nativeLinksSupportedForMigration = [];
|
|
24
|
+
|
|
25
|
+
// Links we can't migrate, but will leave a code comment as a suggestion for manual migration
|
|
26
|
+
var nativeLinksUnsupportedForMigration = [];
|
|
27
|
+
|
|
28
|
+
// Check for existing imports
|
|
29
|
+
var existingLinkImports = getImportDeclaration(j, source, LINK_ENTRY_POINT);
|
|
30
|
+
|
|
31
|
+
// Sets import name to be used. May be updated if an existing import is found with a different name
|
|
32
|
+
var linkImportName = LINK_EXPORT_NAME;
|
|
33
|
+
nativeLinks.forEach(function (path) {
|
|
34
|
+
var _path$value$openingEl;
|
|
35
|
+
var unsupportedMigrations = (_path$value$openingEl = path.value.openingElement) === null || _path$value$openingEl === void 0 || (_path$value$openingEl = _path$value$openingEl.attributes) === null || _path$value$openingEl === void 0 ? void 0 : _path$value$openingEl.reduce(function (acc, attribute) {
|
|
36
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
37
|
+
acc.push({
|
|
38
|
+
name: '',
|
|
39
|
+
reason: 'spreadProps'
|
|
40
|
+
});
|
|
41
|
+
} else if (UNSUPPORTED_STYLE_PROPS.includes(attribute.name.name.toString())) {
|
|
42
|
+
acc.push({
|
|
43
|
+
name: attribute.name.name.toString(),
|
|
44
|
+
reason: 'styleProp'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return acc;
|
|
48
|
+
}, []);
|
|
49
|
+
if (unsupportedMigrations !== null && unsupportedMigrations !== void 0 && unsupportedMigrations.length) {
|
|
50
|
+
nativeLinksUnsupportedForMigration.push({
|
|
51
|
+
path: path,
|
|
52
|
+
unsupportedMigrations: unsupportedMigrations
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
nativeLinksSupportedForMigration.push(path);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (nativeLinksSupportedForMigration.length) {
|
|
59
|
+
// Generate a unique import name if there is a different existing import named "Link"
|
|
60
|
+
var importNameSuffix = 1;
|
|
61
|
+
var uniqueLinkImportName = linkImportName;
|
|
62
|
+
while (source.find(j.ImportDeclaration).some(function (importDecl) {
|
|
63
|
+
var _importDecl$value$spe;
|
|
64
|
+
return Boolean((_importDecl$value$spe = importDecl.value.specifiers) === null || _importDecl$value$spe === void 0 ? void 0 : _importDecl$value$spe.some(function (specifier) {
|
|
65
|
+
var _specifier$local;
|
|
66
|
+
return ((_specifier$local = specifier.local) === null || _specifier$local === void 0 ? void 0 : _specifier$local.name) === uniqueLinkImportName;
|
|
67
|
+
}));
|
|
68
|
+
})) {
|
|
69
|
+
uniqueLinkImportName = "".concat(linkImportName).concat(importNameSuffix);
|
|
70
|
+
importNameSuffix++;
|
|
71
|
+
}
|
|
72
|
+
linkImportName = uniqueLinkImportName;
|
|
73
|
+
|
|
74
|
+
// Add link import
|
|
75
|
+
// If no existing link imports are found, add a new import
|
|
76
|
+
if (!existingLinkImports.length) {
|
|
77
|
+
var linkImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(linkImportName))], j.stringLiteral(LINK_ENTRY_POINT));
|
|
78
|
+
var importDeclarations = source.find(j.ImportDeclaration);
|
|
79
|
+
if (importDeclarations.length) {
|
|
80
|
+
importDeclarations.at(importDeclarations.length - 1).get().insertAfter(linkImport);
|
|
81
|
+
} else {
|
|
82
|
+
source.get().node.program.body.unshift(linkImport);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// If an existing `@atlaskit/link import` is found, import Link if it's not already imported
|
|
86
|
+
else {
|
|
87
|
+
var hasExistingSpecifier = existingLinkImports.some(function (importDecl) {
|
|
88
|
+
var _importDecl$value$spe2;
|
|
89
|
+
return Boolean((_importDecl$value$spe2 = importDecl.value.specifiers) === null || _importDecl$value$spe2 === void 0 ? void 0 : _importDecl$value$spe2.some(function (specifier) {
|
|
90
|
+
var _specifier$local2;
|
|
91
|
+
var isDefaultImport = specifier.type === 'ImportDefaultSpecifier';
|
|
92
|
+
if (isDefaultImport && (_specifier$local2 = specifier.local) !== null && _specifier$local2 !== void 0 && _specifier$local2.name) {
|
|
93
|
+
var _specifier$local3;
|
|
94
|
+
linkImportName = (_specifier$local3 = specifier.local) === null || _specifier$local3 === void 0 ? void 0 : _specifier$local3.name;
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
if (!hasExistingSpecifier) {
|
|
100
|
+
existingLinkImports.at(0).get().node.specifiers.push(j.importDefaultSpecifier(j.identifier(linkImportName)));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
nativeLinksSupportedForMigration.forEach(function (link) {
|
|
104
|
+
var attributes = link.node.openingElement.attributes;
|
|
105
|
+
|
|
106
|
+
// Remove role="link" attributes
|
|
107
|
+
var filteredAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) {
|
|
108
|
+
var _attr$value;
|
|
109
|
+
return !(attr.type === 'JSXAttribute' && attr.name.name === 'role' && ((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral' && attr.value.value === 'link');
|
|
110
|
+
});
|
|
111
|
+
j(link).replaceWith(j.jsxElement.from({
|
|
112
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier(linkImportName), filteredAttributes, false),
|
|
113
|
+
closingElement: j.jsxClosingElement(j.jsxIdentifier(linkImportName)),
|
|
114
|
+
children: link.node.children
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
nativeLinksUnsupportedForMigration.forEach(function (link) {
|
|
119
|
+
addCommentBefore(j, j(link.path), "\n".concat(link.unsupportedMigrations.map(function (unsupported) {
|
|
120
|
+
switch (unsupported.reason) {
|
|
121
|
+
case 'styleProp':
|
|
122
|
+
return stylePropComment({
|
|
123
|
+
propName: unsupported.name
|
|
124
|
+
});
|
|
125
|
+
case 'spreadProps':
|
|
126
|
+
return spreadPropsComment;
|
|
127
|
+
default:
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}).join('\n'), "\n").concat(genericUnsupportedMigrationComment(), "\n\n"));
|
|
131
|
+
});
|
|
132
|
+
return source.toSource(PRINT_SETTINGS);
|
|
133
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
import migrateToLinkTransformer from './codemods/migrate-to-link';
|
|
7
|
+
export default function transformer(_x, _x2) {
|
|
8
|
+
return _transformer.apply(this, arguments);
|
|
9
|
+
}
|
|
10
|
+
function _transformer() {
|
|
11
|
+
_transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(file, api) {
|
|
12
|
+
var transformers, src;
|
|
13
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
14
|
+
while (1) switch (_context.prev = _context.next) {
|
|
15
|
+
case 0:
|
|
16
|
+
transformers = [migrateToLinkTransformer];
|
|
17
|
+
src = file.source;
|
|
18
|
+
transformers.forEach(function (transformer) {
|
|
19
|
+
if (typeof src === 'undefined') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
var nextSrc = transformer(_objectSpread(_objectSpread({}, file), {}, {
|
|
23
|
+
source: src
|
|
24
|
+
}), api);
|
|
25
|
+
if (nextSrc) {
|
|
26
|
+
src = nextSrc;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return _context.abrupt("return", src);
|
|
30
|
+
case 4:
|
|
31
|
+
case "end":
|
|
32
|
+
return _context.stop();
|
|
33
|
+
}
|
|
34
|
+
}, _callee);
|
|
35
|
+
}));
|
|
36
|
+
return _transformer.apply(this, arguments);
|
|
37
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LINK_ENTRY_POINT } from './constants';
|
|
2
|
+
export var stylePropComment = function stylePropComment(_ref) {
|
|
3
|
+
var propName = _ref.propName,
|
|
4
|
+
_ref$prefix = _ref.prefix,
|
|
5
|
+
prefix = _ref$prefix === void 0 ? '' : _ref$prefix;
|
|
6
|
+
return "".concat(prefix, "This link could not be migrated due to custom styles in `").concat(propName, "` prop.");
|
|
7
|
+
};
|
|
8
|
+
export var spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
|
|
9
|
+
export var genericUnsupportedMigrationComment = function genericUnsupportedMigrationComment() {
|
|
10
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
11
|
+
return "".concat(prefix, "- If this is a simple text-based link, replace with `").concat(LINK_ENTRY_POINT, "`.\n").concat(prefix, "- If this is a button-like link style, replace with a link button from `@atlaskit/button`.\n").concat(prefix, "- If this needs to retain custom styles, use the `Anchor` primitive from `@atlaskit/primitives`.");
|
|
12
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export var findJSXAttributeWithValue = function findJSXAttributeWithValue(path, attributeName, attributeValue) {
|
|
2
|
+
var _path$attributes;
|
|
3
|
+
if (!path || path.type === 'JSXSpreadAttribute') {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
var attribute = path === null || path === void 0 || (_path$attributes = path.attributes) === null || _path$attributes === void 0 ? void 0 : _path$attributes.find(function (attribute) {
|
|
7
|
+
var _attribute$value;
|
|
8
|
+
return attribute.type === 'JSXAttribute' && attribute.name.name === attributeName && ((_attribute$value = attribute.value) === null || _attribute$value === void 0 ? void 0 : _attribute$value.type) === 'StringLiteral' && attribute.value.value === attributeValue;
|
|
9
|
+
});
|
|
10
|
+
return Boolean(attribute);
|
|
11
|
+
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import './styled-to-emotion/styled-to-emotion';
|
|
6
6
|
import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
|
|
7
|
+
import './migrate-to-link/migrate-to-link';
|
|
7
8
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
8
9
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
9
10
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const stylePropComment: ({ propName, prefix, }: {
|
|
2
|
+
propName: string;
|
|
3
|
+
prefix?: string | undefined;
|
|
4
|
+
}) => string;
|
|
5
|
+
export declare const spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
|
|
6
|
+
export declare const genericUnsupportedMigrationComment: (prefix?: string) => string;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import './styled-to-emotion/styled-to-emotion';
|
|
6
6
|
import './theme-remove-deprecated-mixins/theme-remove-deprecated-mixins';
|
|
7
|
+
import './migrate-to-link/migrate-to-link';
|
|
7
8
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
8
9
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
9
10
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const stylePropComment: ({ propName, prefix, }: {
|
|
2
|
+
propName: string;
|
|
3
|
+
prefix?: string | undefined;
|
|
4
|
+
}) => string;
|
|
5
|
+
export declare const spreadPropsComment = "This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.";
|
|
6
|
+
export declare const genericUnsupportedMigrationComment: (prefix?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/codemod-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "A cli for distributing codemods for atlassian-frontend components and services",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"bin": "./bin/codemod-cli.js",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
42
|
-
"@atlaskit/tokens": "^2.
|
|
42
|
+
"@atlaskit/tokens": "^2.3.0",
|
|
43
43
|
"@babel/runtime": "^7.0.0",
|
|
44
44
|
"@codeshift/utils": "^0.2.4",
|
|
45
45
|
"@hypermod/utils": "^0.4.2",
|