@atlaskit/codemod-cli 0.33.1 → 0.34.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 +16 -0
- package/dist/cjs/main.js +1 -1
- package/dist/cjs/presets/index.js +3 -1
- package/dist/cjs/presets/lozenge-discovery-to-tag-with-fg/codemods/lozenge-discovery-to-tag-with-fg.js +219 -0
- package/dist/cjs/presets/lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg.js +44 -0
- package/dist/cjs/presets/migrate-deprecated-icon/codemods/migrate-deprecated-icon.js +142 -0
- package/dist/cjs/presets/migrate-deprecated-icon/migrate-deprecated-icon.js +44 -0
- package/dist/cjs/presets/migrate-deprecated-icon/utils/mock.js +81 -0
- package/dist/es2019/presets/index.js +3 -1
- package/dist/es2019/presets/lozenge-discovery-to-tag-with-fg/codemods/lozenge-discovery-to-tag-with-fg.js +207 -0
- package/dist/es2019/presets/lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg.js +18 -0
- package/dist/es2019/presets/migrate-deprecated-icon/codemods/migrate-deprecated-icon.js +130 -0
- package/dist/es2019/presets/migrate-deprecated-icon/migrate-deprecated-icon.js +18 -0
- package/dist/es2019/presets/migrate-deprecated-icon/utils/mock.js +75 -0
- package/dist/esm/main.js +1 -1
- package/dist/esm/presets/index.js +3 -1
- package/dist/esm/presets/lozenge-discovery-to-tag-with-fg/codemods/lozenge-discovery-to-tag-with-fg.js +213 -0
- package/dist/esm/presets/lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg.js +37 -0
- package/dist/esm/presets/migrate-deprecated-icon/codemods/migrate-deprecated-icon.js +135 -0
- package/dist/esm/presets/migrate-deprecated-icon/migrate-deprecated-icon.js +37 -0
- package/dist/esm/presets/migrate-deprecated-icon/utils/mock.js +75 -0
- package/dist/types/presets/index.d.ts +2 -0
- package/dist/types/presets/lozenge-discovery-to-tag-with-fg/codemods/lozenge-discovery-to-tag-with-fg.d.ts +12 -0
- package/dist/types/presets/lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg.d.ts +2 -0
- package/dist/types/presets/migrate-deprecated-icon/codemods/migrate-deprecated-icon.d.ts +3 -0
- package/dist/types/presets/migrate-deprecated-icon/migrate-deprecated-icon.d.ts +2 -0
- package/dist/types-ts4.5/presets/index.d.ts +2 -0
- package/dist/types-ts4.5/presets/lozenge-discovery-to-tag-with-fg/codemods/lozenge-discovery-to-tag-with-fg.d.ts +12 -0
- package/dist/types-ts4.5/presets/lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-deprecated-icon/codemods/migrate-deprecated-icon.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-deprecated-icon/migrate-deprecated-icon.d.ts +2 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.34.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`7e8bbc2620251`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7e8bbc2620251) -
|
|
8
|
+
Added a codemod lozenge-discovery-to-tag-with-fg to migrate Lozenge components with
|
|
9
|
+
appearance='new' or 'discovery' to Tag behind feature gate.
|
|
10
|
+
|
|
11
|
+
## 0.33.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`036c3ee917e3c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/036c3ee917e3c) -
|
|
16
|
+
Icon migration entry point update
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 0.33.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/main.js
CHANGED
|
@@ -362,7 +362,7 @@ function _main() {
|
|
|
362
362
|
case 4:
|
|
363
363
|
_yield$parseArgs = _context6.sent;
|
|
364
364
|
packages = _yield$parseArgs.packages;
|
|
365
|
-
_process$env$_PACKAGE = "0.
|
|
365
|
+
_process$env$_PACKAGE = "0.0.0-development", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
366
366
|
logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
367
367
|
if (packages && packages.length > 0) {
|
|
368
368
|
logger.log(_chalk.default.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
|
|
@@ -16,14 +16,16 @@ require("./remove-dark-theme-vr-options/remove-dark-theme-vr-options");
|
|
|
16
16
|
require("./remove-token-fallbacks/remove-token-fallbacks");
|
|
17
17
|
require("./lozenge-appearance-semantic-migration/lozenge-appearance-semantic-migration");
|
|
18
18
|
require("./lozenge-to-tag-migration/lozenge-to-tag-migration");
|
|
19
|
+
require("./lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg");
|
|
19
20
|
require("./badge-appearance-semantic-migration/badge-appearance-semantic-migration");
|
|
20
21
|
require("./tag-to-newTag-migration/tag-to-newTag-migration");
|
|
22
|
+
require("./migrate-deprecated-icon/migrate-deprecated-icon");
|
|
21
23
|
/**
|
|
22
24
|
* Manually import presets to make sure typescript includes them
|
|
23
25
|
* in the final bundle.
|
|
24
26
|
*/
|
|
25
27
|
|
|
26
|
-
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks', 'lozenge-appearance-semantic-migration', 'lozenge-to-tag-migration', 'badge-appearance-semantic-migration', 'tag-to-newTag-migration'].map(function (preset) {
|
|
28
|
+
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-deprecated-icon', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks', 'lozenge-appearance-semantic-migration', 'lozenge-to-tag-migration', 'lozenge-discovery-to-tag-with-fg', 'badge-appearance-semantic-migration', 'tag-to-newTag-migration'].map(function (preset) {
|
|
27
29
|
return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
|
|
28
30
|
});
|
|
29
31
|
var _default = exports.default = presets;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformer;
|
|
7
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
8
|
+
|
|
9
|
+
var LOZENGE_ENTRY_POINT = '@atlaskit/lozenge';
|
|
10
|
+
var TAG_ENTRY_POINT = '@atlaskit/tag';
|
|
11
|
+
var FG_ENTRY_POINT = '@atlassian/jira-feature-gating';
|
|
12
|
+
var FEATURE_GATE_NAME = 'platform-dst-lozenge-tag-badge-visual-uplifts';
|
|
13
|
+
var PRINT_SETTINGS = {
|
|
14
|
+
quote: 'single'
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Codemod to migrate Lozenge components with appearance='new' or 'discovery' to Tag behind feature gate.
|
|
18
|
+
*
|
|
19
|
+
* This codemod:
|
|
20
|
+
* 1. Finds Lozenges with appearance="new" or appearance="discovery"
|
|
21
|
+
* 2. Also includes discovery Lozenges with isBold={true} or isBold
|
|
22
|
+
* 3. Wraps them in a feature gate: fg('platform-dst-lozenge-tag-badge-visual-uplifts')
|
|
23
|
+
* 4. Converts to Tag with color="purple" when feature gate is off
|
|
24
|
+
* 5. Adds necessary imports (Tag, fg)
|
|
25
|
+
*/
|
|
26
|
+
function transformer(file, api) {
|
|
27
|
+
var j = api.jscodeshift;
|
|
28
|
+
var source;
|
|
29
|
+
|
|
30
|
+
// Try to parse the file
|
|
31
|
+
try {
|
|
32
|
+
source = j(file.source);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// eslint-disable-next-line no-console
|
|
35
|
+
console.error(error);
|
|
36
|
+
return file.source;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Check if Lozenge is imported from @atlaskit/lozenge
|
|
40
|
+
var hasLozengeImport = source.find(j.ImportDeclaration).some(function (importPath) {
|
|
41
|
+
return importPath.value.source.value === LOZENGE_ENTRY_POINT;
|
|
42
|
+
});
|
|
43
|
+
if (!hasLozengeImport) {
|
|
44
|
+
return file.source;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Get all Lozenge component names (handles renamed imports)
|
|
48
|
+
var lozengeNames = new Set();
|
|
49
|
+
source.find(j.ImportDeclaration).forEach(function (importPath) {
|
|
50
|
+
if (importPath.value.source.value === LOZENGE_ENTRY_POINT) {
|
|
51
|
+
var _importPath$value$spe;
|
|
52
|
+
(_importPath$value$spe = importPath.value.specifiers) === null || _importPath$value$spe === void 0 || _importPath$value$spe.forEach(function (specifier) {
|
|
53
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
54
|
+
lozengeNames.add(specifier.local.name);
|
|
55
|
+
} else if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'default') {
|
|
56
|
+
lozengeNames.add(specifier.local.name);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Find all Lozenge elements that should be migrated
|
|
63
|
+
var lozengeElements = [];
|
|
64
|
+
source.find(j.JSXElement).forEach(function (path) {
|
|
65
|
+
var _openingElement$name;
|
|
66
|
+
var openingElement = path.value.openingElement;
|
|
67
|
+
if (((_openingElement$name = openingElement.name) === null || _openingElement$name === void 0 ? void 0 : _openingElement$name.type) === 'JSXIdentifier' && lozengeNames.has(openingElement.name.name)) {
|
|
68
|
+
var _openingElement$attri;
|
|
69
|
+
var element = {
|
|
70
|
+
path: path,
|
|
71
|
+
shouldMigrate: false
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Check for appearance and isBold props
|
|
75
|
+
(_openingElement$attri = openingElement.attributes) === null || _openingElement$attri === void 0 || _openingElement$attri.forEach(function (attr) {
|
|
76
|
+
var _attr$name;
|
|
77
|
+
if (attr.type === 'JSXAttribute' && ((_attr$name = attr.name) === null || _attr$name === void 0 ? void 0 : _attr$name.type) === 'JSXIdentifier') {
|
|
78
|
+
if (attr.name.name === 'appearance') {
|
|
79
|
+
var _attr$value, _attr$value2;
|
|
80
|
+
if (((_attr$value = attr.value) === null || _attr$value === void 0 ? void 0 : _attr$value.type) === 'StringLiteral') {
|
|
81
|
+
element.appearanceValue = attr.value.value;
|
|
82
|
+
} else if (((_attr$value2 = attr.value) === null || _attr$value2 === void 0 ? void 0 : _attr$value2.type) === 'JSXExpressionContainer') {
|
|
83
|
+
var expression = attr.value.expression;
|
|
84
|
+
if (expression.type === 'StringLiteral') {
|
|
85
|
+
element.appearanceValue = expression.value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} else if (attr.name.name === 'isBold') {
|
|
89
|
+
var _attr$value3;
|
|
90
|
+
if (attr.value === null) {
|
|
91
|
+
element.isBoldValue = true;
|
|
92
|
+
} else if (((_attr$value3 = attr.value) === null || _attr$value3 === void 0 ? void 0 : _attr$value3.type) === 'JSXExpressionContainer') {
|
|
93
|
+
var _expression = attr.value.expression;
|
|
94
|
+
if (_expression.type === 'BooleanLiteral') {
|
|
95
|
+
element.isBoldValue = _expression.value;
|
|
96
|
+
} else if (_expression.type === 'Literal' && typeof _expression.value === 'boolean') {
|
|
97
|
+
element.isBoldValue = _expression.value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Determine if this Lozenge should be migrated
|
|
105
|
+
// Migrate if: appearance="new" OR appearance="discovery" OR (appearance="discovery" AND isBold={true})
|
|
106
|
+
if (element.appearanceValue === 'new' || element.appearanceValue === 'discovery' || element.appearanceValue === 'discovery' && element.isBoldValue === true) {
|
|
107
|
+
element.shouldMigrate = true;
|
|
108
|
+
}
|
|
109
|
+
if (element.shouldMigrate) {
|
|
110
|
+
lozengeElements.push(element);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// If no elements to migrate, return early
|
|
116
|
+
if (lozengeElements.length === 0) {
|
|
117
|
+
return file.source;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check if Tag import exists
|
|
121
|
+
var hasTagImport = source.find(j.ImportDeclaration).some(function (importPath) {
|
|
122
|
+
return importPath.value.source.value === TAG_ENTRY_POINT;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Check if fg is already imported from @atlassian/jira-feature-gating
|
|
126
|
+
var hasFgImport = source.find(j.ImportDeclaration).some(function (importPath) {
|
|
127
|
+
if (importPath.value.source.value === FG_ENTRY_POINT) {
|
|
128
|
+
var _importPath$value$spe2;
|
|
129
|
+
// Check if 'fg' is in the specifiers
|
|
130
|
+
return (_importPath$value$spe2 = importPath.value.specifiers) === null || _importPath$value$spe2 === void 0 ? void 0 : _importPath$value$spe2.some(function (spec) {
|
|
131
|
+
return spec.type === 'ImportSpecifier' && spec.imported.name === 'fg';
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Add imports after Lozenge import to avoid blank lines
|
|
138
|
+
var lozengeImport = source.find(j.ImportDeclaration).filter(function (path) {
|
|
139
|
+
return path.value.source.value === LOZENGE_ENTRY_POINT;
|
|
140
|
+
}).at(0);
|
|
141
|
+
if (lozengeImport.length > 0) {
|
|
142
|
+
// Add imports in reverse order so they appear in the right order
|
|
143
|
+
if (!hasFgImport) {
|
|
144
|
+
lozengeImport.insertAfter(j.importDeclaration([j.importSpecifier(j.identifier('fg'))], j.stringLiteral(FG_ENTRY_POINT)));
|
|
145
|
+
}
|
|
146
|
+
if (!hasTagImport) {
|
|
147
|
+
lozengeImport.insertAfter(j.importDeclaration([j.importDefaultSpecifier(j.identifier('Tag'))], j.stringLiteral(TAG_ENTRY_POINT)));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Transform each element
|
|
152
|
+
lozengeElements.forEach(function (element) {
|
|
153
|
+
var _openingElement$attri2;
|
|
154
|
+
var path = element.path;
|
|
155
|
+
var openingElement = path.value.openingElement;
|
|
156
|
+
|
|
157
|
+
// Extract text content or JSX expression from children
|
|
158
|
+
var children = path.value.children;
|
|
159
|
+
var textAttribute = null;
|
|
160
|
+
if (children && children.length > 0) {
|
|
161
|
+
// Check if there's a single JSX expression child (e.g., {formatMessage(...)})
|
|
162
|
+
if (children.length === 1 && children[0].type === 'JSXExpressionContainer') {
|
|
163
|
+
var expression = children[0].expression;
|
|
164
|
+
// Use the expression as the text value
|
|
165
|
+
textAttribute = j.jsxAttribute(j.jsxIdentifier('text'), j.jsxExpressionContainer(expression));
|
|
166
|
+
} else {
|
|
167
|
+
// Extract plain text content from JSXText nodes
|
|
168
|
+
var textContent = children.filter(function (child) {
|
|
169
|
+
return child.type === 'JSXText';
|
|
170
|
+
}).map(function (child) {
|
|
171
|
+
return child.value.trim();
|
|
172
|
+
}).filter(function (text) {
|
|
173
|
+
return text.length > 0;
|
|
174
|
+
}).join(' ');
|
|
175
|
+
if (textContent) {
|
|
176
|
+
textAttribute = j.jsxAttribute(j.jsxIdentifier('text'), j.stringLiteral(textContent));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Create the Tag element
|
|
182
|
+
var tagAttributes = [j.jsxAttribute(j.jsxIdentifier('color'), j.stringLiteral('purple'))];
|
|
183
|
+
if (textAttribute) {
|
|
184
|
+
tagAttributes.unshift(textAttribute);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Copy other props from Lozenge to Tag (except appearance and isBold)
|
|
188
|
+
(_openingElement$attri2 = openingElement.attributes) === null || _openingElement$attri2 === void 0 || _openingElement$attri2.forEach(function (attr) {
|
|
189
|
+
var _attr$name2;
|
|
190
|
+
if (attr.type === 'JSXAttribute' && ((_attr$name2 = attr.name) === null || _attr$name2 === void 0 ? void 0 : _attr$name2.type) === 'JSXIdentifier') {
|
|
191
|
+
if (attr.name.name !== 'appearance' && attr.name.name !== 'isBold') {
|
|
192
|
+
tagAttributes.push(attr);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
var tagElement = j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier('Tag'), tagAttributes, true), null, []);
|
|
197
|
+
|
|
198
|
+
// Keep the original Lozenge element (just the element, without wrapping)
|
|
199
|
+
var lozengeElement = path.value;
|
|
200
|
+
|
|
201
|
+
// Create the conditional expression: fg(FEATURE_GATE_NAME) ? <Tag .../> : <Lozenge .../>
|
|
202
|
+
// When feature gate is ON, show Tag (new behavior)
|
|
203
|
+
// When feature gate is OFF, show Lozenge (old behavior)
|
|
204
|
+
var conditionalExpression = j.conditionalExpression(j.callExpression(j.identifier('fg'), [j.stringLiteral(FEATURE_GATE_NAME)]), tagElement, lozengeElement);
|
|
205
|
+
|
|
206
|
+
// Check if the parent is a JSXElement (means we're inside JSX, need curly braces)
|
|
207
|
+
// Otherwise, it's a regular expression (like in a return statement)
|
|
208
|
+
var parent = path.parent;
|
|
209
|
+
var needsJSXWrapper = parent && (parent.value.type === 'JSXElement' || parent.value.type === 'JSXExpressionContainer');
|
|
210
|
+
if (needsJSXWrapper) {
|
|
211
|
+
// Inside JSX, wrap in expression container
|
|
212
|
+
j(path).replaceWith(j.jsxExpressionContainer(conditionalExpression));
|
|
213
|
+
} else {
|
|
214
|
+
// In regular JS context (like return statement), just use the conditional
|
|
215
|
+
j(path).replaceWith(conditionalExpression);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return source.toSource(PRINT_SETTINGS);
|
|
219
|
+
}
|
|
@@ -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 _lozengeDiscoveryToTagWithFg = _interopRequireDefault(require("./codemods/lozenge-discovery-to-tag-with-fg"));
|
|
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 = [_lozengeDiscoveryToTagWithFg.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,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _deprecatedMap = require("@atlaskit/icon-lab/deprecated-map");
|
|
9
|
+
var _metadata = _interopRequireDefault(require("@atlaskit/icon-lab/metadata"));
|
|
10
|
+
var _deprecatedMap2 = require("@atlaskit/icon/deprecated-map");
|
|
11
|
+
var _metadata2 = require("@atlaskit/icon/metadata");
|
|
12
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
13
|
+
|
|
14
|
+
var extractIconName = function extractIconName(importPath) {
|
|
15
|
+
var match = importPath.match(/\/([^\/]+)$/);
|
|
16
|
+
return match ? match[1] : '';
|
|
17
|
+
};
|
|
18
|
+
var getIconComponentName = function getIconComponentName(name) {
|
|
19
|
+
return name.split(/\W/).map(function (part) {
|
|
20
|
+
return "".concat(part[0].toUpperCase()).concat(part.slice(1));
|
|
21
|
+
}).join('').concat('Icon');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new default import declaration for the transformed component
|
|
26
|
+
*/
|
|
27
|
+
var createDefaultImportDeclaration = function createDefaultImportDeclaration(j, componentName, importPath) {
|
|
28
|
+
var defaultSpecifier = j.importDefaultSpecifier(j.identifier(componentName));
|
|
29
|
+
return j.importDeclaration([defaultSpecifier], j.stringLiteral(importPath));
|
|
30
|
+
};
|
|
31
|
+
var PRINT_SETTINGS = {
|
|
32
|
+
quote: 'single',
|
|
33
|
+
trailingComma: true
|
|
34
|
+
};
|
|
35
|
+
var transformer = function transformer(file, api) {
|
|
36
|
+
var j = api.jscodeshift;
|
|
37
|
+
var fileSource = j(file.source);
|
|
38
|
+
var deprecatedIcons = Object.keys(_deprecatedMap2.deprecatedCore);
|
|
39
|
+
var deprecatedIconLabIcons = Object.keys(_deprecatedMap.deprecatedCore);
|
|
40
|
+
|
|
41
|
+
// Find all deprecated icon imports
|
|
42
|
+
var deprecatedIconImports = fileSource.find(j.ImportDeclaration).filter(function (path) {
|
|
43
|
+
var _coreIconMetadata$ico, _coreIconLabMetadata$;
|
|
44
|
+
var source = path.node.source.value;
|
|
45
|
+
|
|
46
|
+
//Extract icon name from import path
|
|
47
|
+
var iconName = extractIconName(source);
|
|
48
|
+
var isDeprecated = deprecatedIcons.includes(source) || deprecatedIconLabIcons.includes(source);
|
|
49
|
+
var hasReplacement = !!((_coreIconMetadata$ico = _metadata2.coreIconMetadata[iconName]) !== null && _coreIconMetadata$ico !== void 0 && _coreIconMetadata$ico.replacement) || !!((_coreIconLabMetadata$ = _metadata.default[iconName]) !== null && _coreIconLabMetadata$ !== void 0 && _coreIconLabMetadata$.replacement);
|
|
50
|
+
return typeof source === 'string' && isDeprecated && hasReplacement;
|
|
51
|
+
});
|
|
52
|
+
if (!deprecatedIconImports.length) {
|
|
53
|
+
return fileSource.toSource();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Track import name mappings (old name -> new name) and new imports to create
|
|
57
|
+
var importNameMappings = new Map();
|
|
58
|
+
var newImportsToCreate = [];
|
|
59
|
+
|
|
60
|
+
// Process each icon-object import
|
|
61
|
+
deprecatedIconImports.forEach(function (importPath) {
|
|
62
|
+
var _coreIconMetadata$ico2, _coreIconMetadata$ico3, _coreIconLabMetadata$2, _importDeclaration$sp;
|
|
63
|
+
var importDeclaration = importPath.node;
|
|
64
|
+
var source = importDeclaration.source.value;
|
|
65
|
+
|
|
66
|
+
//Extract icon name from import path
|
|
67
|
+
var iconName = extractIconName(source);
|
|
68
|
+
var replacementIconInfo = (_coreIconMetadata$ico2 = (_coreIconMetadata$ico3 = _metadata2.coreIconMetadata[iconName]) === null || _coreIconMetadata$ico3 === void 0 ? void 0 : _coreIconMetadata$ico3.replacement) !== null && _coreIconMetadata$ico2 !== void 0 ? _coreIconMetadata$ico2 : (_coreIconLabMetadata$2 = _metadata.default[iconName]) === null || _coreIconLabMetadata$2 === void 0 ? void 0 : _coreIconLabMetadata$2.replacement;
|
|
69
|
+
if (!replacementIconInfo) {
|
|
70
|
+
return; // No replacement found, skip
|
|
71
|
+
}
|
|
72
|
+
var replacementIconName = getIconComponentName(replacementIconInfo.name);
|
|
73
|
+
var replacementIconImport = "".concat(replacementIconInfo.location, "/core/").concat(replacementIconInfo.name);
|
|
74
|
+
|
|
75
|
+
// Get the current import name (could be default import or renamed)
|
|
76
|
+
var defaultSpecifier = (_importDeclaration$sp = importDeclaration.specifiers) === null || _importDeclaration$sp === void 0 ? void 0 : _importDeclaration$sp.find(function (spec) {
|
|
77
|
+
return spec.type === 'ImportDefaultSpecifier';
|
|
78
|
+
});
|
|
79
|
+
if (defaultSpecifier) {
|
|
80
|
+
var _defaultSpecifier$loc;
|
|
81
|
+
var currentImportName = (_defaultSpecifier$loc = defaultSpecifier.local) === null || _defaultSpecifier$loc === void 0 ? void 0 : _defaultSpecifier$loc.name;
|
|
82
|
+
if (currentImportName) {
|
|
83
|
+
// Map the old import name to the new component name
|
|
84
|
+
importNameMappings.set(currentImportName, replacementIconName);
|
|
85
|
+
|
|
86
|
+
// Track the new import to create
|
|
87
|
+
newImportsToCreate.push({
|
|
88
|
+
componentName: replacementIconName,
|
|
89
|
+
importPath: replacementIconImport,
|
|
90
|
+
oldImportPath: importPath
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Update JSX elements to use new component names
|
|
97
|
+
importNameMappings.forEach(function (newName, oldName) {
|
|
98
|
+
fileSource.find(j.JSXElement).filter(function (path) {
|
|
99
|
+
var openingElement = path.value.openingElement;
|
|
100
|
+
return openingElement.name.type === 'JSXIdentifier' && openingElement.name.name === oldName;
|
|
101
|
+
}).forEach(function (elementPath) {
|
|
102
|
+
var _element$closingEleme;
|
|
103
|
+
var element = elementPath.value;
|
|
104
|
+
|
|
105
|
+
// Update opening tag
|
|
106
|
+
if (element.openingElement.name.type === 'JSXIdentifier') {
|
|
107
|
+
element.openingElement.name.name = newName;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Update closing tag if it exists
|
|
111
|
+
if (((_element$closingEleme = element.closingElement) === null || _element$closingEleme === void 0 ? void 0 : _element$closingEleme.name.type) === 'JSXIdentifier') {
|
|
112
|
+
element.closingElement.name.name = newName;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Update other references (like in render calls, etc.)
|
|
118
|
+
importNameMappings.forEach(function (newName, oldName) {
|
|
119
|
+
fileSource.find(j.Identifier).filter(function (path) {
|
|
120
|
+
return path.node.name === oldName;
|
|
121
|
+
}).forEach(function (path) {
|
|
122
|
+
var _parent$value, _parent$value2;
|
|
123
|
+
// Only update if it's not part of an import declaration or JSX element
|
|
124
|
+
// (those are handled separately)
|
|
125
|
+
var parent = path.parent;
|
|
126
|
+
if ((parent === null || parent === void 0 || (_parent$value = parent.value) === null || _parent$value === void 0 ? void 0 : _parent$value.type) !== 'ImportDefaultSpecifier' && (parent === null || parent === void 0 || (_parent$value2 = parent.value) === null || _parent$value2 === void 0 ? void 0 : _parent$value2.type) !== 'JSXIdentifier') {
|
|
127
|
+
path.node.name = newName;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Create new individual default imports
|
|
133
|
+
newImportsToCreate.forEach(function (_ref) {
|
|
134
|
+
var componentName = _ref.componentName,
|
|
135
|
+
importPath = _ref.importPath,
|
|
136
|
+
oldImportPath = _ref.oldImportPath;
|
|
137
|
+
var newImport = createDefaultImportDeclaration(j, componentName, importPath);
|
|
138
|
+
oldImportPath.replace(newImport);
|
|
139
|
+
});
|
|
140
|
+
return fileSource.toSource(PRINT_SETTINGS);
|
|
141
|
+
};
|
|
142
|
+
var _default = exports.default = transformer;
|
|
@@ -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 _migrateDeprecatedIcon = _interopRequireDefault(require("./codemods/migrate-deprecated-icon"));
|
|
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 = [_migrateDeprecatedIcon.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,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mockMetadata = exports.mockDeprecatedIcons = void 0;
|
|
7
|
+
var mockMetadata = exports.mockMetadata = {
|
|
8
|
+
coreIconMetadata: {
|
|
9
|
+
capture: {
|
|
10
|
+
keywords: ['capture', 'icon', 'focus', 'focus area', 'capture'],
|
|
11
|
+
componentName: 'CaptureIcon',
|
|
12
|
+
package: '@atlaskit/icon/core/capture',
|
|
13
|
+
oldName: ['jira/capture'],
|
|
14
|
+
replacement: {
|
|
15
|
+
name: 'focus-area',
|
|
16
|
+
location: '@atlaskit/icon'
|
|
17
|
+
},
|
|
18
|
+
categorization: 'single-purpose',
|
|
19
|
+
usage: 'Reserved for representing Focus Areas.',
|
|
20
|
+
team: 'Design System Team',
|
|
21
|
+
status: 'deprecated'
|
|
22
|
+
},
|
|
23
|
+
'chart-matrix': {
|
|
24
|
+
keywords: ['chart-matrix', 'chartmatrix', 'icon', 'dot chart', 'graph', 'matrix', ''],
|
|
25
|
+
componentName: 'ChartMatrixIcon',
|
|
26
|
+
package: '@atlaskit/icon/core/chart-matrix',
|
|
27
|
+
replacement: {
|
|
28
|
+
name: 'chart-bubble',
|
|
29
|
+
location: '@atlaskit/icon'
|
|
30
|
+
},
|
|
31
|
+
categorization: 'multi-purpose',
|
|
32
|
+
usage: 'Multi purpose - Known uses: Matrix view in in JPD, and other matrix charts.',
|
|
33
|
+
team: 'Design System Team',
|
|
34
|
+
status: 'deprecated'
|
|
35
|
+
},
|
|
36
|
+
close: {
|
|
37
|
+
keywords: ['close', 'icon', 'cross', 'x', 'close', 'remove'],
|
|
38
|
+
componentName: 'CloseIcon',
|
|
39
|
+
package: '@atlaskit/icon/core/close',
|
|
40
|
+
oldName: ['cross', 'editor/close'],
|
|
41
|
+
replacement: {
|
|
42
|
+
name: 'cross',
|
|
43
|
+
location: '@atlaskit/icon'
|
|
44
|
+
},
|
|
45
|
+
categorization: 'multi-purpose',
|
|
46
|
+
usage: 'Known uses: closing modals, panels, and transient views; removing tags',
|
|
47
|
+
team: 'Design System Team',
|
|
48
|
+
status: 'deprecated'
|
|
49
|
+
},
|
|
50
|
+
error: {
|
|
51
|
+
keywords: ['error', 'warning', 'alert', 'icon', 'filled', 'status', 'danger', 'exclamation', '!', 'error'],
|
|
52
|
+
componentName: 'ErrorIcon',
|
|
53
|
+
package: '@atlaskit/icon/core/error',
|
|
54
|
+
oldName: ['error'],
|
|
55
|
+
replacement: {
|
|
56
|
+
name: 'status-error',
|
|
57
|
+
location: '@atlaskit/icon'
|
|
58
|
+
},
|
|
59
|
+
categorization: 'single-purpose',
|
|
60
|
+
usage: 'Reserved for error statuses and messaging. Filled status icons provide higher visual contrast to draw attention to important information.',
|
|
61
|
+
team: 'Design System Team',
|
|
62
|
+
status: 'deprecated'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
var mockDeprecatedIcons = exports.mockDeprecatedIcons = {
|
|
67
|
+
deprecatedCore: {
|
|
68
|
+
'@atlaskit/icon/core/capture': {
|
|
69
|
+
message: 'The icon "capture" is deprecated in favour of "focus-area" from "@atlaskit/icon/core"'
|
|
70
|
+
},
|
|
71
|
+
'@atlaskit/icon/core/chart-matrix': {
|
|
72
|
+
message: 'The icon "chart-matrix" is deprecated in favour of "chart-bubble" from "@atlaskit/icon/core"'
|
|
73
|
+
},
|
|
74
|
+
'@atlaskit/icon/core/close': {
|
|
75
|
+
message: 'The icon "close" is deprecated in favour of "cross" from "@atlaskit/icon/core"'
|
|
76
|
+
},
|
|
77
|
+
'@atlaskit/icon/core/error': {
|
|
78
|
+
message: 'The icon "error" is deprecated in favour of "status-error" from "@atlaskit/icon/core"'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
@@ -14,7 +14,9 @@ import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
|
14
14
|
import './remove-token-fallbacks/remove-token-fallbacks';
|
|
15
15
|
import './lozenge-appearance-semantic-migration/lozenge-appearance-semantic-migration';
|
|
16
16
|
import './lozenge-to-tag-migration/lozenge-to-tag-migration';
|
|
17
|
+
import './lozenge-discovery-to-tag-with-fg/lozenge-discovery-to-tag-with-fg';
|
|
17
18
|
import './badge-appearance-semantic-migration/badge-appearance-semantic-migration';
|
|
18
19
|
import './tag-to-newTag-migration/tag-to-newTag-migration';
|
|
19
|
-
|
|
20
|
+
import './migrate-deprecated-icon/migrate-deprecated-icon';
|
|
21
|
+
const presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-deprecated-icon', 'migrate-to-link', 'migrate-to-new-buttons', 'migrate-icon-object-to-object', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks', 'lozenge-appearance-semantic-migration', 'lozenge-to-tag-migration', 'lozenge-discovery-to-tag-with-fg', 'badge-appearance-semantic-migration', 'tag-to-newTag-migration'].map(preset => path.join(__dirname, preset, `${preset}.@(ts|js|tsx)`));
|
|
20
22
|
export default presets;
|