From 50e083c76cf9d04603f08d6f591321916478631c Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Mon, 29 Sep 2025 23:36:21 +0200 Subject: [PATCH 1/2] fix: update command descriptions and defaults --- src/commands/_shared.ts | 19 +++++++++++++++++++ src/commands/build.ts | 24 +++++++++++------------- src/commands/prepare.ts | 13 +++---------- 3 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 src/commands/_shared.ts diff --git a/src/commands/_shared.ts b/src/commands/_shared.ts new file mode 100644 index 00000000..53748de9 --- /dev/null +++ b/src/commands/_shared.ts @@ -0,0 +1,19 @@ +import type { ArgDef } from 'citty' + +export const sharedArgs = { + // cwd falls back to rootDir's default (indirect default) + cwd: { + type: 'string', + valueHint: 'directory', + description: 'Specify the working directory, this takes precedence over ROOTDIR (default: `.`)', + default: undefined, + }, + rootDir: { + type: 'positional', + description: 'Specifies the working directory (default: `.`)', + required: false, + default: '.', + }, +} as const satisfies Record + +export const resolveCwd = (args: { cwd?: string, rootDir?: string }) => args.cwd || args.rootDir || '.' diff --git a/src/commands/build.ts b/src/commands/build.ts index 36bc5941..a8ca28f8 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -16,6 +16,7 @@ import { defineCommand } from 'citty' import { convertCompilerOptionsFromJson } from 'typescript' import { name, version } from '../../package.json' +import { resolveCwd, sharedArgs } from './_shared' export default defineCommand({ meta: { @@ -23,44 +24,41 @@ export default defineCommand({ description: 'Build module for distribution', }, args: { - cwd: { - type: 'string', - description: 'Current working directory', - }, - rootDir: { - type: 'positional', - description: 'Root directory', - required: false, - }, + ...sharedArgs, outDir: { type: 'string', + default: 'dist', + description: 'Build directory', }, sourcemap: { type: 'boolean', + default: false, + description: 'Generate sourcemaps', }, stub: { type: 'boolean', + default: false, + description: 'Stub dist instead of actually building it for development', }, }, async run(context) { const { build } = await import('unbuild') - const cwd = resolve(context.args.cwd || context.args.rootDir || '.') + const cwd = resolveCwd(context.args) const jiti = createJiti(cwd) - const outDir = context.args.outDir || 'dist' await build(cwd, false, { declaration: 'node16', sourcemap: context.args.sourcemap, stub: context.args.stub, stubOptions: { absoluteJitiPath: true }, - outDir, + outDir: context.args.outDir, entries: [ 'src/module', { input: 'src/runtime/', - outDir: `${outDir}/runtime`, + outDir: `${context.args.outDir}/runtime`, addRelativeDeclarationExtensions: true, ext: 'js', pattern: [ diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index e6527681..0414d2a9 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -1,6 +1,7 @@ import type { NuxtConfig } from '@nuxt/schema' import { defineCommand } from 'citty' import { resolve } from 'pathe' +import { resolveCwd, sharedArgs } from './_shared' export default defineCommand({ meta: { @@ -8,20 +9,12 @@ export default defineCommand({ description: 'Prepare @nuxt/module-builder environment by writing types and stubs', }, args: { - cwd: { - type: 'string', - description: 'Current working directory', - }, - rootDir: { - type: 'positional', - description: 'Root directory', - required: false, - }, + ...sharedArgs, }, async run(context) { const { runCommand } = await import('@nuxt/cli') - const cwd = resolve(context.args.cwd || context.args.rootDir || '.') + const cwd = resolveCwd(context.args) return runCommand('prepare', [cwd], { overrides: { From 39eb5073f2656c9023484bde006f2774aa7076fd Mon Sep 17 00:00:00 2001 From: Bobbie Goede Date: Tue, 30 Sep 2025 00:18:05 +0200 Subject: [PATCH 2/2] fix: resolve path --- src/commands/_shared.ts | 2 +- src/commands/build.ts | 4 ++-- src/commands/prepare.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/commands/_shared.ts b/src/commands/_shared.ts index 53748de9..80ecb781 100644 --- a/src/commands/_shared.ts +++ b/src/commands/_shared.ts @@ -16,4 +16,4 @@ export const sharedArgs = { }, } as const satisfies Record -export const resolveCwd = (args: { cwd?: string, rootDir?: string }) => args.cwd || args.rootDir || '.' +export const resolveCwdArg = (args: { cwd?: string, rootDir?: string }) => args.cwd || args.rootDir || '.' diff --git a/src/commands/build.ts b/src/commands/build.ts index a8ca28f8..031c4b0f 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -16,7 +16,7 @@ import { defineCommand } from 'citty' import { convertCompilerOptionsFromJson } from 'typescript' import { name, version } from '../../package.json' -import { resolveCwd, sharedArgs } from './_shared' +import { resolveCwdArg, sharedArgs } from './_shared' export default defineCommand({ meta: { @@ -44,7 +44,7 @@ export default defineCommand({ async run(context) { const { build } = await import('unbuild') - const cwd = resolveCwd(context.args) + const cwd = resolve(resolveCwdArg(context.args)) const jiti = createJiti(cwd) diff --git a/src/commands/prepare.ts b/src/commands/prepare.ts index 0414d2a9..9ca8ba73 100644 --- a/src/commands/prepare.ts +++ b/src/commands/prepare.ts @@ -1,7 +1,7 @@ import type { NuxtConfig } from '@nuxt/schema' import { defineCommand } from 'citty' import { resolve } from 'pathe' -import { resolveCwd, sharedArgs } from './_shared' +import { resolveCwdArg, sharedArgs } from './_shared' export default defineCommand({ meta: { @@ -14,7 +14,7 @@ export default defineCommand({ async run(context) { const { runCommand } = await import('@nuxt/cli') - const cwd = resolveCwd(context.args) + const cwd = resolve(resolveCwdArg(context.args)) return runCommand('prepare', [cwd], { overrides: {