bestax-migrate 0.0.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 +59 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +225 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/report.d.ts +24 -0
- package/dist/report.d.ts.map +1 -0
- package/dist/report.js +66 -0
- package/dist/runner.d.ts +16 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +69 -0
- package/dist/sources/react-bulma-components/deps.d.ts +9 -0
- package/dist/sources/react-bulma-components/deps.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/deps.js +96 -0
- package/dist/sources/react-bulma-components/index.d.ts +3 -0
- package/dist/sources/react-bulma-components/index.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/index.js +10 -0
- package/dist/sources/react-bulma-components/jsx-utils.d.ts +69 -0
- package/dist/sources/react-bulma-components/jsx-utils.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/jsx-utils.js +130 -0
- package/dist/sources/react-bulma-components/mapping.d.ts +31 -0
- package/dist/sources/react-bulma-components/mapping.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/mapping.js +852 -0
- package/dist/sources/react-bulma-components/props.d.ts +15 -0
- package/dist/sources/react-bulma-components/props.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/props.js +124 -0
- package/dist/sources/react-bulma-components/responsive.d.ts +17 -0
- package/dist/sources/react-bulma-components/responsive.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/responsive.js +113 -0
- package/dist/sources/react-bulma-components/specials.d.ts +23 -0
- package/dist/sources/react-bulma-components/specials.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/specials.js +546 -0
- package/dist/sources/react-bulma-components/styles.d.ts +13 -0
- package/dist/sources/react-bulma-components/styles.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/styles.js +199 -0
- package/dist/sources/react-bulma-components/transform.d.ts +19 -0
- package/dist/sources/react-bulma-components/transform.d.ts.map +1 -0
- package/dist/sources/react-bulma-components/transform.js +495 -0
- package/dist/sources/registry.d.ts +9 -0
- package/dist/sources/registry.d.ts.map +1 -0
- package/dist/sources/registry.js +14 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/package.json +74 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small AST helpers shared by the react-bulma-components transform passes.
|
|
3
|
+
* All functions operate on the babel/tsx AST that jscodeshift's `tsx` parser
|
|
4
|
+
* produces, via the `j` builder API.
|
|
5
|
+
*/
|
|
6
|
+
import type { JSCodeshift } from 'jscodeshift';
|
|
7
|
+
import type { ASTPath } from 'jscodeshift';
|
|
8
|
+
import type { TodoCollector } from '../../types.js';
|
|
9
|
+
export interface TransformContext {
|
|
10
|
+
j: JSCodeshift;
|
|
11
|
+
file: string;
|
|
12
|
+
collector: TodoCollector | undefined;
|
|
13
|
+
/** RBC top-level import names that must survive the import rewrite. */
|
|
14
|
+
retained: Set<string>;
|
|
15
|
+
/** bestax-bulma imports: imported name → local name (aliased on conflict). */
|
|
16
|
+
needed: Map<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Registers a bestax root name for import and returns the local name to use
|
|
19
|
+
* in JSX — an alias like `BulmaField` when the plain name collides with an
|
|
20
|
+
* existing binding in the file.
|
|
21
|
+
*/
|
|
22
|
+
reserve: (root: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Target overrides set by a parent's structural handler for child elements
|
|
25
|
+
* it has contextual knowledge about (e.g. a Navbar.Dropdown inside a
|
|
26
|
+
* Navbar.Item becomes Navbar.DropdownMenu).
|
|
27
|
+
*/
|
|
28
|
+
overrides: WeakMap<object, string>;
|
|
29
|
+
/** Resolves a JSX name node to its canonical RBC path (set by transform). */
|
|
30
|
+
resolve?: (name: any) => string[] | null;
|
|
31
|
+
dirty: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Flatten a JSXIdentifier / JSXMemberExpression chain into name parts. */
|
|
34
|
+
export declare function jsxNameParts(name: any): string[] | null;
|
|
35
|
+
/** Build a JSXIdentifier / JSXMemberExpression chain from a dotted name. */
|
|
36
|
+
export declare function buildJsxName(j: JSCodeshift, dotted: string): any;
|
|
37
|
+
/** Rename both the opening and (when present) closing element. */
|
|
38
|
+
export declare function renameElement(j: JSCodeshift, element: any, dotted: string): void;
|
|
39
|
+
/** Non-spread attributes of an element. */
|
|
40
|
+
export declare function attributesOf(element: any): any[];
|
|
41
|
+
export declare function findAttr(element: any, name: string): any | undefined;
|
|
42
|
+
export declare function removeAttr(element: any, attr: any): void;
|
|
43
|
+
export declare function addAttr(element: any, attr: any): void;
|
|
44
|
+
export type LiteralValue = {
|
|
45
|
+
kind: 'boolean';
|
|
46
|
+
value: boolean;
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'string';
|
|
49
|
+
value: string;
|
|
50
|
+
} | {
|
|
51
|
+
kind: 'number';
|
|
52
|
+
value: number;
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'expression';
|
|
55
|
+
};
|
|
56
|
+
/** Extract the literal value of a JSX attribute, if it has one. */
|
|
57
|
+
export declare function literalValueOf(attr: any): LiteralValue;
|
|
58
|
+
/** Create `name` (bare boolean) or `name="value"` attribute. */
|
|
59
|
+
export declare function makeAttr(j: JSCodeshift, name: string, value?: string): any;
|
|
60
|
+
/**
|
|
61
|
+
* Attach a `// TODO(bestax-migrate): ...` leading comment to the closest
|
|
62
|
+
* enclosing statement (comments inside JSX children are not valid JS, so the
|
|
63
|
+
* statement is the nearest place a line comment can live), and mirror the
|
|
64
|
+
* entry into the report collector with the element's original line number.
|
|
65
|
+
*/
|
|
66
|
+
export declare function addTodo(ctx: TransformContext, path: ASTPath<any>, rule: string, message: string): void;
|
|
67
|
+
/** Build a plain HTML element (used where bestax has no component). */
|
|
68
|
+
export declare function plainElement(j: JSCodeshift, tag: string, className: string | undefined, attrs: any[], children: any[], selfClosing?: boolean): any;
|
|
69
|
+
//# sourceMappingURL=jsx-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-utils.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/jsx-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpD,MAAM,WAAW,gBAAgB;IAC/B,CAAC,EAAE,WAAW,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,GAAG,SAAS,CAAC;IACrC,uEAAuE;IACvE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB,8EAA8E;IAC9E,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B;;;;OAIG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC;;;;OAIG;IACH,SAAS,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,6EAA6E;IAC7E,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,EAAE,GAAG,IAAI,CAAC;IACzC,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,CASvD;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAOhE;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAC3B,CAAC,EAAE,WAAW,EACd,O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EACZ,QAAQ,EAAE,GAAG,EAAE,EACf,WAAW,UAAQ,GAClB,GAAG,CAcL"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small AST helpers shared by the react-bulma-components transform passes.
|
|
3
|
+
* All functions operate on the babel/tsx AST that jscodeshift's `tsx` parser
|
|
4
|
+
* produces, via the `j` builder API.
|
|
5
|
+
*/
|
|
6
|
+
/** Flatten a JSXIdentifier / JSXMemberExpression chain into name parts. */
|
|
7
|
+
export function jsxNameParts(name) {
|
|
8
|
+
if (!name)
|
|
9
|
+
return null;
|
|
10
|
+
if (name.type === 'JSXIdentifier')
|
|
11
|
+
return [name.name];
|
|
12
|
+
if (name.type === 'JSXMemberExpression') {
|
|
13
|
+
const object = jsxNameParts(name.object);
|
|
14
|
+
if (!object)
|
|
15
|
+
return null;
|
|
16
|
+
return [...object, name.property.name];
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
/** Build a JSXIdentifier / JSXMemberExpression chain from a dotted name. */
|
|
21
|
+
export function buildJsxName(j, dotted) {
|
|
22
|
+
const parts = dotted.split('.');
|
|
23
|
+
let node = j.jsxIdentifier(parts[0]);
|
|
24
|
+
for (const part of parts.slice(1)) {
|
|
25
|
+
node = j.jsxMemberExpression(node, j.jsxIdentifier(part));
|
|
26
|
+
}
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
/** Rename both the opening and (when present) closing element. */
|
|
30
|
+
export function renameElement(j, element, dotted) {
|
|
31
|
+
element.openingElement.name = buildJsxName(j, dotted);
|
|
32
|
+
if (element.closingElement) {
|
|
33
|
+
element.closingElement.name = buildJsxName(j, dotted);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Non-spread attributes of an element. */
|
|
37
|
+
export function attributesOf(element) {
|
|
38
|
+
return (element.openingElement.attributes ?? []).filter((a) => a.type === 'JSXAttribute');
|
|
39
|
+
}
|
|
40
|
+
export function findAttr(element, name) {
|
|
41
|
+
return attributesOf(element).find((a) => a.name.name === name);
|
|
42
|
+
}
|
|
43
|
+
export function removeAttr(element, attr) {
|
|
44
|
+
const attrs = element.openingElement.attributes ?? [];
|
|
45
|
+
const index = attrs.indexOf(attr);
|
|
46
|
+
if (index !== -1)
|
|
47
|
+
attrs.splice(index, 1);
|
|
48
|
+
}
|
|
49
|
+
export function addAttr(element, attr) {
|
|
50
|
+
element.openingElement.attributes = element.openingElement.attributes ?? [];
|
|
51
|
+
element.openingElement.attributes.push(attr);
|
|
52
|
+
}
|
|
53
|
+
/** Extract the literal value of a JSX attribute, if it has one. */
|
|
54
|
+
export function literalValueOf(attr) {
|
|
55
|
+
if (attr.value == null)
|
|
56
|
+
return { kind: 'boolean', value: true };
|
|
57
|
+
const v = attr.value;
|
|
58
|
+
if (v.type === 'StringLiteral') {
|
|
59
|
+
return { kind: 'string', value: v.value };
|
|
60
|
+
}
|
|
61
|
+
if (v.type === 'JSXExpressionContainer') {
|
|
62
|
+
const e = v.expression;
|
|
63
|
+
if (e.type === 'StringLiteral')
|
|
64
|
+
return { kind: 'string', value: e.value };
|
|
65
|
+
if (e.type === 'NumericLiteral')
|
|
66
|
+
return { kind: 'number', value: e.value };
|
|
67
|
+
if (e.type === 'BooleanLiteral')
|
|
68
|
+
return { kind: 'boolean', value: e.value };
|
|
69
|
+
return { kind: 'expression' };
|
|
70
|
+
}
|
|
71
|
+
return { kind: 'expression' };
|
|
72
|
+
}
|
|
73
|
+
/** Create `name` (bare boolean) or `name="value"` attribute. */
|
|
74
|
+
export function makeAttr(j, name, value) {
|
|
75
|
+
return j.jsxAttribute(j.jsxIdentifier(name), value === undefined ? null : j.stringLiteral(value));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Attach a `// TODO(bestax-migrate): ...` leading comment to the closest
|
|
79
|
+
* enclosing statement (comments inside JSX children are not valid JS, so the
|
|
80
|
+
* statement is the nearest place a line comment can live), and mirror the
|
|
81
|
+
* entry into the report collector with the element's original line number.
|
|
82
|
+
*/
|
|
83
|
+
export function addTodo(ctx, path, rule, message) {
|
|
84
|
+
const { j } = ctx;
|
|
85
|
+
let statement = null;
|
|
86
|
+
let current = path;
|
|
87
|
+
while (current && current.node) {
|
|
88
|
+
if (/Statement$|Declaration$/.test(current.node.type) &&
|
|
89
|
+
current.node.type !== 'Program') {
|
|
90
|
+
statement = current;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
current = current.parent;
|
|
94
|
+
}
|
|
95
|
+
// A comment on the declaration inside `export const x = …` prints between
|
|
96
|
+
// `export` and `const`; hoist it to the export statement itself.
|
|
97
|
+
if (statement?.parent?.node &&
|
|
98
|
+
/^Export(Named|Default)Declaration$/.test(statement.parent.node.type)) {
|
|
99
|
+
statement = statement.parent;
|
|
100
|
+
}
|
|
101
|
+
const text = ` TODO(bestax-migrate): ${message}`;
|
|
102
|
+
if (statement) {
|
|
103
|
+
const node = statement.node;
|
|
104
|
+
node.comments = node.comments ?? [];
|
|
105
|
+
const exists = node.comments.some((c) => c.value === text);
|
|
106
|
+
if (!exists) {
|
|
107
|
+
const comment = j.commentLine(text, true, false);
|
|
108
|
+
node.comments.push(comment);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
ctx.collector?.add({
|
|
112
|
+
file: ctx.file,
|
|
113
|
+
line: path.node?.loc?.start?.line ?? null,
|
|
114
|
+
rule,
|
|
115
|
+
message,
|
|
116
|
+
});
|
|
117
|
+
ctx.dirty = true;
|
|
118
|
+
}
|
|
119
|
+
/** Build a plain HTML element (used where bestax has no component). */
|
|
120
|
+
export function plainElement(j, tag, className, attrs, children, selfClosing = false) {
|
|
121
|
+
const allAttrs = [...attrs];
|
|
122
|
+
if (className) {
|
|
123
|
+
allAttrs.unshift(makeAttr(j, 'className', className));
|
|
124
|
+
}
|
|
125
|
+
const opening = j.jsxOpeningElement(j.jsxIdentifier(tag), allAttrs, selfClosing);
|
|
126
|
+
const closing = selfClosing
|
|
127
|
+
? null
|
|
128
|
+
: j.jsxClosingElement(j.jsxIdentifier(tag));
|
|
129
|
+
return j.jsxElement(opening, closing, selfClosing ? [] : children);
|
|
130
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declarative react-bulma-components (v4) → @allxsmith/bestax-bulma mapping.
|
|
3
|
+
*
|
|
4
|
+
* Every entry was verified against the react-bulma-components 4.1.0 type
|
|
5
|
+
* declarations on one side and bulma-ui/src on the other. `special` keys are
|
|
6
|
+
* implemented in transform.ts — they cover structural conversions a rename
|
|
7
|
+
* table can't express (align-driven targets, child rewrites, unwrapping).
|
|
8
|
+
*
|
|
9
|
+
* The mapping-coverage test asserts every name in RBC_EXPORTS (and every
|
|
10
|
+
* compound sub listed there) resolves to an entry here, so extending coverage
|
|
11
|
+
* later is a table edit that cannot silently regress.
|
|
12
|
+
*/
|
|
13
|
+
import type { ComponentMapping, PropAction } from '../../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Universal RBC modifier props (ElementProps) → bestax useBulmaClasses props.
|
|
16
|
+
* Applied to every element that maps to a bestax component, after the
|
|
17
|
+
* component's own `props` actions.
|
|
18
|
+
*/
|
|
19
|
+
export declare const UNIVERSAL_PROPS: Record<string, PropAction>;
|
|
20
|
+
/** Breakpoint-object props flattened by the responsive pass. */
|
|
21
|
+
export declare const RESPONSIVE_BREAKPOINTS: Record<string, string | null>;
|
|
22
|
+
export declare const MAPPING: Record<string, ComponentMapping>;
|
|
23
|
+
/**
|
|
24
|
+
* The complete react-bulma-components v4.1.0 public surface, vendored from its
|
|
25
|
+
* src/index.d.ts + per-component declarations. The mapping-coverage test walks
|
|
26
|
+
* this list against MAPPING, so new RBC surface can never be silently ignored.
|
|
27
|
+
*/
|
|
28
|
+
export declare const RBC_EXPORTS: Record<string, string[]>;
|
|
29
|
+
/** Resolve a canonical RBC path like ['Form','Field','Label'] in MAPPING. */
|
|
30
|
+
export declare function resolveMapping(path: string[]): ComponentMapping | undefined;
|
|
31
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/mapping.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAOnE;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAgFtD,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAUhE,CAAC;AAIF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAspBpD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAsEhD,CAAC;AAEF,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,SAAS,CAM3E"}
|