-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cms): update to payload 3 and fix breaking changes
closed COD-268
- Loading branch information
Showing
151 changed files
with
7,799 additions
and
6,150 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,4 @@ apps/**/pnpm-lock.yaml | |
|
||
# Next.js | ||
.next | ||
out | ||
out |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"jsc": { | ||
"target": "es2017", | ||
"parser": { | ||
"syntax": "typescript", | ||
"decorators": true, | ||
"dynamicImport": true | ||
}, | ||
"transform": { | ||
"decoratorMetadata": true, | ||
"legacyDecorator": true | ||
}, | ||
"keepClassNames": true, | ||
"externalHelpers": true, | ||
"loose": true | ||
}, | ||
"module": { | ||
"type": "commonjs" | ||
}, | ||
"sourceMaps": true, | ||
"exclude": [ | ||
"jest.config.ts", | ||
".*\\.spec.tsx?$", | ||
".*\\.test.tsx?$", | ||
"./src/jest-setup.ts$", | ||
"./**/jest-setup.ts$", | ||
".*.js$", | ||
".*.d.ts$" | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,60 @@ | ||
FROM node:22-slim AS base | ||
|
||
FROM base AS builder | ||
FROM node:20-alpine AS base | ||
|
||
FROM base AS deps | ||
# Check the link to understand why libc6-compat might be needed | ||
# https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine | ||
RUN apk add --no-cache libc6-compat | ||
WORKDIR /app | ||
|
||
# Copy package.json first to leverage Docker cache for dependencies | ||
COPY package.json ./ | ||
|
||
# TODO: Remove once cms is updated to Payload v3 | ||
# Downgrade to React v18 to be compatible with Payload v2 | ||
RUN \ | ||
sed -i 's/react": "19.0.0",/react": "18.3.1",/g' package.json && \ | ||
sed -i 's/react-dom": "19.0.0",/react-dom": "18.3.1",/g' package.json && \ | ||
sed -i 's/react-router-dom": "6.11.2",/react-router-dom": "5.3.4",/g' package.json && \ | ||
sed -i 's/@types\/react": "19.0.0",/@types\/react": "18.3.12",/g' package.json && \ | ||
sed -i 's/@types\/react-dom": "19.0.0",/@types\/react-dom": "18.3.1",/g' package.json | ||
|
||
RUN npm install | ||
# Check the link regarding legacy-peer-deps | ||
# https://payloadcms.com/docs/getting-started/installation#1-install-the-relevant-packages | ||
RUN npm i --legacy-peer-deps | ||
|
||
# Copy the dependencies to builder stage. | ||
# Lock file is important for Nx to calculate a correct project graph. | ||
FROM base AS builder | ||
WORKDIR /app | ||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY --from=deps /app/package-lock.json ./package-lock.json | ||
COPY . . | ||
|
||
# The lock file is needed when building the app so remove it from `.gitignore` | ||
# The lock file is hidden from the build process when included in the .gitignore file. | ||
# Since package-lock.json is needed when building the app, we'll remove it from .gitignore. | ||
RUN sed -i '/package-lock.json/d' .gitignore | ||
|
||
RUN npx nx build cms | ||
# Next.js collects completely anonymous telemetry data about general usage. | ||
# Learn more here: https://nextjs.org/telemetry | ||
# Comment the following line in case you want to enable telemetry during the build. | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
FROM base | ||
|
||
ENV NODE_ENV=production | ||
# Path is relative to workdir, where `node` is invoked | ||
ENV PAYLOAD_CONFIG_PATH="dist/apps/cms/server/apps/cms/src/payload.config.js" | ||
RUN npx nx build cms | ||
|
||
# Production image, copy all the files and run next | ||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
COPY --from=builder /app/dist/apps/cms/package.json ./ | ||
ENV NODE_ENV production | ||
# Disable telemetry during runtime. | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=builder --chown=nextjs:nodejs /app/apps/cms/.next/standalone ./ | ||
COPY --from=builder --chown=nextjs:nodejs /app/apps/cms/.next/static ./apps/cms/.next/static | ||
COPY --from=builder --chown=nextjs:nodejs /app/apps/cms/public ./apps/cms/public | ||
|
||
RUN npm install --omit=dev | ||
# Set the correct ownership | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
RUN chown -R nextjs:nodejs /app | ||
|
||
COPY --from=builder /app/dist ./dist | ||
COPY --from=builder /app/.infisical.json ./ | ||
# Needed as part of the tsconfig paths workaround (and it's not pretty?) | ||
# Must be located where the node command is invoked | ||
COPY --from=builder /app/tsconfig.base.json ./ | ||
USER nextjs | ||
|
||
EXPOSE 3000 | ||
CMD ["node", "dist/apps/cms/server/main.js"] | ||
|
||
ENV PORT 3000 | ||
|
||
ENV HOSTNAME="0.0.0.0" | ||
CMD ["node", "apps/cms/server.js"] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
declare module '*.svg' { | ||
const content: any; | ||
export const ReactComponent: any; | ||
export default content; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
displayName: 'cms', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest', | ||
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/next/babel'] }] | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
coverageDirectory: '../../coverage/apps/cms' | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as nextHeaders from 'next/headers'; | ||
|
||
type MockNextHeaders = typeof nextHeaders; | ||
|
||
/** | ||
* Mock for `next/headers`. | ||
* | ||
* Returns `headers` with empty object. | ||
*/ | ||
const mockNextHeaders: Partial<MockNextHeaders> = { | ||
headers: jest.fn().mockResolvedValue({}) | ||
}; | ||
|
||
export const { headers } = mockNextHeaders; | ||
|
||
export default mockNextHeaders; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
|
||
/** | ||
* Mock for default import of `next/image`. | ||
* | ||
* Returns `HTMLImageElement` with `alt` set to `Mocked Next Image`. | ||
*/ | ||
export const mockNextImage = () => ({ | ||
__esModule: true, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
default: (props: any) => { | ||
// eslint-disable-next-line @next/next/no-img-element | ||
return <img {...props} alt="Mocked Next Image" />; | ||
} | ||
}); | ||
|
||
export default mockNextImage; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Mock for default import of `payload.config`. | ||
* | ||
* Returns `routes` with `admin` set to `/admin`. | ||
*/ | ||
export const mockPayloadConfig = Promise.resolve({ | ||
routes: { | ||
admin: '/admin' | ||
} | ||
}); | ||
|
||
export default mockPayloadConfig; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as payload from 'payload'; | ||
|
||
type MockPayload = typeof payload; | ||
type Payload = payload.Payload; | ||
|
||
/** | ||
* Mock for `payload`. | ||
* | ||
* Returns `getPayload` with `auth` set to unknown user. | ||
*/ | ||
const mockPayload: Partial<MockPayload> = { | ||
getPayload: jest.fn().mockResolvedValue({ | ||
auth: jest | ||
.fn() | ||
.mockResolvedValue({ user: null } as Partial<Payload['auth']>) | ||
} as Partial<Payload>) | ||
}; | ||
|
||
export const { getPayload } = mockPayload; | ||
|
||
export default mockPayload; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information. |
Oops, something went wrong.