jscutlery / semver

Nx plugin to automate semantic versioning and CHANGELOG generation.
MIT License
719 stars 83 forks source link

`runPostTargets` unexpectedly pass target options as overrideOptions #807

Open lyngai opened 2 months ago

lyngai commented 2 months ago

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.

https://github.com/jscutlery/semver/blob/048c4b29686e7fbd1a25e5f3c0cb60350733b481/packages/semver/src/executors/version/utils/post-target.ts#L33-L42

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.