Skip to content

Wire default GitHub template source in CLI#149

Merged
nick-pape merged 9 commits intoSharePoint:mainfrom
nick-pape:claude/wire-default-github-source
Mar 19, 2026
Merged

Wire default GitHub template source in CLI#149
nick-pape merged 9 commits intoSharePoint:mainfrom
nick-pape:claude/wire-default-github-source

Conversation

@nick-pape
Copy link
Contributor

@nick-pape nick-pape commented Mar 19, 2026

Note: This is a re-submission of #130, which became inaccessible when the repository was temporarily made private and the fork was disassociated.

Description

This PR updates spfx create so it can fetch templates from the public SharePoint/spfx GitHub repository by default when --local-template is not provided, making the CLI usable out-of-the-box without requiring local templates.

Changes:

  • Wire PublicGitHubRepositorySource as the default template source when no --local-template is specified
  • Add --template-url parameter (backed by SPFX_TEMPLATE_REPO_URL env var, surfaced in --help) for overriding the default repo URL
  • Add --spfx-version flag to select a branch from the template repository
  • Support /tree/<ref> branch parsing in URLs passed to --template-url
  • Pass this._terminal to PublicGitHubRepositorySource for consistent logging
  • Preserve original fetch error as cause for better stack traces
  • Normalize the env var value (trim whitespace, trailing slashes, .git suffix)
  • Improve error messaging to suggest --local-template for offline/firewalled scenarios
  • Add unit and integration tests for all new behavior

How was this tested

  • rushx build in the affected packages
  • rushx test in apps/spfx-cli and api/spfx-template-api
  • Unit tests added in CreateAction.test.ts and PublicGitHubRepositorySource.test.ts

Type of change

  • New feature

🤖 Generated with Claude Code

nick-pape and others added 7 commits March 17, 2026 15:49
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>
Copilot AI review requested due to automatic review settings March 19, 2026 18:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PublicGitHubRepositorySource using https://github.com/SharePoint/spfx when no local template sources are provided
  • Add --template-url (and SPFX_TEMPLATE_REPO_URL) plus --spfx-version branch 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.

nick-pape and others added 2 commits March 19, 2026 14:53
- 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>
@nick-pape nick-pape enabled auto-merge (squash) March 19, 2026 20:36
@nick-pape nick-pape merged commit e5f209d into SharePoint:main Mar 19, 2026
3 checks passed
@nick-pape nick-pape added area: cli SPFx CLI tool type: enhancement New feature or request labels Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli SPFx CLI tool type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants