Skip to content

fix(astro): resolve Astro's private APIs properly #238

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

Closed
wants to merge 9 commits into from

Conversation

AriPerkkio
Copy link
Member

@AriPerkkio AriPerkkio commented Aug 13, 2024

The usage of private APIs was added in #4 (👋 @d3lm).

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@Nemikolh Nemikolh left a comment

Choose a reason for hiding this comment

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

This API was added after we talked to them 😄

Having that import is intentional here. Once it's stabilized on the Astro side, we'll be able to get rid of the type error.

I would rather us to keep included their logic because:

  • If it's updated then it's less maintenance for us and we don't have to track every version from astro of those swap functions.
  • We don't include the logic multiple times in the final bundle

@AriPerkkio
Copy link
Member Author

we'll be able to get rid of the type error

This is not just type error. In monorepo setups this import actually fails and TutorialKit fails to start. Here's example from https://github.com/AriPerkkio/tutorialkit/tree/test/ui-tests/test/ui which doesn't work without this fix.

@d3lm
Copy link
Contributor

d3lm commented Aug 13, 2024

Yes, I agree with @Nemikolh and I'd like to keep it as is. The whole point to get this in upstream is to avoid copying code from Astro so we can fully rely on upstream for this. I think we can give them the feedback that it works well for us so it can be exposed properly and we don't need to import from node_modules directly. But I am not a fan of copying it again cause that's what we wanted to avoid in the first place.

@AriPerkkio
Copy link
Member Author

Sure, that would be ideal case. It's also breaking change as we would need to set new minimum version of astro but we can do breaking change release at this point easily.

If you have any ideas how to fix #235 and #241 without this change, feel free to help! Otherwise this will block those two, I think.

@Nemikolh
Copy link
Member

@AriPerkkio For #235, I think we can temporarily use a config option. We should definitely provide feedback that this has been working fine for us.

For #241, why is this an issue there? Doesn't the dependency also get installed by pnpm? (I only had a quick look so sorry if it's something obvious 🙈)

@AriPerkkio AriPerkkio changed the title fix(astro): don't import Astro's private modules fix(astro): resolve Astro's private APIs properly Aug 14, 2024
@AriPerkkio
Copy link
Member Author

Removed copied Astro's swap-functions.js and added Vite plugin that resolves it properly. I tried to add module resolving logic directly to Layout.astro but it just didn't work. It's best to do on Vite's side.

Tested with #235 and #241. Checked dev mode and build dist contents.

Using private APIs like this relies on Astro's npm package's file structure and can break at any time. There's reason why package.json's exports are required for imports. In my opinnion it would be best to simply copy-paste this from Astro if it's wanted to be used. And once they include it in their public API (exports), we can start requiring that version as peer dep.

@AriPerkkio AriPerkkio requested review from Nemikolh and d3lm August 14, 2024 06:37
@d3lm
Copy link
Contributor

d3lm commented Aug 14, 2024

We should definitely provide feedback that this has been working fine for us.

@Nemikolh @AriPerkkio I can provide that feedback to them and ask them to expose it properly for us.

Copy link
Member

@Nemikolh Nemikolh left a comment

Choose a reason for hiding this comment

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

Looking good! 🤩

Copy link
Contributor

Choose a reason for hiding this comment

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

Clever!

@d3lm
Copy link
Contributor

d3lm commented Aug 14, 2024

Ok PR is on the way withastro/astro#11708

@Nemikolh
Copy link
Member

@d3lm, @AriPerkkio do we want to wait for that PR to land on Astro's side then? Or are we all happy to move forward with this PR?

@AriPerkkio
Copy link
Member Author

Let's close this and wait for Astro's PR instead. I can add work-around into the #241 for now, and post same instructions in #235.

@AriPerkkio AriPerkkio closed this Aug 20, 2024
@AriPerkkio AriPerkkio deleted the fix/npm-workspace branch August 20, 2024 06:48
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.

Tutorial created in workspace fails
3 participants