@mittwald/flow-codemods 1.6.0-next.66 → 1.6.0-next.68
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.
|
@@ -3,24 +3,6 @@
|
|
|
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: "color-props-brand-palette",
|
|
8
|
-
since: "1.6.0",
|
|
9
|
-
title: "Badge, Avatar, Icon, Color, AccentBox: color values follow the brand palette",
|
|
10
|
-
kind: "migration",
|
|
11
|
-
action: "codemod",
|
|
12
|
-
remotePackage: true,
|
|
13
|
-
apply: 'On `Badge`, `Avatar`, `Icon` (and the generated icons, `IconCheck` & co.) and `Color`, rename `color="violet"` to `color="lilac"` and `color="teal"` to `color="sage"`; on `AccentBox`, do the same for `backgroundColor`, and rename `backgroundColor="gradient"` to `backgroundColor="gradient-navy"` and `backgroundColor="green"` to `backgroundColor="sage"`. An `AccentBox` that still sets its background through `color` (`color="gradient"`, `"green"`) gets `backgroundColor="gradient-navy"` / `"sage"` instead. On `Badge`, also rename `color="green"` to `color="success"`, `color="orange"` to `color="warning"` and `color="red"` to `color="danger"`. Each replacement renders exactly like the old value. `Avatar`\'s `color="green"` is deprecated too, but its replacement `sage` is the brand\'s muted gray-green instead of the success mint. Switch to `sage` where the avatar\'s color carries no meaning, and keep `green` (it still renders) only until you have decided. `AccentBox`\'s `backgroundColor="green"` now renders like `sage` instead of the success mint. Content on a colored `AccentBox` now defaults to `color="dark"`; drop an explicit `color="dark"` there if you like. If you use `@mittwald/flow-stylesheet` or the token CSS variables directly, rename `flow--badge--{violet,teal,green,orange,red}` to `flow--badge--{lilac,sage,success,warning,danger}`, `--badge--{teal,green,orange,red}-*` to `--badge--{sage,success,warning,danger}-*`, `--icon--teal-color` to `--icon--sage-color`, `--decorative--teal-*` to `--decorative--sage-*`, `flow--accent-box--{violet,teal,green}` and `--accent-box--background-color-{violet,teal,green}` to their `lilac`/`sage`/`sage` counterparts, `flow--accent-box--gradient` and `--accent-box--background-color-gradient` to `…-gradient-navy`, drop the `--badge--*-border-color` variables (the badge has no border), and replace `--badge--violet-*`, `--icon--violet-color` and `--decorative--violet-*` by their `lilac` counterparts.',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
id: "color-tokens-brand-theme-neutral",
|
|
17
|
-
since: "1.6.0",
|
|
18
|
-
title: "Color tokens: a new Brand palette that no longer switches with the theme",
|
|
19
|
-
kind: "migration",
|
|
20
|
-
action: "manual",
|
|
21
|
-
remotePackage: false,
|
|
22
|
-
apply: "Search your own CSS, SCSS and TS for `var(--color--`. Replace the moved variables by name — `--color--categorical--X` → `--categorical--color--X`, `--color--code-syntax--X` → `--code-syntax--color--X`, `--color--transparent` → `--transparent--color`, `--color--gradient` → `--gradient--color`, `--color--background-gradient` → `--background-gradient--color`, `--color--static-black-alpha--N` → `--dark-static--color--N`, `--color--static-white-alpha--N` → `--light-static--color--N`; JavaScript reading `color.categorical` from the token JSON reads `categorical.color`. The old palettes are gone — `--color--gray--N`, `--color--hosting-blue--N`, `--color--soft-contrast-violet--N`, `--color--bright-lilac--N`, `--color--super-teal--N`, `--color--amaranth-red--N`, `--color--royal-orange--N` and `--color--espelkamp-green--N` resolve to nothing, and `--color--mittwald-navy--N` holds the new brand values. Replace each with the Semantic variable that carries its meaning, e.g. `--elevation--color--N` for a gray surface, `--content--color--N` for gray text, `--border--color--N` for a gray border, `--primary--color--quiet--N` or `--primary--color--strong--N` for hosting-blue, `--decorative-<hue>--color--…` for navy, lilac and teal, `--danger--`, `--warning--` or `--success--color--…` for the status hues (amaranth-red, royal-orange, espelkamp-green), `--dark--color--…` or `--light--color--…` for `--color--black-alpha--N` or `--color--white-alpha--N`, or a Variant variable such as `--primary-solid-background-color--default`. Do the same for every remaining Brand variable (`--color--mittwald-*`, `--color--system-*`, the alpha ramps), because Brand keeps its light value in dark. Then rename the Semantic variables you use. Colored and alpha groups (`primary`, `info`, `success`, `danger`, `warning`, `neutral`, `unavailable`, `decorative-*`, `dark`, `light`, `dark-static`, `light-static`) keep six tones — `--<group>--color--100/200/300` → `--<group>--color--quiet--100/200/300`, `--<group>--color--800/900/1000` → `--<group>--color--strong--100/200/300` (alpha groups map `800/700/600` → `strong--100/200/300`); the other steps are gone, use the nearest tone. Gray from `--neutral--color--N` moves by role — surfaces 100–300 → `--elevation--color--100/200/300`, text and icons → `--content--color--100` (secondary), `--200` (label) or `--300` (text), on a solid surface `--content--color--inverse`, borders → `--border--color--100` (grouping), `--200` (separator) or `--300` (control), disabled → `--unavailable--color--quiet--100/200/300` (surface, border, content). `--decorative-violet--color--…` → `--decorative-lilac--color--…`, `--decorative-teal--color--…` → `--decorative-sage--color--…`, `--decorative-red--`, `--decorative-green--` and `--decorative-orange--color--…` → `--danger--`, `--success--` and `--warning--color--…`; the brand's green and orange are `--decorative-sage--` and `--decorative-salmon--color--…`. Which one fits is not decidable mechanically — decide whether the color is a surface, content or status.",
|
|
23
|
-
},
|
|
24
6
|
{
|
|
25
7
|
id: "accordion-variant-deprecated",
|
|
26
8
|
since: "1.5.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/flow-codemods",
|
|
3
|
-
"version": "1.6.0-next.
|
|
3
|
+
"version": "1.6.0-next.68",
|
|
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": "b4504a4c6976754472ab63a3207af2e962245dc5"
|
|
42
42
|
}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Renames the deprecated `color` values of `Badge`, `Avatar`, `Icon` (and the
|
|
5
|
-
* generated icons, `IconCheck` & co., which take `Icon`'s props) and `Color`,
|
|
6
|
-
* and the deprecated `backgroundColor` values of `AccentBox`, to the values
|
|
7
|
-
* that render the same: `violet` → `lilac` and `teal` → `sage` everywhere, on
|
|
8
|
-
* `Badge` also `green` → `success`, `orange` → `warning` and `red` → `danger`,
|
|
9
|
-
* and on `AccentBox` also `gradient` → `gradient-navy` and `green` → `sage`.
|
|
10
|
-
* `Avatar`'s `green` is left alone: its replacement `sage` looks different, so
|
|
11
|
-
* that is a decision, not a rename.
|
|
12
|
-
*
|
|
13
|
-
* The scope is deliberately narrow. Only JSX elements that resolve to one of
|
|
14
|
-
* those components — imported (named or as a namespace) from
|
|
15
|
-
* `@mittwald/flow-react-components` or
|
|
16
|
-
* `@mittwald/flow-remote-react-components`, including their subpath entries —
|
|
17
|
-
* are touched. Same-named components from other packages are left untouched.
|
|
18
|
-
*
|
|
19
|
-
* Only literal values are rewritten — either as the whole value (`color="red"`,
|
|
20
|
-
* `color={"red"}`) or in a value position inside a dynamic one (`color={cond ?
|
|
21
|
-
* "neutral" : "red"}`, `color={override ?? "red"}`). A value the transform
|
|
22
|
-
* cannot see into (`color={someVariable}`) is left alone.
|
|
23
|
-
*
|
|
24
|
-
* `AccentBox`'s legacy `color="gradient"`/`"green"` needs no case here:
|
|
25
|
-
* `accent-box-color-to-background-color` runs first in `upgrade` and moves it
|
|
26
|
-
* to `backgroundColor`, where this transform renames it.
|
|
27
|
-
*/
|
|
28
|
-
const colorPropsBrandPaletteTransform = (fileInfo, { j }) => {
|
|
29
|
-
const flowPackages = [
|
|
30
|
-
"@mittwald/flow-react-components",
|
|
31
|
-
"@mittwald/flow-remote-react-components",
|
|
32
|
-
];
|
|
33
|
-
const decorative = { violet: "lilac", teal: "sage" };
|
|
34
|
-
const renamesByComponent = {
|
|
35
|
-
Badge: {
|
|
36
|
-
...decorative,
|
|
37
|
-
green: "success",
|
|
38
|
-
orange: "warning",
|
|
39
|
-
red: "danger",
|
|
40
|
-
},
|
|
41
|
-
Avatar: decorative,
|
|
42
|
-
Icon: decorative,
|
|
43
|
-
Color: decorative,
|
|
44
|
-
AccentBox: { ...decorative, gradient: "gradient-navy", green: "sage" },
|
|
45
|
-
};
|
|
46
|
-
/** The prop holding the color, where it is not `color`. */
|
|
47
|
-
const propByComponent = {
|
|
48
|
-
AccentBox: "backgroundColor",
|
|
49
|
-
};
|
|
50
|
-
const affectedComponents = new Set(Object.keys(renamesByComponent));
|
|
51
|
-
/** The component whose renames apply to an export, if any. */
|
|
52
|
-
const componentOf = (exported) => affectedComponents.has(exported)
|
|
53
|
-
? exported
|
|
54
|
-
: /^Icon[A-Z]/.test(exported)
|
|
55
|
-
? "Icon"
|
|
56
|
-
: undefined;
|
|
57
|
-
const isFlowImport = (source) => flowPackages.some((pkg) => source === pkg || source.startsWith(`${pkg}/`));
|
|
58
|
-
/** The replacement for a renamed string literal, if `node` is one. */
|
|
59
|
-
const renamedLiteral = (node, renames) => {
|
|
60
|
-
if (!node || typeof node !== "object" || !("type" in node)) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
const { type } = node;
|
|
64
|
-
const value = node.value;
|
|
65
|
-
return (type === "StringLiteral" || type === "Literal") &&
|
|
66
|
-
typeof value === "string" &&
|
|
67
|
-
Object.hasOwn(renames, value)
|
|
68
|
-
? renames[value]
|
|
69
|
-
: undefined;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Rewrites every renamed literal sitting in a position whose value can reach
|
|
73
|
-
* the prop: the expression itself, both branches of a ternary, and the
|
|
74
|
-
* operands of `??`/`||` — plus the right operand of `&&`, since `&&` yields
|
|
75
|
-
* its left operand only when that operand is falsy and a non-empty string
|
|
76
|
-
* never is. A literal anywhere else is not a value that reaches the prop (an
|
|
77
|
-
* object key, an index into a lookup table) and stays as it is.
|
|
78
|
-
*
|
|
79
|
-
* This cannot move into a shared module: the CLI loads this file straight out
|
|
80
|
-
* of the published package, which ships only
|
|
81
|
-
* `src/migrations/**\/transform.ts` — see this package's AGENTS.md.
|
|
82
|
-
*/
|
|
83
|
-
const rewriteValuePositions = (node, renames) => {
|
|
84
|
-
const renamed = renamedLiteral(node, renames);
|
|
85
|
-
if (renamed !== undefined) {
|
|
86
|
-
return j.stringLiteral(renamed);
|
|
87
|
-
}
|
|
88
|
-
if (node?.type === "ConditionalExpression") {
|
|
89
|
-
node.consequent = rewriteValuePositions(node.consequent, renames);
|
|
90
|
-
node.alternate = rewriteValuePositions(node.alternate, renames);
|
|
91
|
-
return node;
|
|
92
|
-
}
|
|
93
|
-
if (node?.type === "LogicalExpression") {
|
|
94
|
-
if (node.operator !== "&&") {
|
|
95
|
-
node.left = rewriteValuePositions(node.left, renames);
|
|
96
|
-
}
|
|
97
|
-
node.right = rewriteValuePositions(node.right, renames);
|
|
98
|
-
return node;
|
|
99
|
-
}
|
|
100
|
-
return node;
|
|
101
|
-
};
|
|
102
|
-
const root = j(fileInfo.source, { parser: "tsx" });
|
|
103
|
-
// Local JSX identifier -> canonical component name (resolves `as` aliases).
|
|
104
|
-
const localToComponent = new Map();
|
|
105
|
-
// Local names of `import * as Flow` namespace imports from a Flow package.
|
|
106
|
-
const flowNamespaces = new Set();
|
|
107
|
-
root
|
|
108
|
-
.find(j.ImportDeclaration)
|
|
109
|
-
.filter((path) => isFlowImport(String(path.node.source.value)))
|
|
110
|
-
.forEach((path) => {
|
|
111
|
-
for (const specifier of path.node.specifiers ?? []) {
|
|
112
|
-
const component = specifier.type === "ImportSpecifier" &&
|
|
113
|
-
specifier.imported.type === "Identifier"
|
|
114
|
-
? componentOf(String(specifier.imported.name))
|
|
115
|
-
: undefined;
|
|
116
|
-
if (specifier.type === "ImportSpecifier" && component) {
|
|
117
|
-
localToComponent.set(String(specifier.local?.name ?? specifier.imported.name), component);
|
|
118
|
-
}
|
|
119
|
-
else if (specifier.type === "ImportNamespaceSpecifier" &&
|
|
120
|
-
specifier.local) {
|
|
121
|
-
flowNamespaces.add(String(specifier.local.name));
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
if (localToComponent.size === 0 && flowNamespaces.size === 0) {
|
|
126
|
-
return fileInfo.source;
|
|
127
|
-
}
|
|
128
|
-
root.find(j.JSXOpeningElement).forEach((path) => {
|
|
129
|
-
const name = path.node.name;
|
|
130
|
-
let component;
|
|
131
|
-
if (name.type === "JSXIdentifier") {
|
|
132
|
-
component = localToComponent.get(name.name);
|
|
133
|
-
}
|
|
134
|
-
else if (name.type === "JSXMemberExpression" &&
|
|
135
|
-
name.object.type === "JSXIdentifier" &&
|
|
136
|
-
name.property.type === "JSXIdentifier" &&
|
|
137
|
-
flowNamespaces.has(name.object.name)) {
|
|
138
|
-
component = componentOf(name.property.name);
|
|
139
|
-
}
|
|
140
|
-
const renames = component && renamesByComponent[component];
|
|
141
|
-
if (!component || !renames) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const prop = propByComponent[component] ?? "color";
|
|
145
|
-
for (const attribute of path.node.attributes ?? []) {
|
|
146
|
-
if (attribute.type !== "JSXAttribute" ||
|
|
147
|
-
attribute.name.type !== "JSXIdentifier" ||
|
|
148
|
-
attribute.name.name !== prop) {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
const value = attribute.value;
|
|
152
|
-
// color="red"
|
|
153
|
-
const renamed = renamedLiteral(value, renames);
|
|
154
|
-
if (renamed !== undefined) {
|
|
155
|
-
attribute.value = j.stringLiteral(renamed);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
// color={"red"}, and every value position inside a dynamic value:
|
|
159
|
-
// color={cond ? "red" : "x"}, color={fallback ?? "red"}.
|
|
160
|
-
if (value?.type === "JSXExpressionContainer" &&
|
|
161
|
-
value.expression.type !== "JSXEmptyExpression") {
|
|
162
|
-
value.expression = rewriteValuePositions(value.expression, renames);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
return root.toSource();
|
|
167
|
-
};
|
|
168
|
-
exports.default = colorPropsBrandPaletteTransform;
|