@frigear-nu/cli 0.2.1 → 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 +58 -148
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.mjs +2 -1
- package/dist/shared/cli.BLUxtpPi.mjs +160 -0
- package/dist/shared/{cli.B9oeiTli.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 +1 -1
package/README.md
CHANGED
|
@@ -9,10 +9,15 @@ pnpx @frigear-nu/cli --help
|
|
|
9
9
|
|
|
10
10
|
| Command | What it does |
|
|
11
11
|
| --- | --- |
|
|
12
|
-
| `init [dir] --platform <web\|mobile\|web,mobile>` | New project from a starter (or `-t <giget source>`), then `pnpm install` and `pnpm prepare:env`. |
|
|
13
|
-
| `app:create <name> --template <web\|web-standalone\|mobile>` | Adds a starter's app to `apps/<name>`. |
|
|
12
|
+
| `init [dir] --platform <web\|mobile\|desktop\|web,mobile>` | New project from a starter (or `-t <giget source>`), then `pnpm install` and `pnpm prepare:env`. |
|
|
13
|
+
| `app:create <name> --template <web\|web-standalone\|mobile\|desktop>` | Adds a starter's app to `apps/<name>`. |
|
|
14
14
|
| `module:create <name> [--scope @acme]` | Scaffolds a Nuxt module in `packages/<name>`. |
|
|
15
15
|
| `add <module...> [--app <app>]` | `pnpm add` in the app and adds the modules to its `nuxt.config`. |
|
|
16
|
+
| `package:rename <package> <new-name> [--dir]` | Renames a workspace package in manifests, `pnpm-workspace.yaml`, imports and config. |
|
|
17
|
+
| `module:folder <module> [--runtime]` | Turns `modules/foo.ts` into `modules/foo/index.ts`. |
|
|
18
|
+
| `module:move <module> <destination> [--name <name>]` | Moves a local module or package folder and fixes relative paths. |
|
|
19
|
+
|
|
20
|
+
The three refactoring commands take `--dry-run` to print the changes without writing them.
|
|
16
21
|
|
|
17
22
|
Starters are downloaded from `Frigear-nu/frigear-nu` with [giget](https://github.com/unjs/giget) (`--ref` picks a branch
|
|
18
23
|
or tag). While that repository is not public, set `GIGET_AUTH` to a GitHub token that can read it.
|
|
@@ -15,7 +15,8 @@ import 'node:os';
|
|
|
15
15
|
const APP_TEMPLATES = {
|
|
16
16
|
"web": ".starters/workspace/apps/web",
|
|
17
17
|
"web-standalone": ".starters/mobile-standalone/apps/web",
|
|
18
|
-
"mobile": ".starters/mobile/apps/mobile"
|
|
18
|
+
"mobile": ".starters/mobile/apps/mobile",
|
|
19
|
+
"desktop": ".starters/desktop/apps/desktop"
|
|
19
20
|
};
|
|
20
21
|
const isAppTemplate = (value) => value in APP_TEMPLATES;
|
|
21
22
|
const resolveAppScope = async (root) => {
|
package/dist/chunks/init.mjs
CHANGED
|
@@ -12,11 +12,21 @@ import 'nypm';
|
|
|
12
12
|
import 'giget';
|
|
13
13
|
import 'node:os';
|
|
14
14
|
|
|
15
|
-
const PLATFORMS = ["web", "mobile"];
|
|
15
|
+
const PLATFORMS = ["web", "mobile", "desktop"];
|
|
16
16
|
const STARTERS = {
|
|
17
17
|
"workspace": { platforms: ["web"], hint: "apps/web: users, auth, account and admin" },
|
|
18
18
|
"mobile": { platforms: ["mobile"], hint: "apps/mobile: a Capacitor app against any OAuth issuer" },
|
|
19
|
-
"mobile-standalone": { platforms: ["web", "mobile"], hint: "apps/web + apps/mobile, with apps/web as the OAuth server" }
|
|
19
|
+
"mobile-standalone": { platforms: ["web", "mobile"], hint: "apps/web + apps/mobile, with apps/web as the OAuth server" },
|
|
20
|
+
"desktop": { platforms: ["desktop"], hint: "apps/desktop: a Tauri app against any OAuth issuer, or offline with its own server" }
|
|
21
|
+
};
|
|
22
|
+
const nextSteps = {
|
|
23
|
+
"workspace": [" put your email in NUXT_ACL_ADMINS in apps/web/.env"],
|
|
24
|
+
"mobile-standalone": [" put your email in NUXT_ACL_ADMINS in apps/web/.env"],
|
|
25
|
+
"mobile": [" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/mobile/.env"],
|
|
26
|
+
"desktop": [
|
|
27
|
+
" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/desktop/.env, or DESKTOP_MODE=local",
|
|
28
|
+
" pnpm desktop:init"
|
|
29
|
+
]
|
|
20
30
|
};
|
|
21
31
|
const isStarter = (value) => value in STARTERS;
|
|
22
32
|
const resolveStarter = (value) => {
|
|
@@ -29,7 +39,8 @@ const resolveStarter = (value) => {
|
|
|
29
39
|
return own.length === platforms.size && own.every((platform) => platforms.has(platform));
|
|
30
40
|
});
|
|
31
41
|
};
|
|
32
|
-
const
|
|
42
|
+
const combinations = Object.values(STARTERS).filter(({ platforms }) => platforms.length > 1).map(({ platforms }) => platforms.join(","));
|
|
43
|
+
const choices = `${[...PLATFORMS, ...combinations].join(", ")} or a starter: ${Object.keys(STARTERS).join(", ")}`;
|
|
33
44
|
const init = defineCommand({
|
|
34
45
|
meta: {
|
|
35
46
|
name: "init",
|
|
@@ -115,7 +126,7 @@ const init = defineCommand({
|
|
|
115
126
|
"Next steps:",
|
|
116
127
|
cd === "." ? void 0 : ` cd ${cd}`,
|
|
117
128
|
args.install ? void 0 : ` pnpm install${hasPrepareEnv ? " && pnpm prepare:env" : ""}`,
|
|
118
|
-
|
|
129
|
+
...starter ? nextSteps[starter] : [],
|
|
119
130
|
" pnpm dev"
|
|
120
131
|
].filter(Boolean).join("\n"));
|
|
121
132
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { relative, extname, join, dirname } from 'node:path';
|
|
6
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot } from '../shared/cli.Cfkcp0w9.mjs';
|
|
7
|
+
import { r as resolveLocalModule } from '../shared/cli.CybmnaqF.mjs';
|
|
8
|
+
import { r as resolveArg, a as applyPlan, t as toPosix, p as printPlan, b as planChanges } from '../shared/cli.BLUxtpPi.mjs';
|
|
9
|
+
import 'scule';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
import './add.mjs';
|
|
12
|
+
import 'magicast';
|
|
13
|
+
import 'magicast/helpers';
|
|
14
|
+
import '../shared/cli.CkMCvUCp.mjs';
|
|
15
|
+
import 'nypm';
|
|
16
|
+
|
|
17
|
+
const runtimePluginStub = (name) => `import { defineNuxtPlugin } from '#imports'
|
|
18
|
+
|
|
19
|
+
// Runtime code of the ${name} module. Register it in the module's setup():
|
|
20
|
+
// addPlugin(createResolver(import.meta.url).resolve('./runtime/plugin'))
|
|
21
|
+
export default defineNuxtPlugin(() => {})
|
|
22
|
+
`;
|
|
23
|
+
const resolverHint = (name) => [
|
|
24
|
+
`modules/${name}/index.ts has no createResolver(import.meta.url). Add runtime files from setup() with:`,
|
|
25
|
+
` import { addPlugin, createResolver } from '@nuxt/kit'`,
|
|
26
|
+
` const { resolve } = createResolver(import.meta.url)`,
|
|
27
|
+
` addPlugin(resolve('./runtime/plugin'))`
|
|
28
|
+
].join("\n");
|
|
29
|
+
const planModuleFolder = async (options) => {
|
|
30
|
+
const mod = await resolveLocalModule(options.cwd, options.module, options.app);
|
|
31
|
+
if (mod.kind !== "file") throw new Error(`${options.module} is already a folder${mod.kind === "package" ? " (a package)" : " module"}`);
|
|
32
|
+
const ext = extname(mod.path);
|
|
33
|
+
const folder = join(dirname(mod.path), mod.name);
|
|
34
|
+
if (existsSync(folder)) throw new Error(`${folder} already exists`);
|
|
35
|
+
const root = await findWorkspaceRoot(dirname(mod.path)) ?? dirname(dirname(mod.path));
|
|
36
|
+
const index = join(folder, `index${ext}`);
|
|
37
|
+
const plan = await planChanges(root, [{ from: mod.path, to: index, kind: "file" }]);
|
|
38
|
+
if (options.runtime) {
|
|
39
|
+
const plugin = join(folder, "runtime", `plugin${ext === ".mts" || ext === ".ts" ? ".ts" : ".js"}`);
|
|
40
|
+
plan.writes.set(plugin, runtimePluginStub(mod.name));
|
|
41
|
+
plan.created.add(plugin);
|
|
42
|
+
}
|
|
43
|
+
const source = plan.writes.get(index) ?? await readFile(mod.path, "utf-8");
|
|
44
|
+
const hint = /createResolver\s*\(\s*import\.meta\.url\s*\)/.test(source) ? void 0 : resolverHint(mod.name);
|
|
45
|
+
return { plan, module: mod, folder, index, hint, root };
|
|
46
|
+
};
|
|
47
|
+
const moduleFolder = defineCommand({
|
|
48
|
+
meta: {
|
|
49
|
+
name: "module:folder",
|
|
50
|
+
description: "Turn a single-file local module (modules/foo.ts) into a folder module (modules/foo/index.ts)"
|
|
51
|
+
},
|
|
52
|
+
args: defineCommandArgs({
|
|
53
|
+
module: {
|
|
54
|
+
type: "positional",
|
|
55
|
+
description: "The module: a path to modules/<name>.ts, or a name in the app's modules/",
|
|
56
|
+
required: true
|
|
57
|
+
},
|
|
58
|
+
app: {
|
|
59
|
+
type: "string",
|
|
60
|
+
description: "App whose modules/ a bare name is looked up in: a path, or a folder under apps/"
|
|
61
|
+
},
|
|
62
|
+
runtime: {
|
|
63
|
+
type: "boolean",
|
|
64
|
+
description: "Also create runtime/plugin.ts",
|
|
65
|
+
default: false
|
|
66
|
+
},
|
|
67
|
+
dryRun: {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
description: "Print what would change; write nothing",
|
|
70
|
+
default: false
|
|
71
|
+
}
|
|
72
|
+
}),
|
|
73
|
+
async run({ args }) {
|
|
74
|
+
const logger = consola.withTag("module:folder");
|
|
75
|
+
const result = await planModuleFolder({ cwd: resolveArg(process.cwd(), args.cwd), module: args.module, app: args.app, runtime: args.runtime }).catch((error) => {
|
|
76
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
77
|
+
return process.exit(1);
|
|
78
|
+
});
|
|
79
|
+
if (!args.dryRun) await applyPlan(result.plan);
|
|
80
|
+
logger.success(`${args.dryRun ? "Would move" : "Moved"} ${result.module.name} to ${toPosix(relative(result.root, result.index))}`);
|
|
81
|
+
printPlan(result.plan, "module:folder", {
|
|
82
|
+
dryRun: args.dryRun,
|
|
83
|
+
next: ["Restart `nuxi dev` (or run `nuxi prepare`): Nuxt loads modules/<name>/index.ts like modules/<name>.ts"]
|
|
84
|
+
});
|
|
85
|
+
if (result.hint) logger.info(result.hint);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export { moduleFolder as default, planModuleFolder, resolverHint, runtimePluginStub };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { relative, join, extname, sep, dirname } from 'node:path';
|
|
6
|
+
import { w as workspaceGlobs } from '../shared/cli.DUmSgMcB.mjs';
|
|
7
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot, a as readPackage } from '../shared/cli.Cfkcp0w9.mjs';
|
|
8
|
+
import { r as resolveLocalModule } from '../shared/cli.CybmnaqF.mjs';
|
|
9
|
+
import { r as resolveArg, a as applyPlan, p as printPlan, t as toPosix, f as findNuxtRoot, b as planChanges, w as workspaceFiles } from '../shared/cli.BLUxtpPi.mjs';
|
|
10
|
+
import 'scule';
|
|
11
|
+
import 'pkg-types';
|
|
12
|
+
import './add.mjs';
|
|
13
|
+
import 'magicast';
|
|
14
|
+
import 'magicast/helpers';
|
|
15
|
+
import '../shared/cli.CkMCvUCp.mjs';
|
|
16
|
+
import 'nypm';
|
|
17
|
+
|
|
18
|
+
const matchesWorkspaceGlobs = (path, globs) => globs.some((glob) => {
|
|
19
|
+
const pattern = glob.replace(/\/+$/, "").split("/").map((part) => part === "**" ? ".*" : part.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*")).join("/");
|
|
20
|
+
return new RegExp(`^${pattern.replace(/\/\.\*$/, "(?:/.*)?")}$`).test(path);
|
|
21
|
+
});
|
|
22
|
+
const importedPackages = (text) => {
|
|
23
|
+
const names = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const match of text.matchAll(/\b(?:from|import|require)\s*(?:\(\s*)?['"]([^'"]+)['"]/g)) {
|
|
25
|
+
const spec = match[1];
|
|
26
|
+
if (/^(?:[./~#]|node:|virtual:)/.test(spec) || /^@\//.test(spec) || /^@@\//.test(spec)) continue;
|
|
27
|
+
const parts = spec.split("/");
|
|
28
|
+
names.add(spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]);
|
|
29
|
+
}
|
|
30
|
+
return names;
|
|
31
|
+
};
|
|
32
|
+
const dependencyNames = async (dir) => {
|
|
33
|
+
const pkg = dir ? await readPackage(dir) : void 0;
|
|
34
|
+
return new Set(Object.keys({ ...pkg?.dependencies, ...pkg?.devDependencies, ...pkg?.peerDependencies }));
|
|
35
|
+
};
|
|
36
|
+
const nearestPackageDir = (dir, root) => {
|
|
37
|
+
for (let current = dir; current.startsWith(root); current = dirname(current)) {
|
|
38
|
+
if (existsSync(join(current, "package.json"))) return current;
|
|
39
|
+
if (dirname(current) === current) break;
|
|
40
|
+
}
|
|
41
|
+
return void 0;
|
|
42
|
+
};
|
|
43
|
+
const planModuleMove = async (options) => {
|
|
44
|
+
const mod = await resolveLocalModule(options.cwd, options.module, options.app);
|
|
45
|
+
let destination = resolveArg(options.cwd, options.destination);
|
|
46
|
+
if (mod.kind !== "package" && findNuxtRoot(destination, destination) === destination) destination = join(destination, "modules");
|
|
47
|
+
const name = options.name ?? mod.name;
|
|
48
|
+
if (!/^[\w.-]+$/.test(name)) throw new Error(`${name} is not a valid file or folder name`);
|
|
49
|
+
const to = mod.kind === "file" ? join(destination, `${name}${extname(mod.path)}`) : join(destination, name);
|
|
50
|
+
if (to === mod.path) throw new Error("The module is already there");
|
|
51
|
+
if (existsSync(to)) throw new Error(`${to} already exists`);
|
|
52
|
+
if (mod.kind !== "file" && (to + sep).startsWith(mod.path + sep)) throw new Error("Cannot move a folder into itself");
|
|
53
|
+
if (mod.kind === "file" && existsSync(join(destination, name))) throw new Error(`${join(destination, name)} already exists`);
|
|
54
|
+
if (mod.kind === "dir" && [".ts", ".mts", ".js", ".mjs"].some((ext) => existsSync(join(destination, `${name}${ext}`)))) {
|
|
55
|
+
throw new Error(`A module file named ${name} already exists in ${destination}`);
|
|
56
|
+
}
|
|
57
|
+
const root = await findWorkspaceRoot(options.cwd) ?? options.cwd;
|
|
58
|
+
if (!to.startsWith(root + sep)) throw new Error(`${to} is outside the workspace ${root}`);
|
|
59
|
+
const move = { from: mod.path, to, kind: mod.kind === "file" ? "file" : "dir" };
|
|
60
|
+
const plan = await planChanges(root, [move]);
|
|
61
|
+
if (mod.kind === "package") {
|
|
62
|
+
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
63
|
+
const globs = existsSync(yamlPath) ? workspaceGlobs(await readFile(yamlPath, "utf-8")) : [];
|
|
64
|
+
if (!matchesWorkspaceGlobs(toPosix(relative(root, to)), globs)) {
|
|
65
|
+
plan.warnings.push(`${toPosix(relative(root, to))} is not matched by the packages: globs of pnpm-workspace.yaml (${globs.join(", ") || "none"}): add it, or pnpm will not link it.`);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const files = mod.kind === "file" ? [mod.path] : await workspaceFiles(mod.path);
|
|
69
|
+
const imported = /* @__PURE__ */ new Set();
|
|
70
|
+
for (const file of files) for (const name2 of importedPackages(await readFile(file, "utf-8"))) imported.add(name2);
|
|
71
|
+
const source = await dependencyNames(nearestPackageDir(dirname(mod.path), root));
|
|
72
|
+
const target = await dependencyNames(nearestPackageDir(destination, root));
|
|
73
|
+
const missing = [...imported].filter((name2) => source.has(name2) && !target.has(name2));
|
|
74
|
+
if (missing.length) plan.warnings.push(`The destination's package.json lacks ${missing.join(", ")}, which the module imports.`);
|
|
75
|
+
}
|
|
76
|
+
return { plan, module: mod, to, root };
|
|
77
|
+
};
|
|
78
|
+
const moduleMove = defineCommand({
|
|
79
|
+
meta: {
|
|
80
|
+
name: "module:move",
|
|
81
|
+
description: "Move a local module or a package folder to another directory, fixing relative paths"
|
|
82
|
+
},
|
|
83
|
+
args: defineCommandArgs({
|
|
84
|
+
module: {
|
|
85
|
+
type: "positional",
|
|
86
|
+
description: "The module: a path to modules/<name>.ts, modules/<name>/ or a package folder, or a name in the app's modules/",
|
|
87
|
+
required: true
|
|
88
|
+
},
|
|
89
|
+
destination: {
|
|
90
|
+
type: "positional",
|
|
91
|
+
description: "Directory to move it into, e.g. apps/admin/modules (an app folder means its modules/)",
|
|
92
|
+
required: true
|
|
93
|
+
},
|
|
94
|
+
name: {
|
|
95
|
+
type: "string",
|
|
96
|
+
description: "New file or folder name (default: keep it)"
|
|
97
|
+
},
|
|
98
|
+
app: {
|
|
99
|
+
type: "string",
|
|
100
|
+
description: "App whose modules/ a bare module name is looked up in"
|
|
101
|
+
},
|
|
102
|
+
dryRun: {
|
|
103
|
+
type: "boolean",
|
|
104
|
+
description: "Print what would change; write nothing",
|
|
105
|
+
default: false
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
async run({ args }) {
|
|
109
|
+
const logger = consola.withTag("module:move");
|
|
110
|
+
const result = await planModuleMove({
|
|
111
|
+
cwd: resolveArg(process.cwd(), args.cwd),
|
|
112
|
+
module: args.module,
|
|
113
|
+
destination: args.destination,
|
|
114
|
+
name: args.name,
|
|
115
|
+
app: args.app
|
|
116
|
+
}).catch((error) => {
|
|
117
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
118
|
+
return process.exit(1);
|
|
119
|
+
});
|
|
120
|
+
if (!args.dryRun) await applyPlan(result.plan);
|
|
121
|
+
const rel = (path) => toPosix(relative(result.root, path));
|
|
122
|
+
logger.success(`${args.dryRun ? "Would move" : "Moved"} ${rel(result.module.path)} \u2192 ${rel(result.to)}`);
|
|
123
|
+
printPlan(result.plan, "module:move", {
|
|
124
|
+
dryRun: args.dryRun,
|
|
125
|
+
next: result.module.kind === "package" ? ["`pnpm install` so pnpm links the package from its new folder"] : ["Restart `nuxi dev` (or run `nuxi prepare`) in both apps: Nuxt only scans modules/ on start"]
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export { moduleMove as default, importedPackages, matchesWorkspaceGlobs, planModuleMove };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { defineCommand } from 'citty';
|
|
2
|
+
import consola from 'consola';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { relative, join, dirname, basename } from 'node:path';
|
|
6
|
+
import { a as workspacePackageDirs } from '../shared/cli.DUmSgMcB.mjs';
|
|
7
|
+
import { d as defineCommandArgs, f as findWorkspaceRoot, a as readPackage, p as packageScope } from '../shared/cli.Cfkcp0w9.mjs';
|
|
8
|
+
import { r as resolveArg, a as applyPlan, p as printPlan, t as toPosix, b as planChanges } from '../shared/cli.BLUxtpPi.mjs';
|
|
9
|
+
import 'scule';
|
|
10
|
+
import 'pkg-types';
|
|
11
|
+
|
|
12
|
+
const VALID_NAME = /^(?:@[a-z0-9-~][\w.~-]*\/)?[a-z0-9-~][\w.~-]*$/;
|
|
13
|
+
const DEP_SECTIONS = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies", "peerDependenciesMeta"];
|
|
14
|
+
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
15
|
+
const resolveNewPackageName = (oldName, newName) => {
|
|
16
|
+
const scope = packageScope(oldName);
|
|
17
|
+
return newName.startsWith("@") || !scope ? newName : `${scope}/${newName}`;
|
|
18
|
+
};
|
|
19
|
+
const findWorkspacePackage = async (root, cwd, ref) => {
|
|
20
|
+
const dirs = await workspacePackageDirs(root);
|
|
21
|
+
for (const dir of dirs) {
|
|
22
|
+
if ((await readPackage(dir))?.name === ref) return { dir, name: ref };
|
|
23
|
+
}
|
|
24
|
+
for (const dir of [resolveArg(cwd, ref), resolveArg(root, ref)]) {
|
|
25
|
+
const name = (await readPackage(dir))?.name;
|
|
26
|
+
if (name) return { dir, name };
|
|
27
|
+
}
|
|
28
|
+
return void 0;
|
|
29
|
+
};
|
|
30
|
+
const renameInManifest = (text, oldName, newName) => {
|
|
31
|
+
const name = escape(oldName);
|
|
32
|
+
let out = text.replace(new RegExp(`^(\\s*"name"\\s*:\\s*")${name}(")`, "m"), `$1${newName}$2`);
|
|
33
|
+
for (const section of DEP_SECTIONS) {
|
|
34
|
+
const block = new RegExp(`("${section}"\\s*:\\s*\\{)((?:[^{}]|\\{[^{}]*\\})*)(\\})`, "g");
|
|
35
|
+
out = out.replace(block, (_all, head, body, tail) => `${head}${body.replace(new RegExp(`"${name}"(\\s*:)`, "g"), `"${newName}"$1`)}${tail}`);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
};
|
|
39
|
+
const renameInWorkspaceYaml = (text, oldName, newName) => {
|
|
40
|
+
const name = escape(oldName);
|
|
41
|
+
const key = new RegExp(`^(\\s+)(['"]?)${name}\\2(\\s*:)`);
|
|
42
|
+
const item = new RegExp(`^(\\s*-\\s*)(['"]?)${name}((?:@[^'"\\s#]*)?)\\2(?=\\s|$)`);
|
|
43
|
+
return text.split("\n").map((line) => line.replace(key, `$1$2${newName}$2$3`).replace(item, `$1$2${newName}$3$2`)).join("\n");
|
|
44
|
+
};
|
|
45
|
+
const renameInSource = (text, oldName, newName) => {
|
|
46
|
+
const name = escape(oldName);
|
|
47
|
+
if (oldName.startsWith("@")) {
|
|
48
|
+
return text.replace(new RegExp(`(['"\`])${name}(?=\\1|/)`, "g"), `$1${newName}`);
|
|
49
|
+
}
|
|
50
|
+
return text.replace(
|
|
51
|
+
new RegExp(`(\\b(?:from|import|require)\\s*\\(?\\s*)(['"])${name}(?=\\2|/)`, "g"),
|
|
52
|
+
`$1$2${newName}`
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
const renameInMarkdown = (text, oldName, newName) => text.replace(new RegExp(`(?<![\\w@/.-])${escape(oldName)}(?![\\w.-])`, "g"), newName);
|
|
56
|
+
const renameReferences = (file, text, oldName, newName) => {
|
|
57
|
+
const name = basename(file);
|
|
58
|
+
if (name === "package.json") return renameInManifest(text, oldName, newName);
|
|
59
|
+
if (name === "pnpm-workspace.yaml") return renameInWorkspaceYaml(text, oldName, newName);
|
|
60
|
+
if (file.endsWith(".md") && oldName.startsWith("@")) return renameInMarkdown(text, oldName, newName);
|
|
61
|
+
return renameInSource(text, oldName, newName);
|
|
62
|
+
};
|
|
63
|
+
const planPackageRename = async (options) => {
|
|
64
|
+
const root = await findWorkspaceRoot(options.cwd);
|
|
65
|
+
if (!root) throw new Error(`No pnpm-workspace.yaml found above ${options.cwd}`);
|
|
66
|
+
const found = await findWorkspacePackage(root, options.cwd, options.package);
|
|
67
|
+
if (!found) throw new Error(`No workspace package named or at ${options.package}`);
|
|
68
|
+
const oldName = found.name;
|
|
69
|
+
const newName = resolveNewPackageName(oldName, options.name);
|
|
70
|
+
if (!VALID_NAME.test(newName)) throw new Error(`${newName} is not a valid package name`);
|
|
71
|
+
if (newName === oldName) throw new Error(`${oldName} already has that name`);
|
|
72
|
+
for (const dir of await workspacePackageDirs(root)) {
|
|
73
|
+
if ((await readPackage(dir))?.name === newName) throw new Error(`${toPosix(relative(root, dir)) || "."} is already named ${newName}`);
|
|
74
|
+
}
|
|
75
|
+
const moves = [];
|
|
76
|
+
if (options.dir) {
|
|
77
|
+
if (found.dir === root) throw new Error("--dir cannot move the workspace root");
|
|
78
|
+
const to = join(dirname(found.dir), newName.split("/").pop());
|
|
79
|
+
if (to !== found.dir) {
|
|
80
|
+
if (existsSync(to)) throw new Error(`${toPosix(relative(root, to))} already exists`);
|
|
81
|
+
moves.push({ from: found.dir, to, kind: "dir" });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const yaml = join(root, "pnpm-workspace.yaml");
|
|
85
|
+
const plan = await planChanges(root, moves, (file, text) => renameReferences(file, text, oldName, newName));
|
|
86
|
+
const yamlText = await readFile(yaml, "utf-8");
|
|
87
|
+
const renamed = renameInWorkspaceYaml(yamlText, oldName, newName);
|
|
88
|
+
if (renamed !== yamlText) plan.writes.set(yaml, renamed);
|
|
89
|
+
if (!oldName.startsWith("@")) {
|
|
90
|
+
plan.warnings.push(`${oldName} is unscoped, so only manifests and import specifiers were renamed: search the workspace for other uses.`);
|
|
91
|
+
}
|
|
92
|
+
return { plan, oldName, newName, dir: found.dir };
|
|
93
|
+
};
|
|
94
|
+
const packageRename = defineCommand({
|
|
95
|
+
meta: {
|
|
96
|
+
name: "package:rename",
|
|
97
|
+
description: "Rename a workspace package and every reference to it"
|
|
98
|
+
},
|
|
99
|
+
args: defineCommandArgs({
|
|
100
|
+
package: {
|
|
101
|
+
type: "positional",
|
|
102
|
+
description: "The package: its current name or its folder",
|
|
103
|
+
required: true
|
|
104
|
+
},
|
|
105
|
+
name: {
|
|
106
|
+
type: "positional",
|
|
107
|
+
description: "New name; a bare name keeps the old scope (forms \u2192 @acme/forms)",
|
|
108
|
+
required: true
|
|
109
|
+
},
|
|
110
|
+
dir: {
|
|
111
|
+
type: "boolean",
|
|
112
|
+
description: "Also rename the folder to the new unscoped name",
|
|
113
|
+
default: false
|
|
114
|
+
},
|
|
115
|
+
dryRun: {
|
|
116
|
+
type: "boolean",
|
|
117
|
+
description: "Print what would change; write nothing",
|
|
118
|
+
default: false
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
async run({ args }) {
|
|
122
|
+
const logger = consola.withTag("package:rename");
|
|
123
|
+
const result = await planPackageRename({ cwd: resolveArg(process.cwd(), args.cwd), package: args.package, name: args.name, dir: args.dir }).catch((error) => {
|
|
124
|
+
logger.error(error instanceof Error ? error.message : error);
|
|
125
|
+
return process.exit(1);
|
|
126
|
+
});
|
|
127
|
+
if (!args.dryRun) await applyPlan(result.plan);
|
|
128
|
+
logger.success(`${args.dryRun ? "Would rename" : "Renamed"} ${result.oldName} \u2192 ${result.newName}`);
|
|
129
|
+
printPlan(result.plan, "package:rename", {
|
|
130
|
+
dryRun: args.dryRun,
|
|
131
|
+
next: [
|
|
132
|
+
"`pnpm install` to update pnpm-lock.yaml and the node_modules links (lockfiles were not edited)",
|
|
133
|
+
"`nuxi prepare` (or restart `nuxi dev`) in the apps that use it, so .nuxt types pick up the new name"
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export { packageRename as default, findWorkspacePackage, planPackageRename, renameInManifest, renameInMarkdown, renameInSource, renameInWorkspaceYaml, renameReferences, resolveNewPackageName };
|
package/dist/chunks/upgrade.mjs
CHANGED
|
@@ -1,52 +1,23 @@
|
|
|
1
1
|
import { defineCommand } from 'citty';
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
|
-
import { readFile, writeFile, readdir, stat } from 'node:fs/promises';
|
|
4
|
+
import { readFile, writeFile, readdir, stat, mkdir, rename } from 'node:fs/promises';
|
|
5
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
|
}));
|
|
@@ -109,6 +80,26 @@ const readNuxtConfigs = async (files) => {
|
|
|
109
80
|
const option = (options, path) => path.split(".").reduce((value, key) => value !== null && typeof value === "object" ? value[key] : void 0, options);
|
|
110
81
|
const items = (value) => value !== null && typeof value === "object" && typeof value.length === "number" ? Array.from(value) : [];
|
|
111
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
|
+
|
|
112
103
|
const adminComponents = {
|
|
113
104
|
id: "admin-components",
|
|
114
105
|
package: "@frigear-nu/admin",
|
|
@@ -477,6 +468,7 @@ const migrations = [
|
|
|
477
468
|
usersRoutes,
|
|
478
469
|
adminComponents,
|
|
479
470
|
accountComponents,
|
|
471
|
+
authApi,
|
|
480
472
|
authSessionSecret,
|
|
481
473
|
menuPermission,
|
|
482
474
|
mcpPermission,
|
|
@@ -487,113 +479,6 @@ const migrations = [
|
|
|
487
479
|
usersPermissions
|
|
488
480
|
];
|
|
489
481
|
|
|
490
|
-
const YAML_KEY = /^(\s*)(['"]?)(@frigear-nu\/[\w.-]+)\2(\s*:\s*)(['"]?)([^'"\s#]+)\5/;
|
|
491
|
-
const YAML_ITEM = /^(\s*-\s*)(['"]?)(@frigear-nu\/[\w.-]+)@([^'"\s#]+)\2/;
|
|
492
|
-
const JSON_ENTRY = /("(@frigear-nu\/[\w.-]+)"\s*:\s*")([^"]*)(")/g;
|
|
493
|
-
const IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".nuxt", ".output", ".data", ".git", "dist", "coverage", ".turbo", ".vercel", ".wrangler"]);
|
|
494
|
-
const workspaceGlobs = (yaml) => {
|
|
495
|
-
const globs = [];
|
|
496
|
-
let inPackages = false;
|
|
497
|
-
for (const line of yaml.split("\n")) {
|
|
498
|
-
if (/^\S/.test(line)) inPackages = /^packages\s*:/.test(line);
|
|
499
|
-
else if (inPackages) {
|
|
500
|
-
const item = line.match(/^\s*-\s*['"]?([^'"#\s]+)/);
|
|
501
|
-
if (item && !item[1].startsWith("!")) globs.push(item[1].trim());
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
return globs;
|
|
505
|
-
};
|
|
506
|
-
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)) : [];
|
|
507
|
-
const deepDirs = async (dir) => {
|
|
508
|
-
const children = await subdirs(dir);
|
|
509
|
-
return [dir, ...(await Promise.all(children.map(deepDirs))).flat()];
|
|
510
|
-
};
|
|
511
|
-
const workspacePackageDirs = async (root) => {
|
|
512
|
-
const yamlPath = join(root, "pnpm-workspace.yaml");
|
|
513
|
-
const globs = existsSync(yamlPath) ? workspaceGlobs(await readFile(yamlPath, "utf-8")) : [];
|
|
514
|
-
const dirs = /* @__PURE__ */ new Set([root]);
|
|
515
|
-
for (const glob of globs) {
|
|
516
|
-
const parts = glob.replace(/\/+$/, "").split("/");
|
|
517
|
-
let current = [root];
|
|
518
|
-
for (const part of parts) {
|
|
519
|
-
if (part === "**") current = (await Promise.all(current.map(deepDirs))).flat();
|
|
520
|
-
else if (part.includes("*")) {
|
|
521
|
-
const pattern = new RegExp(`^${part.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
|
|
522
|
-
current = (await Promise.all(current.map(subdirs))).flat().filter((dir) => pattern.test(dir.split(/[\\/]/).pop()));
|
|
523
|
-
} else current = current.map((dir) => join(dir, part));
|
|
524
|
-
}
|
|
525
|
-
for (const dir of current) if (existsSync(join(dir, "package.json"))) dirs.add(dir);
|
|
526
|
-
}
|
|
527
|
-
return [...dirs];
|
|
528
|
-
};
|
|
529
|
-
const manifestFiles = async (root) => {
|
|
530
|
-
const files = (await workspacePackageDirs(root)).map((dir) => join(dir, "package.json")).filter(existsSync);
|
|
531
|
-
const yaml = join(root, "pnpm-workspace.yaml");
|
|
532
|
-
return existsSync(yaml) ? [...files, yaml] : files;
|
|
533
|
-
};
|
|
534
|
-
const findPins = (file, text) => {
|
|
535
|
-
if (file.endsWith(".json")) {
|
|
536
|
-
return [...text.matchAll(JSON_ENTRY)].map((match) => ({ file, name: match[2], range: match[3] }));
|
|
537
|
-
}
|
|
538
|
-
return text.split("\n").flatMap((line) => {
|
|
539
|
-
const key = line.match(YAML_KEY);
|
|
540
|
-
if (key) return [{ file, name: key[3], range: key[6] }];
|
|
541
|
-
const item = line.match(YAML_ITEM);
|
|
542
|
-
return item ? [{ file, name: item[3], range: item[4] }] : [];
|
|
543
|
-
});
|
|
544
|
-
};
|
|
545
|
-
const rewritePins = (file, text, targets) => {
|
|
546
|
-
const bumps = [];
|
|
547
|
-
const bump = (name, range) => {
|
|
548
|
-
const target = targets[name];
|
|
549
|
-
const next = target ? rewriteRange(range, target) : void 0;
|
|
550
|
-
if (next) bumps.push({ file, name, range, next });
|
|
551
|
-
return next;
|
|
552
|
-
};
|
|
553
|
-
if (file.endsWith(".json")) {
|
|
554
|
-
const out2 = text.replace(JSON_ENTRY, (all, head, name, range, tail) => {
|
|
555
|
-
const next = bump(name, range);
|
|
556
|
-
return next ? `${head}${next}${tail}` : all;
|
|
557
|
-
});
|
|
558
|
-
return { text: out2, bumps };
|
|
559
|
-
}
|
|
560
|
-
const out = text.split("\n").map((line) => {
|
|
561
|
-
const key = line.match(YAML_KEY);
|
|
562
|
-
if (key) {
|
|
563
|
-
const [all, indent, q, name, sep, vq, range] = key;
|
|
564
|
-
const next = bump(name, range);
|
|
565
|
-
return next ? line.replace(all, `${indent}${q}${name}${q}${sep}${vq}${next}${vq}`) : line;
|
|
566
|
-
}
|
|
567
|
-
const item = line.match(YAML_ITEM);
|
|
568
|
-
if (item) {
|
|
569
|
-
const [all, dash, q, name, range] = item;
|
|
570
|
-
const next = bump(name, range);
|
|
571
|
-
return next ? line.replace(all, `${dash}${q}${name}@${next}${q}`) : line;
|
|
572
|
-
}
|
|
573
|
-
return line;
|
|
574
|
-
}).join("\n");
|
|
575
|
-
return { text: out, bumps };
|
|
576
|
-
};
|
|
577
|
-
const currentVersions = (pins) => {
|
|
578
|
-
const versions = {};
|
|
579
|
-
for (const pin of pins) {
|
|
580
|
-
const version = parseVersion(pin.range);
|
|
581
|
-
if (!version) continue;
|
|
582
|
-
const value = `${version[0]}.${version[1]}.${version[2]}${version[3] ? `-${version[3]}` : ""}`;
|
|
583
|
-
const known = versions[pin.name];
|
|
584
|
-
if (!known || compareVersions(value, known) < 0) versions[pin.name] = value;
|
|
585
|
-
}
|
|
586
|
-
return versions;
|
|
587
|
-
};
|
|
588
|
-
const duplicateVersions = (lock) => {
|
|
589
|
-
const found = /* @__PURE__ */ new Map();
|
|
590
|
-
for (const match of lock.matchAll(/^ {2}'?(@frigear-nu\/[\w.-]+)@(\d[^'(:\s]*)/gm)) {
|
|
591
|
-
const versions = found.get(match[1]) ?? /* @__PURE__ */ new Set();
|
|
592
|
-
found.set(match[1], versions.add(match[2]));
|
|
593
|
-
}
|
|
594
|
-
return Object.fromEntries([...found].filter(([, versions]) => versions.size > 1).map(([name, versions]) => [name, [...versions].sort(compareVersions)]));
|
|
595
|
-
};
|
|
596
|
-
|
|
597
482
|
const REGISTRY = (process.env.npm_config_registry || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
598
483
|
const latestVersion = async (name) => {
|
|
599
484
|
const response = await fetch(`${REGISTRY}/${name.replace("/", "%2f")}`, {
|
|
@@ -675,16 +560,37 @@ const upgradeWorkspace = async (options) => {
|
|
|
675
560
|
else to[name] = target;
|
|
676
561
|
}));
|
|
677
562
|
const bumps = [];
|
|
563
|
+
const patches = [];
|
|
678
564
|
for (const manifest of manifests) {
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
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);
|
|
682
577
|
}
|
|
683
578
|
const pending = pendingMigrations(options.migrations ?? migrations, from, to);
|
|
684
579
|
const results = await runMigrations(pending, { root, files: await sourceFiles(root), dryRun });
|
|
685
580
|
const fromUpgraded = Object.fromEntries(Object.keys(to).map((name) => [name, from[name]]));
|
|
686
|
-
|
|
687
|
-
|
|
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 };
|
|
688
594
|
};
|
|
689
595
|
const upgrade = defineCommand({
|
|
690
596
|
meta: {
|
|
@@ -713,7 +619,7 @@ const upgrade = defineCommand({
|
|
|
713
619
|
},
|
|
714
620
|
report: {
|
|
715
621
|
type: "string",
|
|
716
|
-
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)",
|
|
717
623
|
default: "frigear-upgrade.md"
|
|
718
624
|
}
|
|
719
625
|
}),
|
|
@@ -741,7 +647,7 @@ const upgrade = defineCommand({
|
|
|
741
647
|
consola.log(result.report);
|
|
742
648
|
return;
|
|
743
649
|
}
|
|
744
|
-
const reportPath =
|
|
650
|
+
const reportPath = resolve(result.root, args.report);
|
|
745
651
|
await writeFile(reportPath, result.report, "utf-8");
|
|
746
652
|
logger.success(`Upgraded ${upgraded.map((name) => `${name} ${result.from[name]} \u2192 ${result.to[name]}`).join(", ")}`);
|
|
747
653
|
logger.info(`${result.bumps.length} pins updated, ${applied} code changes made, ${manual} items to do by hand: ${reportPath}`);
|
|
@@ -758,7 +664,11 @@ const upgrade = defineCommand({
|
|
|
758
664
|
const lock = join(result.root, "pnpm-lock.yaml");
|
|
759
665
|
const duplicates = existsSync(lock) ? duplicateVersions(await readFile(lock, "utf-8")) : {};
|
|
760
666
|
for (const [name, versions] of Object.entries(duplicates)) {
|
|
761
|
-
logger.warn(`${name} is installed in ${versions.length} versions (${versions.join(", ")}). Modules share build-time state through one copy: add \`'${name}': ^${result.to[name] ?? versions.at(-1)}\` to \`overrides\` in pnpm-workspace.yaml
|
|
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.`);
|
|
762
672
|
}
|
|
763
673
|
}
|
|
764
674
|
}
|
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<{
|
|
@@ -133,6 +138,14 @@ interface Pin {
|
|
|
133
138
|
interface Bump extends Pin {
|
|
134
139
|
next: string;
|
|
135
140
|
}
|
|
141
|
+
interface PatchMove {
|
|
142
|
+
file: string;
|
|
143
|
+
name: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string;
|
|
146
|
+
patch: string;
|
|
147
|
+
next: string;
|
|
148
|
+
}
|
|
136
149
|
|
|
137
150
|
interface UpgradeOptions {
|
|
138
151
|
/** Any directory of the workspace; the root is found from it. */
|
|
@@ -157,6 +170,7 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
|
157
170
|
};
|
|
158
171
|
to: Record<string, string>;
|
|
159
172
|
bumps: Bump[];
|
|
173
|
+
patches: PatchMove[];
|
|
160
174
|
results: MigrationResult[];
|
|
161
175
|
skipped: string[];
|
|
162
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<{
|
|
@@ -133,6 +138,14 @@ interface Pin {
|
|
|
133
138
|
interface Bump extends Pin {
|
|
134
139
|
next: string;
|
|
135
140
|
}
|
|
141
|
+
interface PatchMove {
|
|
142
|
+
file: string;
|
|
143
|
+
name: string;
|
|
144
|
+
from: string;
|
|
145
|
+
to: string;
|
|
146
|
+
patch: string;
|
|
147
|
+
next: string;
|
|
148
|
+
}
|
|
136
149
|
|
|
137
150
|
interface UpgradeOptions {
|
|
138
151
|
/** Any directory of the workspace; the root is found from it. */
|
|
@@ -157,6 +170,7 @@ declare const upgradeWorkspace: (options: UpgradeOptions) => Promise<{
|
|
|
157
170
|
};
|
|
158
171
|
to: Record<string, string>;
|
|
159
172
|
bumps: Bump[];
|
|
173
|
+
patches: PatchMove[];
|
|
160
174
|
results: MigrationResult[];
|
|
161
175
|
skipped: string[];
|
|
162
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';
|
|
@@ -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 };
|