Replace deep workspace imports with package exports#27347
Conversation
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.
WalkthroughThis pull request introduces standardized public API entrypoints for the activitypub, posts, and stats packages by adding 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
apps/activitypub/package.jsonapps/admin/src/layout/app-sidebar/nav-main.tsxapps/admin/src/layout/app-sidebar/shared-views.tsapps/admin/src/routes.tsxapps/posts/package.jsonapps/posts/src/api.tsapps/stats/package.jsonapps/stats/src/api.ts



Summary
exportsfield to posts, stats, and activitypub package.json with subpath exportssrc/api.tsin posts and stats as the public cross-package API@tryghost/posts/api,@tryghost/stats/api,@tryghost/activitypub/apiinstead of reaching intosrc/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 deploywithinjectWorkspacePackages=true. The subpath exports currently point at source files (./src/api.ts), which works for normal workspace resolution (pnpm symlinks to the full directory). WheninjectWorkspacePackagesis enabled, thefilesfield in each package will need to includesrc/(or the exports will need to point at built outputs indist/). That change belongs in the pnpm deploy PR.What changed
Posts — new
src/api.tsexports:PostsAppContextProvider,routes,parseAllSharedViewsJSON,SharedViewtype. New./memberssubpath export for lazy-loaded members view.Stats — new
src/api.tsexports:GlobalDataProvider,routes.ActivityPub — new
./apisubpath export pointing to existingsrc/index.tsx.Admin — all 8 deep
src/imports replaced with subpath exports.Test plan
pnpm buildpasses locally (except pre-existing stats test type issue)pnpm devworks correctly