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

Solid: generated library writes incorrect path map into tsconfig.base.json #1161

Open
ricrac-hac opened this issue Dec 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ricrac-hac
Copy link

Describe the bug
running the generator for a solid library results in a path being created with a redundant "libs" directory

To Reproduce

npx create-nx-workspace --preset=apps solid-test
cd solid-test
npm i @nxext/solid
nx g @nxext/solid:application apps/app-web
nx g @nxext/solid:lib libs/lib-app-web
cat tsconfig.base.json

See double libs. This breaks the path imports when you try to use components this exposes later.

    "paths": {
      "@solid-test/lib-app-web": ["libs/libs/lib-app-web/src/index.ts"]
    }

Expected behavior
Single libs

    "paths": {
      "@solid-test/lib-app-web": ["libs/lib-app-web/src/index.ts"]
    }

Additional context
Originally when I encountered this was in a pnpm project and I was passing --directory nx g @nxext/solid:library lib-app-web --directory libs/lib-app-web which had the same result. I recreated it in npm and using the shorthand syntax

This may be the same issue as #1034 but given it's a different generator I wasn't sure.

nx --version
Nx Version:
- Local: v20.2.2
- Global: v20.1.4
@ricrac-hac
Copy link
Author

On testing this more part of the problem is that we're assuming libsDir is needed to generate the path to the library, but

export function updateTsConfig(tree: Tree, options: NormalizedSchema) {
  const { libsDir } = getWorkspaceLayout(tree);
...

but options.projectDirectory already contains the info.

The other half of this is issues is that creating a library assumes you will tell it where the libs folder is:

nx g @nxext/solid:li

What directory would you like to use? (full path; e.g. libs/<my-lib-name>) · libs/mylib

if you don't manually include libs/ when generating then it puts it in the project root.

I think given options.projectDirectory contains the proper path to the lib anyway we can just remove the libsDir check.

This will also mean that directory flag will work properly now as well:

nx g @nxext/solid:lib hello --directory packages/hello
nx g @nxext/solid:lib libs/world
cat tsconfig.base.json
...
"paths": {
      "@proj/hello": ["packages/hello/src/index.ts"],
      "@proj/world": ["libs/world/src/index.ts"]
    }
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant