nxpm / stack

🥭 nxpm-stack lets you generate a complete and opinionated full-stack application in a Nx Workspace, ready to extend and deploy!
https://npm.im/@nxpm/stack
MIT License
108 stars 14 forks source link

NX 13+ removes `projects` from nx.json. Workspace-lint introduces it and causes errors #152

Closed kpaxton closed 2 years ago

kpaxton commented 2 years ago

With the later NX versions, the workspace-lint command causes issues due to it adding projects back to nx.json.

The problematic code is linked below.

https://github.com/nxpm/stack/blob/7a131f7db3c9dd01199181aae70d7ec1d4876609/packages/cli/src/lib/commands/workspace-lint.ts?_pjax=%23js-repo-pjax-container%2C%20div%5Bitemtype%3D%22http%3A%2F%2Fschema.org%2FSoftwareSourceCode%22%5D%20main%2C%20%5Bdata-pjax-container%5D#L33

my suggestion is to wrap the projects property in an iif statement.

....(file?.projects ? { projects: sortItems(file?.projects) } : {})

As well as the same for packageJson and compiler options

...(file?.compilerOptions
      ? {
          compilerOptions: {
            ...file?.compilerOptions,
            paths: sortItems(file?.compilerOptions?.paths)
          }
        }
      : {})

...(file?.scripts ? { scripts: sortItems(file?.scripts) } : {})

That way, if the property doesn't exist, it won't add it back in.

beeman commented 2 years ago

Hi @kpaxton , thanks for creating this issue. I think Nx 13 does most of this out of the box these days, so your suggestion makes sense. In fact, I might get rid of it all together and just format the scripts object in package.json.

I'm happy to review a PR if you're interested in contributing!

kpaxton commented 2 years ago

@beeman PR created to remove the unecessary sorts.

beeman commented 2 years ago

Awesome @kpaxton - I will merge and publish later this week 🙏

beeman commented 2 years ago

@kpaxton this is not merged, thanks for your contribution!

I released it under version 5.0.0-beta.17