Skip to content

Commit

Permalink
feat(core): use runCommand for runScript (#21292)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi authored Jan 24, 2024
1 parent bba9600 commit e5740a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
31 changes: 20 additions & 11 deletions packages/nx/src/executors/run-script/run-script.impl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { execSync } from 'child_process';
import { getPackageManagerCommand } from '../../utils/package-manager';
import type { ExecutorContext } from '../../config/misc-interfaces';
import * as path from 'path';
import { env as appendLocalEnv } from 'npm-run-path';
import { runCommand } from '../../native';

export interface RunScriptOptions {
script: string;
Expand All @@ -15,16 +15,25 @@ export default async function (
) {
const pm = getPackageManagerCommand();
try {
execSync(pm.run(options.script, options.__unparsed__.join(' ')), {
stdio: ['inherit', 'inherit', 'inherit'],
cwd: path.join(
context.root,
context.projectsConfigurations.projects[context.projectName].root
),
env: {
...process.env,
...appendLocalEnv(),
},
await new Promise<void>((res, rej) => {
const cp = runCommand(
pm.run(options.script, options.__unparsed__.join(' ')),
path.join(
context.root,
context.projectsConfigurations.projects[context.projectName].root
),
{
...process.env,
...appendLocalEnv(),
}
);
cp.onExit((code) => {
if (code === 0) {
res();
} else {
rej();
}
});
});
return { success: true };
} catch (e) {
Expand Down
7 changes: 0 additions & 7 deletions packages/nx/src/tasks-runner/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ import { createTaskGraph } from './create-task-graph';
import { findCycle, makeAcyclic } from './task-graph-utils';
import { TargetDependencyConfig } from '../config/workspace-json-project-json';
import { handleErrors } from '../utils/params';
import {
DaemonBasedTaskHasher,
InProcessTaskHasher,
TaskHasher,
} from '../hasher/task-hasher';
import { hashTasksThatDoNotDependOnOutputsOfOtherTasks } from '../hasher/hash-task';
import { daemonClient } from '../daemon/client/client';
import { StoreRunInformationLifeCycle } from './life-cycles/store-run-information-life-cycle';
import { getFileMap } from '../project-graph/build-project-graph';
import { performance } from 'perf_hooks';
import { createTaskHasher } from '../hasher/create-task-hasher';

async function getTerminalOutputLifeCycle(
Expand Down

1 comment on commit e5740a2

@vercel
Copy link

@vercel vercel bot commented on e5740a2 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.