Skip to content

Commit e188775

Browse files
authored
fix(core): check for lerna before parsing lockfiles to prevent errors (#18884)
1 parent 829076d commit e188775

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/nx/src/config/nx-json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type TargetDependencies = Record<
3535
export interface NrwlJsPluginConfig {
3636
analyzeSourceFiles?: boolean;
3737
analyzePackageJson?: boolean;
38+
analyzeLockfile?: boolean;
3839
}
3940

4041
interface NxInstallationConfiguration {

packages/nx/src/plugins/js/index.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
import { NrwlJsPluginConfig, NxJsonConfiguration } from '../../config/nx-json';
1919
import { dirname, join } from 'path';
2020
import { projectGraphCacheDirectory } from '../../utils/cache-directory';
21-
import { readFileSync, writeFileSync } from 'fs';
21+
import { existsSync, readFileSync, writeFileSync } from 'fs';
2222
import { workspaceRoot } from '../../utils/workspace-root';
2323
import { ensureDirSync } from 'fs-extra';
2424
import { performance } from 'perf_hooks';
@@ -49,8 +49,11 @@ export const processProjectGraph: ProjectGraphProcessor = async (
4949
const pluginConfig = jsPluginConfig(readNxJson());
5050

5151
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+
) {
5457
const lockHash = lockFileHash();
5558
let parsedLockFile: ProjectGraph;
5659
if (lockFileNeedsReprocessing(lockHash)) {
@@ -114,16 +117,27 @@ function jsPluginConfig(
114117
const nxJsonConfig: NrwlJsPluginConfig =
115118
nxJson?.pluginsConfig?.['@nx/js'] ?? nxJson?.pluginsConfig?.['@nrwl/js'];
116119

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+
117129
if (nxJsonConfig) {
118130
return {
119131
analyzePackageJson: true,
120132
analyzeSourceFiles: true,
133+
analyzeLockfile,
121134
...nxJsonConfig,
122135
};
123136
}
124137

125138
if (!fileExists(join(workspaceRoot, 'package.json'))) {
126139
return {
140+
analyzeLockfile: false,
127141
analyzePackageJson: false,
128142
analyzeSourceFiles: false,
129143
};
@@ -153,8 +167,16 @@ function jsPluginConfig(
153167
packageJsonDeps['@nrwl/angular'] ||
154168
packageJsonDeps['@nrwl/web']
155169
) {
156-
return { analyzePackageJson: true, analyzeSourceFiles: true };
170+
return {
171+
analyzePackageJson: true,
172+
analyzeLockfile,
173+
analyzeSourceFiles: true,
174+
};
157175
} else {
158-
return { analyzePackageJson: true, analyzeSourceFiles: false };
176+
return {
177+
analyzePackageJson: true,
178+
analyzeLockfile,
179+
analyzeSourceFiles: false,
180+
};
159181
}
160182
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy