Skip to content

fix: get tsconfig in each pkg for monorepos#61

Closed
RikoRodriges wants to merge 2 commits into
acrazing:masterfrom
RikoRodriges:fix-ts-in-monorepos
Closed

fix: get tsconfig in each pkg for monorepos#61
RikoRodriges wants to merge 2 commits into
acrazing:masterfrom
RikoRodriges:fix-ts-in-monorepos

Conversation

@RikoRodriges
Copy link
Copy Markdown

Added support for retrieving individual tsconfig.json files for each package within the monorepo. Previously, a single tsconfig.json file was applied from the invoking package, resulting in a unified rule for aliases across all packages. Now, each package can use its own tsconfig.json with unique aliases, allowing for more flexible build configurations per package

Comment thread src/parser.ts Outdated
const root = findPackageRoot(context);
if (!compilerOptionsByPkg.has(root)) {
let _compilerOptions = ts.parseJsonConfigFileContent(
ts.readConfigFile(path.join(root, 'tsconfig.json'), ts.sys.readFile)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tsconfig.json may not exists. If you want to do that, you may need to findTsconfigDir rather than findPackageRoot.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tsconfig.json does not exist readConfigFile will return:

{
  config: {},
  error: {
    messageText: 'Cannot read file'
  }
}

In this case, the code will not break, and the module will still be parsed.


If you think this is not a good approach, we can pass tsconfig.json by specifying the root directory from the current working directory (where dpdm is run).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will skip the existing tsconfig in root directory if there is a sub directory has package.json.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback. I have taken your comments into account and updated the PR accordingly to ensure the root tsconfig is not skipped when there is a package.json in a subdirectory. Please let me know if there are any additional adjustments you'd like me to make.

Copy link
Copy Markdown
Owner

@acrazing acrazing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the comments.

@RikoRodriges
Copy link
Copy Markdown
Author

@acrazing ping

@acrazing
Copy link
Copy Markdown
Owner

acrazing commented May 9, 2026

Thanks a lot for the PR and for the patience here. I agree the underlying use case is real: monorepos can have subprojects with different path aliases, and dpdm should eventually have a better story for that.

I’m going to close this PR for now, though, because finding the correct tsconfig.json is not quite as simple as walking to the nearest package root. TypeScript itself does not switch configs per imported file in a single project; for subprojects it usually relies on project references or an explicit build/config graph. For dpdm, I think we need a configuration model similar to references so we can resolve subprojects intentionally instead of guessing from package.json locations.

That probably belongs after the config-file feature lands, since this needs user-provided project structure rather than implicit discovery only.

In the meantime, I suspect many cases can still be handled with a single root tsconfig.json. If your project cannot be represented that way, please feel free to share the concrete layout and aliases here. I’m happy to help figure out a working setup or use it to guide the future config design.

@acrazing acrazing closed this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants