Wire default GitHub template source in CLI#149
Merged
nick-pape merged 9 commits intoSharePoint:mainfrom Mar 19, 2026
Merged
Conversation
When no --local-template is provided, the CLI now defaults to fetching templates from the public GitHub repo (SharePoint/spfx). The repo URL can be overridden via SPFX_TEMPLATE_REPO_URL env var for internal or testing use. Template fetch errors now surface a clear message suggesting --local-template for offline scenarios. Fixes SharePoint#91 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Pass terminal to PublicGitHubRepositorySource for consistent logging - Preserve error cause when wrapping fetch errors - Normalize SPFX_TEMPLATE_REPO_URL (trim whitespace, strip trailing slash and .git) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- 17 new unit tests covering source selection, URL normalization, and error handling with user-friendly messages (uses executeWithoutErrorHandlingAsync) - 1 integration test that runs the real CLI against localhost:19999 to verify the helpful error message surfaces end-to-end Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Add `--spfx-version VERSION` parameter to select a template repo branch - Add `_parseGitHubUrlAndRef` helper to extract branch from `/tree/` URLs - Fix whitespace-only SPFX_TEMPLATE_REPO_URL falling through to default - Warn when --spfx-version conflicts with a /tree/ branch or --local-template - Add 9 new unit tests covering all new behaviours - Regenerate CommandLineHelp snapshot Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Replace manual process.env read with ts-command-line environmentVariable option; adds --template-url flag backed by SPFX_TEMPLATE_REPO_URL - Collapse envUrl/rawUrl two-hop logic into a single line - Drop redundant "Warning: " prefix from writeWarningLine strings - Rename _parseGitHubUrlAndRef -> parseGitHubUrlAndRef (module-level functions don't use the _ prefix convention) - Use named capture groups in regex (self-documenting) and drop the redundant lazy ? quantifier on [^/]+ - Regenerate CommandLineHelp snapshot Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The subprocess-based test used a localhost URL to simulate a network failure, but the URL failed at regex validation (no github.com match) rather than at the network level — making the timeout guard misleading. The error-handling scenarios it covered (exit code, 'Failed to fetch templates', and '--local-template' hint) are already tested with proper mocks in CreateAction.test.ts (lines 297-329), so no coverage is lost. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates spfx create to use the public SharePoint/spfx GitHub repository as the default template source (when --local-template isn’t provided), and adds flags/env var support to override the repo URL and select a branch via --spfx-version.
Changes:
- Default to
PublicGitHubRepositorySourceusinghttps://github.com/SharePoint/spfxwhen no local template sources are provided - Add
--template-url(andSPFX_TEMPLATE_REPO_URL) plus--spfx-versionbranch selection, including/tree/<ref>parsing - Add tests and update help snapshot; improve fetch failure error messaging (with
cause)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| common/changes/@microsoft/spfx-cli/wire-default-github-source_2026-03-09.json | Adds a change record for the CLI update |
| apps/spfx-cli/src/cli/test/snapshots/CommandLineHelp.test.ts.snap | Updates help output snapshot for new flags |
| apps/spfx-cli/src/cli/actions/tests/CreateAction.test.ts | Adds unit tests for default GitHub source, URL normalization, ref parsing, and error wrapping |
| apps/spfx-cli/src/cli/actions/CreateAction.ts | Implements default GitHub template source, new flags/env var handling, URL parsing, and improved error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
common/changes/@microsoft/spfx-cli/wire-default-github-source_2026-03-09.json
Show resolved
Hide resolved
iclanton
reviewed
Mar 19, 2026
iclanton
reviewed
Mar 19, 2026
iclanton
reviewed
Mar 19, 2026
iclanton
reviewed
Mar 19, 2026
iclanton
reviewed
Mar 19, 2026
- Remove redundant env-var sentence from --template-url description (ts-command-line already appends it via environmentVariable binding) - Clarify --spfx-version description: it selects a branch name, not a published npm package version - Use longName property references instead of hardcoded flag strings in warning/error messages (--spfx-version, --local-template, --template-url) - Make the /tree/ URL regex host-agnostic to support GitHub Enterprise, and cap the ref capture to a single path segment so subdirectory suffixes are ignored - Add tests for GHE /tree/ parsing and subdirectory suffix stripping - Update CommandLineHelp snapshot Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Combine the string literal and template literal into a single template literal so ESLint no-useless-concat does not fire. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
iclanton
reviewed
Mar 19, 2026
iclanton
reviewed
Mar 19, 2026
iclanton
approved these changes
Mar 19, 2026
This was referenced Mar 19, 2026
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
This PR updates
spfx createso it can fetch templates from the publicSharePoint/spfxGitHub repository by default when--local-templateis not provided, making the CLI usable out-of-the-box without requiring local templates.Changes:
PublicGitHubRepositorySourceas the default template source when no--local-templateis specified--template-urlparameter (backed bySPFX_TEMPLATE_REPO_URLenv var, surfaced in--help) for overriding the default repo URL--spfx-versionflag to select a branch from the template repository/tree/<ref>branch parsing in URLs passed to--template-urlthis._terminaltoPublicGitHubRepositorySourcefor consistent loggingcausefor better stack traces.gitsuffix)--local-templatefor offline/firewalled scenariosHow was this tested
rushx buildin the affected packagesrushx testinapps/spfx-cliandapi/spfx-template-apiCreateAction.test.tsandPublicGitHubRepositorySource.test.tsType of change
🤖 Generated with Claude Code