[create-cloudflare] Stop --lang hiding templates that have no language variants - #15677
Conversation
…age variants `templateSupportsLanguage` returned false for any template whose `copyFiles` is a single path or absent, on the grounds that such a template declares no variant key to match the language against. Passing `--lang` therefore hid every template that has one fixed language rather than a js/ts choice, even when that language was the one being asked for. `create-cloudflare --lang ts` dropped `API starter (OpenAPI compliant)` from the Application Starter list, and `--type=openapi --lang=ts` failed outright with "Unknown application type provided: openapi". The same filter dropped 15 of the 18 framework starters, so `--framework=hono --lang=ts` failed with "Unsupported framework: hono"; only astro, react and vue survived, because those are the only frameworks that declare js/ts variants. Templates that ship a single set of files now declare the languages they can be created with, defaulting to JavaScript and TypeScript. Python filtering is unchanged: it is only ever offered through an explicit `copyFiles` variant, so a template without one is still left out of `--lang python` and the "No templates available for language" error still fires for the demo category. Fixes cloudflare#15649
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
tpmmorris
left a comment
There was a problem hiding this comment.
Please address Devin comments
…te instead of defaulting to both --lang is not passed to a framework's own CLI, so defaulting a template without variants to js and ts offered TypeScript-only frameworks under --lang js: --framework qwik --lang js scaffolded a TypeScript project. Drop the default. Every template without copyFiles variants now declares the languages it can produce, and a test walks all three template maps (experimental included) and fails if one does not. TypeScript only: analog, angular, hono, next, nuxt, qwik, redwood, tanstack-start, vike and waku. Both: templates whose framework CLI or C3 prompt offers the choice (docusaurus, gatsby, react pages, solid, svelte, vue pages, experimental next) and hello-world-assets-only, which ships no code.
🦋 Changeset detectedLatest commit: dd984b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@tpmmorris Addressed Devin's one finding in dd984b7: a template without language variants no longer defaults to both JavaScript and TypeScript, because that offered TypeScript-only frameworks such as Qwik under |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
|
@tpmmorris the Devin finding is addressed in dd984b7, and Devin has marked it resolved.
The one red check, |
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
Fixes #15649.
--langfilters the template lists throughtemplateSupportsLanguageinpackages/create-cloudflare/src/templates.ts, which returnsfalsefor any template whosecopyFilesis a single path or absent:A template like that has one fixed language rather than a js/ts choice, so passing
--langhid it even when its language was exactly the one being asked for. The OpenAPI starter is declared ascopyFiles: { path: "./ts" }inpackages/create-cloudflare/templates/openapi/c3.ts, which is why it disappears under--lang ts. It is genuinely TypeScript, so this is the filter being wrong, not the template's metadata.The same filter hits every other template with no language variants.
filterTemplatesByLanguageis applied to all three maps, so under--lang tsthe Framework Starter list drops from 18 entries to 3 — onlyastro,reactandvuesurvive, because they are the only frameworks that declare js/ts variants. Most frameworks scaffold the app with their own CLI and only overlay Cloudflare-specific files (templates/hono/workers/templatesiswrangler.jsonc,public/index.htmlandsrc/index.ts), so they have no variants either.Repro
--lang tswith the template named directly turns the silent disappearance into a hard error, which makes the before/after easy to see without driving the prompts. Both runs are againstdist/cli.jsbuilt from the tree under test.Before, at
9515011dc:After:
Dropping
--lang tsfrom either command works on both sides, which is the difference the issue reports.The change
A template that ships a single set of files now declares the
--langvalues it can be created with, andtemplateSupportsLanguageasks for that instead of assuming there is none:languages?: string[]onTemplateConfig, andgetTemplateLanguages, which readscopyFiles.variantskeys when there are variants andlanguagesotherwise.--langis not passed to a framework's own CLI, so assuming both languages offered TypeScript-only frameworks under--lang js(Devin's finding:--framework qwik --lang jsrancreate-qwik playgroundand got a TypeScript project). Every template without variants declares what it can produce, and a test fails if one does not.["ts"]:openapiandreact-router(their./tspath), and the frameworks whose CLI only scaffolds TypeScript:analog,angular,hono,next,nuxt,qwik,redwood,tanstack-start,vikeandwaku. The evidence for each is either C3's own code (it copies or edits.tsfiles unconditionally forangular,hono,nuxtandwaku, andqwik'sc3.tssays "Qwik only has a typescript template"), or scaffolding the project exactly as C3 invokes the CLI:analog,qwik,redwood(create-rwsdk),tanstack-startandvikeeach produce atsconfig.jsonand only TypeScript sources.create-vinext-app --helpstates it "always uses … TypeScript", and theopennexttemplate is TypeScript.["js"]:pre-existing(its./jspath).["js", "ts"]: templates where the framework's own CLI offers the choice, through a prompt or flag that the e2e suite drives (docusaurus,solid,svelte,vuepages), C3's variant prompt (reactpages), a user-chosen starter (gatsby), experimentalcreate-next-app, andhello-world-assets-only, which ships no code.copyFilesvariant (./pyon the hello-world family), so a template that does not declare one cannot produce it.Python behaviour is unchanged, including the two cases covered by the e2e tests added in #11184:
This is also compatible with the Python-only starters in #15636: they declare
copyFiles.variants.python, sogetTemplateLanguagesreturns["python"]for them and they stay out of--lang ts. That PR touches the same region oftemplates.tsand will conflict textually.Tests
filterTemplatesByLanguageis now exported so the new tests insrc/__tests__/templates.test.tscan run it over the real template maps. They cover both directions: that a fixed-language template is kept for its own language, and that templates which cannot produce a language are still dropped, including the TypeScript-only frameworks under--lang js. A further test walks every template in all three maps, experimental ones included, and fails if a template without variants has nolanguages.Against
9515011dcwith only the new test file and theexportkeyword applied, so the import resolves:On this branch:
The four negative tests pass on both sides, which is what they are for.
Full
create-cloudflareunit suite,vitest run --config ./vitest.config.mts:The same six tests fail on both sides — four in
src/helpers/__tests__/args.test.tsand twoprintSummarysnapshots insrc/__tests__/dialog.test.ts. They are unrelated to this change and reproduce on an unmodified checkout; the local Node is 26.8.2 rather than the 22.22.1 the repo pins, which is the likely cause.oxfmt --check,oxlint --deny-warnings --type-awareandtsc --noEmitare clean on the touched files.The e2e tests in
packages/create-cloudflare/e2ewere not run — they scaffold real projects and install dependencies.--lang, which is described in--helpas "The programming language of the template"; no user-facing option changes.File and line references are against
main@9515011dc5ecdc5abf3a0c685d80f78e307fb513.