imjuni / ctix

CLI to generate barrel file for webpack, rollup entrypoint
MIT License
82 stars 22 forks source link

Support ts 5.5 tsconfig.json with ${configDir} #133

Closed Q16solver closed 4 months ago

Q16solver commented 5 months ago

Hello! Recently, ts 5.5 was announced in beta with new feature https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#the-configdir-template-variable-for-configuration-files This lets us share tsconfig across packages, and I wanted to use it for my monorepo, but ctix cannot find the files properly, my guess is that it's still using an older version of typescript, I'm not sure if it's this package? or from the ts-morph package where it wraps the ts compiler API, I can think of perhaps 2 ways to solve it here:

Have a "next" branch that ups the deps to the beta version as well and simply just publish it as an alpha/beta Have the typescript dep as a peerDep? and have userland install the required version? I'm not sure if that actually works, just a thought For reference I used with typescript ver: "5.5.0-dev.20240518", and shared configuration package I'm trying to create: https://github.com/Esposter/Esposter/tree/shared-configuration/packages/configuration usage: https://github.com/Esposter/Esposter/blob/shared-configuration/packages/shared/package.json

imjuni commented 5 months ago

Thank you for your feedback, @Q16solver :)

ctix has a strong dependency on the ts-morph package, and ts-morph has TypeScript as a devDependency, so changing TypeScript to a peerDependency is a great idea, but I don't think it would be easy to change it right away because I can't imagine what problems users will have when using a lower version of TypeScript than ctix expects.

However, using a higher version of the TypeScript compiler doesn't seem to be a big problem. As a workaround, could you try using the overrides feature?

Q16solver commented 5 months ago

~~@imjuni Yep! It serves as a good workaround for now, for others who also want to use this feature, here's my PR which hopefully provides a good enough example of how to use it https://github.com/Esposter/Esposter/pull/249/files using pnpm workspaces and pnpm overrides. I think we can leave this open until ts 5.5 is released and we should be able to remove the overrides workaround after~~

Edit: nvm this doesn't work lol

imjuni commented 4 months ago

@Q16solver Hello, thank you for your patience

ctix now supports TypeScript 5.5. I also tested the peerDependencies you suggested and it works fine, so I moved TypeScript to peerDependencies.

Q16solver commented 4 months ago

~Seems to work now, thanks!~

Edit: ctix still is unable to detect the files and builds empty index.js files, might be something to do with ts-morph

imjuni commented 4 months ago

@Q16solver Can you please provide a reproducible repo, or tell me what I need to do in the repo mentioned in the first issue. Thank you.

Q16solver commented 4 months ago

@imjuni If you fork my repo https://github.com/Esposter/Esposter:

  1. Change to shared-configuration branch
  2. Pnpm i
  3. Cd packages/shared for example
  4. Run pnpm build

You should encounter the issue that dist files are empty. If you then change the tsconfig to be the non config dir one (you can reference main branch), then ctix generates fine

Thanks for being willing to investigate!

imjuni commented 4 months ago

@Q16solver Hello,

Due to my recent personal circumstances, it is difficult for me to analyse the problem at this code level. I looked at the repo you uploaded and saw that the include' andexclude' options are missing from the .ctirc file. Could you please add the include and exclude options to your .ctirc file and try again? The include and exclude options work the same as in the tsconfig.json file.

I think the problem is that the tsconfig.json file in the shared project doesn't have the include and exclude options, so it can't find the project files to add to the index.ts file.

Q16solver commented 4 months ago

@imjuni oh you're right! seems like doing */.ts in include option fixes this. Maybe there's some issue now with ctix trying to use $configDir in tsconfig and would only work with normal paths. But either way, this is a good enough workaround, I'm happy for us to close this now, thanks so much C:

imjuni commented 4 months ago

@Q16solver

ctix looks for the target file in the include option; if there is no include option, it uses the TypeScript Compiler API to read the tsconfig.json file and use the SourceFiles list included in the Config object instead of ctix's include option.

However, if neither the ctix include option nor the include option in the tsconfig.json file is present, it creates an empty index.ts file.

I'll add a feature to tell about this in the next version to make it more obvious, thanks.

Q16solver commented 4 months ago

Yeah, though it seems like if the include in tsconfig has $configDir, it doesn't read it properly, might be some weird incompatibilities with how I've specified it with $configDir/src/*/.ts