@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 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) => {
@@ -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 choices = `${PLATFORMS.join(", ")}, ${PLATFORMS.join(",")} or a starter: ${Object.keys(STARTERS).join(", ")}`;
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
- ...!starter ? [] : starter === "mobile" ? [" set NUXT_PUBLIC_AUTHENTICATION_CLIENT_ISSUER (and _API_BASE) in apps/mobile/.env"] : [" put your email in NUXT_ACL_ADMINS in apps/web/.env"],
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 };