-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix(enhanced-img): preserve ambient context for *?enhanced
imports
#12363
Conversation
🦋 Changeset detectedLatest commit: 5dbbe0b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
@benmccann Heads up: CI lints are failing due to the outdated root lockfile. I have regenerated it using |
ba8f0e8
to
f4ce446
Compare
f4ce446
to
07acadd
Compare
Top-level imports and exports automatically upgrade a TypeScript file to the module context. This is not desired in because we want to keep this module ambient in order for the to apply globally across all imports of . By importing the type inside the ambient module context, we preserve the ambient-ness of the file. https://www.typescriptlang.org/docs/handbook/modules/reference.html#ambient-modules fix
07acadd
to
7dabbe4
Compare
I didn't want the thousand line diff, so fixed it and did a force push. That means you won't be able to make changes on your branch without deleting it and checking it out again, but hopefully that's fine as there probably aren't further changes needed at this point |
Thanks! This is super appreciated. The diffs look much cleaner now. 🚀
No worries, nothing that a good ol' |
Hello there! Just checking up and bumping this PR. It would be really nice to have this patch upstream so that our CI need not depend on patched/overridden versions. Thanks! 🚀 |
Preserving the ambient context
#12224 changes the default export of
*?enhanced
modules from a value of typestring
into a value of typePicture
(fromvite-imagetools
). However, this change caused theambient.d.ts
file to no longer be an ambient module. According to the TypeScript docs, top-level imports and exports automatically upgrade the ambient context into a module context. That means thedeclare module '*?enhanced'
is no longer applied "ambiently", but now requires an explicit import somehow. This breakssvelte-check
and other static analysis tooling because TypeScript would report that any module imported as*?enhanced
have no existing type declarations.The fix is quite simple: simply move the top-level
import
into thedeclare module
syntax as shown in 4455725. This preserves the "ambient-ness" of theambient.d.ts
.Ensuring that dependencies are present with
pnpm
This PR also fixes a possible footgun when importing modules with
pnpm
. By default,pnpm
does not hoist dependencies to the top level of thenode_modules
. The direct dependencies of each package is thus locally scoped to that package only. If a package does not declare the dependency,pnpm
will not resolve it.This is problematic for the
types/
of@sveltejs/enhanced-img
because it imports fromvite
andsvelte
. Previously, these were declared asdevDependencies
, which causespnpm
to prune them from module resolution.This PR fixes this by upgrading
vite
andsvelte
as direct dependencies. Alternatively, this may be downgraded topeerDependencies
instead. Let me know if this is preferable.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits