fix(list-templates): treat --spfx-version as output filter instead of branch selector - #259
Open
Vilius Vystartas (vystartasv) wants to merge 4 commits into
Open
Conversation
… branch selector The --spfx-version option was previously used only for branch selection in the template repository, causing errors when the corresponding branch didn't exist. Users naturally expect it to filter the listed templates by SPFx version. - After fetching all templates, filter by spfxVersion field when --spfx-version is provided (using startsWith so '1.22' matches '1.22.0' and '1.22.1') - Show a helpful message when no templates match, suggesting the user run without --spfx-version to see all available versions - Update documentation to describe the filter behavior Fixes SharePoint#236
Copilot started reviewing on behalf of
Vilius Vystartas (vystartasv)
July 10, 2026 21:34
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the spfx list-templates CLI action to support filtering templates by SPFx version, addressing Issue #236 where --spfx-version was expected to filter results.
Changes:
- Updates the command documentation text to describe
--spfx-versionas a filter forlist-templates. - Adds post-fetch filtering logic that filters templates by
template.spfxVersionusing a prefix match. - Adds a “no matches” message instructing users to run without
--spfx-versionto see all templates.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+41
to
+43
| // Apply --spfx-version filter if provided (user expects filter, not just branch selection) | ||
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| if (spfxVersion) { |
Comment on lines
+42
to
+46
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| if (spfxVersion) { | ||
| const filteredTemplates = [...templates.values()].filter( | ||
| (t) => t.spfxVersion && t.spfxVersion.startsWith(spfxVersion) | ||
| ); |
Comment on lines
16
to
+18
| 'This command lists all available templates from the default GitHub source ' + | ||
| 'and any additional sources specified with --local-source or --remote-source.' | ||
| 'and any additional sources specified with --local-source or --remote-source. ' + | ||
| 'Use --spfx-version to filter templates by version (e.g., "--spfx-version 1.22").' |
Comment on lines
+41
to
+52
| // Apply --spfx-version filter if provided (user expects filter, not just branch selection) | ||
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| if (spfxVersion) { | ||
| const filteredTemplates = [...templates.values()].filter( | ||
| (t) => t.spfxVersion && t.spfxVersion.startsWith(spfxVersion) | ||
| ); | ||
| if (filteredTemplates.length === 0) { | ||
| terminal.writeLine( | ||
| `No templates found for SPFx version "${spfxVersion}". ` + | ||
| `Use "spfx list-templates" (without --spfx-version) to see all available versions.` | ||
| ); | ||
| return; |
- Split version string to prevent '1.2' matching '1.20.0' - Handle 'version/1.22' prefix and '-rc.X' suffix normalization - Update parameter description to reflect filter behavior
Copilot started reviewing on behalf of
Vilius Vystartas (vystartasv)
July 11, 2026 21:19
View session
Comment on lines
51
to
57
| this._spfxVersionParameter = this.defineStringParameter({ | ||
| parameterLongName: '--spfx-version', | ||
| argumentName: 'VERSION', | ||
| description: | ||
| 'The SPFx version to use (e.g., "1.22", "1.23-rc.0"). Resolves to the "version/<VERSION>" branch ' + | ||
| 'The SPFx version to filter by (e.g., "1.22"). Also selects a corresponding "version/<VERSION>" branch ' + | ||
| 'in the template repository. Defaults to the "version/latest" branch.' | ||
| }); |
Comment on lines
39
to
+43
| const templates: SPFxTemplateCollection = await this._fetchTemplatesAsync(manager); | ||
|
|
||
| const formattedTable: string = await templates.toFormattedStringAsync(); | ||
| terminal.writeLine(formattedTable); | ||
| // Apply --spfx-version filter if provided (user expects filter, not just branch selection) | ||
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| // Normalize version prefix: "version/1.22" -> "1.22", "1.22-rc.0" -> "1.22" |
Comment on lines
+41
to
+58
| // Apply --spfx-version filter if provided (user expects filter, not just branch selection) | ||
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| // Normalize version prefix: "version/1.22" -> "1.22", "1.22-rc.0" -> "1.22" | ||
| const normalizedVersion: string | undefined = spfxVersion | ||
| ? spfxVersion.replace(/^version\//, '').replace(/-.*$/, '') | ||
| : undefined; | ||
| if (normalizedVersion) { | ||
| // Split into parts and compare major.minor so "1.2" doesn't match "1.20.0" | ||
| const versionParts: string[] = normalizedVersion.split('.'); | ||
| const filteredTemplates = [...templates.values()].filter( | ||
| (t) => t.spfxVersion && t.spfxVersion.split('.').slice(0, versionParts.length).join('.') === normalizedVersion | ||
| ); | ||
| if (filteredTemplates.length === 0) { | ||
| terminal.writeLine( | ||
| `No templates found for SPFx version "${spfxVersion}". ` + | ||
| `Use "spfx list-templates" (without --spfx-version) to see all available versions.` | ||
| ); | ||
| return; |
This was referenced Jul 13, 2026
|
Vilius Vystartas (@vystartasv) does this PR solve the problem when we filter out templates for a branch that does not exist? |
Contributor
Author
|
Adam Wójcik (@Adam-it) Just updating that #260 and #262 have been rebased cleanly off main — they no longer include commits from this PR. This branch (#259) was the base and is unaffected. Thanks for the reviews. |
The --spfx-version filter uses SPFxTemplateCollection as a constructor (new SPFxTemplateCollection()), which requires a value import — a type-only import won't compile with noImplicitOverride enabled.
Copilot started reviewing on behalf of
Vilius Vystartas (vystartasv)
July 13, 2026 14:37
View session
Comment on lines
+41
to
+46
| // Apply --spfx-version filter if provided (user expects filter, not just branch selection) | ||
| const spfxVersion: string | undefined = this._spfxVersionParameter.value?.trim(); | ||
| // Normalize version prefix: "version/1.22" -> "1.22", "1.22-rc.0" -> "1.22" | ||
| const normalizedVersion: string | undefined = spfxVersion | ||
| ? spfxVersion.replace(/^version\//, '').replace(/-.*$/, '') | ||
| : undefined; |
Comment on lines
+47
to
+62
| if (normalizedVersion) { | ||
| // Split into parts and compare major.minor so "1.2" doesn't match "1.20.0" | ||
| const versionParts: string[] = normalizedVersion.split('.'); | ||
| const filteredTemplates = [...templates.values()].filter( | ||
| (t) => t.spfxVersion && t.spfxVersion.split('.').slice(0, versionParts.length).join('.') === normalizedVersion | ||
| ); | ||
| if (filteredTemplates.length === 0) { | ||
| terminal.writeLine( | ||
| `No templates found for SPFx version "${spfxVersion}". ` + | ||
| `Use "spfx list-templates" (without --spfx-version) to see all available versions.` | ||
| ); | ||
| return; | ||
| } | ||
| const displayCollection: SPFxTemplateCollection = new SPFxTemplateCollection(filteredTemplates); | ||
| const formattedTable: string = await displayCollection.toFormattedStringAsync(); | ||
| terminal.writeLine(formattedTable); |
Comment on lines
+48
to
+49
| // Split into parts and compare major.minor so "1.2" doesn't match "1.20.0" | ||
| const versionParts: string[] = normalizedVersion.split('.'); |
Comment on lines
+55
to
56
| 'The SPFx version to filter by (e.g., "1.22"). Also selects a corresponding "version/<VERSION>" branch ' + | ||
| 'in the template repository. Defaults to the "version/latest" branch.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
--spfx-versionflag onspfx list-templateswas used only for branch selection in the template repository. When the corresponding branch didn't exist, the command errored instead of filtering.This fix applies
--spfx-versionas an output filter on thespfxVersionfield of each template after fetching. UsesstartsWith-style matching so1.22matches1.22.0and1.22.1.When no templates match, shows a helpful message suggesting the user run without
--spfx-versionto see all available versions.Also fixes a compile bug: SPFxTemplateCollection was imported as type-only but used as a constructor.
How was this tested?
version/prefix, handles `-rc* suffixes)Type of change