Closed danherd closed 1 year ago
Now that the workspace definition file (workspace.json) is optional, how can we list all the projects, do we have to recursively traverse folders and look for project.json? I need to investigate because this solution is not viable.
I think globbing for ./*/project.json
and ./*/*/project.json
might be the only way besides manually keeping track of what exists in a cache file.
Here's a dry-run for creating a new app:
$ npx nx g @nrwl/node:app asdf-app --dry-run
> NX Generating @nrwl/node:application
CREATE apps/asdf-app/src/app/.gitkeep
CREATE apps/asdf-app/src/assets/.gitkeep
CREATE apps/asdf-app/src/environments/environment.prod.ts
CREATE apps/asdf-app/src/environments/environment.ts
CREATE apps/asdf-app/src/main.ts
CREATE apps/asdf-app/tsconfig.app.json
CREATE apps/asdf-app/tsconfig.json
CREATE apps/asdf-app/project.json
CREATE apps/asdf-app/.eslintrc.json
CREATE apps/asdf-app/jest.config.ts
CREATE apps/asdf-app/tsconfig.spec.json
NOTE: The "dryRun" flag means no changes were made.
Notice how nothing is touched outside of the new apps/asdf-app
dir.
Creating a lib updates the root tsconfig.base.json:
$ npx nx g @nrwl/js:lib asdf-lib --dry-run
> NX Generating @nrwl/js:library
CREATE libs/asdf-lib/README.md
CREATE libs/asdf-lib/package.json
CREATE libs/asdf-lib/src/index.ts
CREATE libs/asdf-lib/src/lib/asdf-lib.spec.ts
CREATE libs/asdf-lib/src/lib/asdf-lib.ts
CREATE libs/asdf-lib/tsconfig.json
CREATE libs/asdf-lib/tsconfig.lib.json
CREATE libs/asdf-lib/project.json
UPDATE tsconfig.base.json
CREATE libs/asdf-lib/.eslintrc.json
CREATE libs/asdf-lib/jest.config.ts
CREATE libs/asdf-lib/tsconfig.spec.json
And that's to set a reference to the lib in the tsconfig paths obj, which probably cant be trusted, since the user can edit it to add their own custom ones too:
"paths": {
"asdf-lib": ["libs/asdf-lib/src/index.ts"],
}
@ryangrahamnc good point, using base tsconfig is not reliable, we have to look for nested project.json, but what if there's no project.json? this file is optional so we have to look for both package.json and project.json, that's much more complex than before (considering that doing this with Zsh will be a nightmare).
nx graph --file="/tmp/output.json"
will export a json file you can use instead of workspace.json
perhaps it should be cached and invalidated only if the file structure has changed.
Since nx is a solution for mono-repos we can make an assumption that the directory is managed with git so cache invalidation will take place only when git shows that something has changed
@edbzn, note with new release of nx, workspace.json
is now deprecated
Here is v15.7.0
migrations.json
file https://github.com/nrwl/nx/blob/8165459568e5bdfadf3f11ab7fe5e7eb044be06c/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts#L33 which removes workspace.json
from repo https://github.com/nrwl/nx/blob/8165459568e5bdfadf3f11ab7fe5e7eb044be06c/packages/workspace/src/generators/convert-to-nx-project/convert-to-nx-project.ts#L33
So, this issue becomes critical now, IMO
And here is console output after upgrade
> NX workspace.json is ignored
Nx no longer reads configuration from workspace.json.
Run "nx g @nrwl/workspace:fix-configuration" to split workspace.json into individual project.json files
Hi there, I added support for the optional workspace.json file. Try it and let me know if you have any issues.
Great work - thanks!
Thanks. It works. It feels a bit slower now, though. Also, even if I would keep workspace.json
in root of the project just to make nx-completion
use it and be faster – nx-completion
seems to ignore it. Not a big problem though.
If the
workspace.json
file does not exist (as is the way with a modern nx monorepo), the plugin generates this error when trying to autocomplete a package name: