Skip to content

Commit

Permalink
fix(core): fix buildTargetFromScript takes a long time (#25209)
Browse files Browse the repository at this point in the history
<!-- 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

(cherry picked from commit 94707d9)
  • Loading branch information
xiongemi authored and FrozenPandaz committed May 23, 2024
1 parent c0b9dd1 commit 85c20ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 6 additions & 1 deletion packages/nx/src/utils/package-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import {
readModulePackageJson,
readTargetsFromPackageJson,
} from './package-json';
import { getPackageManagerCommand } from './package-manager';

describe('buildTargetFromScript', () => {
it('should use nx:run-script', () => {
const target = buildTargetFromScript('build');
const target = buildTargetFromScript(
'build',
{},
getPackageManagerCommand()
);
expect(target.executor).toEqual('nx:run-script');
});
});
Expand Down
13 changes: 8 additions & 5 deletions packages/nx/src/utils/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
import { mergeTargetConfigurations } from '../project-graph/utils/project-configuration-utils';
import { readJsonFile } from './fileutils';
import { getNxRequirePaths } from './installation-directory';
import { getPackageManagerCommand } from './package-manager';
import {
PackageManagerCommands,
getPackageManagerCommand,
} from './package-manager';

export interface NxProjectPackageJsonConfiguration {
implicitDependencies?: string[];
Expand Down Expand Up @@ -118,9 +121,9 @@ export function readNxMigrateConfig(

export function buildTargetFromScript(
script: string,
scripts: Record<string, string> = {}
scripts: Record<string, string> = {},
packageManagerCommand: PackageManagerCommands
): TargetConfiguration {
const packageManagerCommand = getPackageManagerCommand();
return {
executor: 'nx:run-script',
options: {
Expand All @@ -137,9 +140,9 @@ export function readTargetsFromPackageJson(packageJson: PackageJson) {
const { scripts, nx, private: isPrivate } = packageJson ?? {};
const res: Record<string, TargetConfiguration> = {};
const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
//
const packageManagerCommand = getPackageManagerCommand();
for (const script of includedScripts) {
res[script] = buildTargetFromScript(script, scripts);
res[script] = buildTargetFromScript(script, scripts, packageManagerCommand);
}
for (const targetName in nx?.targets) {
res[targetName] = mergeTargetConfigurations(
Expand Down

0 comments on commit 85c20ee

Please sign in to comment.