-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve third-party Astro package support #4623
Conversation
🦋 Changeset detectedLatest commit: a7dfbd7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This make sense to me. We have the same issue for vite-plugin-svelte (.svelte
files and .astro
files are exported raw), and this recursive technique is what we came up too. Reference: dependencies.ts and usage.
Admittedly this is a problem in Vite that we hadn't found a nice solution yet. Ideally nodejs ESM loaders should help when that's stable.
In my second linked code, you'll also notice that we externalize transitive deps too, to prevent transitive CJS deps reporting a Vite caveat like "module" is not defined
error in dev mode. We could probably improve that in the future too.
Thanks @bluwy! I had a suspicion you’d have some good insights into this issue 💜 |
Can a test be added? |
Nate scared me off with his comment, but I can try! |
Our existing `package.json` look-up strategy simply loaded `node_modules/${dep}/package.json` and hoped that was the correct location. That fails in monorepo environments where `node_modules` might be elsewhere making this impossible to test (and presumably also brittle for monorepo Astro users). This commit switches to using `createRequire` to resolve dependencies based on the `vite-plugin-svelte` strategy @bluwy linked to: <https://github.com/sveltejs/vite-plugin-svelte/blob/62b9edfe0a649258809c723e0db6bf6947a1072b/packages/vite-plugin-svelte/src/utils/dependencies.ts#L40>
Add a basic smoke test that checks if pages are built without an error when using `astro-embed`. I deliberately didn’t test the third-party component output, but could add something if that would be better.
Test added! I’ve also had to switch up my fix to get the tests passing, so probably a good call to try testing this. Our existing I’ve switched to using My test uses |
The new changes looks great!
I think the current test method is fine, but if we want to avoid an external dependency, we can use the So you'd have something like: |
We do have some tests that use local packages, like this one: https://github.com/withastro/astro/blob/main/packages/astro/test/fixtures/css-assets/package.json But I think this method is fine for now. |
This PR makes the linter fail now:
when running |
Changes
Fix #4071
Search for Astro package dependencies beyond a project’s direct dependencies.
See this comment for more background — it lays out some alternative approaches, I’d be curious what people think!
TL;DR Current logic only adds direct dependencies to
vite.ssr.noExternal
. The changes in this PR walk the dependency tree, checking child dependencies of any Astro packages it finds recursively. It bails out of a branch when it encounters a non-Astro package. This should still be reasonably performant, while being much more robust.Testing
Help would be appreciated. @natemoo-re’s original PR for this code (#2665) mentions:
What I did manually:
pnpm build
in this repocd packages/astro && npm pack
to get a tarball for the new versionastro-embed
and use itsYouTube
component:npm start
— encounters errors as reported in 🐛 BUG: astro-embed integration fails due to .astro file extension error #4071npm i ../astro/packages/astro/astro-1.1.5.tgz
to install Astro from the tarballnpm start
— errors go away! ✨Docs
Bug fix for an issue that we’re not documenting in detail yet, although this is related to withastro/docs#1455.