39
39
'use strict' ;
40
40
41
41
var chalk = require ( 'chalk' ) ;
42
+ var path = require ( 'path' ) ;
43
+ var semver = require ( 'semver' ) ;
44
+
45
+ function checkNodeVersion ( packageJsonPath ) {
46
+ var packageJson = require ( packageJsonPath ) ;
47
+ if ( ! packageJson . engines || ! packageJson . engines . node ) {
48
+ return ;
49
+ }
50
+
51
+ if ( ! semver . satisfies ( process . version , packageJson . engines . node ) ) {
52
+ console . error (
53
+ chalk . red (
54
+ 'You are running Node %s.\n' +
55
+ 'Create React App requires Node %s or higher. \n' +
56
+ 'Please update your version of Node.'
57
+ ) ,
58
+ process . version ,
59
+ packageJson . engines . node
60
+ ) ;
61
+ process . exit ( 1 ) ;
62
+ }
63
+ }
64
+
65
+ checkNodeVersion ( path . resolve ( __dirname , 'package.json' ) ) ;
42
66
43
67
var currentNodeVersion = process . versions . node
44
68
if ( currentNodeVersion . split ( '.' ) [ 0 ] < 4 ) {
@@ -54,10 +78,8 @@ if (currentNodeVersion.split('.')[0] < 4) {
54
78
55
79
var commander = require ( 'commander' ) ;
56
80
var fs = require ( 'fs-extra' ) ;
57
- var path = require ( 'path' ) ;
58
81
var execSync = require ( 'child_process' ) . execSync ;
59
82
var spawn = require ( 'cross-spawn' ) ;
60
- var semver = require ( 'semver' ) ;
61
83
62
84
var projectName ;
63
85
@@ -180,7 +202,13 @@ function run(root, appName, version, verbose, originalDirectory, template) {
180
202
process . exit ( 1 ) ;
181
203
}
182
204
183
- checkNodeVersion ( packageName ) ;
205
+ var packageJsonPath = path . resolve (
206
+ process . cwd ( ) ,
207
+ 'node_modules' ,
208
+ packageName ,
209
+ 'package.json'
210
+ ) ;
211
+ checkNodeVersion ( packageJsonPath ) ;
184
212
185
213
var scriptsPath = path . resolve (
186
214
process . cwd ( ) ,
@@ -219,32 +247,6 @@ function getPackageName(installPackage) {
219
247
return installPackage ;
220
248
}
221
249
222
- function checkNodeVersion ( packageName ) {
223
- var packageJsonPath = path . resolve (
224
- process . cwd ( ) ,
225
- 'node_modules' ,
226
- packageName ,
227
- 'package.json'
228
- ) ;
229
- var packageJson = require ( packageJsonPath ) ;
230
- if ( ! packageJson . engines || ! packageJson . engines . node ) {
231
- return ;
232
- }
233
-
234
- if ( ! semver . satisfies ( process . version , packageJson . engines . node ) ) {
235
- console . error (
236
- chalk . red (
237
- 'You are running Node %s.\n' +
238
- 'Create React App requires Node %s or higher. \n' +
239
- 'Please update your version of Node.'
240
- ) ,
241
- process . version ,
242
- packageJson . engines . node
243
- ) ;
244
- process . exit ( 1 ) ;
245
- }
246
- }
247
-
248
250
function checkAppName ( appName ) {
249
251
// TODO: there should be a single place that holds the dependencies
250
252
var dependencies = [ 'react' , 'react-dom' ] ;
0 commit comments