@justeattakeaway/eslint-plugin-snacks-pie-migration 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/lib/extract-component-data.js +63 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -173,9 +173,21 @@ The components data used by the plugin is stored in two files: `snacks-component
|
|
|
173
173
|
### `snacks-components-data.json`
|
|
174
174
|
It's an auto-generated file that contains the list of deprecated components and their replacement PIE components (if they exist).
|
|
175
175
|
|
|
176
|
-
Please do not update the `snacks-components-data.json` file directly, as it is generated automatically
|
|
176
|
+
Please do not update the `snacks-components-data.json` file directly, as it is generated automatically.
|
|
177
177
|
|
|
178
|
-
To update the data,
|
|
178
|
+
To update the data, update the `pieMetadata` key of the components in the PIE repository. The CI automation will detect the change, regenerate the file, and open a pull request automatically.
|
|
179
|
+
|
|
180
|
+
To regenerate the file manually, run the `build` command of this package.
|
|
181
|
+
|
|
182
|
+
#### `extractComponentData`
|
|
183
|
+
|
|
184
|
+
The data extraction logic is exported from this package and can be used by other tools:
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
const { extractComponentData } = require('@justeattakeaway/eslint-plugin-snacks-pie-migration/extract-component-data');
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
It reads component `package.json` files from a given directory and returns a sorted map of Snacks component names to their PIE package and status. Only components with `beta` or `stable` status and at least one Snacks replacement are included.
|
|
179
191
|
|
|
180
192
|
### `snacks-components-solutions.js`
|
|
181
193
|
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.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
const { globSync } = require('glob');
|
|
4
|
+
|
|
5
|
+
function listFiles (startPath, globSyncImpl) {
|
|
6
|
+
return globSyncImpl('**/package.json', {
|
|
7
|
+
ignore: 'node_modules/**',
|
|
8
|
+
cwd: startPath,
|
|
9
|
+
absolute: true,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Reads package files from a specified path, extracts component data based on certain criteria,
|
|
15
|
+
* and returns a sorted object of components with their package name and status.
|
|
16
|
+
* @param startPath - directory path from which you want to start searching for package files
|
|
17
|
+
* containing component data.
|
|
18
|
+
* @param [deps] - object that can contain optional dependencies for `fs` and `globSync` modules.
|
|
19
|
+
* These dependencies are used to provide flexibility in testing and mocking these modules when needed.
|
|
20
|
+
* If not provided, the function will default to using the actual `fs` and `globSync` modules.
|
|
21
|
+
* @returns Returns an object containing component data, where the keys are component names and the
|
|
22
|
+
* values are objects with `piePackage` and `status` properties. The components are sorted alphabetically
|
|
23
|
+
* by their names.
|
|
24
|
+
*/
|
|
25
|
+
function extractComponentData (startPath, deps = {}) {
|
|
26
|
+
const fsImpl = deps.fs || fs;
|
|
27
|
+
const globSyncImpl = deps.globSync || globSync;
|
|
28
|
+
const packageFiles = listFiles(startPath, globSyncImpl);
|
|
29
|
+
const components = {};
|
|
30
|
+
|
|
31
|
+
packageFiles.forEach((filePath) => {
|
|
32
|
+
const fileContent = fsImpl.readFileSync(filePath, 'utf8');
|
|
33
|
+
const parsedPackage = JSON.parse(fileContent);
|
|
34
|
+
|
|
35
|
+
if (!parsedPackage.pieMetadata) return;
|
|
36
|
+
const { pieMetadata } = parsedPackage;
|
|
37
|
+
|
|
38
|
+
const hasStatus = pieMetadata?.componentStatus === 'beta' || pieMetadata?.componentStatus === 'stable';
|
|
39
|
+
const isReplacement = pieMetadata?.replaces?.snacks?.length > 0;
|
|
40
|
+
|
|
41
|
+
if (hasStatus && isReplacement) {
|
|
42
|
+
pieMetadata.replaces.snacks.forEach((snacksComponentName) => {
|
|
43
|
+
components[snacksComponentName] = {
|
|
44
|
+
piePackage: parsedPackage.name,
|
|
45
|
+
status: pieMetadata.componentStatus,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (Object.keys(components).length === 0) {
|
|
52
|
+
throw new Error('extractComponentData() failed. No components could be found.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return Object.keys(components)
|
|
56
|
+
.sort()
|
|
57
|
+
.reduce((acc, key) => {
|
|
58
|
+
acc[key] = components[key];
|
|
59
|
+
return acc;
|
|
60
|
+
}, {});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { extractComponentData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/eslint-plugin-snacks-pie-migration",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -24,7 +24,11 @@
|
|
|
24
24
|
"PIE"
|
|
25
25
|
],
|
|
26
26
|
"main": "./lib/index.js",
|
|
27
|
-
"exports":
|
|
27
|
+
"exports": {
|
|
28
|
+
".": "./lib/index.js",
|
|
29
|
+
"./extract-component-data": "./lib/extract-component-data.js",
|
|
30
|
+
"./snacks-components-data.json": "./snacks-components-data.json"
|
|
31
|
+
},
|
|
28
32
|
"files": [
|
|
29
33
|
"lib",
|
|
30
34
|
"snacks-components-data.json",
|