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

Added support for updating tsconfig.json when using astro add #4959

Merged
merged 8 commits into from
Oct 12, 2022

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Oct 3, 2022

Changes

This adds a step at the end of astro add where it updates your tsconfig.json or jsconfig.json:

image

It handles installing multiple frameworks by choosing the first framework and showing a warning with a link to our docs:

image

And a specific message for Vue until Volar 1.0 is out and fix this issue:
image

Fix #4506, Fix #5017

Testing

Added tests for underlying tsconfig loading / manipulation logic. astro add itself is untested at the moment

Docs

N/A, I think? Will consult docs team

@changeset-bot
Copy link

changeset-bot bot commented Oct 3, 2022

🦋 Changeset detected

Latest commit: bf9acd1

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

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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) semver: minor Change triggers a `minor` release labels Oct 3, 2022
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Comment on lines +50 to +51
"react-dom": "^17.0.2 || ^18.0.0",
"@types/react": "^17.0.50 || ^18.0.21"
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated, but those two were missing and are necessary for using React with TypeScript

@Princesseuh
Copy link
Member Author

Princesseuh commented Oct 3, 2022

Putting this back into WIP because I realized there's a major issue with how the configs are merged when using complex tsconfigs

@Princesseuh Princesseuh marked this pull request as draft October 3, 2022 17:53
@Princesseuh Princesseuh changed the title Added support for updating tsconfig.json when using astro add [WIP] Added support for updating tsconfig.json when using astro add Oct 3, 2022
Comment on lines +246 to +247
typeof (globalThis as any).AggregateError !== 'undefined'
? (globalThis as any).AggregateError
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe the type-fest upgrade made this fail. I suspect we were depending on it by accident, weird

Copy link
Contributor

Choose a reason for hiding this comment

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

This code is not accidental, we create AggregateErrors when there are multiple CSS errors during compilation. AggregateError is being polyfilled here as its not available in certain Node versions.

But I guess it's possible that type-fest was shimming the types for it, which is why we weren't getting an error before.

@Princesseuh Princesseuh changed the title [WIP] Added support for updating tsconfig.json when using astro add Added support for updating tsconfig.json when using astro add Oct 5, 2022
@Princesseuh Princesseuh marked this pull request as ready for review October 5, 2022 13:38
@matthewp
Copy link
Contributor

matthewp commented Oct 7, 2022

Fixes #5017

const updateTSConfigResult = await updateTSConfig(cwd, logging, integrations, flags);

switch (updateTSConfigResult) {
case UpdateResult.none: {
Copy link
Contributor

Choose a reason for hiding this comment

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

love it

@chlbri
Copy link

chlbri commented Oct 7, 2022

I think it add another error when you want to reference Astro components inside an index.ts file :
Capture d'écran 2022-10-07 à 19 50 43 PM

@Princesseuh
Copy link
Member Author

Princesseuh commented Oct 7, 2022

I think it add another error when you want to reference Astro components inside an index.ts file : Capture d'écran 2022-10-07 à 19 50 43 PM

Probably an issue inside our TypeScript plugin that is unrelated to this PR, I'm currently working on a rework of the plugin that should fix this kind of issue

@chlbri
Copy link

chlbri commented Oct 7, 2022

Alternatively, you can use a per-file pragma to set this option, like this :

/** @jsxImportSource solid-js */

import type { Component } from 'solid-js';

@chlbri
Copy link

chlbri commented Oct 7, 2022

I think it add another error when you want to reference Astro components inside an index.ts file : Capture d'écran 2022-10-07 à 19 50 43 PM

Probably an issue inside our TypeScript plugin that is unrelated to this PR, I'm currently working on a rework of the plugin that should fix this kind of issue

Yes but it's when I use this config : image

that the error comes.

'astro': minor
---

Added support for updating TypeScript settings automatically when using `astro add`
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind expanding this description a bit more into like a paragraph so it can be copy/pasted into a release blog post? Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, let me do that

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@Princesseuh Princesseuh dismissed GitHub Actions’s stale review October 12, 2022 17:48

Appeared again after rebasing

@Princesseuh Princesseuh merged commit 0ea6187 into main Oct 12, 2022
@Princesseuh Princesseuh deleted the astro-add-ts branch October 12, 2022 18:11
@astrobot-houston astrobot-houston mentioned this pull request Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type for TSX with solid integration @types/react not included in devDependencies when doing astro add react
3 participants