Skip to content

Commit eb3163c

Browse files
iclantonclaude
andauthored
--spfx-version resolves to version/<VERSION> branch (#177)
## Description Updates `--spfx-version` so the value is used as a `version/<VERSION>` branch name in the template repository. For example, `--spfx-version 1.22` now resolves to the `version/1.22` branch instead of `1.22`. Updates parameter description, README, and tests accordingly. ## How was this tested - `heft test` passes (46 tests) ## Type of change - [ ] Bug fix - [x] New feature / behavior change - [ ] Template change (templates/ or examples/) - [ ] Docs / CI only 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent fa808fe commit eb3163c

6 files changed

Lines changed: 38 additions & 17 deletions

File tree

apps/spfx-cli/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Scaffolds a new SPFx component. Templates are pulled from the [SharePoint/spfx](
4545
| `--solution-name NAME` | kebab-cased component name | SharePoint solution name |
4646
| `--component-alias ALIAS` | same as `--component-name` | Short identifier for the component |
4747
| `--component-description TEXT` | `"<name> description"` | Component description string |
48-
| `--spfx-version VERSION` | repo default branch | Branch/tag in the template repo to use (e.g. `1.22`, `1.23-rc.0`) |
48+
| `--spfx-version VERSION` | repo default branch | SPFx version to use; resolves to the `version/<VERSION>` branch (e.g. `1.22`, `1.23-rc.0`) |
4949
| `--template-url URL` | `https://github.com/SharePoint/spfx` | Custom GitHub template repository |
5050
| `--local-template PATH` || Path to a local template folder (repeatable; bypasses GitHub) |
5151

@@ -60,7 +60,7 @@ Scaffolds a new SPFx component. Templates are pulled from the [SharePoint/spfx](
6060

6161
## Templates
6262

63-
Templates are fetched at runtime from the [SharePoint/spfx](https://github.com/SharePoint/spfx) GitHub repository. Use `--spfx-version` to target a specific release branch, or `--local-template` to use templates from disk.
63+
Templates are fetched at runtime from the [SharePoint/spfx](https://github.com/SharePoint/spfx) GitHub repository. Use `--spfx-version` to target a specific release branch (e.g. `--spfx-version 1.22` resolves to the `version/1.22` branch), or `--local-template` to use templates from disk.
6464

6565
### Web Parts
6666

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ export class CreateAction extends CommandLineAction {
137137
parameterLongName: '--spfx-version',
138138
argumentName: 'VERSION',
139139
description:
140-
'The branch name in the template repository to use (e.g., "1.22", "1.23-rc.0"). ' +
141-
"Defaults to the repository's default branch (main)."
140+
'The SPFx version to use (e.g., "1.22", "1.23-rc.0"). Resolves to the "version/<VERSION>" branch ' +
141+
"in the template repository. Defaults to the repository's default branch (main)."
142142
});
143143

144144
this._packageManagerParameter = this.defineChoiceParameter({
@@ -184,14 +184,24 @@ export class CreateAction extends CommandLineAction {
184184
const rawUrl: string = (this._templateUrlParameter.value ?? '').trim() || DEFAULT_GITHUB_REPO;
185185
const { repoUrl, urlBranch } = parseGitHubUrlAndRef(rawUrl);
186186

187-
const spfxVersion: string | undefined = this._spfxVersionParameter.value;
188-
if (spfxVersion !== undefined && urlBranch !== undefined) {
187+
const spfxVersionRaw: string | undefined = this._spfxVersionParameter.value?.trim();
188+
let spfxVersionBranch: string | undefined;
189+
if (spfxVersionRaw) {
190+
if (spfxVersionRaw.startsWith('version/')) {
191+
spfxVersionBranch = spfxVersionRaw;
192+
} else {
193+
spfxVersionBranch = `version/${spfxVersionRaw}`;
194+
}
195+
}
196+
197+
if (spfxVersionBranch && urlBranch) {
189198
terminal.writeWarningLine(
190199
`${this._templateUrlParameter.longName} contains a branch ('/tree/${urlBranch}'). ` +
191-
`${this._spfxVersionParameter.longName} "${spfxVersion}" will take precedence.`
200+
`${this._spfxVersionParameter.longName} "${spfxVersionRaw}" will take precedence.`
192201
);
193202
}
194-
const ref: string | undefined = spfxVersion ?? urlBranch;
203+
204+
const ref: string | undefined = spfxVersionBranch ?? urlBranch;
195205

196206
terminal.writeLine(`Using GitHub template source: ${repoUrl}${ref ? ` (branch: ${ref})` : ''}`);
197207
manager.addSource(new PublicGitHubRepositorySource(repoUrl, ref, this._terminal));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ describe('CreateAction', () => {
226226
await runCreateAsync(['--spfx-version', '1.22']);
227227
expect(MockedGitHub).toHaveBeenCalledWith(
228228
'https://github.com/SharePoint/spfx',
229-
'1.22',
229+
'version/1.22',
230230
expect.anything()
231231
);
232232
});
@@ -236,7 +236,7 @@ describe('CreateAction', () => {
236236
await runCreateAsync(['--spfx-version', '1.22']);
237237
expect(MockedGitHub).toHaveBeenCalledWith(
238238
'https://github.com/my-org/my-templates',
239-
'1.22',
239+
'version/1.22',
240240
expect.anything()
241241
);
242242
});
@@ -247,7 +247,7 @@ describe('CreateAction', () => {
247247
await runCreateAsync(['--spfx-version', '1.22']);
248248
expect(MockedGitHub).toHaveBeenCalledWith(
249249
'https://github.com/SharePoint/spfx',
250-
'1.22',
250+
'version/1.22',
251251
expect.anything()
252252
);
253253
});

apps/spfx-cli/src/cli/actions/tests/__snapshots__/CreateAction.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Array [
101101

102102
exports[`CreateAction --spfx-version passes ref to PublicGitHubRepositorySource when --spfx-version is set 1`] = `
103103
Array [
104-
"[ log] Using GitHub template source: https://github.com/SharePoint/spfx (branch: 1.22)[n]",
104+
"[ log] Using GitHub template source: https://github.com/SharePoint/spfx (branch: version/1.22)[n]",
105105
"[ log] [Mocked SPFxTemplateCollection][n]",
106106
"[ log] targetDir: /tmp/test[n]",
107107
"[ log] [n]",
@@ -112,7 +112,7 @@ Array [
112112

113113
exports[`CreateAction --spfx-version passes ref when SPFX_TEMPLATE_REPO_URL and --spfx-version are both set 1`] = `
114114
Array [
115-
"[ log] Using GitHub template source: https://github.com/my-org/my-templates (branch: 1.22)[n]",
115+
"[ log] Using GitHub template source: https://github.com/my-org/my-templates (branch: version/1.22)[n]",
116116
"[ log] [Mocked SPFxTemplateCollection][n]",
117117
"[ log] targetDir: /tmp/test[n]",
118118
"[ log] [n]",
@@ -124,7 +124,7 @@ Array [
124124
exports[`CreateAction --spfx-version uses --spfx-version over branch encoded in SPFX_TEMPLATE_REPO_URL /tree/ path 1`] = `
125125
Array [
126126
"[warning] --template-url contains a branch ('/tree/pending-fixes'). --spfx-version \\"1.22\\" will take precedence.[n]",
127-
"[ log] Using GitHub template source: https://github.com/SharePoint/spfx (branch: 1.22)[n]",
127+
"[ log] Using GitHub template source: https://github.com/SharePoint/spfx (branch: version/1.22)[n]",
128128
"[ log] [Mocked SPFxTemplateCollection][n]",
129129
"[ log] targetDir: /tmp/test[n]",
130130
"[ log] [n]",

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ Optional arguments:
4141
may alternatively be specified via the
4242
SPFX_TEMPLATE_REPO_URL environment variable.
4343
--spfx-version VERSION
44-
The branch name in the template repository to use (e.
45-
g., \\"1.22\\", \\"1.23-rc.0\\"). Defaults to the
46-
repository's default branch (main).
44+
The SPFx version to use (e.g., \\"1.22\\", \\"1.23-rc.0\\").
45+
Resolves to the \\"version/<VERSION>\\" branch in the
46+
template repository. Defaults to the repository's
47+
default branch (main).
4748
--package-manager {npm,pnpm,yarn,none}
4849
Package manager to use for dependency installation
4950
after scaffolding. Use \\"none\\" to skip installation.
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)