@justeattakeaway/eslint-plugin-snacks-pie-migration 0.2.0 → 0.4.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/README.md
CHANGED
|
@@ -168,13 +168,17 @@ processor: '@justeattakeaway/snacks-pie-migration/added-components',
|
|
|
168
168
|
|
|
169
169
|
## How to update the components data
|
|
170
170
|
|
|
171
|
-
The components data used by the plugin is stored in
|
|
171
|
+
The components data used by the plugin is stored in two files: `snacks-components-data.json` and `snacks-components-solutions.js`
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
### `snacks-components-data.json`
|
|
174
|
+
It's an auto-generated file that contains the list of deprecated components and their replacement PIE components (if they exist).
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
Please do not update the `snacks-components-data.json` file directly, as it is generated automatically by a script.
|
|
177
|
+
|
|
178
|
+
To update the data, you need to update the `pieMetadata` key of the components in the PIE repository, and then run the `build` command of this package to regenerate the JSON file.
|
|
179
|
+
|
|
180
|
+
### `snacks-components-solutions.js`
|
|
181
|
+
This file can be manually updated with solutions that apply to multiple components, such as migration skills, or with specific solutions for individual components that don't have a direct mapping to a PIE component.
|
|
178
182
|
|
|
179
183
|
## VSCode usage
|
|
180
184
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
const snacksComponentsData = require('../../snacks-components-data.json');
|
|
2
|
+
const solutions = require('../../snacks-components-solutions');
|
|
2
3
|
const { getImportSpecifiers } = require('../util/get-import-specifiers');
|
|
3
4
|
|
|
5
|
+
function isReplacedByAnotherComponent (componentName) {
|
|
6
|
+
const replacementData = snacksComponentsData[componentName];
|
|
7
|
+
const piePackage = replacementData && replacementData.status && replacementData.status === 'stable' ? replacementData.piePackage : false;
|
|
8
|
+
return piePackage;
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
/**
|
|
5
12
|
* Checks for imports of deprecated Snacks components
|
|
6
13
|
*/
|
|
@@ -35,16 +42,26 @@ module.exports = {
|
|
|
35
42
|
const [bypassedComponents] = context.options;
|
|
36
43
|
|
|
37
44
|
getImportSpecifiers(node).forEach((componentName) => {
|
|
38
|
-
const replacementData = snacksComponentsData[componentName];
|
|
39
45
|
// Specific components can be bypassed if an array of names are provided
|
|
40
46
|
const isBypassedInOptions = bypassedComponents && bypassedComponents.includes(componentName);
|
|
41
|
-
const
|
|
47
|
+
const alternativeSolution = solutions[componentName];
|
|
42
48
|
|
|
43
|
-
if (!isBypassedInOptions
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
if (!isBypassedInOptions) {
|
|
50
|
+
if (isReplacedByAnotherComponent(componentName)) {
|
|
51
|
+
const replacementComponent = isReplacedByAnotherComponent(componentName);
|
|
52
|
+
const solutionDetails = alternativeSolution ? `\n${alternativeSolution}` : '';
|
|
53
|
+
context.report({
|
|
54
|
+
node,
|
|
55
|
+
message: `The Snacks component "${componentName}" is being deprecated and can be replaced by "${replacementComponent}".${solutionDetails}`,
|
|
56
|
+
});
|
|
57
|
+
} else if (alternativeSolution) {
|
|
58
|
+
const reason = `The Snacks component "${componentName}" is being deprecated and can be replaced with plain HTML and CSS.`;
|
|
59
|
+
const solutionDetails = alternativeSolution ? `\n${alternativeSolution}` : '';
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
message: `${reason}${solutionDetails}`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
48
65
|
}
|
|
49
66
|
});
|
|
50
67
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/eslint-plugin-snacks-pie-migration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "This plugin helps developers to identify deprecated Snacks components and provides suggestions of replacement PIE components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"exports": "./lib/index.js",
|
|
28
28
|
"files": [
|
|
29
29
|
"lib",
|
|
30
|
-
"snacks-components-data.json"
|
|
30
|
+
"snacks-components-data.json",
|
|
31
|
+
"snacks-components-solutions.js"
|
|
31
32
|
],
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@typescript-eslint/parser": "8.46.3",
|
|
@@ -55,6 +55,18 @@
|
|
|
55
55
|
"piePackage": "@justeattakeaway/pie-modal",
|
|
56
56
|
"status": "stable"
|
|
57
57
|
},
|
|
58
|
+
"ModalContent": {
|
|
59
|
+
"piePackage": "@justeattakeaway/pie-modal",
|
|
60
|
+
"status": "stable"
|
|
61
|
+
},
|
|
62
|
+
"ModalFooter": {
|
|
63
|
+
"piePackage": "@justeattakeaway/pie-modal",
|
|
64
|
+
"status": "stable"
|
|
65
|
+
},
|
|
66
|
+
"ModalScrollContent": {
|
|
67
|
+
"piePackage": "@justeattakeaway/pie-modal",
|
|
68
|
+
"status": "stable"
|
|
69
|
+
},
|
|
58
70
|
"Notification": {
|
|
59
71
|
"piePackage": "@justeattakeaway/pie-notification",
|
|
60
72
|
"status": "beta"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// This file is used by the eslint plugin to hint developers on how to migrate away from deprecated Snacks components
|
|
2
|
+
// - Update this file when a Snacks component is deprecated and doesn't map directly to a PIE component
|
|
3
|
+
// - Update this file when a Snacks migration skill is available for components replaced by a PIE component
|
|
4
|
+
// Unlike `snacks-components-data.json`, this file can be edited by hand.
|
|
5
|
+
|
|
6
|
+
const migrateWithSkill = 'Use the "snacks-migration-assistant" skill to migrate this component.\nCheck this page for more details: https://www.pie.design/agents/resources/#snacks-migration-skill';
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
Flex: migrateWithSkill,
|
|
10
|
+
FlexItem: migrateWithSkill,
|
|
11
|
+
Util: migrateWithSkill,
|
|
12
|
+
};
|