Skip to content

Commit b5806b4

Browse files
authored
feat: make --library-name optional, fallback to solution name (#260)
## Description Makes `--library-name` optional on `spfx create`. When omitted, the solution name is used as the default library name instead of requiring explicit input. Closes #246 ## How was this tested? - Change is scoped to CreateAction.ts only — parameter type changed from required to optional, fallback uses computed `solutionName` - Verified the fallback path handles both missing `--library-name` and missing `--solution-name` - Branch rebuilt off `main` to remove earlier cross-PR contamination — only this feature's changes are included ## Type of change - [ ] Bug fix - [x] New feature / enhancement - [ ] Template change - [ ] Documentation / CI / governance
1 parent cb7ac0a commit b5806b4

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

apps/spfx-cli/src/cli/actions/CreateAction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ScaffoldProfileSchema: z.ZodType<IScaffoldProfile> = z.object({
4848
export class CreateAction extends SPFxActionBase {
4949
private readonly _targetDirParameter: CommandLineStringParameter;
5050
private readonly _templateParameter: IRequiredCommandLineStringParameter;
51-
private readonly _libraryNameParameter: IRequiredCommandLineStringParameter;
51+
private readonly _libraryNameParameter: CommandLineStringParameter;
5252
private readonly _componentNameParameter: IRequiredCommandLineStringParameter;
5353
private readonly _componentAliasParameter: CommandLineStringParameter;
5454
private readonly _componentDescriptionParameter: CommandLineStringParameter;
@@ -83,8 +83,8 @@ export class CreateAction extends SPFxActionBase {
8383
this._libraryNameParameter = this.defineStringParameter({
8484
parameterLongName: '--library-name',
8585
argumentName: 'LIBRARY_NAME',
86-
description: 'The library name for the component',
87-
required: true
86+
description: 'The library name for the component. Defaults to the solution name if not specified.',
87+
required: false
8888
});
8989

9090
this._componentNameParameter = this.defineStringParameter({
@@ -204,7 +204,7 @@ export class CreateAction extends SPFxActionBase {
204204
const builtInContext: ISPFxBuiltInContext = buildBuiltInContext(
205205
{
206206
componentName,
207-
libraryName: this._libraryNameParameter.value,
207+
libraryName: this._libraryNameParameter.value || solutionName,
208208
spfxVersion: template.spfxVersion,
209209
solutionName: rawSolutionName || undefined,
210210
componentAlias: this._componentAliasParameter.value?.trim() || undefined,

apps/spfx-cli/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ exports[`CommandLineHelp prints the help: create 1`] = `
44
"usage: spfx create [-h] [--template-url URL] [--spfx-version VERSION]
55
[--local-source TEMPLATE_PATH] [--remote-source URL]
66
[--github-token TOKEN] [--target-dir TARGET_DIR] --template
7-
TEMPLATE_NAME --library-name LIBRARY_NAME --component-name
8-
COMPONENT_NAME [--component-alias COMPONENT_ALIAS]
7+
TEMPLATE_NAME [--library-name LIBRARY_NAME]
8+
--component-name COMPONENT_NAME
9+
[--component-alias COMPONENT_ALIAS]
910
[--component-description COMPONENT_DESCRIPTION]
1011
[--solution-name SOLUTION_NAME]
1112
[--package-manager {npm,pnpm,yarn,none}]
@@ -40,7 +41,8 @@ Optional arguments:
4041
--template TEMPLATE_NAME
4142
The template to use for scaffolding
4243
--library-name LIBRARY_NAME
43-
The library name for the component
44+
The library name for the component. Defaults to the
45+
solution name if not specified.
4446
--component-name COMPONENT_NAME
4547
The component name (e.g., \\"Hello World\\")
4648
--component-alias COMPONENT_ALIAS
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/spfx-cli",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/spfx-cli"
10+
}

0 commit comments

Comments
 (0)