@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
package/dist/chunks/upgrade.mjs
CHANGED
|
@@ -1,52 +1,23 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
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
3
|
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile, writeFile, readdir, stat, mkdir, rename } from 'node:fs/promises';
|
|
5
|
+
import { join, basename, relative, dirname, resolve } from 'node:path';
|
|
6
6
|
import { parseModule } from 'magicast';
|
|
7
7
|
import { getDefaultExportOptions } from 'magicast/helpers';
|
|
8
|
+
import { i as isBetween, d as duplicateVersions, s as sharedDuplicates, m as manifestFiles, f as findPins, c as currentVersions, b as compareVersions, r as rewritePins, e as movePatchedDependencies } from '../shared/cli.DUmSgMcB.mjs';
|
|
8
9
|
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.Cfkcp0w9.mjs';
|
|
9
10
|
import { i as installDeps } from '../shared/cli.CkMCvUCp.mjs';
|
|
10
11
|
|
|
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
12
|
const DOCS = "https://docs.frigear.dev";
|
|
42
13
|
const SOURCE = /\.(?:[cm]?[jt]s|tsx|jsx|vue)$/;
|
|
43
|
-
const IGNORED_DIRS
|
|
14
|
+
const IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", ".git", "dist", "coverage", ".turbo", ".vercel", ".wrangler", "migrations", "ios", "android"]);
|
|
44
15
|
const sourceFiles = async (dir) => {
|
|
45
16
|
if (!existsSync(dir)) return [];
|
|
46
17
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
47
18
|
const nested = await Promise.all(entries.map(async (entry) => {
|
|
48
19
|
const path = join(dir, entry.name);
|
|
49
|
-
if (entry.isDirectory()) return IGNORED_DIRS
|
|
20
|
+
if (entry.isDirectory()) return IGNORED_DIRS.has(entry.name) || entry.name.startsWith(".") ? [] : sourceFiles(path);
|
|
50
21
|
if (!SOURCE.test(entry.name) || entry.name.endsWith(".d.ts")) return [];
|
|
51
22
|
return (await stat(path)).size > 1e6 ? [] : [path];
|
|
52
23
|
}));
|
|
@@ -74,10 +45,13 @@ const runMigrations = async (migrations, ctx) => {
|
|
|
74
45
|
for (const rule of migration.rules ?? []) {
|
|
75
46
|
if (rule.files && !rule.files.test(file)) continue;
|
|
76
47
|
if (rule.when && !rule.when.test(text)) continue;
|
|
48
|
+
if (rule.unless?.test(text)) continue;
|
|
77
49
|
for (const match of text.matchAll(rule.pattern)) {
|
|
78
50
|
const line = lineOf(text, match.index);
|
|
79
|
-
const
|
|
80
|
-
|
|
51
|
+
const hits = rule.replace === void 0 ? result.manual : result.applied;
|
|
52
|
+
const last = hits.at(-1);
|
|
53
|
+
if (last?.file === file && last.line === line && last.message === rule.message) continue;
|
|
54
|
+
hits.push({ file, line, text: lineText(text, line), message: rule.message });
|
|
81
55
|
}
|
|
82
56
|
if (rule.replace !== void 0) text = text.replace(rule.pattern, rule.replace);
|
|
83
57
|
}
|
|
@@ -106,6 +80,26 @@ const readNuxtConfigs = async (files) => {
|
|
|
106
80
|
const option = (options, path) => path.split(".").reduce((value, key) => value !== null && typeof value === "object" ? value[key] : void 0, options);
|
|
107
81
|
const items = (value) => value !== null && typeof value === "object" && typeof value.length === "number" ? Array.from(value) : [];
|
|
108
82
|
|
|
83
|
+
const authApi = {
|
|
84
|
+
id: "auth-api",
|
|
85
|
+
package: "@frigear-nu/auth",
|
|
86
|
+
since: "0.3.0",
|
|
87
|
+
title: "auth provides $api and useApi",
|
|
88
|
+
docs: `${DOCS}/modules/identity/auth`,
|
|
89
|
+
rules: [
|
|
90
|
+
{
|
|
91
|
+
pattern: /\bprovide\s*:\s*\{[^}]*\bapi\b|\bprovide\(\s*['"]api['"]/g,
|
|
92
|
+
message: "auth already provides `$api` (a `$fetch` that sends the session or access token): two plugins providing `api` fail every SSR page with `Cannot redefine property: $api`. Remove this plugin and use auth's `$api` / `useApi()`, or provide it under another name.",
|
|
93
|
+
files: /(?<!\/server)\/plugins\//
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
pattern: /\bexport\s+(?:const|function|async\s+function)\s+useApi\b/g,
|
|
97
|
+
message: "auth auto-imports its own `useApi()`: this one shadows it (Nuxt warns about the duplicate import). Remove it, or rename it if it does something else.",
|
|
98
|
+
files: /(?<!\/server)\/(?:composables|utils)\//
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
};
|
|
102
|
+
|
|
109
103
|
const adminComponents = {
|
|
110
104
|
id: "admin-components",
|
|
111
105
|
package: "@frigear-nu/admin",
|
|
@@ -173,7 +167,7 @@ const authPermissions = {
|
|
|
173
167
|
],
|
|
174
168
|
steps: [
|
|
175
169
|
"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`
|
|
170
|
+
"Everything fails closed: an unregistered permission is a 403 (also for admins), and `*` never covers sensitive (`:pii`) permissions. Click through the staff areas before deploying."
|
|
177
171
|
],
|
|
178
172
|
async project({ root, files }) {
|
|
179
173
|
const manual = [];
|
|
@@ -225,15 +219,42 @@ const authorizationRoles = {
|
|
|
225
219
|
pattern: /\buseAuthorization\(\)/g,
|
|
226
220
|
when: /\bcan\(\s*(?!['"`])/,
|
|
227
221
|
message: "Check the `can(...)` calls in this file: `can(permission, record?)` takes a permission name now, not an ability."
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
pattern: /\b(?:effectiveRole|userHasRole|hasRole)\b/g,
|
|
225
|
+
message: "A role check of its own: access comes from roles that grant permissions now. Check the permission (`authorize` / `allows` on the server, `can()` in the client), and move an env allowlist to an `authorization:roles` hook that pushes the role (it is never stored)."
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
pattern: /\b(?:NUXT_ACL_ADMINS|NUXT_ADMIN_EMAILS|aclAdmins|adminEmails)\b/g,
|
|
229
|
+
unless: /authorization:roles/,
|
|
230
|
+
message: "An admin allowlist: give those users the role in an `authorization:roles` hook (`ctx.roles.push('admin')`, from `ctx.user`, verified addresses only) instead of a role on the session or the user row."
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
pattern: /\b\w*[uU]sers?\??\.role\b/g,
|
|
234
|
+
message: "`users.role` is copied once into `authorization_user_roles` and never read again: a read sees a stale value, a write is silently ignored (new users get no role). Read access with `can()` / `allows`, and assign roles with `setAuthUserRoles` (or the users admin)."
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
pattern: /\brole\s*:\s*['"`][\w-]+['"`]/g,
|
|
238
|
+
when: /\binsert\(\s*users\b|\b(?:createUser|findOrCreateUser|defineTask)\b/,
|
|
239
|
+
message: "Writes `users.role`, which is no longer read: assign the role with `setAuthUserRoles(userId, roles, { source: 'manual' })` instead."
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
pattern: /\brequireAuth\(\s*[\w.]+\s*,\s*\{[^}]*\bsessionOnly\b/g,
|
|
243
|
+
when: /\.role\b|effectiveRole|isAdmin/,
|
|
244
|
+
message: "A session-only route with a role check: register a `sessionOnly` permission granted to that role and check it with `authorize(event, permission)`."
|
|
228
245
|
}
|
|
229
246
|
],
|
|
230
247
|
steps: [
|
|
231
|
-
"Run the verification SQL of the migration guide: `users.role` is copied once into `authorization_user_roles` and no longer read."
|
|
248
|
+
"Run the verification SQL of the migration guide: `users.role` is copied once into `authorization_user_roles` and no longer read.",
|
|
249
|
+
"Roles add up: a user holds their assigned roles plus every `defaultRoles` role. Where a stored role used to replace the default (a `tenant` who is not a `user`), drop the default in an `authorization:roles` hook, or leave it out of `defaultRoles`."
|
|
232
250
|
],
|
|
233
251
|
async project({ root, files }) {
|
|
234
252
|
const manual = [];
|
|
235
253
|
for (const { file, options } of await readNuxtConfigs(files)) {
|
|
236
254
|
const at = relative(root, file);
|
|
255
|
+
if (option(options, "authentication.settings.session.mapper") !== void 0) {
|
|
256
|
+
manual.push(`${at}: \`authentication.settings.session.mapper\` is set. If it puts \`role\` on the session user, remove that (or the mapper): access no longer reads it, and a stale role on the session only misleads the client.`);
|
|
257
|
+
}
|
|
237
258
|
const removed = ["abilities", "resolvers", "rbac"].filter((key) => option(options, `authorization.${key}`) !== void 0);
|
|
238
259
|
const roleKeys = ["hierarchy", "inherits", "grant", "revoke", "labels", "descriptions", "definitions", "defaultRole"].filter((key) => option(options, `authorization.roles.${key}`) !== void 0);
|
|
239
260
|
if (removed.length || roleKeys.length) {
|
|
@@ -393,6 +414,24 @@ const usersRoutes = {
|
|
|
393
414
|
]
|
|
394
415
|
};
|
|
395
416
|
|
|
417
|
+
const SERVER_AUTH = ["@frigear-nu/auth", "@frigear-nu/users", "@frigear-nu/oauth-server"];
|
|
418
|
+
const hasServerSessions = async (config, options) => {
|
|
419
|
+
if (option(options, "ssr") === false || option(options, "authentication.mode") === "client") return false;
|
|
420
|
+
const manifest = join(dirname(config), "package.json");
|
|
421
|
+
if (!existsSync(manifest)) return false;
|
|
422
|
+
const pkg = JSON.parse(await readFile(manifest, "utf-8"));
|
|
423
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
424
|
+
return SERVER_AUTH.some((name) => name in deps);
|
|
425
|
+
};
|
|
426
|
+
const addAppSecret = (text) => {
|
|
427
|
+
const entry = "# Seals the session cookie (32+ random characters).\nNUXT_APP_SECRET=";
|
|
428
|
+
const session = /^\s*NUXT_SESSION_PASSWORD\s*=.*$/m.exec(text);
|
|
429
|
+
if (!session) return `${text.replace(/\n*$/, "\n")}${entry}
|
|
430
|
+
`;
|
|
431
|
+
const end = session.index + session[0].length;
|
|
432
|
+
return `${text.slice(0, end)}
|
|
433
|
+
${entry}${text.slice(end)}`;
|
|
434
|
+
};
|
|
396
435
|
const authSessionSecret = {
|
|
397
436
|
id: "auth-session-secret",
|
|
398
437
|
package: "@frigear-nu/auth",
|
|
@@ -401,21 +440,26 @@ const authSessionSecret = {
|
|
|
401
440
|
docs: `${DOCS}/get-started/upgrading#breaking-changes-by-release`,
|
|
402
441
|
schema: true,
|
|
403
442
|
steps: [
|
|
404
|
-
"Set `NUXT_APP_SECRET` (32+ random characters) in every environment before deploying
|
|
443
|
+
"Set `NUXT_APP_SECRET` (32+ random characters) in every environment before deploying, and in any script that generates `.env`.",
|
|
444
|
+
"`NUXT_SESSION_PASSWORD` no longer seals sessions. Keep it only where the app stores OAuth or Frigear SSO tokens (it is their key) or reads it itself; otherwise remove it.",
|
|
405
445
|
"The session cookie is renamed (`nuxt-auth-session`): every user is signed out once after the deploy."
|
|
406
446
|
],
|
|
407
447
|
async project({ root, files, dryRun }) {
|
|
408
448
|
const applied = [];
|
|
409
|
-
|
|
449
|
+
const manual = [];
|
|
450
|
+
for (const { file: config, options } of await readNuxtConfigs(files)) {
|
|
451
|
+
if (option(options, "runtimeConfig.session.password") !== void 0) {
|
|
452
|
+
manual.push(`${relative(root, config)}: \`runtimeConfig.session.password\` is no longer read (and is a type error): sessions use \`NUXT_APP_SECRET\`. Remove it.`);
|
|
453
|
+
}
|
|
454
|
+
if (!await hasServerSessions(config, options)) continue;
|
|
410
455
|
const example = join(dirname(config), ".env.example");
|
|
411
456
|
if (!existsSync(example)) continue;
|
|
412
457
|
const text = await readFile(example, "utf-8");
|
|
413
458
|
if (/^\s*NUXT_APP_SECRET\s*=/m.test(text)) continue;
|
|
414
|
-
if (!dryRun) await writeFile(example,
|
|
415
|
-
`, "utf-8");
|
|
459
|
+
if (!dryRun) await writeFile(example, addAppSecret(text), "utf-8");
|
|
416
460
|
applied.push(`Added \`NUXT_APP_SECRET=\` to ${relative(root, example)}`);
|
|
417
461
|
}
|
|
418
|
-
return { applied };
|
|
462
|
+
return { applied, manual };
|
|
419
463
|
}
|
|
420
464
|
};
|
|
421
465
|
|
|
@@ -424,6 +468,7 @@ const migrations = [
|
|
|
424
468
|
usersRoutes,
|
|
425
469
|
adminComponents,
|
|
426
470
|
accountComponents,
|
|
471
|
+
authApi,
|
|
427
472
|
authSessionSecret,
|
|
428
473
|
menuPermission,
|
|
429
474
|
mcpPermission,
|
|
@@ -434,105 +479,6 @@ const migrations = [
|
|
|
434
479
|
usersPermissions
|
|
435
480
|
];
|
|
436
481
|
|
|
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
482
|
const REGISTRY = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
537
483
|
const latestVersion = async (name) => {
|
|
538
484
|
const response = await fetch(`${REGISTRY}/${name.replace("/", "%2f")}`, {
|
|
@@ -614,16 +560,37 @@ const upgradeWorkspace = async (options) => {
|
|
|
614
560
|
else to[name] = target;
|
|
615
561
|
}));
|
|
616
562
|
const bumps = [];
|
|
563
|
+
const patches = [];
|
|
617
564
|
for (const manifest of manifests) {
|
|
618
|
-
const
|
|
619
|
-
|
|
620
|
-
|
|
565
|
+
const pinned = rewritePins(manifest.file, manifest.text, to);
|
|
566
|
+
const patched = movePatchedDependencies(manifest.file, pinned.text, to);
|
|
567
|
+
bumps.push(...pinned.bumps);
|
|
568
|
+
patches.push(...patched.moves);
|
|
569
|
+
if ((pinned.bumps.length || patched.moves.length) && !dryRun) await writeFile(manifest.file, patched.text, "utf-8");
|
|
570
|
+
}
|
|
571
|
+
for (const move of patches) {
|
|
572
|
+
const source = join(root, move.patch);
|
|
573
|
+
const target = join(root, move.next);
|
|
574
|
+
if (dryRun || move.next === move.patch || !existsSync(source) || existsSync(target)) continue;
|
|
575
|
+
await mkdir(dirname(target), { recursive: true });
|
|
576
|
+
await rename(source, target);
|
|
621
577
|
}
|
|
622
578
|
const pending = pendingMigrations(options.migrations ?? migrations, from, to);
|
|
623
579
|
const results = await runMigrations(pending, { root, files: await sourceFiles(root), dryRun });
|
|
624
580
|
const fromUpgraded = Object.fromEntries(Object.keys(to).map((name) => [name, from[name]]));
|
|
625
|
-
|
|
626
|
-
|
|
581
|
+
let report = renderReport({ root, from: fromUpgraded, to, bumps, results, dryRun });
|
|
582
|
+
if (patches.length) {
|
|
583
|
+
report += [
|
|
584
|
+
"",
|
|
585
|
+
"## Patched packages",
|
|
586
|
+
"",
|
|
587
|
+
`${dryRun ? "Would move" : "Moved"} these \`patchedDependencies\` to the new version. Check that each patch still applies (\`pnpm install\` fails if not) and is still needed: the release may already include the change.`,
|
|
588
|
+
"",
|
|
589
|
+
...patches.map((move) => `- \`${move.name}\` ${move.from} \u2192 ${move.to}: \`${move.patch}\` \u2192 \`${move.next}\` (${relative(root, move.file)})`),
|
|
590
|
+
""
|
|
591
|
+
].join("\n");
|
|
592
|
+
}
|
|
593
|
+
return { root, from: fromUpgraded, to, bumps, patches, results, skipped, report };
|
|
627
594
|
};
|
|
628
595
|
const upgrade = defineCommand({
|
|
629
596
|
meta: {
|
|
@@ -652,7 +619,7 @@ const upgrade = defineCommand({
|
|
|
652
619
|
},
|
|
653
620
|
report: {
|
|
654
621
|
type: "string",
|
|
655
|
-
description: "Where to write the Markdown report (relative to the workspace root)",
|
|
622
|
+
description: "Where to write the Markdown report (relative to the workspace root, or absolute)",
|
|
656
623
|
default: "frigear-upgrade.md"
|
|
657
624
|
}
|
|
658
625
|
}),
|
|
@@ -680,13 +647,29 @@ const upgrade = defineCommand({
|
|
|
680
647
|
consola.log(result.report);
|
|
681
648
|
return;
|
|
682
649
|
}
|
|
683
|
-
const reportPath =
|
|
650
|
+
const reportPath = resolve(result.root, args.report);
|
|
684
651
|
await writeFile(reportPath, result.report, "utf-8");
|
|
685
652
|
logger.success(`Upgraded ${upgraded.map((name) => `${name} ${result.from[name]} \u2192 ${result.to[name]}`).join(", ")}`);
|
|
686
653
|
logger.info(`${result.bumps.length} pins updated, ${applied} code changes made, ${manual} items to do by hand: ${reportPath}`);
|
|
687
654
|
if (args.install) {
|
|
688
655
|
logger.start("Installing");
|
|
689
|
-
|
|
656
|
+
try {
|
|
657
|
+
await installDeps(result.root);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
logger.warn(`pnpm install failed: ${error instanceof Error ? error.message.split("\n")[0] : error}`);
|
|
660
|
+
logger.info(`Expected while the report still has items that fail the build (\`nuxt prepare\` runs on install). Work through ${reportPath}, then run \`pnpm install\` again.`);
|
|
661
|
+
process.exitCode = 1;
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
const lock = join(result.root, "pnpm-lock.yaml");
|
|
665
|
+
const duplicates = existsSync(lock) ? duplicateVersions(await readFile(lock, "utf-8")) : {};
|
|
666
|
+
for (const [name, versions] of Object.entries(duplicates)) {
|
|
667
|
+
logger.warn(`${name} is installed in ${versions.length} versions (${versions.join(", ")}). Modules share build-time state through one copy. Usually a stale lockfile entry: run \`pnpm dedupe\` (or \`pnpm update -r ${name}\`). If it stays, something pins the old version: raise that range, or add \`'${name}': ^${result.to[name] ?? versions.at(-1)}\` to \`overrides\` in pnpm-workspace.yaml.`);
|
|
668
|
+
}
|
|
669
|
+
const shared = existsSync(lock) ? sharedDuplicates(await readFile(lock, "utf-8")) : {};
|
|
670
|
+
for (const [name, versions] of Object.entries(shared)) {
|
|
671
|
+
logger.warn(`${name} is installed in ${versions.length} versions of one major (${versions.join(", ")}), usually because an app or package pins it lower than the @frigear-nu modules need. The build output can end up with a broken copy (\`Cannot find module \u2026/node_modules/${name}/\u2026\` at boot): raise that range to \`^${versions.at(-1)}\` and run \`pnpm install\` again, then \`pnpm dedupe\` if a stale lockfile entry keeps the old copy.`);
|
|
672
|
+
}
|
|
690
673
|
}
|
|
691
674
|
}
|
|
692
675
|
});
|
package/dist/cli.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import * as citty from 'citty';
|
|
|
3
3
|
declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
|
|
4
4
|
declare function main(): Promise<void>;
|
|
5
5
|
|
|
6
|
-
declare const PLATFORMS: readonly ["web", "mobile"];
|
|
6
|
+
declare const PLATFORMS: readonly ["web", "mobile", "desktop"];
|
|
7
7
|
type Platform = typeof PLATFORMS[number];
|
|
8
8
|
/** Each starter (a folder under `.starters/`) and the platforms it builds for. */
|
|
9
9
|
declare const STARTERS: {
|
|
@@ -19,10 +19,15 @@ declare const STARTERS: {
|
|
|
19
19
|
readonly platforms: readonly ["web", "mobile"];
|
|
20
20
|
readonly hint: "apps/web + apps/mobile, with apps/web as the OAuth server";
|
|
21
21
|
};
|
|
22
|
+
readonly desktop: {
|
|
23
|
+
readonly platforms: readonly ["desktop"];
|
|
24
|
+
readonly hint: "apps/desktop: a Tauri app against any OAuth issuer, or offline with its own server";
|
|
25
|
+
};
|
|
22
26
|
};
|
|
23
27
|
type Starter = keyof typeof STARTERS;
|
|
24
28
|
/**
|
|
25
|
-
* A starter from its name (`mobile-standalone`) or from its platforms (`web`, `mobile`, `web,mobile`, in any
|
|
29
|
+
* A starter from its name (`mobile-standalone`) or from its platforms (`web`, `mobile`, `desktop`, `web,mobile`, in any
|
|
30
|
+
* order).
|
|
26
31
|
*/
|
|
27
32
|
declare const resolveStarter: (value: string) => Starter | undefined;
|
|
28
33
|
declare const _default: citty.CommandDef<{
|
|
@@ -77,6 +82,8 @@ interface Rule {
|
|
|
77
82
|
files?: RegExp;
|
|
78
83
|
/** Only files whose text matches. */
|
|
79
84
|
when?: RegExp;
|
|
85
|
+
/** Not in files whose text matches (already migrated). */
|
|
86
|
+
unless?: RegExp;
|
|
80
87
|
}
|
|
81
88
|
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
89
|
interface ProjectResult {
|
|
@@ -131,6 +138,14 @@ interface Pin {
|
|
|
131
138
|
interface Bump extends Pin {
|
|
132
139
|
next: string;
|
|
133
140
|
}
|
|
141
|
+
interface PatchMove {
|
|
142
|
+
file: string;
|
|
143
|
+
name: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string;
|
|
146
|
+
patch: string;
|
|
147
|
+
next: string;
|
|
148
|
+
}
|
|
134
149
|
|
|
135
150
|
interface UpgradeOptions {
|
|
136
151
|
/** Any directory of the workspace; the root is found from it. */
|
|
@@ -155,6 +170,7 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
|
155
170
|
};
|
|
156
171
|
to: Record<string, string>;
|
|
157
172
|
bumps: Bump[];
|
|
173
|
+
patches: PatchMove[];
|
|
158
174
|
results: MigrationResult[];
|
|
159
175
|
skipped: string[];
|
|
160
176
|
report: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as citty from 'citty';
|
|
|
3
3
|
declare const mainCmd: citty.CommandDef<citty.ArgsDef>;
|
|
4
4
|
declare function main(): Promise<void>;
|
|
5
5
|
|
|
6
|
-
declare const PLATFORMS: readonly ["web", "mobile"];
|
|
6
|
+
declare const PLATFORMS: readonly ["web", "mobile", "desktop"];
|
|
7
7
|
type Platform = typeof PLATFORMS[number];
|
|
8
8
|
/** Each starter (a folder under `.starters/`) and the platforms it builds for. */
|
|
9
9
|
declare const STARTERS: {
|
|
@@ -19,10 +19,15 @@ declare const STARTERS: {
|
|
|
19
19
|
readonly platforms: readonly ["web", "mobile"];
|
|
20
20
|
readonly hint: "apps/web + apps/mobile, with apps/web as the OAuth server";
|
|
21
21
|
};
|
|
22
|
+
readonly desktop: {
|
|
23
|
+
readonly platforms: readonly ["desktop"];
|
|
24
|
+
readonly hint: "apps/desktop: a Tauri app against any OAuth issuer, or offline with its own server";
|
|
25
|
+
};
|
|
22
26
|
};
|
|
23
27
|
type Starter = keyof typeof STARTERS;
|
|
24
28
|
/**
|
|
25
|
-
* A starter from its name (`mobile-standalone`) or from its platforms (`web`, `mobile`, `web,mobile`, in any
|
|
29
|
+
* A starter from its name (`mobile-standalone`) or from its platforms (`web`, `mobile`, `desktop`, `web,mobile`, in any
|
|
30
|
+
* order).
|
|
26
31
|
*/
|
|
27
32
|
declare const resolveStarter: (value: string) => Starter | undefined;
|
|
28
33
|
declare const _default: citty.CommandDef<{
|
|
@@ -77,6 +82,8 @@ interface Rule {
|
|
|
77
82
|
files?: RegExp;
|
|
78
83
|
/** Only files whose text matches. */
|
|
79
84
|
when?: RegExp;
|
|
85
|
+
/** Not in files whose text matches (already migrated). */
|
|
86
|
+
unless?: RegExp;
|
|
80
87
|
}
|
|
81
88
|
/** What a workspace-level check found: changes it made and things a person must do. */
|
|
82
89
|
interface ProjectResult {
|
|
@@ -131,6 +138,14 @@ interface Pin {
|
|
|
131
138
|
interface Bump extends Pin {
|
|
132
139
|
next: string;
|
|
133
140
|
}
|
|
141
|
+
interface PatchMove {
|
|
142
|
+
file: string;
|
|
143
|
+
name: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string;
|
|
146
|
+
patch: string;
|
|
147
|
+
next: string;
|
|
148
|
+
}
|
|
134
149
|
|
|
135
150
|
interface UpgradeOptions {
|
|
136
151
|
/** Any directory of the workspace; the root is found from it. */
|
|
@@ -155,6 +170,7 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
|
155
170
|
};
|
|
156
171
|
to: Record<string, string>;
|
|
157
172
|
bumps: Bump[];
|
|
173
|
+
patches: PatchMove[];
|
|
158
174
|
results: MigrationResult[];
|
|
159
175
|
skipped: string[];
|
|
160
176
|
report: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { m as default, a as mainCmd } from './shared/cli.
|
|
1
|
+
export { m as default, a as mainCmd } from './shared/cli.Bq3BvIWj.mjs';
|
|
2
2
|
export { PLATFORMS, STARTERS, default as initCmd, resolveStarter } from './chunks/init.mjs';
|
|
3
3
|
export { m as migrations, u as upgradeWorkspace } from './chunks/upgrade.mjs';
|
|
4
4
|
import 'citty';
|
|
@@ -16,3 +16,4 @@ import 'giget';
|
|
|
16
16
|
import 'node:os';
|
|
17
17
|
import 'magicast';
|
|
18
18
|
import 'magicast/helpers';
|
|
19
|
+
import './shared/cli.DUmSgMcB.mjs';
|