@maz-ui/upgrade 5.0.0-beta.0 → 5.0.0-beta.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/dist/cli.mjs +65 -15
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +1 -129
- package/dist/shared/upgrade.DtUNapPx.mjs +172 -0
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve, dirname } from 'node:path';
|
|
|
5
5
|
import process from 'node:process';
|
|
6
6
|
import { logger } from '@maz-ui/node';
|
|
7
7
|
import { globby } from 'globby';
|
|
8
|
-
import { transformFile,
|
|
8
|
+
import { A as ALL_GROUPS, h as hasFoundationRadius, t as transformFile, a as hasMazUiRootImport } from './shared/upgrade.DtUNapPx.mjs';
|
|
9
9
|
|
|
10
10
|
const DEFAULT_IGNORES = [
|
|
11
11
|
"**/node_modules/**",
|
|
@@ -88,7 +88,10 @@ Options:
|
|
|
88
88
|
-v, --version Print the upgrade tool version.
|
|
89
89
|
|
|
90
90
|
Transform groups:
|
|
91
|
-
imports maz-ui/styles \u2192 maz-ui/style.css, maz-ui/aos-styles \u2192 maz-ui/aos.css
|
|
91
|
+
imports maz-ui/styles \u2192 maz-ui/style.css, maz-ui/aos-styles \u2192 maz-ui/aos.css,
|
|
92
|
+
from 'maz-ui' \u2192 from '@maz-ui/utils' (root re-export removed in v5).
|
|
93
|
+
When this rewrite fires and the deps group runs, @maz-ui/utils is
|
|
94
|
+
also added to package.json next to maz-ui.
|
|
92
95
|
props left-icon/right-icon \u2192 start-icon/end-icon (props, slots,
|
|
93
96
|
#icon-left/#icon-right, --has-*-icon classes), footer-align,
|
|
94
97
|
variant, color="background", active-color, rounded-size="base"
|
|
@@ -166,12 +169,24 @@ Detected package manager: ${pm}. Running \`${pm} install\`\u2026
|
|
|
166
169
|
process.exit(code);
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
+
const PACKAGE_JSON_RE = /(?:^|[\\/])package\.json$/;
|
|
173
|
+
function applyTransform(file, opts, addUtilsDep) {
|
|
174
|
+
const before = readFileSync(file, "utf8");
|
|
175
|
+
const after = transformFile(file, before, { groups: opts.groups, addUtilsDep });
|
|
176
|
+
return { before, after };
|
|
177
|
+
}
|
|
178
|
+
function reportAndWrite(file, after, opts, cwd) {
|
|
179
|
+
const shown = file.replace(`${cwd}/`, "");
|
|
180
|
+
logger.log(`${opts.dryRun ? "[dry-run] would update" : "updated"}: ${shown}`);
|
|
181
|
+
if (!opts.dryRun)
|
|
182
|
+
writeFileSync(file, after, "utf8");
|
|
183
|
+
}
|
|
184
|
+
async function processSourceFiles(opts, cwd, packageJsonFiles) {
|
|
185
|
+
const importsEnabled = opts.groups.includes("imports");
|
|
172
186
|
let scanned = 0;
|
|
173
187
|
let changed = 0;
|
|
174
|
-
let
|
|
188
|
+
let needsUtilsDep = false;
|
|
189
|
+
const radiusFiles = [];
|
|
175
190
|
for (const root of opts.roots) {
|
|
176
191
|
const absoluteRoot = resolve(cwd, root);
|
|
177
192
|
const files = await globby(
|
|
@@ -190,26 +205,61 @@ async function run() {
|
|
|
190
205
|
}
|
|
191
206
|
);
|
|
192
207
|
for (const file of files) {
|
|
208
|
+
if (PACKAGE_JSON_RE.test(file)) {
|
|
209
|
+
packageJsonFiles.push(file);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
193
212
|
scanned += 1;
|
|
194
|
-
const before =
|
|
195
|
-
|
|
213
|
+
const { before, after } = applyTransform(file, opts, false);
|
|
214
|
+
if (importsEnabled && hasMazUiRootImport(before))
|
|
215
|
+
needsUtilsDep = true;
|
|
216
|
+
if (hasFoundationRadius(before))
|
|
217
|
+
radiusFiles.push(file);
|
|
196
218
|
if (after === before)
|
|
197
219
|
continue;
|
|
198
220
|
changed += 1;
|
|
199
|
-
|
|
200
|
-
depsChanged = true;
|
|
201
|
-
const shown = file.replace(`${cwd}/`, "");
|
|
202
|
-
logger.log(`${opts.dryRun ? "[dry-run] would update" : "updated"}: ${shown}`);
|
|
203
|
-
if (!opts.dryRun) {
|
|
204
|
-
writeFileSync(file, after, "utf8");
|
|
205
|
-
}
|
|
221
|
+
reportAndWrite(file, after, opts, cwd);
|
|
206
222
|
}
|
|
207
223
|
}
|
|
224
|
+
return { scanned, changed, needsUtilsDep, radiusFiles };
|
|
225
|
+
}
|
|
226
|
+
function processPackageJsonFiles(files, opts, cwd, needsUtilsDep) {
|
|
227
|
+
let scanned = 0;
|
|
228
|
+
let changed = 0;
|
|
229
|
+
let depsChanged = false;
|
|
230
|
+
for (const file of files) {
|
|
231
|
+
scanned += 1;
|
|
232
|
+
const { before, after } = applyTransform(file, opts, needsUtilsDep);
|
|
233
|
+
if (after === before)
|
|
234
|
+
continue;
|
|
235
|
+
changed += 1;
|
|
236
|
+
depsChanged = true;
|
|
237
|
+
reportAndWrite(file, after, opts, cwd);
|
|
238
|
+
}
|
|
239
|
+
return { scanned, changed, depsChanged };
|
|
240
|
+
}
|
|
241
|
+
async function run() {
|
|
242
|
+
const opts = parseArgs(process.argv);
|
|
243
|
+
const cwd = process.cwd();
|
|
244
|
+
const packageJsonFiles = [];
|
|
245
|
+
const sources = await processSourceFiles(opts, cwd, packageJsonFiles);
|
|
246
|
+
const pkgs = processPackageJsonFiles(packageJsonFiles, opts, cwd, sources.needsUtilsDep);
|
|
247
|
+
const scanned = sources.scanned + pkgs.scanned;
|
|
248
|
+
const changed = sources.changed + pkgs.changed;
|
|
249
|
+
const depsChanged = pkgs.depsChanged;
|
|
208
250
|
const prefix = opts.dryRun ? "would update" : "updated";
|
|
209
251
|
logger.log(`
|
|
210
252
|
Scanned ${scanned} files, ${prefix} ${changed}.`);
|
|
211
253
|
logger.log(`Groups applied: ${opts.groups.join(", ")}`);
|
|
212
254
|
maybeInstallDeps(opts, depsChanged, cwd);
|
|
255
|
+
if (sources.radiusFiles.length > 0) {
|
|
256
|
+
const cwdPrefix = `${cwd}/`;
|
|
257
|
+
logger.log(`
|
|
258
|
+
\u26A0 foundation.radius detected in ${sources.radiusFiles.length} file(s) \u2014 manual migration required:`);
|
|
259
|
+
for (const file of sources.radiusFiles)
|
|
260
|
+
logger.log(` - ${file.replace(cwdPrefix, "")}`);
|
|
261
|
+
logger.log(` \u2192 Move the value to scales.rounded.md (other rounded keys are now derived from it via calc).`);
|
|
262
|
+
}
|
|
213
263
|
logger.log(`
|
|
214
264
|
Next: see https://maz-ui.com/guide/migration-v5 for the manual steps`);
|
|
215
265
|
logger.log(`(foundation.radius \u2192 scales.rounded.md, MazIcon API, MazBadge sizes, MazChart update-mode).`);
|
package/dist/index.d.mts
CHANGED
|
@@ -4,11 +4,15 @@ declare function transformCssVars(content: string): string;
|
|
|
4
4
|
declare function transformHslVar(content: string): string;
|
|
5
5
|
declare function transformConfig(content: string): string;
|
|
6
6
|
declare function transformPresetColors(content: string): string;
|
|
7
|
-
|
|
7
|
+
interface TransformDepsOptions {
|
|
8
|
+
addUtils?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function transformDeps(content: string, options?: TransformDepsOptions): string;
|
|
8
11
|
type TransformGroup = 'imports' | 'props' | 'css' | 'config' | 'deps';
|
|
9
12
|
declare const ALL_GROUPS: readonly TransformGroup[];
|
|
10
13
|
interface TransformOptions {
|
|
11
14
|
groups?: readonly TransformGroup[];
|
|
15
|
+
addUtilsDep?: boolean;
|
|
12
16
|
}
|
|
13
17
|
declare function transformFile(filename: string, content: string, options?: TransformOptions): string;
|
|
14
18
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,15 @@ declare function transformCssVars(content: string): string;
|
|
|
4
4
|
declare function transformHslVar(content: string): string;
|
|
5
5
|
declare function transformConfig(content: string): string;
|
|
6
6
|
declare function transformPresetColors(content: string): string;
|
|
7
|
-
|
|
7
|
+
interface TransformDepsOptions {
|
|
8
|
+
addUtils?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function transformDeps(content: string, options?: TransformDepsOptions): string;
|
|
8
11
|
type TransformGroup = 'imports' | 'props' | 'css' | 'config' | 'deps';
|
|
9
12
|
declare const ALL_GROUPS: readonly TransformGroup[];
|
|
10
13
|
interface TransformOptions {
|
|
11
14
|
groups?: readonly TransformGroup[];
|
|
15
|
+
addUtilsDep?: boolean;
|
|
12
16
|
}
|
|
13
17
|
declare function transformFile(filename: string, content: string, options?: TransformOptions): string;
|
|
14
18
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,129 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function transformImports(content) {
|
|
3
|
-
return content.replace(IMPORT_PATH, (_, q, sub) => `${q}maz-ui/${sub === "styles" ? "style.css" : "aos.css"}${q}`);
|
|
4
|
-
}
|
|
5
|
-
const ICON_ATTR = /(\s:?)(left|right)-icon\b/g;
|
|
6
|
-
const ICON_SLOT = /#(left|right)-icon\b/g;
|
|
7
|
-
const ICON_LEFT_RIGHT_SLOT = /#icon-(left|right)\b/g;
|
|
8
|
-
const FOOTER_ALIGN = /(\sfooter-align\s*=\s*['"])(left|right)(['"])/g;
|
|
9
|
-
const ROUNDED_SIZE_BASE = /(\srounded-size\s*=\s*['"])base(['"])/g;
|
|
10
|
-
const ACTIVE_COLOR_BG = /(\sactive-color\s*=\s*['"])background(['"])/g;
|
|
11
|
-
const HAS_ICON_CLASS = /\.--has-(left|right)-icon\b/g;
|
|
12
|
-
const MAZ_OPEN_TAG = /<Maz[A-Z]\w*\b[^>]*>/g;
|
|
13
|
-
const VARIANT_LR = /(\svariant\s*=\s*['"])(left|right)(['"])/g;
|
|
14
|
-
const COLOR_BG = /(\scolor\s*=\s*['"])background(['"])/g;
|
|
15
|
-
function flipDirection(value) {
|
|
16
|
-
return value === "left" ? "start" : "end";
|
|
17
|
-
}
|
|
18
|
-
function transformProps(content) {
|
|
19
|
-
let out = content;
|
|
20
|
-
out = out.replace(ICON_ATTR, (_, prefix, dir) => `${prefix}${flipDirection(dir)}-icon`);
|
|
21
|
-
out = out.replace(ICON_SLOT, (_, dir) => `#${flipDirection(dir)}-icon`);
|
|
22
|
-
out = out.replace(ICON_LEFT_RIGHT_SLOT, (_, dir) => `#icon-${flipDirection(dir)}`);
|
|
23
|
-
out = out.replace(FOOTER_ALIGN, (_, p, dir, s) => `${p}${flipDirection(dir)}${s}`);
|
|
24
|
-
out = out.replace(ROUNDED_SIZE_BASE, (_, p, s) => `${p}md${s}`);
|
|
25
|
-
out = out.replace(ACTIVE_COLOR_BG, (_, p, s) => `${p}surface${s}`);
|
|
26
|
-
out = out.replace(HAS_ICON_CLASS, (_, dir) => `.--has-${flipDirection(dir)}-icon`);
|
|
27
|
-
out = out.replace(MAZ_OPEN_TAG, (tag) => tag.replace(VARIANT_LR, (_, p, dir, s) => `${p}${flipDirection(dir)}${s}`).replace(COLOR_BG, (_, p, s) => `${p}surface${s}`));
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
30
|
-
const MAZ_BACKGROUND = /--maz-background(?:(?![-\w])|(?=-(?:foreground|\d)))/g;
|
|
31
|
-
const MAZ_BORDER_COLOR = /--maz-border(?:(?![-\w])|(?=-(?:foreground|\d)))/g;
|
|
32
|
-
const MAZ_VAR = String.raw`var\(--(?:maz|m)-[\w-]+\)`;
|
|
33
|
-
const HSL_WITH_ALPHA = new RegExp(String.raw`hsl\(\s*(${MAZ_VAR})\s*\/\s*([^)]+)\)`, "g");
|
|
34
|
-
const HSL_NO_ALPHA = new RegExp(String.raw`hsl\(\s*(${MAZ_VAR})\s*\)`, "g");
|
|
35
|
-
function transformCssVars(content) {
|
|
36
|
-
return content.replace(MAZ_BACKGROUND, "--maz-surface").replace(MAZ_BORDER_COLOR, "--maz-divider");
|
|
37
|
-
}
|
|
38
|
-
function transformHslVar(content) {
|
|
39
|
-
return content.replace(HSL_WITH_ALPHA, (_, v, alpha) => `color-mix(in srgb, ${v} ${alpha.trim()}, transparent)`).replace(HSL_NO_ALPHA, (_, v) => v);
|
|
40
|
-
}
|
|
41
|
-
const NUXT_INJECT_MAIN_CSS = /\binjectMainCss\b/g;
|
|
42
|
-
const STRATEGY_HYBRID = /(\bstrategy\s*:\s*['"])hybrid(['"])/g;
|
|
43
|
-
const DEPRECATED_THEME_OPTIONS = /^[^\S\n]*(?:injectCriticalCSS|injectFullCSS|injectAllCSSOnServer)\s*:[^,\n]*,?[^\S\n]*\n?/gm;
|
|
44
|
-
function transformConfig(content) {
|
|
45
|
-
return content.replace(NUXT_INJECT_MAIN_CSS, "injectCss").replace(STRATEGY_HYBRID, (_, p, s) => `${p}runtime${s}`).replace(DEPRECATED_THEME_OPTIONS, "");
|
|
46
|
-
}
|
|
47
|
-
const LIGHT_DARK_BLOCK = /(\b(?:light|dark)\s*:\s*\{)([^{}]*)(\})/g;
|
|
48
|
-
function transformPresetColors(content) {
|
|
49
|
-
return content.replace(LIGHT_DARK_BLOCK, (_, open, body, close) => {
|
|
50
|
-
const renamed = body.replace(/(['"]?)background\1(\s*:)/g, (_match, q, suffix) => `${q}surface${q}${suffix}`).replace(/(['"]?)border\1(\s*:)/g, (_match, q, suffix) => `${q}divider${q}${suffix}`);
|
|
51
|
-
return `${open}${renamed}${close}`;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
const MAZ_UI_PKG = /^(?:maz-ui|@maz-ui\/.+)$/;
|
|
55
|
-
const TARGET_VERSION = "^5.0.0";
|
|
56
|
-
const PROTECTED_PREFIX = /^(?:workspace|link|file|portal|npm|http|https|git\+|github):/;
|
|
57
|
-
function shouldBump(name, range) {
|
|
58
|
-
if (!MAZ_UI_PKG.test(name))
|
|
59
|
-
return false;
|
|
60
|
-
if (PROTECTED_PREFIX.test(range))
|
|
61
|
-
return false;
|
|
62
|
-
if (["latest", "next", "beta", "alpha", "canary", "*"].includes(range))
|
|
63
|
-
return false;
|
|
64
|
-
return range !== TARGET_VERSION;
|
|
65
|
-
}
|
|
66
|
-
function detectIndent(content) {
|
|
67
|
-
const match = content.match(/\n([ \t]+)"/);
|
|
68
|
-
return match ? match[1] : 2;
|
|
69
|
-
}
|
|
70
|
-
const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
71
|
-
function transformDeps(content) {
|
|
72
|
-
let pkg;
|
|
73
|
-
try {
|
|
74
|
-
pkg = JSON.parse(content);
|
|
75
|
-
} catch {
|
|
76
|
-
return content;
|
|
77
|
-
}
|
|
78
|
-
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
|
|
79
|
-
return content;
|
|
80
|
-
let changed = false;
|
|
81
|
-
for (const field of DEP_FIELDS) {
|
|
82
|
-
const deps = pkg[field];
|
|
83
|
-
if (!deps || typeof deps !== "object" || Array.isArray(deps))
|
|
84
|
-
continue;
|
|
85
|
-
const map = deps;
|
|
86
|
-
for (const [name, range] of Object.entries(map)) {
|
|
87
|
-
if (typeof range !== "string")
|
|
88
|
-
continue;
|
|
89
|
-
if (shouldBump(name, range)) {
|
|
90
|
-
map[name] = TARGET_VERSION;
|
|
91
|
-
changed = true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!changed)
|
|
96
|
-
return content;
|
|
97
|
-
const indent = detectIndent(content);
|
|
98
|
-
const trailingNewline = content.endsWith("\n") ? "\n" : "";
|
|
99
|
-
return JSON.stringify(pkg, null, indent) + trailingNewline;
|
|
100
|
-
}
|
|
101
|
-
const ALL_GROUPS = ["imports", "props", "css", "config", "deps"];
|
|
102
|
-
function transformFile(filename, content, options = {}) {
|
|
103
|
-
const groups = options.groups ?? ALL_GROUPS;
|
|
104
|
-
const enabled = (g) => groups.includes(g);
|
|
105
|
-
const isVue = filename.endsWith(".vue");
|
|
106
|
-
const isCss = filename.endsWith(".css");
|
|
107
|
-
const isJs = /\.[cm]?[jt]sx?$/.test(filename);
|
|
108
|
-
const isPackageJson = /(?:^|[\\/])package\.json$/.test(filename);
|
|
109
|
-
let out = content;
|
|
110
|
-
if (enabled("imports") && (isVue || isJs))
|
|
111
|
-
out = transformImports(out);
|
|
112
|
-
if (enabled("props") && isVue)
|
|
113
|
-
out = transformProps(out);
|
|
114
|
-
if (enabled("css")) {
|
|
115
|
-
if (isVue || isCss)
|
|
116
|
-
out = transformCssVars(out);
|
|
117
|
-
if (isVue || isCss || isJs)
|
|
118
|
-
out = transformHslVar(out);
|
|
119
|
-
}
|
|
120
|
-
if (enabled("config") && (isVue || isJs)) {
|
|
121
|
-
out = transformConfig(out);
|
|
122
|
-
out = transformPresetColors(out);
|
|
123
|
-
}
|
|
124
|
-
if (enabled("deps") && isPackageJson)
|
|
125
|
-
out = transformDeps(out);
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export { ALL_GROUPS, transformConfig, transformCssVars, transformDeps, transformFile, transformHslVar, transformImports, transformPresetColors, transformProps };
|
|
1
|
+
export { A as ALL_GROUPS, b as transformConfig, c as transformCssVars, d as transformDeps, t as transformFile, e as transformHslVar, f as transformImports, g as transformPresetColors, i as transformProps } from './shared/upgrade.DtUNapPx.mjs';
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
const IMPORT_PATH = /(['"])maz-ui\/(styles|aos-styles)\1/g;
|
|
2
|
+
const ROOT_IMPORT_SPECIFIER = /(\bfrom\s+|\bimport\s*\(\s*|\brequire\s*\(\s*)(['"])maz-ui\2/g;
|
|
3
|
+
function transformImports(content) {
|
|
4
|
+
return content.replace(IMPORT_PATH, (_, q, sub) => `${q}maz-ui/${sub === "styles" ? "style.css" : "aos.css"}${q}`).replace(ROOT_IMPORT_SPECIFIER, (_, prefix, quote) => `${prefix}${quote}@maz-ui/utils${quote}`);
|
|
5
|
+
}
|
|
6
|
+
function hasMazUiRootImport(content) {
|
|
7
|
+
return /(?:\bfrom\s+|\bimport\s*\(\s*|\brequire\s*\(\s*)(['"])maz-ui\1/.test(content);
|
|
8
|
+
}
|
|
9
|
+
const ICON_ATTR = /(\s:?)(left|right)-icon\b/g;
|
|
10
|
+
const ICON_SLOT = /#(left|right)-icon\b/g;
|
|
11
|
+
const ICON_LEFT_RIGHT_SLOT = /#icon-(left|right)\b/g;
|
|
12
|
+
const FOOTER_ALIGN = /(\sfooter-align\s*=\s*['"])(left|right)(['"])/g;
|
|
13
|
+
const ROUNDED_SIZE_BASE = /(\srounded-size\s*=\s*['"])base(['"])/g;
|
|
14
|
+
const ACTIVE_COLOR_BG = /(\sactive-color\s*=\s*['"])background(['"])/g;
|
|
15
|
+
const HAS_ICON_CLASS = /\.--has-(left|right)-icon\b/g;
|
|
16
|
+
const MAZ_OPEN_TAG = /<Maz[A-Z]\w*\b[^>]*>/g;
|
|
17
|
+
const VARIANT_LR = /(\svariant\s*=\s*['"])(left|right)(['"])/g;
|
|
18
|
+
const COLOR_BG = /(\scolor\s*=\s*['"])background(['"])/g;
|
|
19
|
+
function flipDirection(value) {
|
|
20
|
+
return value === "left" ? "start" : "end";
|
|
21
|
+
}
|
|
22
|
+
function transformProps(content) {
|
|
23
|
+
let out = content;
|
|
24
|
+
out = out.replace(ICON_ATTR, (_, prefix, dir) => `${prefix}${flipDirection(dir)}-icon`);
|
|
25
|
+
out = out.replace(ICON_SLOT, (_, dir) => `#${flipDirection(dir)}-icon`);
|
|
26
|
+
out = out.replace(ICON_LEFT_RIGHT_SLOT, (_, dir) => `#icon-${flipDirection(dir)}`);
|
|
27
|
+
out = out.replace(FOOTER_ALIGN, (_, p, dir, s) => `${p}${flipDirection(dir)}${s}`);
|
|
28
|
+
out = out.replace(ROUNDED_SIZE_BASE, (_, p, s) => `${p}md${s}`);
|
|
29
|
+
out = out.replace(ACTIVE_COLOR_BG, (_, p, s) => `${p}surface${s}`);
|
|
30
|
+
out = out.replace(HAS_ICON_CLASS, (_, dir) => `.--has-${flipDirection(dir)}-icon`);
|
|
31
|
+
out = out.replace(MAZ_OPEN_TAG, (tag) => tag.replace(VARIANT_LR, (_, p, dir, s) => `${p}${flipDirection(dir)}${s}`).replace(COLOR_BG, (_, p, s) => `${p}surface${s}`));
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
const MAZ_BACKGROUND = /--maz-background(?:(?![-\w])|(?=-(?:foreground|\d)))/g;
|
|
35
|
+
const MAZ_BORDER_COLOR = /--maz-border(?:(?![-\w])|(?=-(?:foreground|\d)))/g;
|
|
36
|
+
const MAZ_VAR = String.raw`var\(--(?:maz|m)-[\w-]+\)`;
|
|
37
|
+
const HSL_WITH_ALPHA = new RegExp(String.raw`hsl\(\s*(${MAZ_VAR})\s*\/\s*([^)]+)\)`, "g");
|
|
38
|
+
const HSL_NO_ALPHA = new RegExp(String.raw`hsl\(\s*(${MAZ_VAR})\s*\)`, "g");
|
|
39
|
+
function transformCssVars(content) {
|
|
40
|
+
return content.replace(MAZ_BACKGROUND, "--maz-surface").replace(MAZ_BORDER_COLOR, "--maz-divider");
|
|
41
|
+
}
|
|
42
|
+
function transformHslVar(content) {
|
|
43
|
+
return content.replace(HSL_WITH_ALPHA, (_, v, alpha) => `color-mix(in srgb, ${v} ${alpha.trim()}, transparent)`).replace(HSL_NO_ALPHA, (_, v) => v);
|
|
44
|
+
}
|
|
45
|
+
const NUXT_INJECT_MAIN_CSS = /\binjectMainCss\b/g;
|
|
46
|
+
const STRATEGY_HYBRID = /(\bstrategy\s*:\s*['"])hybrid(['"])/g;
|
|
47
|
+
const DEPRECATED_THEME_OPTIONS = /^[^\S\n]*(?:injectCriticalCSS|injectFullCSS|injectAllCSSOnServer)\s*:[^,\n]*,?[^\S\n]*\n?/gm;
|
|
48
|
+
function transformConfig(content) {
|
|
49
|
+
return content.replace(NUXT_INJECT_MAIN_CSS, "injectCss").replace(STRATEGY_HYBRID, (_, p, s) => `${p}runtime${s}`).replace(DEPRECATED_THEME_OPTIONS, "");
|
|
50
|
+
}
|
|
51
|
+
const LIGHT_DARK_BLOCK = /(\b(?:light|dark)\s*:\s*\{)([^{}]*)(\})/g;
|
|
52
|
+
function transformPresetColors(content) {
|
|
53
|
+
return content.replace(LIGHT_DARK_BLOCK, (_, open, body, close) => {
|
|
54
|
+
const renamed = body.replace(/(['"]?)background\1(\s*:)/g, (_match, q, suffix) => `${q}surface${q}${suffix}`).replace(/(['"]?)border\1(\s*:)/g, (_match, q, suffix) => `${q}divider${q}${suffix}`);
|
|
55
|
+
return `${open}${renamed}${close}`;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const FOUNDATION_BLOCK = /\bfoundation\s*:\s*\{([^{}]*)\}/g;
|
|
59
|
+
const RADIUS_KEY_INSIDE = /(?:^|[\s,{])(['"]?)radius\1\s*:/;
|
|
60
|
+
function hasFoundationRadius(content) {
|
|
61
|
+
for (const match of content.matchAll(FOUNDATION_BLOCK)) {
|
|
62
|
+
if (RADIUS_KEY_INSIDE.test(match[1]))
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const MAZ_UI_PKG = /^(?:maz-ui|@maz-ui\/.+)$/;
|
|
68
|
+
const TARGET_VERSION = "^5.0.0";
|
|
69
|
+
const UTILS_PKG = "@maz-ui/utils";
|
|
70
|
+
const PROTECTED_PREFIX = /^(?:workspace|link|file|portal|npm|http|https|git\+|github):/;
|
|
71
|
+
function shouldBump(name, range) {
|
|
72
|
+
if (!MAZ_UI_PKG.test(name))
|
|
73
|
+
return false;
|
|
74
|
+
if (PROTECTED_PREFIX.test(range))
|
|
75
|
+
return false;
|
|
76
|
+
if (["latest", "next", "beta", "alpha", "canary", "*"].includes(range))
|
|
77
|
+
return false;
|
|
78
|
+
return range !== TARGET_VERSION;
|
|
79
|
+
}
|
|
80
|
+
function detectIndent(content) {
|
|
81
|
+
const match = content.match(/\n([ \t]+)"/);
|
|
82
|
+
return match ? match[1] : 2;
|
|
83
|
+
}
|
|
84
|
+
const DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
85
|
+
function getDepMap(pkg, field) {
|
|
86
|
+
const deps = pkg[field];
|
|
87
|
+
if (!deps || typeof deps !== "object" || Array.isArray(deps))
|
|
88
|
+
return void 0;
|
|
89
|
+
return deps;
|
|
90
|
+
}
|
|
91
|
+
function packageHasUtils(pkg) {
|
|
92
|
+
return DEP_FIELDS.some((field) => {
|
|
93
|
+
const map = getDepMap(pkg, field);
|
|
94
|
+
return !!map && UTILS_PKG in map;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function findMazUiHostField(pkg) {
|
|
98
|
+
for (const field of DEP_FIELDS) {
|
|
99
|
+
const map = getDepMap(pkg, field);
|
|
100
|
+
if (!map)
|
|
101
|
+
continue;
|
|
102
|
+
if (Object.keys(map).some((k) => k === "maz-ui" || k.startsWith("@maz-ui/")))
|
|
103
|
+
return field;
|
|
104
|
+
}
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
function transformDeps(content, options = {}) {
|
|
108
|
+
let pkg;
|
|
109
|
+
try {
|
|
110
|
+
pkg = JSON.parse(content);
|
|
111
|
+
} catch {
|
|
112
|
+
return content;
|
|
113
|
+
}
|
|
114
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
|
|
115
|
+
return content;
|
|
116
|
+
let changed = false;
|
|
117
|
+
for (const field of DEP_FIELDS) {
|
|
118
|
+
const map = getDepMap(pkg, field);
|
|
119
|
+
if (!map)
|
|
120
|
+
continue;
|
|
121
|
+
for (const [name, range] of Object.entries(map)) {
|
|
122
|
+
if (typeof range !== "string")
|
|
123
|
+
continue;
|
|
124
|
+
if (shouldBump(name, range)) {
|
|
125
|
+
map[name] = TARGET_VERSION;
|
|
126
|
+
changed = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (options.addUtils && !packageHasUtils(pkg)) {
|
|
131
|
+
const host = findMazUiHostField(pkg);
|
|
132
|
+
if (host) {
|
|
133
|
+
const map = getDepMap(pkg, host);
|
|
134
|
+
map[UTILS_PKG] = TARGET_VERSION;
|
|
135
|
+
changed = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!changed)
|
|
139
|
+
return content;
|
|
140
|
+
const indent = detectIndent(content);
|
|
141
|
+
const trailingNewline = content.endsWith("\n") ? "\n" : "";
|
|
142
|
+
return JSON.stringify(pkg, null, indent) + trailingNewline;
|
|
143
|
+
}
|
|
144
|
+
const ALL_GROUPS = ["imports", "props", "css", "config", "deps"];
|
|
145
|
+
function transformFile(filename, content, options = {}) {
|
|
146
|
+
const groups = options.groups ?? ALL_GROUPS;
|
|
147
|
+
const enabled = (g) => groups.includes(g);
|
|
148
|
+
const isVue = filename.endsWith(".vue");
|
|
149
|
+
const isCss = filename.endsWith(".css");
|
|
150
|
+
const isJs = /\.[cm]?[jt]sx?$/.test(filename);
|
|
151
|
+
const isPackageJson = /(?:^|[\\/])package\.json$/.test(filename);
|
|
152
|
+
let out = content;
|
|
153
|
+
if (enabled("imports") && (isVue || isJs))
|
|
154
|
+
out = transformImports(out);
|
|
155
|
+
if (enabled("props") && isVue)
|
|
156
|
+
out = transformProps(out);
|
|
157
|
+
if (enabled("css")) {
|
|
158
|
+
if (isVue || isCss)
|
|
159
|
+
out = transformCssVars(out);
|
|
160
|
+
if (isVue || isCss || isJs)
|
|
161
|
+
out = transformHslVar(out);
|
|
162
|
+
}
|
|
163
|
+
if (enabled("config") && (isVue || isJs)) {
|
|
164
|
+
out = transformConfig(out);
|
|
165
|
+
out = transformPresetColors(out);
|
|
166
|
+
}
|
|
167
|
+
if (enabled("deps") && isPackageJson)
|
|
168
|
+
out = transformDeps(out, { addUtils: options.addUtilsDep });
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { ALL_GROUPS as A, hasMazUiRootImport as a, transformConfig as b, transformCssVars as c, transformDeps as d, transformHslVar as e, transformImports as f, transformPresetColors as g, hasFoundationRadius as h, transformProps as i, transformFile as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/upgrade",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.1",
|
|
5
5
|
"description": "Automated source rewrites for migrating a project from Maz-UI v4 to v5.",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"globby": "^16.2.0",
|
|
44
|
-
"@maz-ui/node": "5.0.0-beta.
|
|
44
|
+
"@maz-ui/node": "5.0.0-beta.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^25.6.0",
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"unbuild": "^3.6.1",
|
|
50
50
|
"vitest": "4.1.5",
|
|
51
|
-
"@maz-ui/eslint-config": "5.0.0-beta.
|
|
51
|
+
"@maz-ui/eslint-config": "5.0.0-beta.1"
|
|
52
52
|
},
|
|
53
53
|
"lint-staged": {
|
|
54
54
|
"*.{js,ts,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix"
|