refactor(annotation): use #src/* subpath imports over ../ relative imports - #250
Merged
Conversation
…ports
The 'Subpath imports for intra-package refs' convention requires
cross-directory imports to use the #src/* alias; only same-directory
siblings may stay relative. The annotation package was the sole holdout:
it lacked the imports mapping and used ../ / ../../ for all 26
cross-directory references.
- Declare "imports": { "#src/*": "./src/*" } in packages/annotation/package.json
- Rewrite all 26 ../ and ../../ imports to #src/* paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The root
AGENTS.mdImports convention states:A repo-wide scan found this was the single most-violated convention class. All 26 cross-directory
..//../../intra-package imports lived in@contextbridge/annotation— the one library package that also failed to declare the#src/*mapping. Every other package (cli,context,harness,instrumentation,server,shared,skills,storage,ui) already declares the mapping and uses#src/*.This is the most egregious class by all three ranking axes: highest frequency (26 instances vs. 0–1 for other candidates), unambiguous contradiction of an explicit convention, and safe to fix with zero runtime behavior change.
Changes
packages/annotation/package.json— added"imports": { "#src/*": "./src/*" }(placed after"type", matching sibling packages).packages/annotation/src/**from..//../../to#src/*. Same-directory./sibling imports were intentionally left relative, as the convention permits.Files touched:
demo/DemoStage.tsx,element/ElementAdapter.ts,element/mermaid/MermaidBlock.tsx,element/mermaid/mermaidAdapter.ts,element/mermaid/mermaidAdapter.test.ts,element/useElementTargets.ts,testHelpers/FakeThemeController.ts,testHelpers/appContextDecorator.tsx,testHelpers/createFakeAppContext.ts,testHelpers/index.tsx,testHelpers/renderAnnotationHook.tsx.Verification
bun run --cwd packages/annotation typecheck— passes (confirms#src/*resolves undertscbundler resolution and Node packageimports).bun run format:check— passes.bun run lint(--max-warnings 0) — passes.The only remaining
../../references in the codebase are cross-package bundled-asset text imports (../../../annotation/dist/index.html,../../../harnessIntegrations/.../SKILL.md) which intentionally reach into build outputs and are outside the intra-package subpath convention.Other violation classes noted (not addressed, per one-class-per-run)
#src/*mapping inpackages/review— the review package also lacks the imports field, but it's a WIP scaffold with no cross-directory imports yet, so there's nothing to convert.createDeferredinpackages/instrumentation/src/node/harnessDiscovery.test.ts(1 instance) — violates the testing-patterns rule "Use the shared deferred-promise helper; do not hand-roll it" (@contextbridge/shared/testHelpers).createXxx()test fixtures with inline object literals (e.g.createHookDependencies,createFakeReviewDeps,createReportFixture,createFakeClient) instead of FisheryFactory.define<T>()factories — several instances across cli/context/instrumentation test files.