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,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stylesheet migration for react-bulma-components apps: Bulma 0.9 Sass
|
|
3
|
+
* (`@import` + `$var !default` overrides, `_all` aggregator partials) →
|
|
4
|
+
* Bulma v1 modules (`@use "bulma/sass" with (…)`), plus the bestax extras.
|
|
5
|
+
*
|
|
6
|
+
* Sass has no jscodeshift parser, so this is a conservative line-based text
|
|
7
|
+
* transform: it only rewrites patterns it can prove safe and leaves a
|
|
8
|
+
* `// TODO(bestax-migrate): …` everywhere else (line comments are valid in
|
|
9
|
+
* both SCSS and indented Sass).
|
|
10
|
+
*/
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
const TODO = 'TODO(bestax-migrate)';
|
|
13
|
+
const GUIDE = 'https://bestax.io/docs/guides/getting-started/migration/react-bulma-components';
|
|
14
|
+
const EXTRAS_USE = "@use '@allxsmith/bestax-bulma/scss/extras';";
|
|
15
|
+
/** Bulma v1 sass tree — directories that replaced the 0.9 `_all` partials. */
|
|
16
|
+
const V1_DIRS = new Set([
|
|
17
|
+
'utilities',
|
|
18
|
+
'base',
|
|
19
|
+
'elements',
|
|
20
|
+
'form',
|
|
21
|
+
'components',
|
|
22
|
+
'grid',
|
|
23
|
+
'layout',
|
|
24
|
+
'helpers',
|
|
25
|
+
'themes',
|
|
26
|
+
]);
|
|
27
|
+
/** Known Bulma v1 leaf partials (path after `bulma/sass/`). */
|
|
28
|
+
const V1_LEAVES = new Set([
|
|
29
|
+
'utilities/initial-variables',
|
|
30
|
+
'utilities/derived-variables',
|
|
31
|
+
'utilities/css-variables',
|
|
32
|
+
'utilities/mixins',
|
|
33
|
+
'utilities/functions',
|
|
34
|
+
'utilities/controls',
|
|
35
|
+
'utilities/extends',
|
|
36
|
+
'themes/light',
|
|
37
|
+
'themes/dark',
|
|
38
|
+
'themes/setup',
|
|
39
|
+
]);
|
|
40
|
+
/**
|
|
41
|
+
* The 0.9 root imports that become `@use "bulma/sass"`. The specifier may be
|
|
42
|
+
* bare (`bulma/bulma`), tilde-prefixed (webpack), or a relative path into
|
|
43
|
+
* node_modules (`../../node_modules/bulma/bulma`, common under Parcel) —
|
|
44
|
+
* relative prefixes are preserved in the emitted `@use`.
|
|
45
|
+
*/
|
|
46
|
+
const ROOT_IMPORT = /^(\s*)@import\s+(['"])((?:\.\.?\/)+node_modules\/|~)?bulma\/(?:bulma(?:\.sass|\.scss)?|css\/bulma(?:\.min)?\.css)\2\s*;?\s*$/;
|
|
47
|
+
/** 0.9 partial imports under bulma/sass/… (same prefix forms as the root). */
|
|
48
|
+
const PARTIAL_IMPORT = /^(\s*)@import\s+(['"])((?:\.\.?\/)+node_modules\/|~)?bulma\/sass\/([\w/-]+)\2\s*;?\s*$/;
|
|
49
|
+
/** A preserved path prefix for the rewritten `@use` (tilde never survives). */
|
|
50
|
+
function keptPrefix(prefix) {
|
|
51
|
+
return prefix && prefix !== '~' ? prefix : '';
|
|
52
|
+
}
|
|
53
|
+
/** Any other line that still `@import`s something bulma-ish. */
|
|
54
|
+
const OTHER_BULMA_IMPORT = /^\s*@import\s+['"][^'"]*bulma[^'"]*['"]/;
|
|
55
|
+
/**
|
|
56
|
+
* Third-party Bulma extension packages (`bulma-checkradio`, `bulma-switch`,
|
|
57
|
+
* …) — 0.9-era add-ons whose v1 compatibility varies; several are covered
|
|
58
|
+
* by the bestax extras.
|
|
59
|
+
*/
|
|
60
|
+
const EXTENSION_IMPORT = /^\s*@import\s+['"][^'"]*\bbulma-([\w-]+?)(?:\/|\.|['"])/;
|
|
61
|
+
/** Any `$name: value;` declaration (with or without `!default`). */
|
|
62
|
+
const VAR_DECL = /^\s*\$([\w-]+)\s*:\s*(.+?)\s*(!default)?\s*;\s*$/;
|
|
63
|
+
/**
|
|
64
|
+
* A value is fold-safe for `with (…)` when it is a plain literal — no
|
|
65
|
+
* function calls, interpolation, variable references, or at-rules. Hex
|
|
66
|
+
* colors (`#ff6b35`) are fine; `#{…}` interpolation is not.
|
|
67
|
+
*/
|
|
68
|
+
function isFoldableValue(value) {
|
|
69
|
+
return !/[()$@]|#\{/.test(value);
|
|
70
|
+
}
|
|
71
|
+
function report(collector, file, line, rule, message) {
|
|
72
|
+
collector?.add({ file, line, rule, message });
|
|
73
|
+
}
|
|
74
|
+
export const transformStyles = (filePath, source, collector, options) => {
|
|
75
|
+
const cssMode = options.cssMode ?? 'bestax';
|
|
76
|
+
if (!/bulma/.test(source))
|
|
77
|
+
return null;
|
|
78
|
+
// Indented-syntax files: flag only — rewriting without a parser is unsafe.
|
|
79
|
+
if (path.extname(filePath) === '.sass') {
|
|
80
|
+
if (source.includes(`${TODO}`))
|
|
81
|
+
return null;
|
|
82
|
+
report(collector, filePath, 1, 'sass', `indented-syntax file references Bulma; convert its @import lines to @use "bulma/sass" by hand — see ${GUIDE}`);
|
|
83
|
+
return `// ${TODO}: convert Bulma 0.9 @import lines to @use "bulma/sass" with (…) — see ${GUIDE}\n${source}`;
|
|
84
|
+
}
|
|
85
|
+
const lines = source.split('\n');
|
|
86
|
+
const out = [];
|
|
87
|
+
let changed = false;
|
|
88
|
+
let extrasAdded = source.includes('@allxsmith/bestax-bulma/scss');
|
|
89
|
+
// Pass 1: find safe leading variable overrides and the first root import.
|
|
90
|
+
const rootImportIndex = lines.findIndex(line => ROOT_IMPORT.test(line));
|
|
91
|
+
const foldableVars = [];
|
|
92
|
+
const unsafeVarLines = [];
|
|
93
|
+
if (rootImportIndex !== -1) {
|
|
94
|
+
for (let i = 0; i < rootImportIndex; i += 1) {
|
|
95
|
+
const line = lines[i];
|
|
96
|
+
const match = line.match(VAR_DECL);
|
|
97
|
+
if (match && isFoldableValue(match[2])) {
|
|
98
|
+
foldableVars.push({ index: i, name: match[1], value: match[2].trim() });
|
|
99
|
+
}
|
|
100
|
+
else if (/^\s*\$[\w-]+\s*:/.test(line)) {
|
|
101
|
+
unsafeVarLines.push(i);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const folded = new Set(foldableVars.map(v => v.index));
|
|
106
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
107
|
+
const line = lines[i];
|
|
108
|
+
if (i === rootImportIndex) {
|
|
109
|
+
const rootMatch = line.match(ROOT_IMPORT);
|
|
110
|
+
const indent = rootMatch?.[1] ?? '';
|
|
111
|
+
const bulmaSass = `${keptPrefix(rootMatch?.[3])}bulma/sass`;
|
|
112
|
+
if (foldableVars.length > 0) {
|
|
113
|
+
out.push(`${indent}@use '${bulmaSass}' with (`);
|
|
114
|
+
foldableVars.forEach(({ name, value }, index) => {
|
|
115
|
+
const comma = index < foldableVars.length - 1 ? ',' : '';
|
|
116
|
+
out.push(`${indent} $${name}: ${value}${comma}`);
|
|
117
|
+
});
|
|
118
|
+
out.push(`${indent});`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
out.push(`${indent}@use '${bulmaSass}';`);
|
|
122
|
+
}
|
|
123
|
+
if (unsafeVarLines.length > 0) {
|
|
124
|
+
out.push(`${indent}// ${TODO}: the variable override(s) above use computed values; move them into the @use "bulma/sass" with (…) configuration by hand`);
|
|
125
|
+
report(collector, filePath, i + 1, 'sass', 'variable overrides with computed values could not be folded into `with (…)`');
|
|
126
|
+
}
|
|
127
|
+
if (cssMode === 'bestax' && !extrasAdded) {
|
|
128
|
+
// A path-prefixed root import means the toolchain resolves raw file
|
|
129
|
+
// paths, not package specifiers — point at the shipped file directly.
|
|
130
|
+
const extrasPrefix = keptPrefix(rootMatch?.[3]);
|
|
131
|
+
out.push(extrasPrefix
|
|
132
|
+
? `${indent}@use '${extrasPrefix}@allxsmith/bestax-bulma/src/scss/extras';`
|
|
133
|
+
: `${indent}${EXTRAS_USE}`);
|
|
134
|
+
extrasAdded = true;
|
|
135
|
+
}
|
|
136
|
+
changed = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (folded.has(i)) {
|
|
140
|
+
changed = true; // folded into with(...) above
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const partial = line.match(PARTIAL_IMPORT);
|
|
144
|
+
if (partial) {
|
|
145
|
+
const [, indent, , rawPrefix, importPath] = partial;
|
|
146
|
+
const prefix = keptPrefix(rawPrefix);
|
|
147
|
+
// Partial-only files (modular builds with no root import) still need
|
|
148
|
+
// the extras for the bestax components' styling; the extras tree only
|
|
149
|
+
// reads Bulma utilities, never configures them, so this is load-safe.
|
|
150
|
+
const pushExtras = () => {
|
|
151
|
+
if (cssMode !== 'bestax' || extrasAdded || rootImportIndex !== -1) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
out.push(prefix
|
|
155
|
+
? `${indent}@use '${prefix}@allxsmith/bestax-bulma/src/scss/extras';`
|
|
156
|
+
: `${indent}${EXTRAS_USE}`);
|
|
157
|
+
extrasAdded = true;
|
|
158
|
+
};
|
|
159
|
+
const segments = importPath.split('/');
|
|
160
|
+
const last = segments[segments.length - 1].replace(/^_/, '');
|
|
161
|
+
const dir = segments[0];
|
|
162
|
+
if ((last === 'all' || last === 'index') && V1_DIRS.has(dir)) {
|
|
163
|
+
out.push(`${indent}@use '${prefix}bulma/sass/${dir}';`);
|
|
164
|
+
pushExtras();
|
|
165
|
+
changed = true;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const leaf = segments.map(s => s.replace(/^_/, '')).join('/');
|
|
169
|
+
if (V1_DIRS.has(leaf) || V1_LEAVES.has(leaf)) {
|
|
170
|
+
out.push(`${indent}@use '${prefix}bulma/sass/${leaf}';`);
|
|
171
|
+
pushExtras();
|
|
172
|
+
changed = true;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
out.push(`${indent}// ${TODO}: this Bulma 0.9 partial path no longer exists in Bulma v1; find its replacement under bulma/sass/ — see ${GUIDE}`);
|
|
176
|
+
out.push(line);
|
|
177
|
+
report(collector, filePath, i + 1, 'sass', `Bulma 0.9 partial path \`bulma/sass/${importPath}\` has no direct v1 equivalent`);
|
|
178
|
+
changed = true;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (OTHER_BULMA_IMPORT.test(line) && !line.includes(TODO)) {
|
|
182
|
+
const extension = line.match(EXTENSION_IMPORT);
|
|
183
|
+
if (extension) {
|
|
184
|
+
out.push(`// ${TODO}: bulma-${extension[1]} is a Bulma 0.9-era extension — check its Bulma v1 compatibility; the bestax extras already style Radio/Checkbox and the advanced form controls — see ${GUIDE}`);
|
|
185
|
+
out.push(line);
|
|
186
|
+
report(collector, filePath, i + 1, 'sass', `third-party Bulma extension \`bulma-${extension[1]}\` left in place; verify it against Bulma v1 or replace it with the bestax extras`);
|
|
187
|
+
changed = true;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
out.push(`// ${TODO}: Bulma v1 uses @use instead of @import — see ${GUIDE}`);
|
|
191
|
+
out.push(line);
|
|
192
|
+
report(collector, filePath, i + 1, 'sass', 'unrecognized Bulma @import left in place; convert to @use by hand');
|
|
193
|
+
changed = true;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
out.push(line);
|
|
197
|
+
}
|
|
198
|
+
return changed ? out.join('\n') : null;
|
|
199
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The react-bulma-components (v4) → @allxsmith/bestax-bulma transform.
|
|
3
|
+
*
|
|
4
|
+
* Passes, in order:
|
|
5
|
+
* 1. resolve imports (named/namespace) and `const { X } = Form`-style
|
|
6
|
+
* destructuring into canonical RBC component paths
|
|
7
|
+
* 2. per-element: structural special → rename → responsive flattening →
|
|
8
|
+
* component prop map → universal modifier props
|
|
9
|
+
* 3. rewrite imports: drop RBC, add one merged bestax-bulma import; keep a
|
|
10
|
+
* trimmed RBC import (with a TODO) only for components that have no
|
|
11
|
+
* bestax equivalent (Element, Tile)
|
|
12
|
+
*
|
|
13
|
+
* Anything unsafe gets a `// TODO(bestax-migrate)` comment on the enclosing
|
|
14
|
+
* statement plus an entry in the run report.
|
|
15
|
+
*/
|
|
16
|
+
import type { API, FileInfo } from 'jscodeshift';
|
|
17
|
+
import type { TransformOptions } from '../../types.js';
|
|
18
|
+
export default function transform(fileInfo: FileInfo, api: API, options?: TransformOptions): string | undefined;
|
|
19
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/sources/react-bulma-components/transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAoCvD,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,GAAG,EACR,OAAO,GAAE,gBAAqB,GAC7B,MAAM,GAAG,SAAS,CAofpB"}
|