Skip to content

fix: support semver ranges in tsp init template compilerVersion - #11467

Draft
timotheeguerin with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-template-compiler-version
Draft

fix: support semver ranges in tsp init template compilerVersion#11467
timotheeguerin with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-template-compiler-version

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Setting compilerVersion to a semver range like ^0.50.0 in a template index crashed with TypeError: Invalid Version because the check unconditionally called semver.gte(), which requires exact versions.

Changes

  • init.ts: isTemplateCompatibleWithTspVersion now detects whether compilerVersion is a plain version or a range:
    • Plain x.y.z → treated as >=x.y.z (backward compat preserved)
    • Semver range (^x.y.z, >=x.y.z, etc.) → evaluated with semver.satisfies()
  • templates/scaffolding.json: Updated built-in templates from "1.14.0" to "^1.14.0"
  • test/cli/init.test.ts: Added unit tests covering plain versions, ranges that satisfy, and ranges that don't
{
  "compilerVersion": "^0.50.0"
}

Previously crashed; now correctly evaluates the current compiler version against the range.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Templates can now specify compilerVersion as a semver range (e.g.,
^0.50.0) instead of crashing with TypeError: Invalid Version.

- Plain versions like `1.2.3` continue to work as `>=1.2.3` (backward compat)
- Semver ranges like `^1.0.0`, `>=1.0.0` are now properly handled via semver.satisfies()
- Updated built-in templates to use `^1.14.0` format
- Added unit tests for isTemplateCompatibleWithTspVersion

Closes #2743

Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix template with a compilerVersion semver range fix: support semver ranges in tsp init template compilerVersion Jul 30, 2026
Copilot AI requested a review from timotheeguerin July 30, 2026 01:36
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jul 30, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11467

commit: ea85eef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template with a compilerVersion that is a semver range doesn't work

2 participants