Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runPostTargets unexpectedly pass target options as overrideOptions #807

Open
lyngai opened this issue Apr 30, 2024 · 0 comments
Open

runPostTargets unexpectedly pass target options as overrideOptions #807

lyngai opened this issue Apr 30, 2024 · 0 comments

Comments

@lyngai
Copy link

lyngai commented Apr 30, 2024

When executing targets by postTargets options, the original options for the target is always treated as unparsed options and will be appended to the end of the command-line command.

For example, the target build using nx internal executor nx:run-script configured like this.

// project.json
{
  "targets": [
    "build": {
      "executor": "nx:run-script",
      "options": {
        "script": "build"
      }
    },
    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "postTargets": ["{projectName}:build"]
      }
    }
  ]
}

// package.json
{
  "scripts": {
    "build": "tsc -p tsconfig.json"
  }
}

Before runing the build script from postTargets, the following code read options from the project's config and pass the options as the second argument to runExecutor which is treated as override options.

const targetOptions = _getTargetOptions({
options: readTargetOptions(target, context),
context: templateStringContext,
});
for await (const { success } of await runExecutor(
target,
targetOptions,
context,
)) {

https://github.com/nrwl/nx/blob/458f2cc1e8511c60389a8edad233ab3f77afd410/packages/nx/src/command-line/run/run.ts#L261-L271

https://github.com/nrwl/nx/blob/458f2cc1e8511c60389a8edad233ab3f77afd410/packages/nx/src/utils/serialize-overrides-into-command-line.ts#L3-L15

And override options will transform to command line arguments. Which means { "script": "build" } is transformed to --script=build and will be appended to the end of the origin command tsc -p tsconfig.json.

Finally, the command is unexpectedly changed from tsc -p tsconfig.json to tsc -p tsconfig.json --script=build.

So, i am wondering if the readTargetOptions is necessary or if this should be considered a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant