refactor(think): make create-think standalone; think init augments existing projects#1699
Merged
Conversation
…isting projects
Installing `create-think` previously pulled in all of `@cloudflare/think`
(codemode, shell, ai, agents, ...) just to copy a starter template, making
`npm create think` slow to start. Invert the dependency so `create-think` is a
lightweight, self-contained scaffolder.
create-think (standalone)
- Owns the starter-template logic: `init.ts` + `templates.ts` moved here from
`@cloudflare/think`, with the degit (tiged) fetcher now built in by default.
- Drops the `@cloudflare/think` dependency entirely; depends only on `tiged`
and `yargs`.
- Adds a side-effect-free `.` export (initCommand + template registry) so the
framework can reuse it.
@cloudflare/think
- `think init` now dispatches between two modes:
- New project (`--template` given, or run outside an existing npm project):
delegates to `create-think` to fetch a complete starter template.
- Augment in place (inside an existing project, no `--template`): adds Think
framework files (agent, Vite/Wrangler config, generated types) and merges
dependencies into the current project. Restores the pre-template behavior.
- Depends on `create-think` (tiny: tiged + yargs).
- Removes the internal `@cloudflare/think/cli` export, its build entry, and
`src/cli.ts`; restores the `--route-prefix` option used by the augment path.
Tests
- CLI init tests exercise the dispatcher (template path via create-think) and
add coverage for augment mode, template-inside-existing-project, the
Vite-config migration guard, and augment dry-run (30 tests).
Adds a changeset (both packages, patch).
🦋 Changeset detectedLatest commit: 05a1e63 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
- Augment no longer aborts when the project already has files Think wants to write (e.g. an existing tsconfig.json). Such files are kept as-is and listed in the output; only the migration guard (vite/wrangler) still blocks. - Augment merge forces package.json `type: module` so Think + Vite work even when the existing project is CommonJS. - create-think: in an empty starting folder the interactive prompt now defaults to `.` (scaffold in place); non-empty folders still default to a new subfolder, and `--yes` always uses a fresh subfolder. - Dedupe: `looksLikeThinkApp` is exported from create-think and reused by @cloudflare/think instead of being copy-pasted. - `think init` command description now mentions both modes (new app / augment). - Add a direct create-think test suite (10 tests) covering template fetch, finalize, prompt defaults, --yes, guards, and dry-run. New @cloudflare/think tests cover the skip-existing-files and force-ESM augment behaviors.
The augment path previously pinned every dependency to `latest`, including third-party packages (ai, vite, wrangler, typescript, workers-ai-provider, @cloudflare/vite-plugin, @cloudflare/workers-types) that are not released in tandem with this repo. A fresh `think init` could therefore pull an untested major and produce a worse dependency set than the template path right beside it. - In-repo packages (@cloudflare/think, agents) still float to `latest` — they release together via changesets. - Third-party deps are now pinned to the exact ranges the starter templates are tested against (think-starters/basic/package.json), matching the template path's behavior. - Prevent future drift: a test asserts the augment generator's third-party ranges equal the basic starter's, so bumping one without the other fails CI.
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.
Why
Installing
create-thinkpulled in all of@cloudflare/think(codemode, shell,ai,agents, …) just to copy a starter template, makingnpm create thinkslow to start. This inverts the dependency socreate-thinkis a lightweight, self-contained scaffolder.create-think— now standaloneinit.ts+templates.tsmoved here from@cloudflare/think, with the degit (tiged) fetcher now built in by default.@cloudflare/thinkdependency entirely — depends only ontiged+yargs..export (initCommand+ template registry) so the framework can reuse the exact same logic.@cloudflare/think—think initgets two modes--templategiven, or run outside an existing npm project) → delegates tocreate-thinkto fetch a complete starter template.--template) → adds Think framework files (agent, Vite/Wrangler config, generated types) and merges dependencies into the current project. This restores the pre-templatethink initbehavior.Also:
create-think(tiny:tiged+yargs) — no dependency cycle.@cloudflare/think/cliexport, its build entry, andsrc/cli.ts.--route-prefixoption (used by the augment path).Tests
CLI init tests exercise the dispatcher (template path through
create-think) and add coverage for augment mode, template-inside-an-existing-project, the Vite-config migration guard, and augment dry-run. 30 tests pass.Checks
pnpm run checkgreen (sherif + exports + format + lint + 102 projects typecheck); lockfile reflects the inverted dependency. Changeset added (both packages, patch).Notes
create-think's scaffolding is covered throughthink init's dispatcher tests (same compiledinitCommand); no separate vitest harness was added tocreate-think.