MCPcopy
hub / github.com/blitz-js/blitz / determinePkgManagerToInstallDeps

Function determinePkgManagerToInstallDeps

packages/blitz/src/cli/commands/new.ts:151–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

149}
150
151const determinePkgManagerToInstallDeps = async () => {
152 if (args["--skip-install"]) {
153 shouldInstallDeps = false
154 return
155 }
156
157 const isPkgManagerSpecifiedAsFlag = args["--npm"] || args["--yarn"] || args["--pnpm"]
158 if (isPkgManagerSpecifiedAsFlag) {
159 if (args["--npm"]) {
160 projectPkgManger = "npm"
161 } else if (args["--pnpm"]) {
162 if (IS_PNPM_INSTALLED) {
163 projectPkgManger = "pnpm"
164 } else {
165 console.warn(`Pnpm is not installed. Fallback to ${projectPkgManger}`)
166 }
167 } else if (args["--yarn"]) {
168 if (IS_YARN_INSTALLED) {
169 projectPkgManger = "yarn"
170 } else {
171 console.warn(`Yarn is not installed. Fallback to ${projectPkgManger}`)
172 }
173 }
174 } else {
175 const hasPkgManagerChoice = IS_YARN_INSTALLED || IS_PNPM_INSTALLED
176 if (hasPkgManagerChoice) {
177 const res = await prompts({
178 type: "select",
179 name: "pkgManager",
180 message: "Install dependencies?",
181 initial: 0,
182 choices: [
183 {title: "npm", value: "npm"},
184 {title: "yarn", value: "yarn", disabled: !IS_YARN_INSTALLED},
185 {title: "pnpm", value: "pnpm", disabled: !IS_PNPM_INSTALLED},
186 {title: "skip", value: "skip"},
187 ],
188 })
189
190 if (res.pkgManager === "skip") {
191 projectPkgManger = PREFERABLE_PKG_MANAGER
192 } else {
193 projectPkgManger = res.pkgManager
194 }
195
196 shouldInstallDeps = res.pkgManager !== "skip"
197 } else {
198 const res = await prompts({
199 type: "confirm",
200 name: "installDeps",
201 message: "Install dependencies?",
202 initial: true,
203 })
204 shouldInstallDeps = res.installDeps
205 }
206 }
207}
208

Callers 1

newAppFunction · 0.85

Calls 1

warnMethod · 0.80

Tested by

no test coverage detected