Skip to content

Commit d86bdb3

Browse files
committed
feat(executor): support build as targetName in addition to run type + other improvements
1 parent a9c6ddd commit d86bdb3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/nx/src/executors/build/executor.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
1111
try {
1212
const projectConfig = context.workspace.projects[context.projectName];
1313
// determine if running or building only
14-
const isBuild = process.argv.find((a) => a === 'build' || a.endsWith(':build'));
14+
const isBuild = context.targetName === 'build' || process.argv.find((a) => a === 'build' || a.endsWith(':build'));
1515
if (isBuild) {
1616
// allow build options to override run target options
1717
const buildTarget = projectConfig.targets['build'];
@@ -103,6 +103,13 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
103103
}
104104
}
105105

106+
if (!options.platform) {
107+
// a platform must be set
108+
// absent of it being explicitly set, we default to 'ios'
109+
// this helps cases where nx run-many is used for general targets used in, for example, pull request auto prepare/build checks (just need to know if there are any .ts errors in the build where platform often doesn't matter - much)
110+
options.platform = 'ios';
111+
}
112+
106113
if (options.platform) {
107114
nsOptions.push(options.platform);
108115
}
@@ -181,8 +188,11 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
181188
const extraFlags = process.argv.slice(projectTargetCmdIndex + 1, process.argv.length);
182189
for (const flag of extraFlags) {
183190
const optionName = parseOptionName(flag);
184-
if (!nsOptions.includes(flag) && !additionalArgs.includes(flag) && !enforceSingularOptions.includes(optionName)) {
185-
additionalArgs.push(flag);
191+
if (optionName?.indexOf('/') === -1 && optionName?.indexOf('{') === -1) {
192+
// no valid options should start with '/' or '{' - those are often extra process.argv context args that should be ignored
193+
if (!nsOptions.includes(flag) && !additionalArgs.includes(flag) && !enforceSingularOptions.includes(optionName)) {
194+
additionalArgs.push(flag);
195+
}
186196
}
187197
}
188198
// console.log('additionalArgs:', additionalArgs);
@@ -194,6 +204,11 @@ export default async function runExecutor(options: BuildBuilderSchema, context:
194204
console.log(' ');
195205
console.log([`ns`, ...nsOptions, ...additionalArgs].join(' '));
196206
console.log(' ');
207+
if (additionalArgs.length) {
208+
console.log('Note: When using extra cli flags, ensure all key/value pairs are separated with =, for example: --provision="Name"');
209+
console.log(' ');
210+
}
211+
console.log(`---`);
197212
const child = childProcess.spawn(/^win/.test(process.platform) ? 'ns.cmd' : 'ns', [...nsOptions, ...additionalArgs], {
198213
cwd: projectCwd,
199214
stdio: 'inherit',

0 commit comments

Comments
 (0)