MCPcopy Create free account
hub / github.com/Create-Node-App/create-node-app / install

Function install

src/install.js:163–219  ·  view source on GitHub ↗
(root, useYarn, dependencies, verbose, isOnline, isDevDependencies)

Source from the content-addressed store, hash-verified

161}
162
163function install(root, useYarn, dependencies, verbose, isOnline, isDevDependencies) {
164 return new Promise((resolve, reject) => {
165 let command;
166 let args;
167 if (useYarn) {
168 command = 'yarnpkg';
169 //args = ['add', '--exact']
170 args = ['add'];
171 if (!isOnline) {
172 args.push('--offline');
173 }
174 if (isDevDependencies) {
175 args.push('--dev');
176 }
177 [].push.apply(args, dependencies);
178
179 // Explicitly set cwd() to work around issues like
180 // https://github.com/facebook/create-react-app/issues/3326.
181 // Unfortunately we can only do this for Yarn because npm support for
182 // equivalent --prefix flag doesn't help with this issue.
183 // This is why for npm, we run checkThatNpmCanReadCwd() early instead.
184 args.push('--cwd');
185 args.push(root);
186
187 if (!isOnline) {
188 console.log(chalk.yellow('You appear to be offline.'));
189 console.log(chalk.yellow('Falling back to the local Yarn cache.'));
190 console.log();
191 }
192 } else {
193 command = 'npm';
194 args = ['install', '--loglevel', 'error'];
195 if (isDevDependencies) {
196 args.push('--save-dev');
197 } else {
198 args.push('--save');
199 }
200
201 [].push.apply(args, dependencies);
202 }
203
204 if (verbose) {
205 args.push('--verbose');
206 }
207
208 const child = spawn(command, args, { stdio: 'inherit' });
209 child.on('close', (code) => {
210 if (code !== 0) {
211 reject({
212 command: `${command} ${args.join(' ')}`,
213 });
214 return;
215 }
216 resolve();
217 });
218 });
219}
220

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected