Skip to content

Commit 97f49f9

Browse files
author
Mo Binni
committed
Moved NPM check to method, it is only executed when you use NPM and the version is < 3.
1 parent c5cbee8 commit 97f49f9

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea/
12
.vscode/
23
node_modules/
34
build

packages/create-react-app/index.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,6 @@ function createApp(name, verbose, version, template) {
121121
);
122122
console.log();
123123

124-
// Check npm version
125-
var npmVersionProc = spawn.sync('npm', ['--version']),
126-
npmVersion = npmVersionProc.stdout;
127-
if (npmVersion) {
128-
var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0');
129-
if (recommendVersion) {
130-
console.log(
131-
chalk.green(
132-
'Tip: It looks like you are using npm 2.\n' +
133-
'We suggest using npm 3 or Yarn for faster install times and less disk space usage.'
134-
)
135-
);
136-
}
137-
}
138-
139124
var packageJson = {
140125
name: appName,
141126
version: '0.1.0',
@@ -167,6 +152,7 @@ function install(dependencies, verbose, callback) {
167152
command = 'yarnpkg';
168153
args = [ 'add', '--exact'].concat(dependencies);
169154
} else {
155+
checkNpmVersion();
170156
command = 'npm';
171157
args = ['install', '--save', '--save-exact'].concat(dependencies);
172158
}
@@ -245,6 +231,24 @@ function getPackageName(installPackage) {
245231
return installPackage;
246232
}
247233

234+
function checkNpmVersion() {
235+
// Check npm version
236+
var npmVersionProc = spawn.sync('npm', ['--version']),
237+
npmVersion = npmVersionProc.stdout;
238+
239+
if (npmVersion) {
240+
var recommendVersion = semver.lt(npmVersion.toString(), '3.0.0');
241+
if (recommendVersion) {
242+
console.log(
243+
chalk.green(
244+
'Tip: It looks like you are using npm 2.\n' +
245+
'We suggest using npm 3 or Yarn for faster install times and less disk space usage.'
246+
)
247+
);
248+
}
249+
}
250+
}
251+
248252
function checkNodeVersion(packageName) {
249253
var packageJsonPath = path.resolve(
250254
process.cwd(),

0 commit comments

Comments
 (0)