Skip to content

Commit 73babcf

Browse files
ceccecclaude
andcommitted
refactor: consolidate getPayload + deploymentTarget onto src/lib
Two divergent getPayload entries existed: src/lib/getPayload.ts (thin, raw Payload Local API) and src/plugins/payload-runtime/getPayload.ts (194 lines: a deepUuidWrap Proxy + initializePlatformBackends). The Proxy was a no-op (deepUuidWrap returns its input unchanged) and the platform-backend singletons (getCacheBackend/getStorageBackend/getImageTransformer) are read only by unit tests, so the two entries were behaviorally identical for every runtime path. - Migrate the 10 payload-runtime/getPayload importers (+ the jest.mock path) onto @root/lib/getPayload; drop the no-op Proxy and the dead backend bootstrap. - The two deploymentTarget copies differed only in formatting / relative-import depth; migrate the 2 payload-runtime/deploymentTarget importers onto @root/lib/deploymentTarget. - Remove the now-empty src/plugins/payload-runtime/ directory. - Note in lib/cache + lib/storage that the backend init is no longer auto-invoked. Verified: tsc 0; dev server boots and serves home/admin/post (200, seeded content). Tests not run — jest config is broken under ESM (pre-existing, tracked separately). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent fa78797 commit 73babcf

17 files changed

Lines changed: 23 additions & 261 deletions

File tree

src/__tests__/integration/api/stripe.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { NextRequest } from 'next/server'
1010
/**
1111
* Mock Payload and Stripe modules
1212
*/
13-
jest.mock('@root/plugins/payload-runtime/getPayload', () => ({
13+
jest.mock('@root/lib/getPayload', () => ({
1414
getPayload: jest.fn(),
1515
}))
1616

1717
jest.mock('@root/plugins/site-billing/marketingCheckout', () => ({
1818
createMarketingCheckout: jest.fn(),
1919
}))
2020

21-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
21+
import { getPayload } from '@root/lib/getPayload'
2222
import { createMarketingCheckout } from '@root/plugins/site-billing/marketingCheckout'
2323

2424
/**

src/app/(frontend)/(cloud)/cloud/_actions/paymentActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* ```
1414
*/
1515

16-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
16+
import { getPayload } from '@root/lib/getPayload'
1717
import type { SetupIntentResponse, SubscriptionResponse } from '@root/plugins/payments'
1818
import { getPaymentProvider } from '@root/plugins/payments'
1919
import {

src/app/api/docs-local-search/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDeploymentTarget } from '@root/plugins/payload-runtime/deploymentTarget'
1+
import { getDeploymentTarget } from '@root/lib/deploymentTarget'
22
import { execFile } from 'node:child_process'
33
import fs from 'node:fs'
44
import path from 'node:path'

src/app/api/preview/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
import type { PayloadRequest } from 'payload'
33

4-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
4+
import { getPayload } from '@root/lib/getPayload'
55
import { draftMode } from 'next/headers'
66
import { redirect } from 'next/navigation'
77

src/app/api/share/[token]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { NextRequest } from 'next/server'
22

3-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
3+
import { getPayload } from '@root/lib/getPayload'
44
import { formatPagePath } from '@root/utilities/formatPagePath'
55
import { NextResponse } from 'next/server'
66

src/app/api/stripe/billing-portal/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
import type { PayloadRequest } from 'payload'
33

4-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
4+
import { getPayload } from '@root/lib/getPayload'
55
import { createMarketingBillingSession } from '@root/plugins/site-billing/marketingBilling'
66
import { NextResponse } from 'next/server'
77

src/app/api/stripe/checkout-session/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextRequest } from 'next/server'
22
import type { PayloadRequest } from 'payload'
33

4-
import { getPayload } from '@root/plugins/payload-runtime/getPayload'
4+
import { getPayload } from '@root/lib/getPayload'
55
import { createMarketingCheckout } from '@root/plugins/site-billing/marketingCheckout'
66
import { NextResponse } from 'next/server'
77

src/lib/cache/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@ export class MemoryCacheBackend implements CacheBackend {
142142
let globalCacheBackend: CacheBackend | null = null
143143

144144
/**
145-
* Initialize the global cache backend
146-
* Called during app startup in src/plugins/payload-runtime/getPayload.ts
145+
* Initialize the global cache backend.
146+
*
147+
* Not currently auto-invoked: the platform-backend bootstrap was removed when the two getPayload
148+
* entries were consolidated onto `@root/lib/getPayload`. Nothing in the app reads this backend yet
149+
* (only unit tests) — call this explicitly once a consumer is wired up.
147150
*/
148151
export function initializeCacheBackend(backend: CacheBackend): void {
149152
globalCacheBackend = backend

src/lib/storage/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ export class MemoryStorageBackend implements StorageBackend {
208208
let globalStorageBackend: StorageBackend | null = null
209209

210210
/**
211-
* Initialize the global storage backend
212-
* Called during app startup in src/plugins/payload-runtime/getPayload.ts
211+
* Initialize the global storage backend.
212+
*
213+
* Not currently auto-invoked: the platform-backend bootstrap was removed when the two getPayload
214+
* entries were consolidated onto `@root/lib/getPayload`. Nothing in the app reads this backend yet
215+
* (only unit tests) — call this explicitly once a consumer is wired up.
213216
*/
214217
export function initializeStorageBackend(backend: StorageBackend): void {
215218
globalStorageBackend = backend

src/platform/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { DeploymentTarget } from '@root/plugins/payload-runtime/deploymentTarget'
1+
import type { DeploymentTarget } from '@root/lib/deploymentTarget'
22
import type { TypedLocale } from 'payload'
33

44
/**

0 commit comments

Comments
 (0)