@frigear-nu/cli 0.1.2 → 0.2.0
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/chunks/add.mjs +1 -1
- package/dist/chunks/app-create.mjs +1 -1
- package/dist/chunks/init.mjs +1 -1
- package/dist/chunks/upgrade.mjs +700 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +103 -2
- package/dist/index.d.ts +103 -2
- package/dist/index.mjs +5 -2
- package/dist/shared/{cli.Bt1wuyrA.mjs → cli.BNukBQzw.mjs} +4 -3
- package/dist/shared/{cli.CCJgOooL.mjs → cli.CkMCvUCp.mjs} +1 -1
- package/package.json +1 -1
package/dist/chunks/add.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { resolve, join, relative } from 'node:path';
|
|
|
6
6
|
import { parseModule, generateCode } from 'magicast';
|
|
7
7
|
import { getDefaultExportOptions, addNuxtModule } from 'magicast/helpers';
|
|
8
8
|
import { a as readPackage, d as defineCommandArgs, f as findWorkspaceRoot, l as listDirs } from '../shared/cli.Cfkcp0w9.mjs';
|
|
9
|
-
import { a as addDeps } from '../shared/cli.
|
|
9
|
+
import { a as addDeps } from '../shared/cli.CkMCvUCp.mjs';
|
|
10
10
|
import 'scule';
|
|
11
11
|
import 'pkg-types';
|
|
12
12
|
import 'nypm';
|
|
@@ -2,7 +2,7 @@ import { defineCommand } from 'citty';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { f as findWorkspaceRoot, t as toPackageName, h as hasPackage, r as renamePackage, d as defineCommandArgs, b as templateArgs, l as listDirs, p as packageScope, a as readPackage } from '../shared/cli.Cfkcp0w9.mjs';
|
|
5
|
-
import { i as installDeps } from '../shared/cli.
|
|
5
|
+
import { i as installDeps } from '../shared/cli.CkMCvUCp.mjs';
|
|
6
6
|
import { d as downloadTemplateToDir, r as repoSource } from '../shared/cli.C_0i5HKZ.mjs';
|
|
7
7
|
import 'scule';
|
|
8
8
|
import 'node:fs';
|
package/dist/chunks/init.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { defineCommand } from 'citty';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { resolve, basename, relative } from 'node:path';
|
|
4
4
|
import { i as isEmptyDir, h as hasPackage, r as renamePackage, t as toPackageName, a as readPackage, d as defineCommandArgs, b as templateArgs } from '../shared/cli.Cfkcp0w9.mjs';
|
|
5
|
-
import { i as installDeps, r as runPackageScript } from '../shared/cli.
|
|
5
|
+
import { i as installDeps, r as runPackageScript } from '../shared/cli.CkMCvUCp.mjs';
|
|
6
6
|
import { d as downloadTemplateToDir, r as repoSource } from '../shared/cli.C_0i5HKZ.mjs';
|
|
7
7
|
import 'scule';
|
|
8
8
|
import 'node:fs';
|
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { readFile, writeFile, readdir, stat } from 'node:fs/promises';
|
|
4
|
+
import { join, basename, relative, dirname, resolve } from 'node:path';
|
|
5
|
+
import { existsSync } from 'node:fs';
|
|
6
|
+
import { parseModule } from 'magicast';
|
|
7
|
+
import { getDefaultExportOptions } from 'magicast/helpers';
|
|
8
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.Cfkcp0w9.mjs';
|
|
9
|
+
import { i as installDeps } from '../shared/cli.CkMCvUCp.mjs';
|
|
10
|
+
|
|
11
|
+
const VERSION = /(\d+)\.(\d+)\.(\d+)(?:-([\w.-]+))?/;
|
|
12
|
+
const parseVersion = (value) => {
|
|
13
|
+
const match = value.match(VERSION);
|
|
14
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3]), match[4] ?? ""] : void 0;
|
|
15
|
+
};
|
|
16
|
+
const compareVersions = (a, b) => {
|
|
17
|
+
const va = parseVersion(a);
|
|
18
|
+
const vb = parseVersion(b);
|
|
19
|
+
if (!va || !vb) throw new Error(`Not a version: ${!va ? a : b}`);
|
|
20
|
+
for (let i = 0; i < 3; i++) {
|
|
21
|
+
const diff = va[i] - vb[i];
|
|
22
|
+
if (diff) return diff;
|
|
23
|
+
}
|
|
24
|
+
if (va[3] === vb[3]) return 0;
|
|
25
|
+
if (!va[3]) return 1;
|
|
26
|
+
if (!vb[3]) return -1;
|
|
27
|
+
return va[3] < vb[3] ? -1 : 1;
|
|
28
|
+
};
|
|
29
|
+
const isBetween = (version, from, to) => compareVersions(version, from) > 0 && compareVersions(version, to) <= 0;
|
|
30
|
+
const SKIP = /^(?:workspace:|catalog:|link:|file:|portal:|npm:|git|https?:)/;
|
|
31
|
+
const rewriteRange = (range, version) => {
|
|
32
|
+
const trimmed = range.trim();
|
|
33
|
+
if (SKIP.test(trimmed) || /\|\||\s-\s|\s/.test(trimmed)) return void 0;
|
|
34
|
+
const match = trimmed.match(/^([\^~]|>=|[>=v])?(\d+\.\d+\.\d+(?:-[\w.-]+)?)$/);
|
|
35
|
+
if (!match) return void 0;
|
|
36
|
+
const operator = { "v": "", "=": "", ">": ">=" }[match[1] ?? ""] ?? match[1] ?? "";
|
|
37
|
+
const next = `${operator}${version}`;
|
|
38
|
+
return next === trimmed ? void 0 : next;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const DOCS = "https://docs.frigear.dev";
|
|
42
|
+
const SOURCE = /\.(?:[cm]?[jt]s|tsx|jsx|vue)$/;
|
|
43
|
+
const IGNORED_DIRS$1 = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", ".git", "dist", "coverage", ".turbo", ".vercel", ".wrangler", "migrations", "ios", "android"]);
|
|
44
|
+
const sourceFiles = async (dir) => {
|
|
45
|
+
if (!existsSync(dir)) return [];
|
|
46
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
47
|
+
const nested = await Promise.all(entries.map(async (entry) => {
|
|
48
|
+
const path = join(dir, entry.name);
|
|
49
|
+
if (entry.isDirectory()) return IGNORED_DIRS$1.has(entry.name) || entry.name.startsWith(".") ? [] : sourceFiles(path);
|
|
50
|
+
if (!SOURCE.test(entry.name) || entry.name.endsWith(".d.ts")) return [];
|
|
51
|
+
return (await stat(path)).size > 1e6 ? [] : [path];
|
|
52
|
+
}));
|
|
53
|
+
return nested.flat();
|
|
54
|
+
};
|
|
55
|
+
const pendingMigrations = (migrations, from, to) => migrations.filter((migration) => {
|
|
56
|
+
const a = from[migration.package];
|
|
57
|
+
const b = to[migration.package];
|
|
58
|
+
return a && b && isBetween(migration.since, a, b);
|
|
59
|
+
});
|
|
60
|
+
const lineOf = (text, index) => text.slice(0, index).split("\n").length;
|
|
61
|
+
const lineText = (text, line) => text.split("\n")[line - 1].trim().slice(0, 160);
|
|
62
|
+
const runMigrations = async (migrations, ctx) => {
|
|
63
|
+
const results = new Map(migrations.map((migration) => [migration, {
|
|
64
|
+
migration,
|
|
65
|
+
applied: [],
|
|
66
|
+
manual: [],
|
|
67
|
+
project: { applied: [], manual: [] }
|
|
68
|
+
}]));
|
|
69
|
+
for (const file of ctx.files) {
|
|
70
|
+
const original = await readFile(file, "utf-8");
|
|
71
|
+
let text = original;
|
|
72
|
+
for (const migration of migrations) {
|
|
73
|
+
const result = results.get(migration);
|
|
74
|
+
for (const rule of migration.rules ?? []) {
|
|
75
|
+
if (rule.files && !rule.files.test(file)) continue;
|
|
76
|
+
if (rule.when && !rule.when.test(text)) continue;
|
|
77
|
+
for (const match of text.matchAll(rule.pattern)) {
|
|
78
|
+
const line = lineOf(text, match.index);
|
|
79
|
+
const hit = { file, line, text: lineText(text, line), message: rule.message };
|
|
80
|
+
(rule.replace === void 0 ? result.manual : result.applied).push(hit);
|
|
81
|
+
}
|
|
82
|
+
if (rule.replace !== void 0) text = text.replace(rule.pattern, rule.replace);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (text !== original && !ctx.dryRun) await writeFile(file, text, "utf-8");
|
|
86
|
+
}
|
|
87
|
+
for (const migration of migrations) {
|
|
88
|
+
if (!migration.project) continue;
|
|
89
|
+
const found = await migration.project(ctx);
|
|
90
|
+
const result = results.get(migration);
|
|
91
|
+
result.project = { applied: found.applied ?? [], manual: found.manual ?? [] };
|
|
92
|
+
}
|
|
93
|
+
return [...results.values()];
|
|
94
|
+
};
|
|
95
|
+
const nuxtConfigs = (files) => files.filter((file) => /^nuxt\.config\.[cm]?[jt]s$/.test(basename(file)));
|
|
96
|
+
const readNuxtConfigs = async (files) => {
|
|
97
|
+
const configs = [];
|
|
98
|
+
for (const file of nuxtConfigs(files)) {
|
|
99
|
+
try {
|
|
100
|
+
configs.push({ file, options: getDefaultExportOptions(parseModule(await readFile(file, "utf-8"))) });
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return configs;
|
|
105
|
+
};
|
|
106
|
+
const option = (options, path) => path.split(".").reduce((value, key) => value !== null && typeof value === "object" ? value[key] : void 0, options);
|
|
107
|
+
const items = (value) => value !== null && typeof value === "object" && typeof value.length === "number" ? Array.from(value) : [];
|
|
108
|
+
|
|
109
|
+
const adminComponents = {
|
|
110
|
+
id: "admin-components",
|
|
111
|
+
package: "@frigear-nu/admin",
|
|
112
|
+
since: "0.1.3",
|
|
113
|
+
title: "Admin* components are replaced by @frigear-nu/ui",
|
|
114
|
+
docs: `${DOCS}/guide/ux-patterns`,
|
|
115
|
+
rules: [
|
|
116
|
+
{
|
|
117
|
+
pattern: /<Admin(?:PageHeader|Page|Section|Toolbar|Empty|Table|StatCard|KeyValue|ListCard)\b/g,
|
|
118
|
+
message: "Removed: use the `@frigear-nu/ui` patterns (`PageHeading`, `SectionCard`, `PageToolbar`, `TableCard`, `UEmpty`, \u2026). Props and slots differ."
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
};
|
|
122
|
+
const accountComponents = {
|
|
123
|
+
id: "account-components",
|
|
124
|
+
package: "@frigear-nu/account",
|
|
125
|
+
since: "0.1.3",
|
|
126
|
+
title: "AccountHeaderRight is AccountIdentity",
|
|
127
|
+
docs: `${DOCS}/guide/ux-patterns`,
|
|
128
|
+
rules: [
|
|
129
|
+
{
|
|
130
|
+
pattern: /\bAccountHeaderRight\b/g,
|
|
131
|
+
message: "Removed with the account layout redesign: use `AccountIdentity`, and `AccountHeader` for a page heading."
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const GUIDE = `${DOCS}/guide/going-further/migrate-access-control`;
|
|
137
|
+
const authPermissions = {
|
|
138
|
+
id: "auth-permissions",
|
|
139
|
+
package: "@frigear-nu/auth",
|
|
140
|
+
since: "0.5.0",
|
|
141
|
+
title: "Access checks use permissions: authorize(event, permission, record?)",
|
|
142
|
+
docs: GUIDE,
|
|
143
|
+
schema: true,
|
|
144
|
+
rules: [
|
|
145
|
+
{
|
|
146
|
+
pattern: /\b(?:defineStaffGuard|definePolicyGate|defineStaffScopes|addAuthScope|addAuthRole|principalHasScopes|isGrantableScope|isPiiScope|ALL_SCOPES)\b/g,
|
|
147
|
+
message: "Removed in auth 0.5. Register permissions with `defineAccess` + `registerAccess` (or `addPermission`), and check them with `await authorize(event, 'resource:action', record?)`."
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
pattern: /#auth\/scopes\b/g,
|
|
151
|
+
message: "`#auth/scopes` is gone: permissions are registered with `defineAccess` / `addPermission`."
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
pattern: /\b(?:requireUser|requireAuth|getUser)\(\s*[\w.]+\s*,\s*\{[^}]*\bscopes\b/g,
|
|
155
|
+
message: "The `scopes` option is gone: `requireUser` / `requireAuth` only authenticate. Check access with `await authorize(event, 'resource:action')`."
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
pattern: /\bhasScopes?\(/g,
|
|
159
|
+
message: "`hasScope(s)` is gone: use `await allows(event, permission)` on the server, `ctx.can(permission)` in MCP, `can(permission)` in the client."
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
pattern: /\brequireUserSession\(/g,
|
|
163
|
+
message: "Do not use nuxt-auth-utils' `requireUserSession`: it ignores API and OAuth tokens. Use `authorize(event, permission)`, or `requireAuth(event)` for a route any signed-in user may call."
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
pattern: /['"](?!users:admin:)[\w-]+:authorize['"]/g,
|
|
167
|
+
message: "A `<module>:authorize` hook is the old pattern: register the module's permissions (`defineAccess` + `registerAccess`), check them with `authorize(event, permission, record)`, and move host rules to a policy (`definePolicy`) or `authorization:before`."
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
pattern: /['"](?:auth:user-permissions|auth:scope-available|oauth:scope:staff|oauth:user:roles)['"]/g,
|
|
171
|
+
message: "This hook never fires since auth 0.5: move it to `authorization:roles` (roles) or `authorization:before` (overrides)."
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
steps: [
|
|
175
|
+
"Mint API tokens again: a token issued before the upgrade has no frozen permissions and holds nothing.",
|
|
176
|
+
"Everything fails closed: an unregistered permission is a 403 (also for admins), and `*` never covers `:pii` or `sessionOnly` permissions. Click through the staff areas before deploying."
|
|
177
|
+
],
|
|
178
|
+
async project({ root, files }) {
|
|
179
|
+
const manual = [];
|
|
180
|
+
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
181
|
+
const at = relative(root, file);
|
|
182
|
+
if (option(options, "authentication.scopes") !== void 0) {
|
|
183
|
+
manual.push(`${at}: \`authentication.scopes\` is ignored since auth 0.5. Rename it to \`authentication.permissions\` and give each entry \`{ name, label, grantTo }\`.`);
|
|
184
|
+
}
|
|
185
|
+
const rules = option(options, "routeRules");
|
|
186
|
+
if (rules && typeof rules === "object") {
|
|
187
|
+
for (const [path, rule] of Object.entries(rules)) {
|
|
188
|
+
const old = ["roles", "ability", "scopes"].filter((key) => option(rule, key) !== void 0);
|
|
189
|
+
if (old.length) manual.push(`${at}: route rule \`${path}\` uses \`${old.join("`, `")}\`, which fail the build: use \`permission: 'resource:action'\`.`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { manual };
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const authorizationRoles = {
|
|
197
|
+
id: "authorization-roles",
|
|
198
|
+
package: "@frigear-nu/authorization",
|
|
199
|
+
since: "0.5.0",
|
|
200
|
+
title: "Abilities and RBAC options are replaced by roles and policies",
|
|
201
|
+
docs: GUIDE,
|
|
202
|
+
schema: true,
|
|
203
|
+
rules: [
|
|
204
|
+
{
|
|
205
|
+
pattern: /\b(?:defineAbility|bouncer|resolveAuthorizationUser)\b/g,
|
|
206
|
+
message: "Removed in authorization 0.5: an ability becomes a permission granted to roles, plus a `definePolicy` for rules about the record."
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
pattern: /\bauthorize\(\s*[\w.]+\s*,\s*(?![\w.]*(?:[Aa]ccess|permissions)\b)[A-Za-z_$][\w$]*\s*[,)]/g,
|
|
210
|
+
message: "Check this call: `authorize(event, permission, record?)` takes a permission name now, not an ability."
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
pattern: /<(?:Can|Cannot)\b[^>]*\s:?(?:ability|role)=/g,
|
|
214
|
+
message: '`<Can ability>` / `<Can role>` are gone: use `<Can permission="resource:action" :record="record">`.'
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
pattern: /\bauthorize\s*:\s*\{[^}]*\b(?:roles|ability)\b/g,
|
|
218
|
+
message: "`definePageMeta({ authorize: { roles | ability } })` is gone: use `authorize: 'resource:action'`."
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
pattern: /['"]authorization:(?:role|authorize)['"]/g,
|
|
222
|
+
message: "This hook is gone: use `authorization:roles` (push to `ctx.roles`) or `authorization:before` (`allow()` / `deny()`)."
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
pattern: /\buseAuthorization\(\)/g,
|
|
226
|
+
when: /\bcan\(\s*(?!['"`])/,
|
|
227
|
+
message: "Check the `can(...)` calls in this file: `can(permission, record?)` takes a permission name now, not an ability."
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
steps: [
|
|
231
|
+
"Run the verification SQL of the migration guide: `users.role` is copied once into `authorization_user_roles` and no longer read."
|
|
232
|
+
],
|
|
233
|
+
async project({ root, files }) {
|
|
234
|
+
const manual = [];
|
|
235
|
+
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
236
|
+
const at = relative(root, file);
|
|
237
|
+
const removed = ["abilities", "resolvers", "rbac"].filter((key) => option(options, `authorization.${key}`) !== void 0);
|
|
238
|
+
const roleKeys = ["hierarchy", "inherits", "grant", "revoke", "labels", "descriptions", "definitions", "defaultRole"].filter((key) => option(options, `authorization.roles.${key}`) !== void 0);
|
|
239
|
+
if (removed.length || roleKeys.length) {
|
|
240
|
+
const names = [...removed.map((key) => `authorization.${key}`), ...roleKeys.map((key) => `authorization.roles.${key}`)];
|
|
241
|
+
manual.push(`${at}: \`${names.join("`, `")}\` are gone. Declare each role as \`authorization.roles.<name>: { grant, inherit, label }\` and set \`authorization.defaultRoles\`.`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return { manual };
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const usersPermissions = {
|
|
248
|
+
id: "users-permissions",
|
|
249
|
+
package: "@frigear-nu/users",
|
|
250
|
+
since: "3.0.0",
|
|
251
|
+
title: "The users admin checks users:* permissions",
|
|
252
|
+
docs: GUIDE,
|
|
253
|
+
rules: [
|
|
254
|
+
{
|
|
255
|
+
pattern: /['"]users:admin:(?:authorize|roles)['"]/g,
|
|
256
|
+
message: "This hook is gone: use `authorization:before` or a policy on `users:*`; roles come from `authorization.roles`."
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
pattern: /\b(?:isUsersAdminAllowed|assignableRoles|usersHaveRoles|USERS_READ_SCOPE)\b/g,
|
|
260
|
+
message: "Removed in users 3.0: check `users:*` permissions with `authorize` / `allows`."
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
pattern: /\/api\/admin\/users\/roles\b/g,
|
|
264
|
+
message: "`GET /api/admin/users/roles` is gone: roles come from `authorization.roles`, and `GET /api/auth/me/access` lists the caller's."
|
|
265
|
+
}
|
|
266
|
+
],
|
|
267
|
+
steps: [
|
|
268
|
+
"Listing users needs `users:list` now (`users:read` opens one user): grant both to the roles that had `users:read`."
|
|
269
|
+
]
|
|
270
|
+
};
|
|
271
|
+
const adminPermission = {
|
|
272
|
+
id: "admin-permission",
|
|
273
|
+
package: "@frigear-nu/admin",
|
|
274
|
+
since: "0.4.0",
|
|
275
|
+
title: "admin.settings.roles is admin.settings.permission",
|
|
276
|
+
docs: GUIDE,
|
|
277
|
+
async project({ root, files }) {
|
|
278
|
+
const manual = [];
|
|
279
|
+
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
280
|
+
if (option(options, "admin.settings.roles") !== void 0) {
|
|
281
|
+
manual.push(`${relative(root, file)}: \`admin.settings.roles\` throws at build time. Remove it and grant \`admin:access\` (the default \`admin.settings.permission\`) to those roles in \`authorization.roles\`.`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return { manual };
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
const accountPermission = {
|
|
288
|
+
id: "account-permission",
|
|
289
|
+
package: "@frigear-nu/account",
|
|
290
|
+
since: "0.5.0",
|
|
291
|
+
title: "account.settings.documents[].roles is permission",
|
|
292
|
+
docs: GUIDE,
|
|
293
|
+
async project({ root, files }) {
|
|
294
|
+
const manual = [];
|
|
295
|
+
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
296
|
+
const documents = items(option(options, "account.settings.documents"));
|
|
297
|
+
if (documents.some((document) => option(document, "roles") !== void 0)) {
|
|
298
|
+
manual.push(`${relative(root, file)}: \`account.settings.documents[].roles\` throws at build time: use \`permission: 'resource:action'\`.`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { manual };
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const menuPermission = {
|
|
305
|
+
id: "menu-permission",
|
|
306
|
+
package: "@frigear-nu/menu",
|
|
307
|
+
since: "0.3.0",
|
|
308
|
+
title: "Menu items, widgets and tabs filter by permission",
|
|
309
|
+
docs: GUIDE,
|
|
310
|
+
rules: [
|
|
311
|
+
{
|
|
312
|
+
pattern: /\b(?:roles|requires)\s*:/g,
|
|
313
|
+
when: /\b(?:addMenuItems|pushMenuItems|extendTabs|addWidgets?|registerWidgets?)\b/,
|
|
314
|
+
message: "Menu items, widgets and tabs filter by `permission: 'resource:action'` now: replace role names with the permission the target route checks."
|
|
315
|
+
}
|
|
316
|
+
]
|
|
317
|
+
};
|
|
318
|
+
const mcpPermission = {
|
|
319
|
+
id: "mcp-permission",
|
|
320
|
+
package: "@frigear-nu/mcp",
|
|
321
|
+
since: "0.4.0",
|
|
322
|
+
title: "MCP definitions take { permission }",
|
|
323
|
+
docs: GUIDE,
|
|
324
|
+
rules: [
|
|
325
|
+
{
|
|
326
|
+
pattern: /\b(?:scopes|gate|sessionOnly)\s*:/g,
|
|
327
|
+
when: /\bdefineScopedMcp(?:Tool|Resource|Prompt)\b/,
|
|
328
|
+
message: "`defineScopedMcp*` take only `{ permission: 'resource:action' }` now; a definition without one throws. Use a `sessionOnly` permission for money and credentials."
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
pattern: /\bctx\.hasScopes?\(/g,
|
|
332
|
+
message: "`ctx.hasScope(s)` is `await ctx.can(permission)`."
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
pattern: /\bScopedGate\b/g,
|
|
336
|
+
message: "`ScopedGate` is gone: definitions declare a `permission`."
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const UPGRADING = `${DOCS}/get-started/upgrading`;
|
|
342
|
+
const authRoutes = {
|
|
343
|
+
id: "auth-routes",
|
|
344
|
+
package: "@frigear-nu/auth",
|
|
345
|
+
since: "0.1.4",
|
|
346
|
+
title: "Auth API routes moved under /api/auth",
|
|
347
|
+
docs: `${UPGRADING}#breaking-changes-by-release`,
|
|
348
|
+
rules: [
|
|
349
|
+
{
|
|
350
|
+
pattern: /\/api\/auth\/tokens\b/g,
|
|
351
|
+
replace: "/api/auth/me/tokens",
|
|
352
|
+
message: "`/api/auth/tokens` is `/api/auth/me/tokens` (create answers 201, revoke 204). `authApi.me.tokens` from `@frigear-nu/auth/api` names it."
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
pattern: /\/api\/auth\/webauthn\/credentials\b/g,
|
|
356
|
+
replace: "/api/auth/me/passkeys",
|
|
357
|
+
message: "`/api/auth/webauthn/credentials` is `/api/auth/me/passkeys` (delete answers 204)."
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
pattern: /\/api\/_bootstrap\b/g,
|
|
361
|
+
replace: "/api/auth/bootstrap",
|
|
362
|
+
message: "`/api/_bootstrap` is `/api/auth/bootstrap`."
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
pattern: /(['"`])\/auth\/logout\b/g,
|
|
366
|
+
replace: "$1/api/auth/logout",
|
|
367
|
+
message: "Logout is `POST /api/auth/logout` now (204): a link or `navigateTo` to it must become `$fetch(authApi.logout, { method: 'POST' })`, and a menu item needs `method: 'post'`."
|
|
368
|
+
}
|
|
369
|
+
]
|
|
370
|
+
};
|
|
371
|
+
const usersRoutes = {
|
|
372
|
+
id: "users-routes",
|
|
373
|
+
package: "@frigear-nu/users",
|
|
374
|
+
since: "1.1.4",
|
|
375
|
+
title: "Users self-service routes are REST",
|
|
376
|
+
docs: `${UPGRADING}#breaking-changes-by-release`,
|
|
377
|
+
rules: [
|
|
378
|
+
{
|
|
379
|
+
pattern: /\/api\/users\/me\/profile\b/g,
|
|
380
|
+
replace: "/api/users/me",
|
|
381
|
+
message: "The profile update is `PATCH /api/users/me` (was `POST \u2026/me/profile`): change the method too. `usersApi.me` from `@frigear-nu/users/api` names it."
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
pattern: /\/api\/users\/me\/change-email\b/g,
|
|
385
|
+
replace: "/api/users/me/email",
|
|
386
|
+
message: "The email change is `PUT /api/users/me/email` (was `POST \u2026/me/change-email`): change the method too."
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
pattern: /\/api\/users\/me\/change-password\b/g,
|
|
390
|
+
replace: "/api/users/me/password",
|
|
391
|
+
message: "The password change is `PUT /api/users/me/password` (was `POST \u2026/me/change-password`): change the method too."
|
|
392
|
+
}
|
|
393
|
+
]
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const authSessionSecret = {
|
|
397
|
+
id: "auth-session-secret",
|
|
398
|
+
package: "@frigear-nu/auth",
|
|
399
|
+
since: "0.4.0",
|
|
400
|
+
title: "Sessions are sealed with NUXT_APP_SECRET",
|
|
401
|
+
docs: `${DOCS}/get-started/upgrading#breaking-changes-by-release`,
|
|
402
|
+
schema: true,
|
|
403
|
+
steps: [
|
|
404
|
+
"Set `NUXT_APP_SECRET` (32+ random characters) in every environment before deploying. Keep `NUXT_SESSION_PASSWORD`: it is still the fallback key for stored OAuth tokens.",
|
|
405
|
+
"The session cookie is renamed (`nuxt-auth-session`): every user is signed out once after the deploy."
|
|
406
|
+
],
|
|
407
|
+
async project({ root, files, dryRun }) {
|
|
408
|
+
const applied = [];
|
|
409
|
+
for (const config of nuxtConfigs(files)) {
|
|
410
|
+
const example = join(dirname(config), ".env.example");
|
|
411
|
+
if (!existsSync(example)) continue;
|
|
412
|
+
const text = await readFile(example, "utf-8");
|
|
413
|
+
if (/^\s*NUXT_APP_SECRET\s*=/m.test(text)) continue;
|
|
414
|
+
if (!dryRun) await writeFile(example, `${text.replace(/\n*$/, "\n")}NUXT_APP_SECRET=
|
|
415
|
+
`, "utf-8");
|
|
416
|
+
applied.push(`Added \`NUXT_APP_SECRET=\` to ${relative(root, example)}`);
|
|
417
|
+
}
|
|
418
|
+
return { applied };
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const migrations = [
|
|
423
|
+
authRoutes,
|
|
424
|
+
usersRoutes,
|
|
425
|
+
adminComponents,
|
|
426
|
+
accountComponents,
|
|
427
|
+
authSessionSecret,
|
|
428
|
+
menuPermission,
|
|
429
|
+
mcpPermission,
|
|
430
|
+
adminPermission,
|
|
431
|
+
authPermissions,
|
|
432
|
+
authorizationRoles,
|
|
433
|
+
accountPermission,
|
|
434
|
+
usersPermissions
|
|
435
|
+
];
|
|
436
|
+
|
|
437
|
+
const YAML_KEY = /^(\s*)(['"]?)(@frigear-nu\/[\w.-]+)\2(\s*:\s*)(['"]?)([^'"\s#]+)\5/;
|
|
438
|
+
const YAML_ITEM = /^(\s*-\s*)(['"]?)(@frigear-nu\/[\w.-]+)@([^'"\s#]+)\2/;
|
|
439
|
+
const JSON_ENTRY = /("(@frigear-nu\/[\w.-]+)"\s*:\s*")([^"]*)(")/g;
|
|
440
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", ".git", "dist", "coverage", ".turbo", ".vercel", ".wrangler"]);
|
|
441
|
+
const workspaceGlobs = (yaml) => {
|
|
442
|
+
const globs = [];
|
|
443
|
+
let inPackages = false;
|
|
444
|
+
for (const line of yaml.split("\n")) {
|
|
445
|
+
if (/^\S/.test(line)) inPackages = /^packages\s*:/.test(line);
|
|
446
|
+
else if (inPackages) {
|
|
447
|
+
const item = line.match(/^\s*-\s*['"]?([^'"#\s]+)/);
|
|
448
|
+
if (item && !item[1].startsWith("!")) globs.push(item[1].trim());
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return globs;
|
|
452
|
+
};
|
|
453
|
+
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)) : [];
|
|
454
|
+
const deepDirs = async (dir) => {
|
|
455
|
+
const children = await subdirs(dir);
|
|
456
|
+
return [dir, ...(await Promise.all(children.map(deepDirs))).flat()];
|
|
457
|
+
};
|
|
458
|
+
const workspacePackageDirs = async (root) => {
|
|
459
|
+
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
460
|
+
const globs = existsSync(yamlPath) ? workspaceGlobs(await readFile(yamlPath, "utf-8")) : [];
|
|
461
|
+
const dirs = /* @__PURE__ */ new Set([root]);
|
|
462
|
+
for (const glob of globs) {
|
|
463
|
+
const parts = glob.replace(/\/+$/, "").split("/");
|
|
464
|
+
let current = [root];
|
|
465
|
+
for (const part of parts) {
|
|
466
|
+
if (part === "**") current = (await Promise.all(current.map(deepDirs))).flat();
|
|
467
|
+
else if (part.includes("*")) {
|
|
468
|
+
const pattern = new RegExp(`^${part.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
|
|
469
|
+
current = (await Promise.all(current.map(subdirs))).flat().filter((dir) => pattern.test(dir.split(/[\\/]/).pop()));
|
|
470
|
+
} else current = current.map((dir) => join(dir, part));
|
|
471
|
+
}
|
|
472
|
+
for (const dir of current) if (existsSync(join(dir, "package.json"))) dirs.add(dir);
|
|
473
|
+
}
|
|
474
|
+
return [...dirs];
|
|
475
|
+
};
|
|
476
|
+
const manifestFiles = async (root) => {
|
|
477
|
+
const files = (await workspacePackageDirs(root)).map((dir) => join(dir, "package.json")).filter(existsSync);
|
|
478
|
+
const yaml = join(root, "pnpm-workspace.yaml");
|
|
479
|
+
return existsSync(yaml) ? [...files, yaml] : files;
|
|
480
|
+
};
|
|
481
|
+
const findPins = (file, text) => {
|
|
482
|
+
if (file.endsWith(".json")) {
|
|
483
|
+
return [...text.matchAll(JSON_ENTRY)].map((match) => ({ file, name: match[2], range: match[3] }));
|
|
484
|
+
}
|
|
485
|
+
return text.split("\n").flatMap((line) => {
|
|
486
|
+
const key = line.match(YAML_KEY);
|
|
487
|
+
if (key) return [{ file, name: key[3], range: key[6] }];
|
|
488
|
+
const item = line.match(YAML_ITEM);
|
|
489
|
+
return item ? [{ file, name: item[3], range: item[4] }] : [];
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
const rewritePins = (file, text, targets) => {
|
|
493
|
+
const bumps = [];
|
|
494
|
+
const bump = (name, range) => {
|
|
495
|
+
const target = targets[name];
|
|
496
|
+
const next = target ? rewriteRange(range, target) : void 0;
|
|
497
|
+
if (next) bumps.push({ file, name, range, next });
|
|
498
|
+
return next;
|
|
499
|
+
};
|
|
500
|
+
if (file.endsWith(".json")) {
|
|
501
|
+
const out2 = text.replace(JSON_ENTRY, (all, head, name, range, tail) => {
|
|
502
|
+
const next = bump(name, range);
|
|
503
|
+
return next ? `${head}${next}${tail}` : all;
|
|
504
|
+
});
|
|
505
|
+
return { text: out2, bumps };
|
|
506
|
+
}
|
|
507
|
+
const out = text.split("\n").map((line) => {
|
|
508
|
+
const key = line.match(YAML_KEY);
|
|
509
|
+
if (key) {
|
|
510
|
+
const [all, indent, q, name, sep, vq, range] = key;
|
|
511
|
+
const next = bump(name, range);
|
|
512
|
+
return next ? line.replace(all, `${indent}${q}${name}${q}${sep}${vq}${next}${vq}`) : line;
|
|
513
|
+
}
|
|
514
|
+
const item = line.match(YAML_ITEM);
|
|
515
|
+
if (item) {
|
|
516
|
+
const [all, dash, q, name, range] = item;
|
|
517
|
+
const next = bump(name, range);
|
|
518
|
+
return next ? line.replace(all, `${dash}${q}${name}@${next}${q}`) : line;
|
|
519
|
+
}
|
|
520
|
+
return line;
|
|
521
|
+
}).join("\n");
|
|
522
|
+
return { text: out, bumps };
|
|
523
|
+
};
|
|
524
|
+
const currentVersions = (pins) => {
|
|
525
|
+
const versions = {};
|
|
526
|
+
for (const pin of pins) {
|
|
527
|
+
const version = parseVersion(pin.range);
|
|
528
|
+
if (!version) continue;
|
|
529
|
+
const value = `${version[0]}.${version[1]}.${version[2]}${version[3] ? `-${version[3]}` : ""}`;
|
|
530
|
+
const known = versions[pin.name];
|
|
531
|
+
if (!known || compareVersions(value, known) < 0) versions[pin.name] = value;
|
|
532
|
+
}
|
|
533
|
+
return versions;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const REGISTRY = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
537
|
+
const latestVersion = async (name) => {
|
|
538
|
+
const response = await fetch(`${REGISTRY}/${name.replace("/", "%2f")}`, {
|
|
539
|
+
headers: { accept: "application/vnd.npm.install-v1+json" }
|
|
540
|
+
});
|
|
541
|
+
if (response.status === 404) return void 0;
|
|
542
|
+
if (!response.ok) throw new Error(`npm registry answered ${response.status} for ${name}`);
|
|
543
|
+
const body = await response.json();
|
|
544
|
+
return body["dist-tags"]?.latest;
|
|
545
|
+
};
|
|
546
|
+
const parseTargets = (value) => {
|
|
547
|
+
const targets = {};
|
|
548
|
+
for (const spec of (value ?? "").split(/[\s,]+/).filter(Boolean)) {
|
|
549
|
+
const at = spec.lastIndexOf("@");
|
|
550
|
+
if (at <= 0) throw new Error(`Expected <package>@<version>, got "${spec}"`);
|
|
551
|
+
const name = spec.slice(0, at);
|
|
552
|
+
targets[name.includes("/") ? name : `@frigear-nu/${name}`] = spec.slice(at + 1);
|
|
553
|
+
}
|
|
554
|
+
return targets;
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const code = (text) => `\`${text.replace(/`/g, "'")}\``;
|
|
558
|
+
const renderReport = ({ root, from, to, bumps, results, dryRun }) => {
|
|
559
|
+
const at = (hit) => `${relative(root, hit.file)}:${hit.line}`;
|
|
560
|
+
const lines = [`# @frigear-nu upgrade${dryRun ? " (dry run)" : ""}`, ""];
|
|
561
|
+
const names = Object.keys(to).filter((name) => from[name] && from[name] !== to[name]).sort();
|
|
562
|
+
if (!names.length) return [...lines, "Every `@frigear-nu/*` package is already at its target version.", ""].join("\n");
|
|
563
|
+
lines.push("| Package | From | To |", "| --- | --- | --- |", ...names.map((name) => `| ${name} | ${from[name]} | ${to[name]} |`), "");
|
|
564
|
+
const files = [...new Set(bumps.map((bump) => relative(root, bump.file)))];
|
|
565
|
+
lines.push(`${dryRun ? "Would update" : "Updated"} ${bumps.length} version pins in ${files.map(code).join(", ")}.`, "");
|
|
566
|
+
const applied = results.filter((result) => result.applied.length || result.project.applied.length);
|
|
567
|
+
if (applied.length) {
|
|
568
|
+
lines.push(`## ${dryRun ? "Would be rewritten" : "Rewritten"}`, "");
|
|
569
|
+
for (const { migration, applied: hits, project } of applied) {
|
|
570
|
+
lines.push(`### ${migration.title}`, "", `${migration.package}@${migration.since} \xB7 [docs](${migration.docs})`, "");
|
|
571
|
+
for (const hit of hits) lines.push(`- ${code(at(hit))} ${hit.message}`);
|
|
572
|
+
for (const message of project.applied) lines.push(`- ${message}`);
|
|
573
|
+
lines.push("");
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const manual = results.filter((result) => result.manual.length || result.project.manual.length || result.migration.steps?.length);
|
|
577
|
+
if (manual.length) {
|
|
578
|
+
lines.push("## To do by hand", "");
|
|
579
|
+
for (const { migration, manual: hits, project } of manual) {
|
|
580
|
+
lines.push(`### ${migration.title}`, "", `${migration.package}@${migration.since} \xB7 [docs](${migration.docs})`, "");
|
|
581
|
+
for (const hit of hits) lines.push(`- [ ] ${code(at(hit))} ${code(hit.text)}: ${hit.message}`);
|
|
582
|
+
for (const message of project.manual) lines.push(`- [ ] ${message}`);
|
|
583
|
+
for (const step of migration.steps ?? []) lines.push(`- [ ] ${step}`);
|
|
584
|
+
lines.push("");
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const schema = results.some((result) => result.migration.schema);
|
|
588
|
+
lines.push(
|
|
589
|
+
"## Next",
|
|
590
|
+
"",
|
|
591
|
+
"1. `pnpm install`",
|
|
592
|
+
schema ? "2. Generate a migration in every app with a database (`pnpm db:generate`, or `nuxt db generate`) and commit it: these releases changed the schema." : "2. Generate a migration in every app with a database (`pnpm db:generate`) if it prints changes, and commit it.",
|
|
593
|
+
"3. `pnpm lint`, `pnpm typecheck`, `pnpm test` and `pnpm build`. Stale `.nuxt` types cause false errors: run `nuxt prepare` first.",
|
|
594
|
+
""
|
|
595
|
+
);
|
|
596
|
+
return lines.join("\n");
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
const upgradeWorkspace = async (options) => {
|
|
600
|
+
const root = await findWorkspaceRoot(options.cwd) ?? options.cwd;
|
|
601
|
+
const dryRun = options.dryRun === true;
|
|
602
|
+
const resolveLatest = options.resolveLatest ?? latestVersion;
|
|
603
|
+
const manifests = await Promise.all((await manifestFiles(root)).map(async (file) => ({ file, text: await readFile(file, "utf-8") })));
|
|
604
|
+
const pins = manifests.flatMap(({ file, text }) => findPins(file, text));
|
|
605
|
+
const from = currentVersions(pins);
|
|
606
|
+
let names = Object.keys(from);
|
|
607
|
+
if (options.only?.length) names = names.filter((name) => options.only.includes(name));
|
|
608
|
+
const to = {};
|
|
609
|
+
const skipped = [];
|
|
610
|
+
await Promise.all(names.map(async (name) => {
|
|
611
|
+
const target = options.to?.[name] ?? await resolveLatest(name);
|
|
612
|
+
if (!target) return;
|
|
613
|
+
if (compareVersions(target, from[name]) < 0) skipped.push(`${name}: pinned ${from[name]} is newer than ${target}`);
|
|
614
|
+
else to[name] = target;
|
|
615
|
+
}));
|
|
616
|
+
const bumps = [];
|
|
617
|
+
for (const manifest of manifests) {
|
|
618
|
+
const { text, bumps: made } = rewritePins(manifest.file, manifest.text, to);
|
|
619
|
+
bumps.push(...made);
|
|
620
|
+
if (made.length && !dryRun) await writeFile(manifest.file, text, "utf-8");
|
|
621
|
+
}
|
|
622
|
+
const pending = pendingMigrations(options.migrations ?? migrations, from, to);
|
|
623
|
+
const results = await runMigrations(pending, { root, files: await sourceFiles(root), dryRun });
|
|
624
|
+
const fromUpgraded = Object.fromEntries(Object.keys(to).map((name) => [name, from[name]]));
|
|
625
|
+
const report = renderReport({ root, from: fromUpgraded, to, bumps, results, dryRun });
|
|
626
|
+
return { root, from: fromUpgraded, to, bumps, results, skipped, report };
|
|
627
|
+
};
|
|
628
|
+
const upgrade = defineCommand({
|
|
629
|
+
meta: {
|
|
630
|
+
name: "upgrade",
|
|
631
|
+
description: "Upgrade every @frigear-nu package of a workspace and apply the code changes of the releases in between"
|
|
632
|
+
},
|
|
633
|
+
args: defineCommandArgs({
|
|
634
|
+
packages: {
|
|
635
|
+
type: "positional",
|
|
636
|
+
description: "Only these packages, e.g. auth users (default: all)",
|
|
637
|
+
required: false
|
|
638
|
+
},
|
|
639
|
+
to: {
|
|
640
|
+
type: "string",
|
|
641
|
+
description: "Target versions instead of latest, e.g. auth@0.6.1,users@3.1.0"
|
|
642
|
+
},
|
|
643
|
+
dryRun: {
|
|
644
|
+
type: "boolean",
|
|
645
|
+
description: "Only print the report; change nothing",
|
|
646
|
+
default: false
|
|
647
|
+
},
|
|
648
|
+
install: {
|
|
649
|
+
type: "boolean",
|
|
650
|
+
description: "Run pnpm install afterwards (--no-install to skip)",
|
|
651
|
+
default: true
|
|
652
|
+
},
|
|
653
|
+
report: {
|
|
654
|
+
type: "string",
|
|
655
|
+
description: "Where to write the Markdown report (relative to the workspace root)",
|
|
656
|
+
default: "frigear-upgrade.md"
|
|
657
|
+
}
|
|
658
|
+
}),
|
|
659
|
+
async run({ args }) {
|
|
660
|
+
const logger = consola.withTag("upgrade");
|
|
661
|
+
const only = args._.map(String).filter(Boolean).map((name) => name.includes("/") ? name : `@frigear-nu/${name}`);
|
|
662
|
+
const result = await upgradeWorkspace({
|
|
663
|
+
cwd: resolve(args.cwd),
|
|
664
|
+
to: parseTargets(args.to),
|
|
665
|
+
only,
|
|
666
|
+
dryRun: args.dryRun
|
|
667
|
+
}).catch((error) => {
|
|
668
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
669
|
+
return process.exit(1);
|
|
670
|
+
});
|
|
671
|
+
for (const message of result.skipped) logger.warn(message);
|
|
672
|
+
const upgraded = Object.keys(result.to).filter((name) => result.from[name] !== result.to[name]);
|
|
673
|
+
if (!upgraded.length) {
|
|
674
|
+
logger.success("Every @frigear-nu package is already at its target version.");
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
const manual = result.results.reduce((sum, r) => sum + r.manual.length + r.project.manual.length + (r.migration.steps?.length ?? 0), 0);
|
|
678
|
+
const applied = result.results.reduce((sum, r) => sum + r.applied.length + r.project.applied.length, 0);
|
|
679
|
+
if (args.dryRun) {
|
|
680
|
+
consola.log(result.report);
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const reportPath = join(result.root, args.report);
|
|
684
|
+
await writeFile(reportPath, result.report, "utf-8");
|
|
685
|
+
logger.success(`Upgraded ${upgraded.map((name) => `${name} ${result.from[name]} \u2192 ${result.to[name]}`).join(", ")}`);
|
|
686
|
+
logger.info(`${result.bumps.length} pins updated, ${applied} code changes made, ${manual} items to do by hand: ${reportPath}`);
|
|
687
|
+
if (args.install) {
|
|
688
|
+
logger.start("Installing");
|
|
689
|
+
await installDeps(result.root);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
const upgrade$1 = {
|
|
695
|
+
__proto__: null,
|
|
696
|
+
default: upgrade,
|
|
697
|
+
upgradeWorkspace: upgradeWorkspace
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
export { upgrade$1 as a, migrations as m, upgradeWorkspace as u };
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -65,5 +65,106 @@ declare const _default: citty.CommandDef<{
|
|
|
65
65
|
};
|
|
66
66
|
}>;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/** A pattern looked for in the workspace's source files. */
|
|
69
|
+
interface Rule {
|
|
70
|
+
/** Must be global (`/…/g`). */
|
|
71
|
+
pattern: RegExp;
|
|
72
|
+
/** What to do about a match (for a `replace` rule: what changed and what to check). */
|
|
73
|
+
message: string;
|
|
74
|
+
/** Rewrites each match (`String.prototype.replace` semantics); without it the match is only listed. */
|
|
75
|
+
replace?: string;
|
|
76
|
+
/** Only files whose path matches. */
|
|
77
|
+
files?: RegExp;
|
|
78
|
+
/** Only files whose text matches. */
|
|
79
|
+
when?: RegExp;
|
|
80
|
+
}
|
|
81
|
+
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
|
+
interface ProjectResult {
|
|
83
|
+
applied?: string[];
|
|
84
|
+
manual?: string[];
|
|
85
|
+
}
|
|
86
|
+
interface ProjectContext {
|
|
87
|
+
root: string;
|
|
88
|
+
/** Source files (absolute), including every `nuxt.config.*`. */
|
|
89
|
+
files: string[];
|
|
90
|
+
dryRun: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** One breaking change of one release, and what the upgrade does about it. */
|
|
93
|
+
interface Migration {
|
|
94
|
+
id: string;
|
|
95
|
+
/** `@frigear-nu/<name>` */
|
|
96
|
+
package: string;
|
|
97
|
+
/** The first version with the change: the migration runs when upgrading across it. */
|
|
98
|
+
since: string;
|
|
99
|
+
title: string;
|
|
100
|
+
/** Docs page that explains the change. */
|
|
101
|
+
docs: string;
|
|
102
|
+
rules?: Rule[];
|
|
103
|
+
/** Checks or changes that need the whole workspace (nuxt.config options, env files). */
|
|
104
|
+
project?: (ctx: ProjectContext) => Promise<ProjectResult>;
|
|
105
|
+
/** One-off steps a person takes after the upgrade (ops, data checks). */
|
|
106
|
+
steps?: string[];
|
|
107
|
+
/** The release changed a database schema: the app needs a new migration. */
|
|
108
|
+
schema?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface Hit {
|
|
111
|
+
file: string;
|
|
112
|
+
line: number;
|
|
113
|
+
text: string;
|
|
114
|
+
message: string;
|
|
115
|
+
}
|
|
116
|
+
interface MigrationResult {
|
|
117
|
+
migration: Migration;
|
|
118
|
+
applied: Hit[];
|
|
119
|
+
manual: Hit[];
|
|
120
|
+
project: Required<ProjectResult>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A version pin of a `@frigear-nu/*` package somewhere in the workspace. */
|
|
124
|
+
interface Pin {
|
|
125
|
+
/** File, relative to the workspace root. */
|
|
126
|
+
file: string;
|
|
127
|
+
name: string;
|
|
128
|
+
range: string;
|
|
129
|
+
}
|
|
130
|
+
/** A rewritten pin. */
|
|
131
|
+
interface Bump extends Pin {
|
|
132
|
+
next: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface UpgradeOptions {
|
|
136
|
+
/** Any directory of the workspace; the root is found from it. */
|
|
137
|
+
cwd: string;
|
|
138
|
+
/** Target versions per package; packages left out go to their `latest` dist-tag. */
|
|
139
|
+
to?: Record<string, string>;
|
|
140
|
+
/** Only these packages (default: every `@frigear-nu/*` package the workspace pins). */
|
|
141
|
+
only?: string[];
|
|
142
|
+
dryRun?: boolean;
|
|
143
|
+
/** Resolves a package's latest version (the npm registry by default). */
|
|
144
|
+
resolveLatest?: (name: string) => Promise<string | undefined>;
|
|
145
|
+
migrations?: Migration[];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Moves every `@frigear-nu/*` pin of a workspace (package.json files and `pnpm-workspace.yaml`) to its target version
|
|
149
|
+
* and runs the migrations of the breaking releases in between. Returns what it did, and the report as Markdown.
|
|
150
|
+
*/
|
|
151
|
+
declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
152
|
+
root: string;
|
|
153
|
+
from: {
|
|
154
|
+
[k: string]: string;
|
|
155
|
+
};
|
|
156
|
+
to: Record<string, string>;
|
|
157
|
+
bumps: Bump[];
|
|
158
|
+
results: MigrationResult[];
|
|
159
|
+
skipped: string[];
|
|
160
|
+
report: string;
|
|
161
|
+
}>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Every breaking change a consuming app has to handle, oldest first. A release with a breaking change adds an entry
|
|
165
|
+
* here (`since` = the first version with the change), so `frigear-nu upgrade` carries it to every app.
|
|
166
|
+
*/
|
|
167
|
+
declare const migrations: Migration[];
|
|
168
|
+
|
|
169
|
+
export { PLATFORMS, STARTERS, main as default, _default as initCmd, mainCmd, migrations, resolveStarter, upgradeWorkspace };
|
|
170
|
+
export type { Migration, Platform, Rule, Starter, UpgradeOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -65,5 +65,106 @@ declare const _default: citty.CommandDef<{
|
|
|
65
65
|
};
|
|
66
66
|
}>;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
/** A pattern looked for in the workspace's source files. */
|
|
69
|
+
interface Rule {
|
|
70
|
+
/** Must be global (`/…/g`). */
|
|
71
|
+
pattern: RegExp;
|
|
72
|
+
/** What to do about a match (for a `replace` rule: what changed and what to check). */
|
|
73
|
+
message: string;
|
|
74
|
+
/** Rewrites each match (`String.prototype.replace` semantics); without it the match is only listed. */
|
|
75
|
+
replace?: string;
|
|
76
|
+
/** Only files whose path matches. */
|
|
77
|
+
files?: RegExp;
|
|
78
|
+
/** Only files whose text matches. */
|
|
79
|
+
when?: RegExp;
|
|
80
|
+
}
|
|
81
|
+
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
|
+
interface ProjectResult {
|
|
83
|
+
applied?: string[];
|
|
84
|
+
manual?: string[];
|
|
85
|
+
}
|
|
86
|
+
interface ProjectContext {
|
|
87
|
+
root: string;
|
|
88
|
+
/** Source files (absolute), including every `nuxt.config.*`. */
|
|
89
|
+
files: string[];
|
|
90
|
+
dryRun: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** One breaking change of one release, and what the upgrade does about it. */
|
|
93
|
+
interface Migration {
|
|
94
|
+
id: string;
|
|
95
|
+
/** `@frigear-nu/<name>` */
|
|
96
|
+
package: string;
|
|
97
|
+
/** The first version with the change: the migration runs when upgrading across it. */
|
|
98
|
+
since: string;
|
|
99
|
+
title: string;
|
|
100
|
+
/** Docs page that explains the change. */
|
|
101
|
+
docs: string;
|
|
102
|
+
rules?: Rule[];
|
|
103
|
+
/** Checks or changes that need the whole workspace (nuxt.config options, env files). */
|
|
104
|
+
project?: (ctx: ProjectContext) => Promise<ProjectResult>;
|
|
105
|
+
/** One-off steps a person takes after the upgrade (ops, data checks). */
|
|
106
|
+
steps?: string[];
|
|
107
|
+
/** The release changed a database schema: the app needs a new migration. */
|
|
108
|
+
schema?: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface Hit {
|
|
111
|
+
file: string;
|
|
112
|
+
line: number;
|
|
113
|
+
text: string;
|
|
114
|
+
message: string;
|
|
115
|
+
}
|
|
116
|
+
interface MigrationResult {
|
|
117
|
+
migration: Migration;
|
|
118
|
+
applied: Hit[];
|
|
119
|
+
manual: Hit[];
|
|
120
|
+
project: Required<ProjectResult>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A version pin of a `@frigear-nu/*` package somewhere in the workspace. */
|
|
124
|
+
interface Pin {
|
|
125
|
+
/** File, relative to the workspace root. */
|
|
126
|
+
file: string;
|
|
127
|
+
name: string;
|
|
128
|
+
range: string;
|
|
129
|
+
}
|
|
130
|
+
/** A rewritten pin. */
|
|
131
|
+
interface Bump extends Pin {
|
|
132
|
+
next: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
interface UpgradeOptions {
|
|
136
|
+
/** Any directory of the workspace; the root is found from it. */
|
|
137
|
+
cwd: string;
|
|
138
|
+
/** Target versions per package; packages left out go to their `latest` dist-tag. */
|
|
139
|
+
to?: Record<string, string>;
|
|
140
|
+
/** Only these packages (default: every `@frigear-nu/*` package the workspace pins). */
|
|
141
|
+
only?: string[];
|
|
142
|
+
dryRun?: boolean;
|
|
143
|
+
/** Resolves a package's latest version (the npm registry by default). */
|
|
144
|
+
resolveLatest?: (name: string) => Promise<string | undefined>;
|
|
145
|
+
migrations?: Migration[];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Moves every `@frigear-nu/*` pin of a workspace (package.json files and `pnpm-workspace.yaml`) to its target version
|
|
149
|
+
* and runs the migrations of the breaking releases in between. Returns what it did, and the report as Markdown.
|
|
150
|
+
*/
|
|
151
|
+
declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
152
|
+
root: string;
|
|
153
|
+
from: {
|
|
154
|
+
[k: string]: string;
|
|
155
|
+
};
|
|
156
|
+
to: Record<string, string>;
|
|
157
|
+
bumps: Bump[];
|
|
158
|
+
results: MigrationResult[];
|
|
159
|
+
skipped: string[];
|
|
160
|
+
report: string;
|
|
161
|
+
}>;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Every breaking change a consuming app has to handle, oldest first. A release with a breaking change adds an entry
|
|
165
|
+
* here (`since` = the first version with the change), so `frigear-nu upgrade` carries it to every app.
|
|
166
|
+
*/
|
|
167
|
+
declare const migrations: Migration[];
|
|
168
|
+
|
|
169
|
+
export { PLATFORMS, STARTERS, main as default, _default as initCmd, mainCmd, migrations, resolveStarter, upgradeWorkspace };
|
|
170
|
+
export type { Migration, Platform, Rule, Starter, UpgradeOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { m as default, a as mainCmd } from './shared/cli.
|
|
1
|
+
export { m as default, a as mainCmd } from './shared/cli.BNukBQzw.mjs';
|
|
2
2
|
export { PLATFORMS, STARTERS, default as initCmd, resolveStarter } from './chunks/init.mjs';
|
|
3
|
+
export { m as migrations, u as upgradeWorkspace } from './chunks/upgrade.mjs';
|
|
3
4
|
import 'citty';
|
|
4
5
|
import 'consola';
|
|
5
6
|
import 'node:path';
|
|
@@ -8,8 +9,10 @@ import 'scule';
|
|
|
8
9
|
import 'node:fs';
|
|
9
10
|
import 'node:fs/promises';
|
|
10
11
|
import 'pkg-types';
|
|
11
|
-
import './shared/cli.
|
|
12
|
+
import './shared/cli.CkMCvUCp.mjs';
|
|
12
13
|
import 'nypm';
|
|
13
14
|
import './shared/cli.C_0i5HKZ.mjs';
|
|
14
15
|
import 'giget';
|
|
15
16
|
import 'node:os';
|
|
17
|
+
import 'magicast';
|
|
18
|
+
import 'magicast/helpers';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineCommand, runMain } from 'citty';
|
|
2
2
|
|
|
3
|
-
const version = "0.
|
|
3
|
+
const version = "0.2.0";
|
|
4
4
|
const pkg = {
|
|
5
5
|
version: version};
|
|
6
6
|
|
|
@@ -8,13 +8,14 @@ const mainCmd = defineCommand({
|
|
|
8
8
|
meta: {
|
|
9
9
|
name: "frigear-nu",
|
|
10
10
|
version: pkg.version,
|
|
11
|
-
description: "Scaffold Frigear projects, apps and modules"
|
|
11
|
+
description: "Scaffold Frigear projects, apps and modules, and upgrade them"
|
|
12
12
|
},
|
|
13
13
|
subCommands: {
|
|
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
|
-
"add": () => import('../chunks/add.mjs').then((module) => module.default)
|
|
17
|
+
"add": () => import('../chunks/add.mjs').then((module) => module.default),
|
|
18
|
+
"upgrade": () => import('../chunks/upgrade.mjs').then(function (n) { return n.a; }).then((module) => module.default)
|
|
18
19
|
}
|
|
19
20
|
});
|
|
20
21
|
async function main() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { installDependencies, addDependency, runScript } from 'nypm';
|
|
2
2
|
|
|
3
3
|
const installDeps = (cwd) => installDependencies({ cwd, packageManager: "pnpm" });
|
|
4
4
|
const addDeps = (names, cwd) => addDependency(names, { cwd, packageManager: "pnpm" });
|