Skip to content

Commit dfd1810

Browse files
jycouetmanuel3108
andauthored
fix(cli): avoid printing duplicated --no-install flag (#803)
* fix(cli): display agrs with no duplicates * simple * fix also the [path] * bring back default to local place * don't use absolute path * better changeset --------- Co-authored-by: Manuel Serret <[email protected]>
1 parent 532206e commit dfd1810

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

.changeset/ripe-hoops-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix(cli): avoid printing duplicated `--no-install` flag

documentation/docs/20-commands/10-sv-create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Add add-ons to the project in the `create` command. Following the same format as
4848
Example:
4949

5050
```sh
51-
npx sv create --add eslint prettier
51+
npx sv create --add eslint prettier [path]
5252
```
5353

5454
### `--no-add-ons`

packages/cli/commands/add/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const add = new Command('add')
184184
options,
185185
selectedAddons,
186186
workspace,
187-
withLogArgs: true
187+
fromCommand: 'add'
188188
});
189189

190190
if (nextSteps.length > 0) {
@@ -547,15 +547,15 @@ export async function runAddonsApply({
547547
selectedAddons,
548548
addonSetupResults,
549549
workspace,
550-
withLogArgs
550+
fromCommand
551551
}: {
552552
answersOfficial: Record<string, OptionValues<any>>;
553553
answersCommunity: Record<string, OptionValues<any>>;
554554
options: Options;
555555
selectedAddons: SelectedAddon[];
556556
addonSetupResults?: Record<string, AddonSetupResult>;
557557
workspace: Workspace;
558-
withLogArgs?: boolean;
558+
fromCommand: 'create' | 'add';
559559
}): Promise<{ nextSteps: string[]; argsFormattedAddons: string[] }> {
560560
if (!addonSetupResults) {
561561
const setups = selectedAddons.length
@@ -657,11 +657,7 @@ export async function runAddonsApply({
657657
}
658658
}
659659

660-
if (packageManager === null || packageManager === undefined)
661-
argsFormattedAddons.push('--no-install');
662-
else argsFormattedAddons.push('--install', packageManager);
663-
664-
if (withLogArgs) common.logArgs(packageManager ?? 'npm', 'add', argsFormattedAddons);
660+
if (fromCommand === 'add') common.logArgs(packageManager, 'add', argsFormattedAddons);
665661

666662
if (packageManager) {
667663
workspace.packageManager = packageManager;

packages/cli/commands/create.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ async function createProject(cwd: ProjectPath, options: Options) {
281281
},
282282
selectedAddons,
283283
addonSetupResults: undefined,
284-
workspace
284+
workspace,
285+
fromCommand: 'create'
285286
});
286287
argsFormattedAddons = argsFormatted;
287288

@@ -296,7 +297,7 @@ async function createProject(cwd: ProjectPath, options: Options) {
296297
: options.install;
297298

298299
// Build args for next time based on non-default options
299-
const argsFormatted = [cwd ?? defaultPath];
300+
const argsFormatted: string[] = [];
300301

301302
argsFormatted.push('--template', template);
302303

@@ -306,10 +307,7 @@ async function createProject(cwd: ProjectPath, options: Options) {
306307

307308
if (argsFormattedAddons.length > 0) argsFormatted.push('--add', ...argsFormattedAddons);
308309

309-
if (packageManager === null || packageManager === undefined) argsFormatted.push('--no-install');
310-
else argsFormatted.push('--install', packageManager);
311-
312-
common.logArgs(packageManager ?? 'npm', 'create', argsFormatted);
310+
common.logArgs(packageManager, 'create', argsFormatted, [cwd ?? defaultPath]);
313311

314312
await addPnpmBuildDependencies(projectPath, packageManager, ['esbuild']);
315313
if (packageManager) await installDependencies(packageManager, projectPath);

packages/cli/utils/common.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,20 @@ export function parseAddonOptions(optionFlags: string | undefined): string[] | u
137137
return options;
138138
}
139139

140-
export function logArgs(agent: AgentName, actionName: string, args: string[]) {
141-
const defaultArgs = ['sv', actionName, ...args];
142-
const res = resolveCommand(agent, 'execute', defaultArgs);
143-
if (res) p.log.message(pc.dim([res.command, ...res.args].join(' ')));
144-
else p.log.message(pc.dim([`npx`, ...defaultArgs].join(' ')));
140+
export function logArgs(
141+
agent: AgentName | null | undefined,
142+
command: 'create' | 'add',
143+
args: string[],
144+
lastArgs: string[] = []
145+
) {
146+
const allArgs = ['sv', command, ...args];
147+
148+
// Handle install option
149+
if (agent === null || agent === undefined) allArgs.push('--no-install');
150+
else allArgs.push('--install', agent);
151+
152+
const res = resolveCommand(agent ?? 'npm', 'execute', [...allArgs, ...lastArgs])!;
153+
p.log.message(pc.dim([res.command, ...res.args].join(' ')));
145154
}
146155

147156
export function errorAndExit(message: string) {

0 commit comments

Comments
 (0)