@@ -18,7 +18,7 @@ import {
18
18
import { NrwlJsPluginConfig , NxJsonConfiguration } from '../../config/nx-json' ;
19
19
import { dirname , join } from 'path' ;
20
20
import { projectGraphCacheDirectory } from '../../utils/cache-directory' ;
21
- import { readFileSync , writeFileSync } from 'fs' ;
21
+ import { existsSync , readFileSync , writeFileSync } from 'fs' ;
22
22
import { workspaceRoot } from '../../utils/workspace-root' ;
23
23
import { ensureDirSync } from 'fs-extra' ;
24
24
import { performance } from 'perf_hooks' ;
@@ -49,8 +49,11 @@ export const processProjectGraph: ProjectGraphProcessor = async (
49
49
const pluginConfig = jsPluginConfig ( readNxJson ( ) ) ;
50
50
51
51
if ( pluginConfig . analyzePackageJson ) {
52
- // during the create-nx-workspace lock file might not exists yet
53
- if ( lockFileExists ( ) ) {
52
+ if (
53
+ // during the create-nx-workspace lock file might not exists yet
54
+ lockFileExists ( ) &&
55
+ pluginConfig . analyzeLockfile
56
+ ) {
54
57
const lockHash = lockFileHash ( ) ;
55
58
let parsedLockFile : ProjectGraph ;
56
59
if ( lockFileNeedsReprocessing ( lockHash ) ) {
@@ -114,16 +117,27 @@ function jsPluginConfig(
114
117
const nxJsonConfig : NrwlJsPluginConfig =
115
118
nxJson ?. pluginsConfig ?. [ '@nx/js' ] ?? nxJson ?. pluginsConfig ?. [ '@nrwl/js' ] ;
116
119
120
+ // using lerna _before_ installing deps is causing an issue when parsing lockfile.
121
+ // See: https://github.com/lerna/lerna/issues/3807
122
+ // Note that previous attempt to fix this caused issues with Nx itself, thus we're checking
123
+ // for Lerna explicitly.
124
+ // See: https://github.com/nrwl/nx/pull/18784/commits/5416138e1ddc1945d5b289672dfb468e8c544e14
125
+ const analyzeLockfile =
126
+ ! existsSync ( join ( workspaceRoot , 'lerna.json' ) ) ||
127
+ existsSync ( join ( workspaceRoot , 'nx.json' ) ) ;
128
+
117
129
if ( nxJsonConfig ) {
118
130
return {
119
131
analyzePackageJson : true ,
120
132
analyzeSourceFiles : true ,
133
+ analyzeLockfile,
121
134
...nxJsonConfig ,
122
135
} ;
123
136
}
124
137
125
138
if ( ! fileExists ( join ( workspaceRoot , 'package.json' ) ) ) {
126
139
return {
140
+ analyzeLockfile : false ,
127
141
analyzePackageJson : false ,
128
142
analyzeSourceFiles : false ,
129
143
} ;
@@ -153,8 +167,16 @@ function jsPluginConfig(
153
167
packageJsonDeps [ '@nrwl/angular' ] ||
154
168
packageJsonDeps [ '@nrwl/web' ]
155
169
) {
156
- return { analyzePackageJson : true , analyzeSourceFiles : true } ;
170
+ return {
171
+ analyzePackageJson : true ,
172
+ analyzeLockfile,
173
+ analyzeSourceFiles : true ,
174
+ } ;
157
175
} else {
158
- return { analyzePackageJson : true , analyzeSourceFiles : false } ;
176
+ return {
177
+ analyzePackageJson : true ,
178
+ analyzeLockfile,
179
+ analyzeSourceFiles : false ,
180
+ } ;
159
181
}
160
182
}
0 commit comments