Skip to content

fix(ts-plugin): only inject Astro types into Astro projects - #17668

Merged
matthewp merged 1 commit into
withastro:mainfrom
lazerg:fix/issue-17667-ts-plugin-astro-project-check
Aug 15, 2026
Merged

fix(ts-plugin): only inject Astro types into Astro projects#17668
matthewp merged 1 commit into
withastro:mainfrom
lazerg:fix/issue-17667-ts-plugin-astro-project-check

Conversation

@lazerg

@lazerg lazerg commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Changes

  • The TS plugin is registered globally, so it runs for every project in a workspace. Since Find Astro.locals references from .ts files in the TypeScript plugin #17269 it calls addAstroTypes() unconditionally, and findAstroPackageDirectory() just walks up the tree looking for node_modules/astro/. With a hoisted node_modules (pnpm nodeLinker: hoisted, npm, classic Yarn) that lookup succeeds from any sibling project, so env.d.ts and astro-jsx.d.ts were injected into projects that have nothing to do with Astro. Those files transitively pull in @types/node, and its global shims then win over lib.dom.d.ts, so "Go to Definition" on Blob, fetch or URL in a browser-only app lands in @types/node.
  • Adds an isAstroProject() guard in front of the injection: the nearest package.json has to list astro, or there has to be an astro.config.* next to it. The language server already does this through getAstroInstall(), the plugin was the one place missing it.

Closes #17667

Testing

  • Three cases in packages/language-tools/ts-plugin/test/units/astro-types.test.mts over a fixture monorepo with a hoisted node_modules: a React project that only reaches astro through the shared root is skipped, a project that depends on astro is detected, and so is one with an astro.config.mjs but no dependency.

Docs

  • No docs change, this only narrows when the plugin injects its own ambient types.

@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7019410

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

This PR includes changesets to release 1 package
Name Type
@astrojs/ts-plugin Patch

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

@matthewp
matthewp requested a review from Princesseuh August 12, 2026 20:02
@matthewp
matthewp merged commit bef9db5 into withastro:main Aug 15, 2026
27 checks passed
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.

VS Code plugin injects @types/node into other workspaces in a pnpm monorepo with nodeLinker: hoisted

3 participants