@mittwald/flow-codemods 1.5.0-next.8 → 1.5.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.
|
@@ -12,6 +12,7 @@ export const flowPackages = [
|
|
|
12
12
|
"@mittwald/flow-remote-elements",
|
|
13
13
|
"@mittwald/flow-remote-react-components",
|
|
14
14
|
"@mittwald/flow-remote-react-renderer",
|
|
15
|
+
"@mittwald/flow-remote-vue-components",
|
|
15
16
|
"@mittwald/flow-stylesheet",
|
|
16
17
|
"@mittwald/mstudio-ext-react-components",
|
|
17
18
|
"@mittwald/react-tunnel",
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Removes the deprecated `variant` prop from `Accordion`. The prop has no
|
|
5
|
+
* effect anymore, whatever its value, so a dynamic value goes as well.
|
|
6
|
+
*
|
|
7
|
+
* Only JSX elements that resolve to `Accordion` — imported (named, aliased or
|
|
8
|
+
* as a namespace) from `@mittwald/flow-react-components` or
|
|
9
|
+
* `@mittwald/flow-remote-react-components`, including their subpath entries —
|
|
10
|
+
* are touched. A same-named component from another package keeps its prop.
|
|
11
|
+
*
|
|
12
|
+
* Grouping accordions that used the outline to look separated is not here:
|
|
13
|
+
* whether they belong into one `AccordionGroup` depends on the layout around
|
|
14
|
+
* them. `apply` asks for that by hand.
|
|
15
|
+
*/
|
|
16
|
+
const accordionVariantDeprecatedTransform = (fileInfo, { j }) => {
|
|
17
|
+
const flowPackages = [
|
|
18
|
+
"@mittwald/flow-react-components",
|
|
19
|
+
"@mittwald/flow-remote-react-components",
|
|
20
|
+
];
|
|
21
|
+
const affectedComponent = "Accordion";
|
|
22
|
+
const isFlowImport = (source) => flowPackages.some((pkg) => source === pkg || source.startsWith(`${pkg}/`));
|
|
23
|
+
const root = j(fileInfo.source, { parser: "tsx" });
|
|
24
|
+
// Local JSX identifiers of `Accordion` (resolves `as` aliases).
|
|
25
|
+
const localNames = new Set();
|
|
26
|
+
// Local names of `import * as Flow` namespace imports from a Flow package.
|
|
27
|
+
const flowNamespaces = new Set();
|
|
28
|
+
root
|
|
29
|
+
.find(j.ImportDeclaration)
|
|
30
|
+
.filter((path) => isFlowImport(String(path.node.source.value)))
|
|
31
|
+
.forEach((path) => {
|
|
32
|
+
for (const specifier of path.node.specifiers ?? []) {
|
|
33
|
+
if (specifier.type === "ImportSpecifier" &&
|
|
34
|
+
specifier.imported.type === "Identifier" &&
|
|
35
|
+
specifier.imported.name === affectedComponent) {
|
|
36
|
+
localNames.add(String(specifier.local?.name ?? affectedComponent));
|
|
37
|
+
}
|
|
38
|
+
else if (specifier.type === "ImportNamespaceSpecifier" &&
|
|
39
|
+
specifier.local) {
|
|
40
|
+
flowNamespaces.add(String(specifier.local.name));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (localNames.size === 0 && flowNamespaces.size === 0) {
|
|
45
|
+
return fileInfo.source;
|
|
46
|
+
}
|
|
47
|
+
let changed = false;
|
|
48
|
+
root.find(j.JSXOpeningElement).forEach((path) => {
|
|
49
|
+
const name = path.node.name;
|
|
50
|
+
const isAffected = (name.type === "JSXIdentifier" && localNames.has(name.name)) ||
|
|
51
|
+
(name.type === "JSXMemberExpression" &&
|
|
52
|
+
name.object.type === "JSXIdentifier" &&
|
|
53
|
+
name.property.type === "JSXIdentifier" &&
|
|
54
|
+
flowNamespaces.has(name.object.name) &&
|
|
55
|
+
name.property.name === affectedComponent);
|
|
56
|
+
if (!isAffected) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const attributes = path.node.attributes ?? [];
|
|
60
|
+
const remaining = attributes.filter((attribute) => attribute.type !== "JSXAttribute" ||
|
|
61
|
+
attribute.name.type !== "JSXIdentifier" ||
|
|
62
|
+
attribute.name.name !== "variant");
|
|
63
|
+
if (remaining.length !== attributes.length) {
|
|
64
|
+
path.node.attributes = remaining;
|
|
65
|
+
changed = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return changed ? root.toSource() : fileInfo.source;
|
|
69
|
+
};
|
|
70
|
+
exports.default = accordionVariantDeprecatedTransform;
|
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
// Source: packages/codemods/src/migrations/<id>/entry.md
|
|
4
4
|
/** Every migration, newest first. Bodies live in `src/migrations`. */
|
|
5
5
|
export const migrations = [
|
|
6
|
+
{
|
|
7
|
+
id: "accordion-variant-deprecated",
|
|
8
|
+
since: "1.5.0",
|
|
9
|
+
title: "Accordion: `variant` deprecated",
|
|
10
|
+
kind: "deprecation",
|
|
11
|
+
action: "codemod",
|
|
12
|
+
remotePackage: true,
|
|
13
|
+
apply: 'Remove the `variant` prop from every `Accordion` — a codemod does it. Then check where `variant="outline"` was used: where several accordions stand directly below each other, wrap them in an `AccordionGroup`, which draws separators between them; where a single accordion needs to stand apart from the surrounding content, place it in a `LayoutCard`. That part is not mechanically decidable.',
|
|
14
|
+
},
|
|
6
15
|
{
|
|
7
16
|
id: "image-rounded-corners-default",
|
|
8
17
|
since: "1.4.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-codemods",
|
|
3
|
-
"version": "1.5.0
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Codemods and an upgrade CLI for consumers of Flow, mittwald's design system",
|
|
6
6
|
"homepage": "https://flow.mittwald.de",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"vitest": "^4.1.11",
|
|
39
39
|
"yaml": "^2.8.1"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "81f7a593e7062165272869509f9186b19f9520fc"
|
|
42
42
|
}
|