( opts: RunPkgManagerInstallOptions, )
| 14 | } |
| 15 | |
| 16 | export const runPkgManagerInstall = async ( |
| 17 | opts: RunPkgManagerInstallOptions, |
| 18 | ) => { |
| 19 | const { pkgManager, devMode, projectDir, packages, noInstallMode } = opts; |
| 20 | |
| 21 | if (noInstallMode) { |
| 22 | const pkgJson = (await fs.readJSON( |
| 23 | path.join(projectDir, "package.json"), |
| 24 | )) as PackageJson; |
| 25 | |
| 26 | for (const pkg of packages) { |
| 27 | if (pkg === "") { |
| 28 | // sometimes empty string is passed as a package when using ternaries so escaping that to prevent it pulling node's version |
| 29 | continue; |
| 30 | } |
| 31 | const { stdout: latestVersion } = await execa(`npm show ${pkg} version`); |
| 32 | if (!latestVersion) { |
| 33 | logger.warn("WARN: Failed to resolve latest version of package:", pkg); |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | const pkgName = pkg.replace(/^(@?[^@]+)(?:@.+)?$/, "$1"); |
| 38 | |
| 39 | // Note: We know that pkgJson.[dev]Dependencies exists in the base Next.js template so we don't need to validate it |
| 40 | if (devMode) { |
| 41 | pkgJson.devDependencies![pkgName] = `^${latestVersion.trim()}`; //eslint-disable-line @typescript-eslint/no-non-null-assertion |
| 42 | } else { |
| 43 | pkgJson.dependencies![pkgName] = `^${latestVersion.trim()}`; //eslint-disable-line @typescript-eslint/no-non-null-assertion |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | await fs.writeJSON(path.join(projectDir, "package.json"), pkgJson, { |
| 48 | spaces: 2, |
| 49 | }); |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | const installCmd = |
| 54 | pkgManager === "yarn" ? `${pkgManager} add` : `${pkgManager} install`; |
| 55 | const flag = devMode ? "-D" : ""; |
| 56 | const fullCmd = `${installCmd} ${flag} ${packages.join(" ")}`; |
| 57 | await execa(fullCmd, { cwd: projectDir }); |
| 58 | }; |
| 59 | |
| 60 | export type CurryRunPkgManagerInstallOptions = Omit< |
| 61 | RunPkgManagerInstallOptions, |
no outgoing calls
no test coverage detected