How does ct3a launch the cli on install?

Hi! I am trying to build a template/cli app of my own and I've been studying the ct3a github repo (the cli portion specifically), and I don't really have a clue as to how the cli is launched on install! Currently, my app works by pnpm init -> pnpm install package -> npx package. (Weirdly, it only works if I use pnpm, npm is a no-go). On a similar note, create-next-app uses npx to launch itself which adds more to the confusion. Any clue about any of these would be great help!
Solution:
npm fetches the create-t3-app package, as well as it's dependencies, and stores them in a cache before executing the command. more details: https://docs.npmjs.com/cli/v8/commands/npm-exec#description
npm-exec | npm Docs
Run a command from a local or remote npm package
Jump to solution
4 Replies
Sturlen
Sturlen11mo ago
npx and npm init both run the file given by the bin field in the package.json, which here points to dist/index.js https://github.com/t3-oss/create-t3-app/blob/next/cli/package.json#L23C4-L23C4 This script file then starts the CLI https://github.com/t3-oss/create-t3-app/blob/next/cli/src/index.ts#L36C22-L36C22
metalpipemomo
metalpipemomo11mo ago
Ah! makes sense. So the key "create-t3-app" in bin would be the name of the command as well. How does that allow it to skip the npm install step?
Solution
Sturlen
Sturlen11mo ago
npm fetches the create-t3-app package, as well as it's dependencies, and stores them in a cache before executing the command. more details: https://docs.npmjs.com/cli/v8/commands/npm-exec#description
npm-exec | npm Docs
Run a command from a local or remote npm package
metalpipemomo
metalpipemomo11mo ago
Thanks! This should be enough for me to figure the rest of my questions out :]
Want results from more Discord servers?
Add your server
More Posts