1
+ const Path = require ( 'path' ) ;
1
2
const importFrom = require ( 'import-from' ) ;
3
+ const resolvePkg = require ( 'resolve-pkg' ) ;
4
+ const semver = require ( 'semver' ) ;
2
5
3
6
module . exports = {
4
7
utils : { getPackages} ,
@@ -7,16 +10,33 @@ module.exports = {
7
10
}
8
11
} ;
9
12
10
- async function getPackages ( context ) {
11
- const ctx = context || { } ;
12
- const cwd = ctx . cwd || process . cwd ( ) ;
13
+ function getPackages ( context ) {
14
+ return Promise . resolve ( )
15
+ . then ( ( ) => {
16
+ const ctx = context || { } ;
17
+ const cwd = ctx . cwd || process . cwd ( ) ;
18
+ const lernaDirectory = resolvePkg ( 'lerna' , { cwd} ) ;
19
+ const lernaVersion = require ( Path . join ( lernaDirectory , 'package.json' ) )
20
+ . version ;
13
21
14
- const Project = importFrom ( cwd , '@lerna/project' ) ;
22
+ if ( semver . lt ( lernaVersion , '3.0.0' ) ) {
23
+ const Repository = importFrom ( cwd , 'lerna/lib/Repository' ) ;
24
+ const PackageUtilities = importFrom ( cwd , 'lerna/lib/PackageUtilities' ) ;
15
25
16
- const project = new Project ( cwd ) ;
17
- const packages = await project . getPackages ( ) ;
18
-
19
- return packages
20
- . map ( pkg => pkg . name )
21
- . map ( name => ( name . charAt ( 0 ) === '@' ? name . split ( '/' ) [ 1 ] : name ) ) ;
26
+ const repository = new Repository ( cwd ) ;
27
+ return PackageUtilities . getPackages ( {
28
+ packageConfigs : repository . packageConfigs ,
29
+ rootPath : cwd
30
+ } ) ;
31
+ }
32
+ const Project = importFrom ( cwd , '@lerna/project' ) ;
33
+ const project = new Project ( cwd ) ;
34
+ return project . getPackages ( ) ;
35
+
36
+ } )
37
+ . then ( packages => {
38
+ return packages
39
+ . map ( pkg => pkg . name )
40
+ . map ( name => ( name . charAt ( 0 ) === '@' ? name . split ( '/' ) [ 1 ] : name ) ) ;
41
+ } ) ;
22
42
}
0 commit comments