Skip to content

Commit

Permalink
fix(core): runExecutor should set overrides_unparsed to mimic the inv…
Browse files Browse the repository at this point in the history
…ocation from the terminal
  • Loading branch information
vsavkin committed Jun 15, 2022
1 parent d68b9bb commit da1faaf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions docs/generated/devkit/index.md
Expand Up @@ -1605,7 +1605,7 @@ B will depend on A.

### runExecutor

**runExecutor**<`T`\>(`targetDescription`, `options`, `context`): `Promise`<`AsyncIterableIterator`<`T`\>\>
**runExecutor**<`T`\>(`targetDescription`, `overrides`, `context`): `Promise`<`AsyncIterableIterator`<`T`\>\>

Loads and invokes executor.

Expand Down Expand Up @@ -1649,7 +1649,7 @@ Note that the return value is a promise of an iterator, so you need to await bef
| `targetDescription.configuration?` | `string` |
| `targetDescription.project` | `string` |
| `targetDescription.target` | `string` |
| `options` | `Object` |
| `overrides` | `Object` |
| `context` | [`ExecutorContext`](../../devkit/index#executorcontext) |

#### Returns
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/devkit.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions packages/nx/src/command-line/run.ts
Expand Up @@ -20,6 +20,7 @@ import {
ProjectsConfigurations,
} from '../config/workspace-json-project-json';
import { Executor, ExecutorContext } from '../config/misc-interfaces';
import { serializeOverridesIntoCommandLine } from 'nx/src/utils/serialize-overrides-into-command-line';

export interface Target {
project: string;
Expand Down Expand Up @@ -123,7 +124,7 @@ async function runExecutorInternal<T extends { success: boolean }>(
target: string;
configuration?: string;
},
options: { [k: string]: any },
overrides: { [k: string]: any },
root: string,
cwd: string,
workspace: ProjectsConfigurations & NxJsonConfiguration,
Expand Down Expand Up @@ -164,7 +165,7 @@ async function runExecutorInternal<T extends { success: boolean }>(
}

const combinedOptions = combineOptionsForExecutor(
options,
overrides,
configuration,
targetConfig,
schema,
Expand Down Expand Up @@ -245,12 +246,15 @@ export async function runExecutor<T extends { success: boolean }>(
target: string;
configuration?: string;
},
options: { [k: string]: any },
overrides: { [k: string]: any },
context: ExecutorContext
): Promise<AsyncIterableIterator<T>> {
return await runExecutorInternal<T>(
targetDescription,
options,
{
...overrides,
__overrides_unparsed__: serializeOverridesIntoCommandLine(overrides),
},
context.root,
context.cwd,
context.workspace,
Expand Down
20 changes: 2 additions & 18 deletions packages/nx/src/utils/command-line-utils.ts
Expand Up @@ -5,8 +5,8 @@ import { output } from './output';
import { NxJsonConfiguration } from '../config/nx-json';
import { execSync } from 'child_process';
import { readAllWorkspaceConfiguration } from '../config/configuration';
import { serializeOverridesIntoCommandLine } from './serialize-overrides-into-command-line';

//
export function names(name: string): {
name: string;
className: string;
Expand Down Expand Up @@ -199,7 +199,7 @@ export function splitArgsIntoNxArgsAndOverrides(
}
} else {
overrides = overridesFromMainArgs;
overrides['__overrides_unparsed__'] = serializeArgsIntoCommandLine(
overrides['__overrides_unparsed__'] = serializeOverridesIntoCommandLine(
overridesFromMainArgs
);
}
Expand Down Expand Up @@ -395,19 +395,3 @@ export function getProjectRoots(projectNames: string[]): string[] {
const { projects } = readAllWorkspaceConfiguration();
return projectNames.map((name) => projects[name].root);
}

export function serializeArgsIntoCommandLine(args: {
[k: string]: any;
}): string[] {
const r = args['_'] ? [...args['_']] : [];
Object.keys(args).forEach((a) => {
if (a !== '_') {
r.push(
typeof args[a] === 'string' && args[a].includes(' ')
? `--${a}="${args[a].replace(/"/g, '"')}"`
: `--${a}=${args[a]}`
);
}
});
return r;
}
15 changes: 15 additions & 0 deletions packages/nx/src/utils/serialize-overrides-into-command-line.ts
@@ -0,0 +1,15 @@
export function serializeOverridesIntoCommandLine(args: {
[k: string]: any;
}): string[] {
const r = args['_'] ? [...args['_']] : [];
Object.keys(args).forEach((a) => {
if (a !== '_') {
r.push(
typeof args[a] === 'string' && args[a].includes(' ')
? `--${a}="${args[a].replace(/"/g, '"')}"`
: `--${a}=${args[a]}`
);
}
});
return r;
}

1 comment on commit da1faaf

@vercel
Copy link

@vercel vercel bot commented on da1faaf Jun 15, 2022

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-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.