chore: establishes package pattern

This commit is contained in:
James
2023-11-15 16:00:45 -05:00
parent 0996f8cccb
commit fee8838e7b
20 changed files with 243 additions and 47 deletions

View File

@@ -1,9 +1,9 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
// experimental: { experimental: {
// serverComponentsExternalPackages: ['@payloadcms/db-mongodb'], serverComponentsExternalPackages: ['@payloadcms/db-mongodb', 'mongoose'],
// }, },
// transpilePackages: ['@payloadcms/db-mongodb'], transpilePackages: ['@payloadcms/db-mongodb', 'mongoose'],
webpack: (config) => { webpack: (config) => {
return { return {
...config, ...config,

View File

@@ -9,12 +9,13 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"next": "14.0.2-canary.18", "next": "14.0.2",
"react": "^18", "react": "^18",
"react-dom": "^18" "react-dom": "^18"
}, },
"devDependencies": { "devDependencies": {
"@payloadcms/db-mongodb": "workspace:*", "@payloadcms/db-mongodb": "workspace:*",
"@payloadcms/next": "workspace:*",
"@payloadcms/richtext-lexical": "workspace:*", "@payloadcms/richtext-lexical": "workspace:*",
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^18", "@types/react": "^18",

View File

@@ -1,4 +1,6 @@
import { initHandler } from 'payload/handlers' /* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import { init } from '@payloadcms/next/handlers'
import config from 'payload-config' import config from 'payload-config'
export const GET = initHandler({ config }) export const GET = init({ config })

View File

@@ -12,16 +12,19 @@
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"composite": true, // Make sure typescript knows that this module depends on their references
"plugins": [ "plugins": [
{ {
"name": "next" "name": "next"
} }
], ],
"paths": { "paths": {
"payload-config": ["./src/payload.config.ts"] "payload-config": ["./src/payload.config.ts"],
"@payloadcms/next/*": ["../next/src/exports/*.ts"]
} }
}, },
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"], "include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"], "exclude": ["node_modules"],
"references": [{ "path": "../payload" }] "composite": true, // Make sure typescript knows that this module depends on their references
"references": [{ "path": "../payload" }, { "path": "../next" }]
} }

View File

@@ -0,0 +1,41 @@
{
"name": "@payloadcms/next",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"clean": "rimraf {dist,*.tsbuildinfo}",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
"prepublishOnly": "pnpm clean && pnpm build"
},
"exports": {
"./*": {
"import": "./src/exports/*.ts",
"require": "./src/exports/*.ts",
"types": "./src/exports/*.ts"
}
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"payload": "workspace:*"
},
"peerDependencies": {
"payload": "^2.0.0"
},
"publishConfig": {
"exports": {
"./*": {
"import": "./dist/exports/*.ts",
"require": "./dist/exports/*.ts",
"types": "./dist/exports/*.d.ts"
}
},
"registry": "https://registry.npmjs.org/",
"types": "./dist/index.d.ts"
},
"files": [
"dist"
]
}

View File

@@ -0,0 +1,6 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import { init } from '@payloadcms/next/handlers'
import config from 'payload-config'
export const GET = init({ config })

View File

@@ -0,0 +1,3 @@
import { SanitizedConfig } from 'payload/config'
export default {} as Promise<SanitizedConfig>

View File

@@ -0,0 +1,17 @@
import type { SanitizedConfig, PayloadRequest } from 'payload/types'
import { getPayload } from 'payload'
type Args = {
request: Request
config: Promise<SanitizedConfig>
}
export const createPayloadRequest = async ({ request, config }: Args): Promise<PayloadRequest> => {
const payload = await getPayload({ config })
const req: PayloadRequest = Object.assign(request, {
payload,
})
return req
}

View File

@@ -0,0 +1 @@
export { init } from '../handlers/init'

View File

@@ -0,0 +1,15 @@
import type { SanitizedConfig } from 'payload/types'
import { init as initOperation } from 'payload/operations'
import { createPayloadRequest } from '../createPayloadRequest'
export const init = ({ config }: { config: Promise<SanitizedConfig> }) =>
async function (request: Request, { params }: { params: { collection: string } }) {
const req = await createPayloadRequest({ request, config })
const initialized = await initOperation({
collection: params.collection,
req,
})
return Response.json({ initialized })
}

View File

View File

@@ -0,0 +1,27 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true, // Make sure typescript knows that this module depends on their references
"noEmit": false /* Do not emit outputs. */,
"emitDeclarationOnly": true,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
"paths": {
"payload-config": ["./src/config.ts"]
}
},
"exclude": [
"dist",
"build",
"tests",
"test",
"node_modules",
".eslintrc.js",
"src/**/*.spec.js",
"src/**/*.spec.jsx",
"src/**/*.spec.ts",
"src/**/*.spec.tsx"
],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
"references": [{ "path": "../payload" }]
}

View File

@@ -1,4 +1,4 @@
import type { PayloadRequest } from '../../express/types' import type { PayloadRequest } from '../../types'
async function init(args: { collection: string; req: PayloadRequest }): Promise<boolean> { async function init(args: { collection: string; req: PayloadRequest }): Promise<boolean> {
const { collection: slug, req } = args const { collection: slug, req } = args

View File

@@ -0,0 +1 @@
export { default as init } from '../auth/operations/init'

View File

@@ -45,7 +45,7 @@ export type {
TypeWithID, TypeWithID,
} from './../collections/config/types' } from './../collections/config/types'
export type { Access, AccessArgs } from './../config/types' export type { Access, AccessArgs, SanitizedConfig } from './../config/types'
export type { export type {
ArrayField, ArrayField,

View File

@@ -1,7 +1,10 @@
import type payload from '../'
import type { TypeWithTimestamps } from '../collections/config/types' import type { TypeWithTimestamps } from '../collections/config/types'
import type { validOperators } from './constants' import type { validOperators } from './constants'
export type { PayloadRequest } from '../express/types' export type PayloadRequest = Request & {
payload: typeof payload
}
export type Operator = (typeof validOperators)[number] export type Operator = (typeof validOperators)[number]

29
packages/ui/package.json Normal file
View File

@@ -0,0 +1,29 @@
{
"name": "@payloadcms/ui",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
"build:types": "tsc --emitDeclarationOnly --outDir dist",
"clean": "rimraf {dist,*.tsbuildinfo}",
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
"prepublishOnly": "pnpm clean && pnpm build"
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"payload": "workspace:*"
},
"peerDependencies": {
"payload": "^2.0.0"
},
"publishConfig": {
"exports": null,
"main": "./dist/index.js",
"registry": "https://registry.npmjs.org/",
"types": "./dist/index.d.ts"
},
"files": [
"dist"
]
}

24
packages/ui/tsconfig.json Normal file
View File

@@ -0,0 +1,24 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true, // Make sure typescript knows that this module depends on their references
"noEmit": false /* Do not emit outputs. */,
"emitDeclarationOnly": true,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"rootDir": "./src" /* Specify the root folder within your source files. */
},
"exclude": [
"dist",
"build",
"tests",
"test",
"node_modules",
".eslintrc.js",
"src/**/*.spec.js",
"src/**/*.spec.jsx",
"src/**/*.spec.ts",
"src/**/*.spec.tsx"
],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
"references": [{ "path": "../payload" }] // db-postgres depends on payload
}

89
pnpm-lock.yaml generated
View File

@@ -498,8 +498,8 @@ importers:
packages/dev: packages/dev:
dependencies: dependencies:
next: next:
specifier: 14.0.2-canary.18 specifier: 14.0.2
version: 14.0.2-canary.18(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0) version: 14.0.2(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0)
react: react:
specifier: ^18 specifier: ^18
version: 18.2.0 version: 18.2.0
@@ -510,6 +510,9 @@ importers:
'@payloadcms/db-mongodb': '@payloadcms/db-mongodb':
specifier: workspace:* specifier: workspace:*
version: link:../db-mongodb version: link:../db-mongodb
'@payloadcms/next':
specifier: workspace:*
version: link:../next
'@payloadcms/richtext-lexical': '@payloadcms/richtext-lexical':
specifier: workspace:* specifier: workspace:*
version: link:../richtext-lexical version: link:../richtext-lexical
@@ -605,6 +608,15 @@ importers:
specifier: workspace:* specifier: workspace:*
version: link:../payload version: link:../payload
packages/next:
devDependencies:
'@payloadcms/eslint-config':
specifier: workspace:*
version: link:../eslint-config-payload
payload:
specifier: workspace:*
version: link:../payload
packages/payload: packages/payload:
dependencies: dependencies:
'@date-io/date-fns': '@date-io/date-fns':
@@ -1309,6 +1321,15 @@ importers:
specifier: workspace:* specifier: workspace:*
version: link:../payload version: link:../payload
packages/ui:
devDependencies:
'@payloadcms/eslint-config':
specifier: workspace:*
version: link:../eslint-config-payload
payload:
specifier: workspace:*
version: link:../payload
packages: packages:
/@aashutoshrathi/word-wrap@1.2.6: /@aashutoshrathi/word-wrap@1.2.6:
@@ -4180,12 +4201,12 @@ packages:
sparse-bitfield: 3.0.3 sparse-bitfield: 3.0.3
optional: true optional: true
/@next/env@14.0.2-canary.18: /@next/env@14.0.2:
resolution: {integrity: sha512-P0TbiW5a1H2EjHuVsx1hcYRokZRNd8BxPIqw8GG9ZDbMLRQMZQt9MBhyQDavPjPaKvHenTsw2cztPjDxGkKBig==} resolution: {integrity: sha512-HAW1sljizEaduEOes/m84oUqeIDAUYBR1CDwu2tobNlNDFP3cSm9d6QsOsGeNlIppU1p/p1+bWbYCbvwjFiceA==}
dev: false dev: false
/@next/swc-darwin-arm64@14.0.2-canary.18: /@next/swc-darwin-arm64@14.0.2:
resolution: {integrity: sha512-7zEjO7sTC5vfYpIln8CFYO/Nm5mMZkdfMU/bpRA3SMyM2WWg5k9M+TEoJ71rQ3GpMvC9N5VzUJ8B2tRC8H/1Tw==} resolution: {integrity: sha512-i+jQY0fOb8L5gvGvojWyZMfQoQtDVB2kYe7fufOEiST6sicvzI2W5/EXo4lX5bLUjapHKe+nFxuVv7BA+Pd7LQ==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [darwin] os: [darwin]
@@ -4193,8 +4214,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-darwin-x64@14.0.2-canary.18: /@next/swc-darwin-x64@14.0.2:
resolution: {integrity: sha512-2Jtr2HeR5YNFyyVV4nmwIVrpz97+fu+eqIsZC8JbwDcWtd4+Bbd/MnN7XCdyUHFrrhGBuRbX52LxMTMl9tnY6Q==} resolution: {integrity: sha512-zRCAO0d2hW6gBEa4wJaLn+gY8qtIqD3gYd9NjruuN98OCI6YyelmhWVVLlREjS7RYrm9OUQIp/iVJFeB6kP1hg==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [darwin] os: [darwin]
@@ -4202,8 +4223,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-linux-arm64-gnu@14.0.2-canary.18: /@next/swc-linux-arm64-gnu@14.0.2:
resolution: {integrity: sha512-+p5xZod0o9HBffPH6s0/m8XXKK5/mmZK7jORyHBqGihOVZEuJFl0hGNNBqnIE7brUuRdGLlS4EYQvEHqtC9z3A==} resolution: {integrity: sha512-tSJmiaon8YaKsVhi7GgRizZoV0N1Sx5+i+hFTrCKKQN7s3tuqW0Rov+RYdPhAv/pJl4qiG+XfSX4eJXqpNg3dA==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
@@ -4211,8 +4232,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-linux-arm64-musl@14.0.2-canary.18: /@next/swc-linux-arm64-musl@14.0.2:
resolution: {integrity: sha512-T7aXq6S6PlobMDEyxEb7B9hB3cMu6A9gWjD3gx6FrQEWp/V3+TrbBN/mXSpsT7QtvS1WA+vuK7jnS2IvpcJtXw==} resolution: {integrity: sha512-dXJLMSEOwqJKcag1BeX1C+ekdPPJ9yXbWIt3nAadhbLx5CjACoB2NQj9Xcqu2tmdr5L6m34fR+fjGPs+ZVPLzA==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [linux] os: [linux]
@@ -4220,8 +4241,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-linux-x64-gnu@14.0.2-canary.18: /@next/swc-linux-x64-gnu@14.0.2:
resolution: {integrity: sha512-aIKt/fUlSmpiBmprMXpcNSryAVaoW2/GbEsL1qvu5u6/oG85tKf7wtAkudF0UqVji8RM59YTqpn9iGeAdSpCfA==} resolution: {integrity: sha512-WC9KAPSowj6as76P3vf1J3mf2QTm3Wv3FBzQi7UJ+dxWjK3MhHVWsWUo24AnmHx9qDcEtHM58okgZkXVqeLB+Q==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
@@ -4229,8 +4250,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-linux-x64-musl@14.0.2-canary.18: /@next/swc-linux-x64-musl@14.0.2:
resolution: {integrity: sha512-0eeuzkyVpfEodkSH3NNOAPq3/Zgb5l8nrpsWA7+bw7wztPuY41g+roD2BcslpZ1LaCgD38d4g7NPmXpKcGGVIA==} resolution: {integrity: sha512-KSSAwvUcjtdZY4zJFa2f5VNJIwuEVnOSlqYqbQIawREJA+gUI6egeiRu290pXioQXnQHYYdXmnVNZ4M+VMB7KQ==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [linux] os: [linux]
@@ -4238,8 +4259,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-win32-arm64-msvc@14.0.2-canary.18: /@next/swc-win32-arm64-msvc@14.0.2:
resolution: {integrity: sha512-wqA/P/tkb8VN22xLvekO5Ze+p3xuNPzzeIx+MFgxMZownxsMaRr9mjMZs7JgS3SXn3XYEIO98FVZoXCXPmC1Tg==} resolution: {integrity: sha512-2/O0F1SqJ0bD3zqNuYge0ok7OEWCQwk55RPheDYD0va5ij7kYwrFkq5ycCRN0TLjLfxSF6xI5NM6nC5ux7svEQ==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [arm64] cpu: [arm64]
os: [win32] os: [win32]
@@ -4247,8 +4268,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-win32-ia32-msvc@14.0.2-canary.18: /@next/swc-win32-ia32-msvc@14.0.2:
resolution: {integrity: sha512-5p6vXquoHiJ16agnghlCtCLj8zzAH54AEZr8Y8wsvHwH2afxqQgd/8WdnkSdpoqlKEkzD/GQyHkpJ0mwkiyvAw==} resolution: {integrity: sha512-vJI/x70Id0oN4Bq/R6byBqV1/NS5Dl31zC+lowO8SDu1fHmUxoAdILZR5X/sKbiJpuvKcCrwbYgJU8FF/Gh50Q==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [ia32] cpu: [ia32]
os: [win32] os: [win32]
@@ -4256,8 +4277,8 @@ packages:
dev: false dev: false
optional: true optional: true
/@next/swc-win32-x64-msvc@14.0.2-canary.18: /@next/swc-win32-x64-msvc@14.0.2:
resolution: {integrity: sha512-JCrMBHM8KXZONoLVwbBghLVZxXkshpkZpl1mRlAEHLnYVSp6nXhV40pNDSHUP4lpd9hYTRXZF34BjzdLa8LB1Q==} resolution: {integrity: sha512-Ut4LXIUvC5m8pHTe2j0vq/YDnTEyq6RSR9vHYPqnELrDapPhLNz9Od/L5Ow3J8RNDWpEnfCiQXuVdfjlNEJ7ug==}
engines: {node: '>= 10'} engines: {node: '>= 10'}
cpu: [x64] cpu: [x64]
os: [win32] os: [win32]
@@ -13246,8 +13267,8 @@ packages:
/next-tick@1.1.0: /next-tick@1.1.0:
resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==}
/next@14.0.2-canary.18(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0): /next@14.0.2(@babel/core@7.22.20)(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-ulPinl+SEPCn6BGYznkHQZE9YBW9TA1dJJyD8NUeJIriHN0ag28S5kzfgAYVKSQGyxViNETfroiyNDbZDV0gMQ==} resolution: {integrity: sha512-jsAU2CkYS40GaQYOiLl9m93RTv2DA/tTJ0NRlmZIBIL87YwQ/xR8k796z7IqgM3jydI8G25dXvyYMC9VDIevIg==}
engines: {node: '>=18.17.0'} engines: {node: '>=18.17.0'}
hasBin: true hasBin: true
peerDependencies: peerDependencies:
@@ -13261,7 +13282,7 @@ packages:
sass: sass:
optional: true optional: true
dependencies: dependencies:
'@next/env': 14.0.2-canary.18 '@next/env': 14.0.2
'@swc/helpers': 0.5.2 '@swc/helpers': 0.5.2
busboy: 1.6.0 busboy: 1.6.0
caniuse-lite: 1.0.30001535 caniuse-lite: 1.0.30001535
@@ -13271,15 +13292,15 @@ packages:
styled-jsx: 5.1.1(@babel/core@7.22.20)(react@18.2.0) styled-jsx: 5.1.1(@babel/core@7.22.20)(react@18.2.0)
watchpack: 2.4.0 watchpack: 2.4.0
optionalDependencies: optionalDependencies:
'@next/swc-darwin-arm64': 14.0.2-canary.18 '@next/swc-darwin-arm64': 14.0.2
'@next/swc-darwin-x64': 14.0.2-canary.18 '@next/swc-darwin-x64': 14.0.2
'@next/swc-linux-arm64-gnu': 14.0.2-canary.18 '@next/swc-linux-arm64-gnu': 14.0.2
'@next/swc-linux-arm64-musl': 14.0.2-canary.18 '@next/swc-linux-arm64-musl': 14.0.2
'@next/swc-linux-x64-gnu': 14.0.2-canary.18 '@next/swc-linux-x64-gnu': 14.0.2
'@next/swc-linux-x64-musl': 14.0.2-canary.18 '@next/swc-linux-x64-musl': 14.0.2
'@next/swc-win32-arm64-msvc': 14.0.2-canary.18 '@next/swc-win32-arm64-msvc': 14.0.2
'@next/swc-win32-ia32-msvc': 14.0.2-canary.18 '@next/swc-win32-ia32-msvc': 14.0.2
'@next/swc-win32-x64-msvc': 14.0.2-canary.18 '@next/swc-win32-x64-msvc': 14.0.2
transitivePeerDependencies: transitivePeerDependencies:
- '@babel/core' - '@babel/core'
- babel-plugin-macros - babel-plugin-macros

View File

@@ -39,6 +39,8 @@
{ "path": "./packages/payload" }, { "path": "./packages/payload" },
{ "path": "./packages/plugin-nested-docs" }, { "path": "./packages/plugin-nested-docs" },
{ "path": "./packages/live-preview" }, { "path": "./packages/live-preview" },
{ "path": "./packages/live-preview-react" } { "path": "./packages/live-preview-react" },
{ "path": "./packages/next" },
{ "path": "./packages/ui" }
] ]
} }