[BUG]: `--group-by-package` does not work in a monorepo without a root tsconfig

#68 · closed · 6 comments

View on GitHub ↗

KostyaTretyak

**Describe the bug** All my tsconfig files are in `packages/*`, and it makes no sense to keep tsconfig in the root. And this is not work: ```bash dpdm --no-warning --no-tree -T --group-by-package './packages/*/src/index.ts' ``` **To Reproduce** Run this command from root folder in monorepository. **Expected behavior** Cyclic dependencies should be found. **Additional context** Two working versions with other options: ```bash # 1 dpdm --no-warning --no-tree -T --cwd packages/core src # 2 dpdm --no-warning --no-tree -T --tsconfig packages/core/tsconfig.json packages/core/src ```

Comments

acrazing

How do you configure your type check command (like `tsc -p ?`)? A shared tsconfig.json is required for dpdm to resolve path alias. But if your build tool doesn't need it, dpdm can also work without it.

KostyaTretyak

What do you mean by "type check command"? I guess you're talking about the build command? In [my monorepo](https://github.com/ditsmod/ditsmod) I use TypeScript [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html) and `tsc -b packages/tsconfig.build.json`. In this file I have this config: ```json { "files": [], "references": [ { "path": "authjs/tsconfig.build.json" }, { "path": "body-parser/tsconfig.build.json" }, { "path": "core/tsconfig.build.json" }, { "path": "cors/tsconfig.build.json" }, { "path": "i18n/tsconfig.build.json" }, { "path": "jwt/tsconfig.build.json" }, { "path": "openapi/tsconfig.build.json" }, { "path": "openapi-validation/tsconfig.build.json" }, { "path": "rest/tsconfig.build.json" }, { "path": "rest-diagnostics/tsconfig.build.json" }, { "path": "rest-testing/tsconfig.build.json" }, { "path": "session-cookie/tsconfig.build.json" }, { "path": "sqb/tsconfig.build.json" }, { "path": "testing/tsconfig.build.json" }, { "path": "trpc/tsconfig.build.json" }, { "path": "graphql/tsconfig.build.json" }, { "path": "versions/tsconfig.build.json" }, ] } ``` So, no need in the root any tsconfig.

KostyaTretyak

To check for a cyclic dependency, you can clone my repository. Then go back to the state where the cyclic dependency was: ```bash git clone https://github.com/ditsmod/ditsmod.git cd ditsmod git checkout 5f2f1ee # works npx dpdm --no-warning --no-tree -T --cwd packages/core src # not works npx dpdm --no-warning --no-tree -T --group-by-package './packages/*/src/index.ts' ```

acrazing

Got it. `references` is a flag that `dpdm` doesn't yet support. I'll try to implement it these days.

KostyaTretyak

I created my own package that finds similar cycles: ```bash npx @ts-stack/cycle-detector packages/*/src/index.ts ```

acrazing

Fixed in `[email protected]`: `dpdm` now resolves package-local `tsconfig.json` files and referenced tsconfig projects, and `--group-by-package` can report internal package cycles as package self-cycles. I also verified the fix against the reported Ditsmod commit (`5f2f1ee`); the command now reports the package cycles for `@ditsmod/core`, `@ditsmod/rest`, and `@ditsmod/trpc`.