55*/
66var Promise = require ( '../ext/promise' ) ;
77var path = require ( 'path' ) ;
8- var findup = Promise . denodeify ( require ( 'findup' ) ) ;
8+ var findUp = require ( '../../../utilities/find-up' ) . findUp ;
99var resolve = Promise . denodeify ( require ( 'resolve' ) ) ;
1010var fs = require ( 'fs' ) ;
1111var find = require ( 'lodash/find' ) ;
@@ -470,7 +470,7 @@ Project.closest = function(pathName, _ui, _cli) {
470470 return new Project ( result . directory , result . pkg , ui , _cli ) ;
471471 } )
472472 . catch ( function ( reason ) {
473- handleFindupError ( pathName , reason ) ;
473+ handleFindupError ( pathName ) ;
474474 } ) ;
475475} ;
476476
@@ -546,7 +546,7 @@ Project.projectOrnullProject = function(_ui, _cli) {
546546 */
547547Project . getProjectRoot = function ( ) {
548548 try {
549- var directory = findup . sync ( process . cwd ( ) , 'package.json' ) ;
549+ var directory = path . dirname ( findUp ( process . cwd ( ) , 'package.json' ) ) ;
550550 var pkg = require ( path . join ( directory , 'package.json' ) ) ;
551551
552552 if ( pkg && pkg . name === 'ember-cli' ) {
@@ -557,12 +557,8 @@ Project.getProjectRoot = function () {
557557 debug ( 'getProjectRoot %s -> %s' , process . cwd ( ) , directory ) ;
558558 return directory ;
559559 } catch ( reason ) {
560- if ( isFindupError ( reason ) ) {
561- debug ( 'getProjectRoot: not found. Will use cwd: %s' , process . cwd ( ) ) ;
562- return process . cwd ( ) ;
563- } else {
564- throw reason ;
565- }
560+ debug ( 'getProjectRoot: not found. Will use cwd: %s' , process . cwd ( ) ) ;
561+ return process . cwd ( ) ;
566562 }
567563} ;
568564
@@ -594,34 +590,24 @@ function ensureUI(_ui) {
594590}
595591
596592function closestPackageJSON ( pathName ) {
597- return findup ( pathName , 'package.json' )
598- . then ( function ( directory ) {
599- return Promise . hash ( {
600- directory : directory ,
601- pkg : require ( path . join ( directory , 'package.json' ) )
602- } ) ;
603- } ) ;
593+ return Promise . resolve ( )
594+ . then ( ( ) => findUp ( 'package.json' , pathName ) )
595+ . then ( filePath => ( {
596+ directory : path . dirname ( filePath ) ,
597+ pkg : require ( filePath )
598+ } ) ) ;
604599}
605600
606601function findupPath ( pathName ) {
607602 try {
608- return findup . sync ( pathName , 'package.json' ) ;
603+ return path . dirname ( findUp ( 'package.json' , pathName ) ) ;
609604 } catch ( reason ) {
610- handleFindupError ( pathName , reason ) ;
605+ handleFindupError ( pathName ) ;
611606 }
612607}
613608
614- function isFindupError ( reason ) {
615- // Would be nice if findup threw error subclasses
616- return reason && / n o t f o u n d / i. test ( reason . message ) ;
617- }
618-
619- function handleFindupError ( pathName , reason ) {
620- if ( isFindupError ( reason ) ) {
621- throw new NotFoundError ( 'No project found at or up from: `' + pathName + '`' ) ;
622- } else {
623- throw reason ;
624- }
609+ function handleFindupError ( pathName ) {
610+ throw new NotFoundError ( 'No project found at or up from: `' + pathName + '`' ) ;
625611}
626612
627613// Export
0 commit comments