fix(enhanced-img): preserve ambient context for *?enhanced imports#12363
fix(enhanced-img): preserve ambient context for *?enhanced imports#12363benmccann merged 2 commits intosveltejs:mainfrom
*?enhanced imports#12363Conversation
🦋 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
*?enhancedmodules from a value of typestringinto a value of typePicture(fromvite-imagetools). However, this change caused theambient.d.tsfile 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-checkand other static analysis tooling because TypeScript would report that any module imported as*?enhancedhave no existing type declarations.The fix is quite simple: simply move the top-level
importinto thedeclare modulesyntax as shown in 4455725. This preserves the "ambient-ness" of theambient.d.ts.Ensuring that dependencies are present with
pnpmThis PR also fixes a possible footgun when importing modules with
pnpm. By default,pnpmdoes 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,pnpmwill not resolve it.This is problematic for the
types/of@sveltejs/enhanced-imgbecause it imports fromviteandsvelte. Previously, these were declared asdevDependencies, which causespnpmto prune them from module resolution.This PR fixes this by upgrading
viteandsvelteas direct dependencies. Alternatively, this may be downgraded topeerDependenciesinstead. 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 testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits