MCPcopy
hub / github.com/vercel/next.js / install

Function install

packages/next-codemod/lib/install.ts:25–106  ·  view source on GitHub ↗
(
  root: string,
  dependencies: string[] | null,
  { useYarn, isOnline, devDependencies }: InstallArgs
)

Source from the content-addressed store, hash-verified

23 * @returns A Promise that resolves once the installation is finished.
24 */
25export function install(
26 root: string,
27 dependencies: string[] | null,
28 { useYarn, isOnline, devDependencies }: InstallArgs
29): Promise<void> {
30 /**
31 * NPM-specific command-line flags.
32 */
33 const npmFlags: string[] = ['--logLevel', 'error']
34 /**
35 * Yarn-specific command-line flags.
36 */
37 const yarnFlags: string[] = []
38 /**
39 * Return a Promise that resolves once the installation is finished.
40 */
41 return new Promise((resolve, reject) => {
42 let args: string[]
43 let command: string = useYarn ? 'yarnpkg' : 'npm'
44
45 if (dependencies && dependencies.length) {
46 /**
47 * If there are dependencies, run a variation of `{displayCommand} add`.
48 */
49 if (useYarn) {
50 /**
51 * Call `yarn add --exact (--offline)? (-D)? ...`.
52 */
53 args = ['add', '--exact']
54 if (!isOnline) args.push('--offline')
55 args.push('--cwd', root)
56 if (devDependencies) args.push('--dev')
57 args.push(...dependencies)
58 } else {
59 /**
60 * Call `npm install [--save|--save-dev] ...`.
61 */
62 args = ['install', '--save-exact']
63 args.push(devDependencies ? '--save-dev' : '--save')
64 args.push(...dependencies)
65 }
66 } else {
67 /**
68 * If there are no dependencies, run a variation of `{displayCommand}
69 * install`.
70 */
71 args = ['install']
72 if (!isOnline) {
73 console.log(yellow('You appear to be offline.'))
74 if (useYarn) {
75 console.log(yellow('Falling back to the local Yarn cache.'))
76 console.log()
77 args.push('--offline')
78 } else {
79 console.log()
80 }
81 }
82 }

Callers 2

updatePackageJsonMethod · 0.90
npm.jsFile · 0.50

Calls 8

yellowFunction · 0.85
pushMethod · 0.65
spawnFunction · 0.50
rejectFunction · 0.50
resolveFunction · 0.50
logMethod · 0.45
onMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected