Skip to content

Replace deep workspace imports with package exports#27347

Merged
9larsons merged 1 commit intomainfrom
fix-admin-cross-imports
Apr 11, 2026
Merged

Replace deep workspace imports with package exports#27347
9larsons merged 1 commit intomainfrom
fix-admin-cross-imports

Conversation

@9larsons
Copy link
Copy Markdown
Contributor

@9larsons 9larsons commented Apr 11, 2026

Summary

  • Add exports field to posts, stats, and activitypub package.json with subpath exports
  • Create src/api.ts in posts and stats as the public cross-package API
  • Update admin to import from @tryghost/posts/api, @tryghost/stats/api, @tryghost/activitypub/api instead of reaching into src/

Why

Admin was importing directly into other workspace packages' src/ directories (@tryghost/posts/src/providers/...). This is a cross-package boundary violation — it bypasses the package's public API and couples admin to internal file structure.

Scope

This is prep work for pnpm deploy with injectWorkspacePackages=true. The subpath exports currently point at source files (./src/api.ts), which works for normal workspace resolution (pnpm symlinks to the full directory). When injectWorkspacePackages is enabled, the files field in each package will need to include src/ (or the exports will need to point at built outputs in dist/). That change belongs in the pnpm deploy PR.

What changed

Posts — new src/api.ts exports: PostsAppContextProvider, routes, parseAllSharedViewsJSON, SharedView type. New ./members subpath export for lazy-loaded members view.

Stats — new src/api.ts exports: GlobalDataProvider, routes.

ActivityPub — new ./api subpath export pointing to existing src/index.tsx.

Admin — all 8 deep src/ imports replaced with subpath exports.

Test plan

  • pnpm build passes locally (except pre-existing stats test type issue)
  • CI passes
  • pnpm dev works correctly

Admin was importing directly into workspace packages' src/ directories:
  @tryghost/posts/src/providers/posts-app-context
  @tryghost/posts/src/routes
  @tryghost/posts/src/views/members/members
  @tryghost/posts/src/views/members/shared-views
  @tryghost/stats/src/providers/global-data-provider
  @tryghost/stats/src/routes
  @tryghost/activitypub/src/index

These deep imports break with pnpm's inject-workspace-packages because
injected copies only include files declared in the package.json "files"
field, not the full source tree.

Fix: add explicit exports to posts, stats, and activitypub via subpath
exports in package.json, and update admin to import from the public API
instead of internal src/ paths.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

Walkthrough

This pull request introduces standardized public API entrypoints for the activitypub, posts, and stats packages by adding exports maps to their package.json files and creating API modules that re-export selected public symbols. The admin package is updated to import from these new API entrypoints instead of directly referencing internal src paths. This establishes a stable, version-independent interface for cross-package imports.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: replacing deep workspace imports with package exports via new subpath exports.
Description check ✅ Passed The pull request description clearly explains the changes (adding exports fields and subpath exports, creating src/api.ts files, updating admin imports), the motivation (avoiding cross-package boundary violations and preparing for pnpm deploy), and the scope of affected packages.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-admin-cross-imports

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/activitypub/package.json`:
- Around line 17-23: The package "exports" entry for "./api" points to source
file "./src/index.tsx" which is not included in the package "files" list,
causing resolution failures; update the package.json so that the "./api" export
points to a built/distributed entry (e.g. the corresponding file under "dist")
or add the "src/index.tsx" into the "files" array; specifically, change the
"./api" export target from "./src/index.tsx" to the compiled output (matching
how "." maps to "./dist/activitypub.js") or add "./src/index.tsx" to "files" to
ensure consumers can resolve `@tryghost/activitypub/api` (apply the same fix for
the analogous entries in apps/stats and apps/posts package.json).

In `@apps/posts/package.json`:
- Around line 17-24: The package.json currently exports "./api" and "./members"
pointing at source files ("./src/api.ts" and "./src/views/members/members.tsx")
while the "files" field only includes "dist/", which will break consumers of the
built package; either add "src/" to the "files" array so those source paths are
published, or (preferably) update the build to emit compiled equivalents into
dist/ and change the exports for "./api" and "./members" to point at their built
files in dist/ (e.g., dist/api.js, dist/views/members/members.js) and ensure the
build pipeline (tsconfig/rollup/webpack) includes those entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0c452e6c-d19f-48cc-b634-f0c30910e634

📥 Commits

Reviewing files that changed from the base of the PR and between 370f405 and 1b610e2.

📒 Files selected for processing (8)
  • apps/activitypub/package.json
  • apps/admin/src/layout/app-sidebar/nav-main.tsx
  • apps/admin/src/layout/app-sidebar/shared-views.ts
  • apps/admin/src/routes.tsx
  • apps/posts/package.json
  • apps/posts/src/api.ts
  • apps/stats/package.json
  • apps/stats/src/api.ts

@9larsons 9larsons merged commit 972e295 into main Apr 11, 2026
42 checks passed
@9larsons 9larsons deleted the fix-admin-cross-imports branch April 11, 2026 17:40
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.

1 participant