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

feat(dev-server-esbuild): allow extended tsconfig #2161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

venikx
Copy link

@venikx venikx commented Mar 15, 2023

What I did

  1. Added a test case when referencing a tsconfig.json in the esbuildPlugin that uses extends to extend from a base tsconfig.json
  2. Added a possible implementation how it could work using --showConfig when running tsc. See https://www.typescriptlang.org/docs/handbook/compiler-options.html
  3. Change the target of the fixture, since es2022 was reported as invalid by tsc

I'm not sure about the actual implementation, but it covers my test case, without breaking the other tests of dev-server-esbuild (at least on Mac) 🤷🏽

@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2023

🦋 Changeset detected

Latest commit: 99ae905

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@web/dev-server-esbuild Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@venikx
Copy link
Author

venikx commented Mar 15, 2023

changeset-bot message...

So if I understand this correctly, I can trigger an automatic release of the package, by applying a change set?

@Westbrook
Copy link
Member

Apply the changeset to clarify that there are changes requiring a release.

Full the changeset with a lingual representation of the changes so that they are included in the CHANGELOG.md.

@venikx
Copy link
Author

venikx commented Mar 17, 2023

Apply the changeset to clarify that there are changes requiring a release.

Full the changeset with a lingual representation of the changes so that they are included in the CHANGELOG.md.

Let me know if the formatting of the changeset should be adjusted!

@@ -61,7 +62,15 @@ export class EsbuildPlugin implements Plugin {
this.config = config;
this.logger = logger;
if (this.esbuildConfig.tsconfig) {
this.tsconfigRaw = await promisify(fs.readFile)(this.esbuildConfig.tsconfig, 'utf8');
try {
const { stderr, stdout } = await promisify(child_process.exec)(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does reading the file not work? We have to shell out to tsc?

Copy link
Author

@venikx venikx Mar 31, 2023

Choose a reason for hiding this comment

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

Reading 1 tsconfig.json file works, but only if you only have 1 tsconfig.json, without extending from another another tsconfig.json file.

Technically you could try parsing the file that you initially read, and then recursively call the same function over and over again until all the extends's are resolved. This is exactly what tsc --show-config does, so I chose to lean on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting! I'm wondering if we should really be using the .tsconfig setter instead of .tsconfigRaw. I'm not sure, but from reading the docs, it seems like that setting will work with extending configs?

If not, I think this is good!

Copy link
Author

@venikx venikx Apr 4, 2023

Choose a reason for hiding this comment

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

What do you mean with the .tsconfig setter? And are you referring to the dev-server-esbuild setting, or esbuild itself?

I think I tested this already, but I can try it again. If you revert my change from the code, but keep the test you’ll get a failing test.

From dev-server-esbuild side we can’t set a .tsconfigRaw. We pass in the .tsconfig, convert it and then pass it as tsconfigRaw to esbuild.

Logically, I’d think .tsconfigRaw would use the tsconfig as you passed it in, without expanding it further automagically.

Copy link
Author

Choose a reason for hiding this comment

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

@koddsson I just tested this again, and with the test case I added the test fails, without the change I've proposed here.

@venikx venikx force-pushed the feat/extends-tsconfig branch from ff9f749 to 99ae905 Compare April 17, 2023 20:44
@venikx
Copy link
Author

venikx commented Apr 17, 2023

I rebased the PR to be up to date with latest changes.

@venikx venikx requested a review from koddsson April 17, 2023 20:46
Copy link
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

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

This is great! I'm slightly worried about performance here since we'll be shelling out to tsc but it's probably fine.

We should probably have some performance testing in the future to help us get insights into how changes affect performance.

@koddsson
Copy link
Contributor

We've got #2180 queued up to merge to master soon. I want to make sure we land that first so that we don't delay that release any more. We'll merge this once that PR has landed.

@venikx
Copy link
Author

venikx commented Apr 18, 2023

No worries, I've come across another way to possibly solve it while going through the dependabot PR's at work. Would something like this be preferred over shelling out tsc? qmhc/vite-plugin-dts#202

You are still using the typescript ecosystem, but have to do a bit more manual recursion in favour of not having to run a command.

EDIT: Also sorry for the re-review, I was worried you might not have seen this message, before potentially merging this PR.

@venikx venikx requested a review from koddsson April 18, 2023 10:05
@koddsson
Copy link
Contributor

No worries, I've come across another way to possibly solve it while going through the dependabot PR's at work. Would something like this be preferred over shelling out tsc? qmhc/vite-plugin-dts#202

Oh, yeah! I would love to do this instead. Looks like we need to upgrade to TypeScript 5 first, which I think is also a positive, so I'd prefer that.

What do you think?

@venikx
Copy link
Author

venikx commented Apr 20, 2023

No worries, I've come across another way to possibly solve it while going through the dependabot PR's at work. Would something like this be preferred over shelling out tsc? qmhc/vite-plugin-dts#202

Oh, yeah! I would love to do this instead. Looks like we need to upgrade to TypeScript 5 first, which I think is also a positive, so I'd prefer that.

What do you think?

Yeah, I think it might be better, but it does indeed seem to require typescript 5. Would that then be considered a breaking change for dev-server-esbuild?

@koddsson
Copy link
Contributor

Would that then be considered a breaking change for dev-server-esbuild?

Probably! But that's no worries, we can just make a breaking change.

@koddsson
Copy link
Contributor

We should be on TypeScript 5 now if you pull master 👯

@venikx
Copy link
Author

venikx commented Apr 25, 2023

We should be on TypeScript 5 now if you pull master 👯

I'll modify my PR somewhere this weekend, I have busy schedule for this week unfortunately.

@koddsson
Copy link
Contributor

We should be on TypeScript 5 now if you pull master 👯

I'll modify my PR somewhere this weekend, I have busy schedule for this week unfortunately.

No worries! Let me know if we can help :)

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.

3 participants