-
Notifications
You must be signed in to change notification settings - Fork 807
Fix autocomplete suggesting unexported internal files from monorepo packages #2584
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
base: main
Are you sure you want to change the base?
Conversation
…o packages When a package has an "exports" field in its package.json, only files explicitly exposed via exports should be importable. Previously, internal files that were transitively imported within a package were incorrectly suggested for auto-import, resulting in import statements that wouldn't resolve. The fix: 1. Added PackageHasExports field to ResolvedEntrypoints to track whether a package has an exports field 2. Added PackagesWithExports set to RegistryBucket to efficiently lookup which packages have exports 3. Modified GetModuleSpecifier to skip EndingChangeable entrypoints (files discovered by directory scanning rather than exports) when the package has an exports field 4. Added isInvalidPackageSpecifier to filter out bare package specifiers with subpaths that don't resolve to valid entrypoints Added test case TestAutoImportTransitiveLeak that reproduces the issue. Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
|
Thanks @DanielRosenwasser! It might be worth noting that I believe having a |
|
@copilot this doesn’t look right. Let me tell you how I think it should work and then you investigate and tell me which assumption is breaking down:
Please do a thorough investigation of the root cause and report back your findings. |
|
@copilot try again |
Auto-import was suggesting internal files from symlinked monorepo packages when the package has an
exportsfield that doesn't expose them. Accepting such suggestions produces unresolvable imports likeimport { fooInternal } from "@packages/foo/src/internal/index.js".Changes
ResolvedEntrypoints.PackageHasExports- New field to track whether a package has anexportsfield during entrypoint generationRegistryBucket.PackagesWithExports- Set for O(1) lookup of packages with exports during specifier generationGetModuleSpecifier- SkipEndingChangeableentrypoints (directory-scanned files not in exports) when package has exportsisInvalidPackageSpecifier- Filter bare specifiers with subpaths that aren't valid entrypoints in project bucket pathTest case
Added
TestAutoImportTransitiveLeakreproducing the scenario:Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.