Skip to content

Commit 94707d9

Browse files
authored
fix(core): fix buildTargetFromScript takes a long time (#25209)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #25923
1 parent c1b1c5b commit 94707d9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/nx/src/utils/package-json.spec.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import {
77
readModulePackageJson,
88
readTargetsFromPackageJson,
99
} from './package-json';
10+
import { getPackageManagerCommand } from './package-manager';
1011

1112
describe('buildTargetFromScript', () => {
1213
it('should use nx:run-script', () => {
13-
const target = buildTargetFromScript('build');
14+
const target = buildTargetFromScript(
15+
'build',
16+
{},
17+
getPackageManagerCommand()
18+
);
1419
expect(target.executor).toEqual('nx:run-script');
1520
});
1621
});

packages/nx/src/utils/package-json.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
import { mergeTargetConfigurations } from '../project-graph/utils/project-configuration-utils';
88
import { readJsonFile } from './fileutils';
99
import { getNxRequirePaths } from './installation-directory';
10-
import { getPackageManagerCommand } from './package-manager';
10+
import {
11+
PackageManagerCommands,
12+
getPackageManagerCommand,
13+
} from './package-manager';
1114

1215
export interface NxProjectPackageJsonConfiguration {
1316
implicitDependencies?: string[];
@@ -118,9 +121,9 @@ export function readNxMigrateConfig(
118121

119122
export function buildTargetFromScript(
120123
script: string,
121-
scripts: Record<string, string> = {}
124+
scripts: Record<string, string> = {},
125+
packageManagerCommand: PackageManagerCommands
122126
): TargetConfiguration {
123-
const packageManagerCommand = getPackageManagerCommand();
124127
return {
125128
executor: 'nx:run-script',
126129
options: {
@@ -137,9 +140,9 @@ export function readTargetsFromPackageJson(packageJson: PackageJson) {
137140
const { scripts, nx, private: isPrivate } = packageJson ?? {};
138141
const res: Record<string, TargetConfiguration> = {};
139142
const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
140-
//
143+
const packageManagerCommand = getPackageManagerCommand();
141144
for (const script of includedScripts) {
142-
res[script] = buildTargetFromScript(script, scripts);
145+
res[script] = buildTargetFromScript(script, scripts, packageManagerCommand);
143146
}
144147
for (const targetName in nx?.targets) {
145148
res[targetName] = mergeTargetConfigurations(

0 commit comments

Comments
 (0)