Skip to content

Comments

feat(core): forward string array arguments#27761

Open
ThePlenkov wants to merge 2 commits intonrwl:masterfrom
ThePlenkov:forwardArrayArgs
Open

feat(core): forward string array arguments#27761
ThePlenkov wants to merge 2 commits intonrwl:masterfrom
ThePlenkov:forwardArrayArgs

Conversation

@ThePlenkov
Copy link
Contributor

Original discussion:
#27760

Current Behavior

Currently if I create a task like:

{
  "targets": {
    "build-cds": {
      "options": {
        "schema": "SCHEMA_NAME ",
        "filter": [
          "TABLE1",
          "TABLE1"
        ]
      }
    } 
  }
}

it will still call my command like: mycommand --schema SCHEMA_NAME

Expected Behavior

After my change it would run mycommand --schema SCHEMA_NAME --filter=TABLE1,TABLE2,TABLE3

@ThePlenkov ThePlenkov requested a review from a team as a code owner September 4, 2024 11:50
@vercel
Copy link

vercel bot commented Sep 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Sep 4, 2024 11:53am

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Sep 4, 2024

View your CI Pipeline Execution ↗ for commit 57df512

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ⛔ Cancelled 1h 14m 43s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 54s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-19 22:05:26 UTC

@ThePlenkov
Copy link
Contributor Author

I have also reached same goal by creating a plugin:

import {
  CreateNodesContextV2,
  createNodesFromFiles,
  CreateNodesV2,
  ProjectConfiguration,
  readJsonFile,
} from "@nx/devkit";
import { dirname } from "path";

interface Options {
  replace?: {
    regex?: string;
    with?: string;
  };
}

export const createNodesV2: CreateNodesV2<Options> = [
  "**/project.json",
  (projectConfigurationFiles, options, context) => {
    return createNodesFromFiles(
      (configFile, options, context) =>
        createNodesInternal(configFile, options, context),
      projectConfigurationFiles,
      options,
      context,
    );
  },
];

function createNodesInternal(
  configFilePath: string,
  options: Options,
  context: CreateNodesContextV2,
) {
  const root = dirname(configFilePath);
  const project = readJsonFile(configFilePath) as ProjectConfiguration;

  for (const targetName in project.targets) {
    const target = project.targets[targetName];
    for (const optionName in target.options) {
      const option = target.options[optionName];
      if (isArrayOfStrings(option)) {
        const targetOptionName = optionName.replace(/\[\]$/, "");
        target.options[targetOptionName] = option.toString();
      }
    }
  }

  return {
    projects: {
      [root]: project,
    },
  };
}

function isArrayOfStrings(arg: unknown): arg is Array<string> {
  if (Array.isArray(arg)) {
    return arg.every((item) => typeof item === "string");
  }
}

And then in configuration something like:

  "targets": {
    "build": {
      "options": {
        "schema": "MY_SCHEMA",
        "filter[]": [
          "Foo",
          "Bar"        
        ]
      }
    },

unfortunately with my apporach I had to introduce these array brackets in the name because simply replacing the value of the target options will not work. There is another core plugin which is reading project.json in the end and replacing plugin generated values with values from the file. So I'm generating two options, one array, another string. Array is ignored, string not.

With the current PR this plugin will not be needed because array will be directly parsed to comma-separated string.

@FrozenPandaz FrozenPandaz added the priority: high High Priority (important issues which affect many people severely) label May 14, 2025
@github-actions github-actions bot added the stale label Nov 11, 2025
@netlify
Copy link

netlify bot commented Feb 10, 2026

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 57df512

@netlify
Copy link

netlify bot commented Feb 10, 2026

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 57df512

nx-cloud[bot]

This comment was marked as outdated.

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

These changes fix the issue where the readyWhenStatus internal option was being incorrectly forwarded to underlying CLI tools (TypeScript, Vite, Storybook, etc.), causing them to fail with "unknown option" errors. By adding readyWhenStatus to the propKeys array, we ensure this internal Nx option is filtered out while still allowing the PR's intended functionality of forwarding user-provided string array arguments like --filter=TABLE1,TABLE2.

Tip

We verified this fix by re-running nx:test.

Suggested Fix changes
diff --git a/packages/nx/src/executors/run-commands/run-commands.impl.ts b/packages/nx/src/executors/run-commands/run-commands.impl.ts
index b656917e5b..fdd21a1668 100644
--- a/packages/nx/src/executors/run-commands/run-commands.impl.ts
+++ b/packages/nx/src/executors/run-commands/run-commands.impl.ts
@@ -54,6 +54,7 @@ const propKeys = [
   'parallel',
   'no-parallel',
   'readyWhen',
+  'readyWhenStatus',
   'cwd',
   'args',
   'envFile',

Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally FvzQ-fQmP

Apply fix locally with your editor ↗   View interactive diff ↗


🎓 Learn more about Self-Healing CI on nx.dev

ThePlenkov and others added 2 commits February 19, 2026 15:44
….impl.ts

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high High Priority (important issues which affect many people severely)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants