jscutlery / semver

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

Synced mode seems to be incompatible with nx 13 and project.json files #420

Open maxmousse opened 2 years ago

maxmousse commented 2 years ago

Hi everybody,

We have some projects using jscutlery/semver, and as we are migrating to nx 13 and the new project.json configuration structure, we are encountering the next problem: we cannot have a project.json at the workspace level because it causes some problems with the Nx cli (commands that use the dependencies graph are looping).

Did some of you encountered the same problem ?

For now, the solution we came with is to create two projects (let's call them apps-workspace and libs-workspace) with only a version target.

apps/apps-workspace/project.json

{
  "ignore": true,
  "projectType": "application",
  "root": "apps",
  "targets": {
    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "syncVersions": true
      }
    }
  }
}

libs/libs-workspace/project.json

{
  "ignore": true,
  "projectType": "library",
  "root": "libs",
  "targets": {
    "version": {
      "executor": "@jscutlery/semver:version",
      "options": {
        "syncVersions": true
      }
    }
  }
}

This allows to continue to use the sync mode and to run the target with nx run-many --all --target version. But it also makes possible to have divergences between the versions of the apps and the libs.

One solution would be to add a cwd option to the @jscutlery/version executor to allow to run it in another directory than the projectRoot directory, but not sure this is the most elegant solution.

Thank you in advance for your help!

hcharley commented 2 years ago

I believe I'm running into this too.

hcharley commented 2 years ago

For my use case, I don't version the apps, so just changing the root from . to libs worked:

    "workspace": {
      "targets": {
        "version": {
          "executor": "@jscutlery/semver:version",
          "options": {
            "syncVersions": true
          }
        }
      },
      "root": "libs",
      "tags": []
    },

You might notice I'm not using the project.json scheme. Others might run into a similar situation as me

edbzn commented 2 years ago

Hi there, in your workspace.json file you can mix standalone configuration for your projects and the virtual "workspace" project for versioning the whole repo.

{
  "version": 2,
  "projects": {
    "workspace": {
      "root": ".",
      "targets": {
        "version": {
          "executor": "@jscutlery/semver:version",
          "options": {
            "syncVersions": true
          }
        },
      }
    },
    "demo": "apps/demo",
    "demo-e2e": "apps/demo-e2e"
  }
}

Hope it helps.

the-ult commented 2 years ago

This seems to result in:

>  NX   The angular.json file is out of sync

   - Cannot find project 'workspace' in '.' 

when running: nx workspace-lint && nx lint

{
  "version": 2,
  "projects": {
    "my-app": "apps/my-app",
    "my-app-e2e": "apps/my-app-e2e",
    "my-lib": "libs/my-lib",
    "workspace": {
      "root": ".",
      "targets": {
        "version": {
          "executor": "@jscutlery/semver:version",
          "options": {
            "syncVersions": true,
            "commitMessageFormat": "chore(${projectName}): release version ${version}"
          }
        }
      }
    }
  }
}

nx report

➜  my-workspace git:(release) ✗ nx report

 >  NX   Report complete - copy this into the issue template

   Node : 17.4.0
   OS   : darwin x64
   npm  : 8.3.1

   nx : 13.6.1
   @nrwl/angular : 13.6.1
   @nrwl/cli : 13.6.1
   @nrwl/cypress : 13.6.1
   @nrwl/detox : undefined
   @nrwl/devkit : 13.6.1
   @nrwl/eslint-plugin-nx : 13.6.1
   @nrwl/express : undefined
   @nrwl/jest : 13.6.1
   @nrwl/js : undefined
   @nrwl/linter : 13.6.1
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : undefined
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.6.1
   @nrwl/tao : 13.6.1
   @nrwl/web : undefined
   @nrwl/workspace : 13.6.1
   typescript : 4.4.4
   rxjs : 7.4.0
   ---------------------------------------
   Community plugins:
         @angular/animations: 13.1.3
         @angular/common: 13.1.3
         @angular/compiler: 13.1.3
         @angular/core: 13.1.3
         @angular/forms: 13.1.3
         @angular/platform-browser: 13.1.3
         @angular/platform-browser-dynamic: 13.1.3
         @angular/router: 13.1.3
         @angular-devkit/build-angular: 13.1.4
         @angular/cli: 13.1.4
         @angular/compiler-cli: 13.1.3
         @angular/language-service: 13.1.3
         @jscutlery/semver: 2.17.6
the-ult commented 2 years ago

@edbzn any idee what could cause the above error? Atm the fix seems to be: "root": "packages", but this results in having to copy the newly generated packages/CHANGELOG.md back to the root, before push / publish

nx.json

"workspaceLayout": {
    "appsDir": "apps",
    "libsDir": "packages"
  },
edbzn commented 2 years ago

I quickly checked but found nothing relevant. I think it's time to drop the sync mode root hack and really think about #98.

shawnmclean commented 2 years ago

@edbzn how can I use postTargetHooks such as @jscutlery/semver:github and ngx-deploy-npm:deploy in sync mode using workspace.json?

Project ref: https://github.com/Samelogic/microsurveys