@frigear-nu/cli 0.2.0 → 0.2.2
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 +7 -2
- package/dist/chunks/app-create.mjs +2 -1
- package/dist/chunks/init.mjs +15 -4
- package/dist/chunks/module-folder.mjs +89 -0
- package/dist/chunks/module-move.mjs +130 -0
- package/dist/chunks/package-rename.mjs +139 -0
- package/dist/chunks/upgrade.mjs +133 -150
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +2 -1
- package/dist/shared/cli.BLUxtpPi.mjs +160 -0
- package/dist/shared/{cli.BNukBQzw.mjs → cli.Bq3BvIWj.mjs} +4 -1
- package/dist/shared/cli.CybmnaqF.mjs +29 -0
- package/dist/shared/cli.DUmSgMcB.mjs +175 -0
- package/package.json +2 -2
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdir, rename, writeFile, readFile, readdir, stat } from 'node:fs/promises';
|
|
3
|
+
import consola from 'consola';
|
|
4
|
+
import { isAbsolute, resolve, dirname, sep, join, extname, basename, relative } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const emptyPlan = (root) => ({ root, moves: [], writes: /* @__PURE__ */ new Map(), created: /* @__PURE__ */ new Set(), warnings: [] });
|
|
7
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", "dist", "coverage"]);
|
|
8
|
+
const IGNORED_FILES = /* @__PURE__ */ new Set(["package-lock.json", "CHANGELOG.md"]);
|
|
9
|
+
const SOURCE = /\.(?:[cm]?[jt]s|tsx|jsx|vue|json|md)$/;
|
|
10
|
+
const JS_EXT = /\.(?:[cm]?[jt]s|tsx|jsx)$/;
|
|
11
|
+
const RESOLVE_EXTS = [".ts", ".mts", ".cts", ".tsx", ".js", ".mjs", ".cjs", ".jsx", ".vue", ".json", ".d.ts"];
|
|
12
|
+
const NUXT_CONFIGS = ["nuxt.config.ts", "nuxt.config.mts", "nuxt.config.js", "nuxt.config.mjs"];
|
|
13
|
+
const workspaceFiles = async (dir) => {
|
|
14
|
+
if (!existsSync(dir)) return [];
|
|
15
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
16
|
+
const nested = await Promise.all(entries.map(async (entry) => {
|
|
17
|
+
const path = join(dir, entry.name);
|
|
18
|
+
if (entry.isDirectory()) return IGNORED_DIRS.has(entry.name) || entry.name.startsWith(".") ? [] : workspaceFiles(path);
|
|
19
|
+
if (!entry.isFile() || !SOURCE.test(entry.name) || IGNORED_FILES.has(entry.name)) return [];
|
|
20
|
+
return (await stat(path)).size > 1e6 ? [] : [path];
|
|
21
|
+
}));
|
|
22
|
+
return nested.flat();
|
|
23
|
+
};
|
|
24
|
+
const toPosix = (path) => path.split(sep).join("/");
|
|
25
|
+
const isInside = (path, dir) => path === dir || path.startsWith(dir + sep);
|
|
26
|
+
const stripExt = (path) => JS_EXT.test(path) ? path.slice(0, -extname(path).length) : path;
|
|
27
|
+
const relocate = (path, moves) => {
|
|
28
|
+
for (const move of moves) {
|
|
29
|
+
if (move.kind === "dir") {
|
|
30
|
+
if (isInside(path, move.from)) return move.to + path.slice(move.from.length);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (path === move.from) return move.to;
|
|
34
|
+
const ext = extname(path);
|
|
35
|
+
if (ext && !JS_EXT.test(path)) continue;
|
|
36
|
+
if (stripExt(path) !== stripExt(move.from)) continue;
|
|
37
|
+
const stem = stripExt(move.to);
|
|
38
|
+
if (!ext) return basename(stem) === "index" ? dirname(stem) : stem;
|
|
39
|
+
return stem + ext;
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
};
|
|
43
|
+
const targetExists = (abs) => {
|
|
44
|
+
if (existsSync(abs)) return true;
|
|
45
|
+
const stem = stripExt(abs);
|
|
46
|
+
return RESOLVE_EXTS.some((ext) => existsSync(stem + ext));
|
|
47
|
+
};
|
|
48
|
+
const findNuxtRoot = (dir, root) => {
|
|
49
|
+
for (let current = dir; isInside(current, root); current = dirname(current)) {
|
|
50
|
+
if (NUXT_CONFIGS.some((file) => existsSync(join(current, file)))) return current;
|
|
51
|
+
if (dirname(current) === current) break;
|
|
52
|
+
}
|
|
53
|
+
return void 0;
|
|
54
|
+
};
|
|
55
|
+
const aliasBase = (alias, nuxtRoot) => alias === "~~" || alias === "@@" ? nuxtRoot : existsSync(join(nuxtRoot, "app")) ? join(nuxtRoot, "app") : nuxtRoot;
|
|
56
|
+
const ALIAS = /^(~~|@@|~|@)\//;
|
|
57
|
+
const SPECIFIER = /(['"`])((?:\.\.?|~~?|@@?)\/[^'"`\n]*)\1/g;
|
|
58
|
+
const MARKDOWN_LINK = /(\]\()(\.\.?\/[^)\s#?]*)/g;
|
|
59
|
+
const relativeSpecifier = (fromDir, abs) => {
|
|
60
|
+
const rel = toPosix(relative(fromDir, abs)) || ".";
|
|
61
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
62
|
+
};
|
|
63
|
+
const rewritePaths = (text, file, ctx) => {
|
|
64
|
+
if (!ctx.moves.length) return text;
|
|
65
|
+
const newFile = relocate(file, ctx.moves) ?? file;
|
|
66
|
+
const fileMoves = newFile !== file;
|
|
67
|
+
const oldDir = dirname(file);
|
|
68
|
+
const newDir = dirname(newFile);
|
|
69
|
+
const nuxtRoot = findNuxtRoot(oldDir, ctx.root);
|
|
70
|
+
const rewrite = (spec) => {
|
|
71
|
+
if (spec.includes("${")) return void 0;
|
|
72
|
+
const alias = spec.match(ALIAS)?.[1];
|
|
73
|
+
let abs;
|
|
74
|
+
if (alias) {
|
|
75
|
+
if (!nuxtRoot) return void 0;
|
|
76
|
+
abs = join(aliasBase(alias, nuxtRoot), spec.slice(alias.length + 1));
|
|
77
|
+
} else abs = resolve(oldDir, spec);
|
|
78
|
+
const moved = relocate(abs, ctx.moves);
|
|
79
|
+
if (!moved && !fileMoves) return void 0;
|
|
80
|
+
if (!moved && !targetExists(abs)) return void 0;
|
|
81
|
+
const newAbs = moved ?? abs;
|
|
82
|
+
const trailing = spec.endsWith("/") && !newAbs.endsWith("/") ? "/" : "";
|
|
83
|
+
if (alias) {
|
|
84
|
+
const movedRoot = nuxtRoot ? relocate(nuxtRoot, ctx.moves) : void 0;
|
|
85
|
+
const newRoot = movedRoot ?? findNuxtRoot(newDir, ctx.root) ?? nuxtRoot;
|
|
86
|
+
if (!moved) {
|
|
87
|
+
if (newRoot !== nuxtRoot && !movedRoot) {
|
|
88
|
+
ctx.warnings.push(`${toPosix(relative(ctx.root, newFile))}: \`${spec}\` now resolves against ${toPosix(relative(ctx.root, newRoot)) || "."}`);
|
|
89
|
+
}
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
92
|
+
const base = aliasBase(alias, newRoot);
|
|
93
|
+
if (isInside(newAbs, base)) {
|
|
94
|
+
const next2 = `${alias}/${toPosix(relative(base, newAbs))}${trailing}`;
|
|
95
|
+
return next2 === spec ? void 0 : next2;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const next = relativeSpecifier(newDir, newAbs) + trailing;
|
|
99
|
+
return next === spec ? void 0 : next;
|
|
100
|
+
};
|
|
101
|
+
if (file.endsWith(".md")) {
|
|
102
|
+
return text.replace(MARKDOWN_LINK, (all, head, spec) => {
|
|
103
|
+
const next = rewrite(spec);
|
|
104
|
+
return next === void 0 ? all : `${head}${next}`;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return text.replace(SPECIFIER, (all, quote, spec) => {
|
|
108
|
+
const next = rewrite(spec);
|
|
109
|
+
return next === void 0 ? all : `${quote}${next}${quote}`;
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const planChanges = async (root, moves, rewrite) => {
|
|
113
|
+
const plan = emptyPlan(root);
|
|
114
|
+
plan.moves.push(...moves);
|
|
115
|
+
const ctx = { root, moves, warnings: plan.warnings };
|
|
116
|
+
const files = new Set(await workspaceFiles(root));
|
|
117
|
+
for (const move of moves) {
|
|
118
|
+
if (move.kind === "file" && SOURCE.test(move.from)) files.add(move.from);
|
|
119
|
+
}
|
|
120
|
+
for (const file of files) {
|
|
121
|
+
const original = await readFile(file, "utf-8");
|
|
122
|
+
let text = rewrite ? rewrite(file, original) : original;
|
|
123
|
+
text = rewritePaths(text, file, ctx);
|
|
124
|
+
if (text !== original) plan.writes.set(relocate(file, moves) ?? file, text);
|
|
125
|
+
}
|
|
126
|
+
return plan;
|
|
127
|
+
};
|
|
128
|
+
const applyPlan = async (plan) => {
|
|
129
|
+
for (const move of plan.moves) {
|
|
130
|
+
if (existsSync(move.to)) throw new Error(`${move.to} already exists`);
|
|
131
|
+
await mkdir(dirname(move.to), { recursive: true });
|
|
132
|
+
await rename(move.from, move.to);
|
|
133
|
+
}
|
|
134
|
+
for (const [file, text] of plan.writes) {
|
|
135
|
+
await mkdir(dirname(file), { recursive: true });
|
|
136
|
+
await writeFile(file, text, "utf-8");
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const describePlan = (plan) => {
|
|
140
|
+
const rel = (path) => toPosix(relative(plan.root, path)) || ".";
|
|
141
|
+
const lines = [];
|
|
142
|
+
for (const move of plan.moves) lines.push(`moved ${rel(move.from)}${move.kind === "dir" ? "/" : ""} \u2192 ${rel(move.to)}${move.kind === "dir" ? "/" : ""}`);
|
|
143
|
+
const files = [...plan.writes.keys()].sort();
|
|
144
|
+
for (const file of files) lines.push(`${plan.created.has(file) ? "created" : "changed"} ${rel(file)}`);
|
|
145
|
+
return lines;
|
|
146
|
+
};
|
|
147
|
+
const resolveArg = (cwd, path) => isAbsolute(path) ? path : resolve(cwd, path);
|
|
148
|
+
const printPlan = (plan, tag, options) => {
|
|
149
|
+
const logger = consola.withTag(tag);
|
|
150
|
+
const lines = describePlan(plan);
|
|
151
|
+
if (!lines.length) logger.info("Nothing to change.");
|
|
152
|
+
else logger.log(`${options.dryRun ? "Would change" : "Changed"} ${lines.length} ${lines.length === 1 ? "path" : "paths"}:
|
|
153
|
+
${lines.map((line) => ` ${line}`).join("\n")}`);
|
|
154
|
+
for (const warning of plan.warnings) logger.warn(warning);
|
|
155
|
+
if (options.dryRun) logger.info("Dry run: nothing was written.");
|
|
156
|
+
else if (options.next?.length) logger.info(`Next:
|
|
157
|
+
${options.next.map((step) => ` ${step}`).join("\n")}`);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export { applyPlan as a, planChanges as b, findNuxtRoot as f, printPlan as p, resolveArg as r, toPosix as t, workspaceFiles as w };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
2
|
|
|
3
|
-
const version = "0.2.
|
|
3
|
+
const version = "0.2.2";
|
|
4
4
|
const pkg = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
@@ -14,6 +14,9 @@ const mainCmd = defineCommand({
|
|
|
14
14
|
"init": () => import('../chunks/init.mjs').then((module) => module.default),
|
|
15
15
|
"app:create": () => import('../chunks/app-create.mjs').then((module) => module.default),
|
|
16
16
|
"module:create": () => import('../chunks/module-create.mjs').then((module) => module.default),
|
|
17
|
+
"module:folder": () => import('../chunks/module-folder.mjs').then((module) => module.default),
|
|
18
|
+
"module:move": () => import('../chunks/module-move.mjs').then((module) => module.default),
|
|
19
|
+
"package:rename": () => import('../chunks/package-rename.mjs').then((module) => module.default),
|
|
17
20
|
"add": () => import('../chunks/add.mjs').then((module) => module.default),
|
|
18
21
|
"upgrade": () => import('../chunks/upgrade.mjs').then(function (n) { return n.a; }).then((module) => module.default)
|
|
19
22
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { existsSync, statSync } from 'node:fs';
|
|
2
|
+
import { extname, join, basename } from 'node:path';
|
|
3
|
+
import { resolveTargetApp } from '../chunks/add.mjs';
|
|
4
|
+
import { r as resolveArg } from './cli.BLUxtpPi.mjs';
|
|
5
|
+
|
|
6
|
+
const MODULE_EXTS = [".ts", ".mts", ".js", ".mjs"];
|
|
7
|
+
const inspectModulePath = (path) => {
|
|
8
|
+
if (!existsSync(path)) return void 0;
|
|
9
|
+
if (statSync(path).isFile()) {
|
|
10
|
+
const ext = extname(path);
|
|
11
|
+
return MODULE_EXTS.includes(ext) ? { kind: "file", path, name: basename(path, ext) } : void 0;
|
|
12
|
+
}
|
|
13
|
+
if (existsSync(join(path, "package.json"))) return { kind: "package", path, name: basename(path) };
|
|
14
|
+
if (MODULE_EXTS.some((ext) => existsSync(join(path, `index${ext}`)))) return { kind: "dir", path, name: basename(path) };
|
|
15
|
+
return void 0;
|
|
16
|
+
};
|
|
17
|
+
const resolveLocalModule = async (cwd, ref, app) => {
|
|
18
|
+
const direct = inspectModulePath(resolveArg(cwd, ref));
|
|
19
|
+
if (direct) return direct;
|
|
20
|
+
if (/[\\/]/.test(ref) || extname(ref)) throw new Error(`No module file or folder at ${ref}`);
|
|
21
|
+
const appDir = await resolveTargetApp(cwd, app);
|
|
22
|
+
for (const candidate of [...MODULE_EXTS.map((ext) => join(appDir, "modules", `${ref}${ext}`)), join(appDir, "modules", ref)]) {
|
|
23
|
+
const found = inspectModulePath(candidate);
|
|
24
|
+
if (found) return found;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(`No module ${ref} in ${join(appDir, "modules")}`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { resolveLocalModule as r };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const VERSION = /(\d+)\.(\d+)\.(\d+)(?:-([\w.-]+))?/;
|
|
6
|
+
const parseVersion = (value) => {
|
|
7
|
+
const match = value.match(VERSION);
|
|
8
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3]), match[4] ?? ""] : void 0;
|
|
9
|
+
};
|
|
10
|
+
const compareVersions = (a, b) => {
|
|
11
|
+
const va = parseVersion(a);
|
|
12
|
+
const vb = parseVersion(b);
|
|
13
|
+
if (!va || !vb) throw new Error(`Not a version: ${!va ? a : b}`);
|
|
14
|
+
for (let i = 0; i < 3; i++) {
|
|
15
|
+
const diff = va[i] - vb[i];
|
|
16
|
+
if (diff) return diff;
|
|
17
|
+
}
|
|
18
|
+
if (va[3] === vb[3]) return 0;
|
|
19
|
+
if (!va[3]) return 1;
|
|
20
|
+
if (!vb[3]) return -1;
|
|
21
|
+
return va[3] < vb[3] ? -1 : 1;
|
|
22
|
+
};
|
|
23
|
+
const isBetween = (version, from, to) => compareVersions(version, from) > 0 && compareVersions(version, to) <= 0;
|
|
24
|
+
const SKIP = /^(?:workspace:|catalog:|link:|file:|portal:|npm:|git|https?:)/;
|
|
25
|
+
const rewriteRange = (range, version) => {
|
|
26
|
+
const trimmed = range.trim();
|
|
27
|
+
if (SKIP.test(trimmed) || /\|\||\s-\s|\s/.test(trimmed)) return void 0;
|
|
28
|
+
const match = trimmed.match(/^([\^~]|>=|[>=v])?(\d+\.\d+\.\d+(?:-[\w.-]+)?)$/);
|
|
29
|
+
if (!match) return void 0;
|
|
30
|
+
const operator = { "v": "", "=": "", ">": ">=" }[match[1] ?? ""] ?? match[1] ?? "";
|
|
31
|
+
const next = `${operator}${version}`;
|
|
32
|
+
return next === trimmed ? void 0 : next;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const YAML_KEY = /^(\s*)(['"]?)(@frigear-nu\/[\w.-]+)\2(\s*:\s*)(['"]?)([^'"\s#]+)\5/;
|
|
36
|
+
const YAML_ITEM = /^(\s*-\s*)(['"]?)(@frigear-nu\/[\w.-]+)@([^'"\s#]+)\2/;
|
|
37
|
+
const JSON_ENTRY = /("(@frigear-nu\/[\w.-]+)"\s*:\s*")([^"]*)(")/g;
|
|
38
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", ".git", "dist", "coverage", ".turbo", ".vercel", ".wrangler"]);
|
|
39
|
+
const workspaceGlobs = (yaml) => {
|
|
40
|
+
const globs = [];
|
|
41
|
+
let inPackages = false;
|
|
42
|
+
for (const line of yaml.split("\n")) {
|
|
43
|
+
if (/^\S/.test(line)) inPackages = /^packages\s*:/.test(line);
|
|
44
|
+
else if (inPackages) {
|
|
45
|
+
const item = line.match(/^\s*-\s*['"]?([^'"#\s]+)/);
|
|
46
|
+
if (item && !item[1].startsWith("!")) globs.push(item[1].trim());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return globs;
|
|
50
|
+
};
|
|
51
|
+
const subdirs = async (dir) => existsSync(dir) ? (await readdir(dir, { withFileTypes: true })).filter((entry) => entry.isDirectory() && !IGNORED_DIRS.has(entry.name)).map((entry) => join(dir, entry.name)) : [];
|
|
52
|
+
const deepDirs = async (dir) => {
|
|
53
|
+
const children = await subdirs(dir);
|
|
54
|
+
return [dir, ...(await Promise.all(children.map(deepDirs))).flat()];
|
|
55
|
+
};
|
|
56
|
+
const workspacePackageDirs = async (root) => {
|
|
57
|
+
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
58
|
+
const globs = existsSync(yamlPath) ? workspaceGlobs(await readFile(yamlPath, "utf-8")) : [];
|
|
59
|
+
const dirs = /* @__PURE__ */ new Set([root]);
|
|
60
|
+
for (const glob of globs) {
|
|
61
|
+
const parts = glob.replace(/\/+$/, "").split("/");
|
|
62
|
+
let current = [root];
|
|
63
|
+
for (const part of parts) {
|
|
64
|
+
if (part === "**") current = (await Promise.all(current.map(deepDirs))).flat();
|
|
65
|
+
else if (part.includes("*")) {
|
|
66
|
+
const pattern = new RegExp(`^${part.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
|
|
67
|
+
current = (await Promise.all(current.map(subdirs))).flat().filter((dir) => pattern.test(dir.split(/[\\/]/).pop()));
|
|
68
|
+
} else current = current.map((dir) => join(dir, part));
|
|
69
|
+
}
|
|
70
|
+
for (const dir of current) if (existsSync(join(dir, "package.json"))) dirs.add(dir);
|
|
71
|
+
}
|
|
72
|
+
return [...dirs];
|
|
73
|
+
};
|
|
74
|
+
const manifestFiles = async (root) => {
|
|
75
|
+
const files = (await workspacePackageDirs(root)).map((dir) => join(dir, "package.json")).filter(existsSync);
|
|
76
|
+
const yaml = join(root, "pnpm-workspace.yaml");
|
|
77
|
+
return existsSync(yaml) ? [...files, yaml] : files;
|
|
78
|
+
};
|
|
79
|
+
const findPins = (file, text) => {
|
|
80
|
+
if (file.endsWith(".json")) {
|
|
81
|
+
return [...text.matchAll(JSON_ENTRY)].map((match) => ({ file, name: match[2], range: match[3] }));
|
|
82
|
+
}
|
|
83
|
+
return text.split("\n").flatMap((line) => {
|
|
84
|
+
const key = line.match(YAML_KEY);
|
|
85
|
+
if (key) return [{ file, name: key[3], range: key[6] }];
|
|
86
|
+
const item = line.match(YAML_ITEM);
|
|
87
|
+
return item ? [{ file, name: item[3], range: item[4] }] : [];
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
const rewritePins = (file, text, targets) => {
|
|
91
|
+
const bumps = [];
|
|
92
|
+
const bump = (name, range) => {
|
|
93
|
+
const target = targets[name];
|
|
94
|
+
const next = target ? rewriteRange(range, target) : void 0;
|
|
95
|
+
if (next) bumps.push({ file, name, range, next });
|
|
96
|
+
return next;
|
|
97
|
+
};
|
|
98
|
+
if (file.endsWith(".json")) {
|
|
99
|
+
const out2 = text.replace(JSON_ENTRY, (all, head, name, range, tail) => {
|
|
100
|
+
const next = bump(name, range);
|
|
101
|
+
return next ? `${head}${next}${tail}` : all;
|
|
102
|
+
});
|
|
103
|
+
return { text: out2, bumps };
|
|
104
|
+
}
|
|
105
|
+
const out = text.split("\n").map((line) => {
|
|
106
|
+
const key = line.match(YAML_KEY);
|
|
107
|
+
if (key) {
|
|
108
|
+
const [all, indent, q, name, sep, vq, range] = key;
|
|
109
|
+
const next = bump(name, range);
|
|
110
|
+
return next ? line.replace(all, `${indent}${q}${name}${q}${sep}${vq}${next}${vq}`) : line;
|
|
111
|
+
}
|
|
112
|
+
const item = line.match(YAML_ITEM);
|
|
113
|
+
if (item) {
|
|
114
|
+
const [all, dash, q, name, range] = item;
|
|
115
|
+
const next = bump(name, range);
|
|
116
|
+
return next ? line.replace(all, `${dash}${q}${name}@${next}${q}`) : line;
|
|
117
|
+
}
|
|
118
|
+
return line;
|
|
119
|
+
}).join("\n");
|
|
120
|
+
return { text: out, bumps };
|
|
121
|
+
};
|
|
122
|
+
const currentVersions = (pins) => {
|
|
123
|
+
const versions = {};
|
|
124
|
+
for (const pin of pins) {
|
|
125
|
+
const version = parseVersion(pin.range);
|
|
126
|
+
if (!version) continue;
|
|
127
|
+
const value = `${version[0]}.${version[1]}.${version[2]}${version[3] ? `-${version[3]}` : ""}`;
|
|
128
|
+
const known = versions[pin.name];
|
|
129
|
+
if (!known || compareVersions(value, known) < 0) versions[pin.name] = value;
|
|
130
|
+
}
|
|
131
|
+
return versions;
|
|
132
|
+
};
|
|
133
|
+
const duplicateVersions = (lock) => {
|
|
134
|
+
const found = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const match of lock.matchAll(/^ {2}'?(@frigear-nu\/[\w.-]+)@(\d[^'(:\s]*)/gm)) {
|
|
136
|
+
const versions = found.get(match[1]) ?? /* @__PURE__ */ new Set();
|
|
137
|
+
found.set(match[1], versions.add(match[2]));
|
|
138
|
+
}
|
|
139
|
+
return Object.fromEntries([...found].filter(([, versions]) => versions.size > 1).map(([name, versions]) => [name, [...versions].sort(compareVersions)]));
|
|
140
|
+
};
|
|
141
|
+
const SHARED_LIBRARIES = ["zod", "h3", "vue", "vue-router", "drizzle-orm", "@nuxt/kit"];
|
|
142
|
+
const sharedDuplicates = (lock, names = SHARED_LIBRARIES) => {
|
|
143
|
+
const found = /* @__PURE__ */ new Map();
|
|
144
|
+
for (const match of lock.matchAll(/^ {2}'?((?:@[\w.-]+\/)?[\w.-]+)@(\d[^'(:\s]*)/gm)) {
|
|
145
|
+
if (!names.includes(match[1])) continue;
|
|
146
|
+
const versions = found.get(match[1]) ?? /* @__PURE__ */ new Set();
|
|
147
|
+
found.set(match[1], versions.add(match[2]));
|
|
148
|
+
}
|
|
149
|
+
const duplicates = {};
|
|
150
|
+
for (const [name, versions] of found) {
|
|
151
|
+
const byMajor = /* @__PURE__ */ new Map();
|
|
152
|
+
for (const version of versions) {
|
|
153
|
+
const major = version.split(".")[0];
|
|
154
|
+
byMajor.set(major, [...byMajor.get(major) ?? [], version]);
|
|
155
|
+
}
|
|
156
|
+
for (const same of byMajor.values()) {
|
|
157
|
+
if (same.length > 1) duplicates[name] = [...duplicates[name] ?? [], ...same.sort(compareVersions)];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return duplicates;
|
|
161
|
+
};
|
|
162
|
+
const PATCH_ENTRY = /^(\s*)(["']?)(@frigear-nu\/[\w.-]+)@(\d[^"'\s:]*)\2(\s*:\s*)(["']?)([^"'\s,]+)\6/gm;
|
|
163
|
+
const movePatchedDependencies = (file, text, targets) => {
|
|
164
|
+
const moves = [];
|
|
165
|
+
const out = text.replace(PATCH_ENTRY, (all, indent, q, name, version, sep, vq, patch) => {
|
|
166
|
+
const to = targets[name];
|
|
167
|
+
if (!to || to === version) return all;
|
|
168
|
+
const next = patch.split(version).join(to);
|
|
169
|
+
moves.push({ file, name, from: version, to, patch, next });
|
|
170
|
+
return `${indent}${q}${name}@${to}${q}${sep}${vq}${next}${vq}`;
|
|
171
|
+
});
|
|
172
|
+
return { text: out, moves };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export { workspacePackageDirs as a, compareVersions as b, currentVersions as c, duplicateVersions as d, movePatchedDependencies as e, findPins as f, isBetween as i, manifestFiles as m, rewritePins as r, sharedDuplicates as s, workspaceGlobs as w };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Frigear CLI: scaffold projects, apps and modules, and add Frigear modules to an app.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@frigear-nu/eslint-config": "^0.2.5",
|
|
48
48
|
"@types/node": "^26.6.6",
|
|
49
|
-
"eslint": "^10.
|
|
49
|
+
"eslint": "^10.15.0",
|
|
50
50
|
"jiti": "^2.7.0",
|
|
51
51
|
"typescript": "^6.0.3",
|
|
52
52
|
"unbuild": "^3.6.1",
|