Compare commits
303 Commits
v3.0.0-alp
...
plugin-clo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8c6827b68 | ||
|
|
c038acb3a4 | ||
|
|
f8c2ccf6b1 | ||
|
|
e6092fd36c | ||
|
|
e0eae77758 | ||
|
|
0780ff22bb | ||
|
|
e7f6bfbe9d | ||
|
|
23df60dba5 | ||
|
|
8919b86571 | ||
|
|
8104fac5ed | ||
|
|
59ef1263a5 | ||
|
|
813e3dbc98 | ||
|
|
12a23092e1 | ||
|
|
4a49beb552 | ||
|
|
80530c666e | ||
|
|
f53e2df951 | ||
|
|
db58e2bab2 | ||
|
|
d88e97e123 | ||
|
|
bb72e506e6 | ||
|
|
b1f727fd6a | ||
|
|
72af18229b | ||
|
|
af52b526c8 | ||
|
|
60525623bf | ||
|
|
0fba582926 | ||
|
|
5d1cad3adb | ||
|
|
e31f72da8e | ||
|
|
7aa058d604 | ||
|
|
64e80d242e | ||
|
|
e8f2ca484e | ||
|
|
ceca5c4e97 | ||
|
|
ee13736288 | ||
|
|
815bdfac0b | ||
|
|
7a7f0ed7e8 | ||
|
|
ad42d541b3 | ||
|
|
32ed95e1ee | ||
|
|
70e57fef18 | ||
|
|
0a07f607b9 | ||
|
|
3918fc7c21 | ||
|
|
13f71ac475 | ||
|
|
07720e777a | ||
|
|
efff47e400 | ||
|
|
453ac218ea | ||
|
|
d4b09bd9cd | ||
|
|
dd67e03fc1 | ||
|
|
548de80bee | ||
|
|
2c05fbbb5e | ||
|
|
9b54659818 | ||
|
|
e9f550406e | ||
|
|
98b87e2278 | ||
|
|
5f3d0169be | ||
|
|
35c2a085ef | ||
|
|
1ac943ed5e | ||
|
|
25cee8bb10 | ||
|
|
419aef452d | ||
|
|
ea52489126 | ||
|
|
e80c70acae | ||
|
|
70b0064d0b | ||
|
|
9636bf6efd | ||
|
|
8f4d0da4e0 | ||
|
|
f0f1dbdcb0 | ||
|
|
a895aee8b1 | ||
|
|
aa1dac08c1 | ||
|
|
b8cd1c6ba4 | ||
|
|
6344464bc6 | ||
|
|
5d4022f144 | ||
|
|
bf942fdfa6 | ||
|
|
d6c25783cf | ||
|
|
82e9d31127 | ||
|
|
399e606b34 | ||
|
|
0d18822062 | ||
|
|
00fc0343da | ||
|
|
6323965c65 | ||
|
|
6d6823c3e5 | ||
|
|
ca70298436 | ||
|
|
4f565759f6 | ||
|
|
df39602758 | ||
|
|
6ea6172afa | ||
|
|
486774796d | ||
|
|
1cd1c38764 | ||
|
|
f6d7da7510 | ||
|
|
cdc4cb971b | ||
|
|
e0191b54e1 | ||
|
|
2315781f18 | ||
|
|
a0a58e7fd2 | ||
|
|
e1813fb884 | ||
|
|
da184d40ec | ||
|
|
ca8675f89d | ||
|
|
e8c6c9338d | ||
|
|
558534aff8 | ||
|
|
29c901ba9b | ||
|
|
f3876c2a39 | ||
|
|
c3a3942969 | ||
|
|
23b135b963 | ||
|
|
e3c8105cc2 | ||
|
|
2c71aaef75 | ||
|
|
922fb9b7fa | ||
|
|
0740d5095e | ||
|
|
b392d656fe | ||
|
|
c0eef90cdc | ||
|
|
db22cbdf21 | ||
|
|
1e8a6b7899 | ||
|
|
5d934ba02d | ||
|
|
f651665f2f | ||
|
|
5d3659d48a | ||
|
|
47106d5a1a | ||
|
|
afa2b942e0 | ||
|
|
20ddd0de5b | ||
|
|
64f705c3c9 | ||
|
|
b30ea8aa6b | ||
|
|
471d2113a7 | ||
|
|
8725d41164 | ||
|
|
0bd81aa25a | ||
|
|
8c09ca9be5 | ||
|
|
90d7ee3e65 | ||
|
|
58bbd8c00f | ||
|
|
003ad065c3 | ||
|
|
70715926a8 | ||
|
|
b3a6bfacf2 | ||
|
|
e1d9accb27 | ||
|
|
f2f55a84cc | ||
|
|
eba53ba60a | ||
|
|
f73d503fec | ||
|
|
6930c4e9f2 | ||
|
|
3eb681e847 | ||
|
|
cb4638cfa1 | ||
|
|
b40e9f85a2 | ||
|
|
e5a7907a72 | ||
|
|
3f25d1ca84 | ||
|
|
d5720bea7b | ||
|
|
8ce15c8b07 | ||
|
|
9f5efef78f | ||
|
|
dfba5222f3 | ||
|
|
b99d24fcfa | ||
|
|
836ed77568 | ||
|
|
1c5d5b07c8 | ||
|
|
da5f1f2240 | ||
|
|
c84c58c7b4 | ||
|
|
1c1b8f3cec | ||
|
|
3f69f83180 | ||
|
|
371353f153 | ||
|
|
a92c6334b6 | ||
|
|
eb9e771a9c | ||
|
|
ee5390aaca | ||
|
|
a861311c5a | ||
|
|
74c3fe1bb2 | ||
|
|
a2be50279e | ||
|
|
403eb06acf | ||
|
|
f5c2cd74cc | ||
|
|
a6a1963ec6 | ||
|
|
0647c870f1 | ||
|
|
3b88adc7d0 | ||
|
|
82383a5b5f | ||
|
|
f9dda628b2 | ||
|
|
93eb0e4a31 | ||
|
|
2e362f44f4 | ||
|
|
775502b161 | ||
|
|
84d75ce6ca | ||
|
|
175cf229c0 | ||
|
|
bb40bd3efb | ||
|
|
3d74c133aa | ||
|
|
0f6b6ca970 | ||
|
|
8e1692ef10 | ||
|
|
1d1ee913fc | ||
|
|
beca43341f | ||
|
|
84818469ea | ||
|
|
0a259d27b5 | ||
|
|
e2e56a4d58 | ||
|
|
d0f7677d5f | ||
|
|
35956eb837 | ||
|
|
d92af295eb | ||
|
|
493fde5ccc | ||
|
|
c6bd20ef33 | ||
|
|
6d5ac1de1e | ||
|
|
fa3b3dd62d | ||
|
|
1115387744 | ||
|
|
53e8690feb | ||
|
|
4319fe1c6e | ||
|
|
2fee0c0d44 | ||
|
|
7923edd7bc | ||
|
|
5702b83e82 | ||
|
|
63e5c43fe6 | ||
|
|
04f2888135 | ||
|
|
0f69b9c2f8 | ||
|
|
f1bb2f8151 | ||
|
|
ea528b8c10 | ||
|
|
0053e40404 | ||
|
|
605c0be43c | ||
|
|
3152b4c4c5 | ||
|
|
a64b80babc | ||
|
|
5cfde542b1 | ||
|
|
772020963e | ||
|
|
5e083689d0 | ||
|
|
911764a490 | ||
|
|
e3b81d913d | ||
|
|
41b3b17911 | ||
|
|
e9860b36f3 | ||
|
|
14b39fbc85 | ||
|
|
d08e85d08c | ||
|
|
abcbf9974d | ||
|
|
d01437d212 | ||
|
|
06729a0a73 | ||
|
|
2bd7822a16 | ||
|
|
bc7daf6b49 | ||
|
|
feab679ef7 | ||
|
|
be39ed4317 | ||
|
|
570e192eb4 | ||
|
|
22f4967dd4 | ||
|
|
4873c36129 | ||
|
|
f0ec21cdda | ||
|
|
da737bdf8e | ||
|
|
40508880c1 | ||
|
|
8f420d841a | ||
|
|
9022e27308 | ||
|
|
acf2e41312 | ||
|
|
6acfae8ee7 | ||
|
|
20bdd91da4 | ||
|
|
50502834c9 | ||
|
|
2b731c1088 | ||
|
|
983733ad74 | ||
|
|
555d02769a | ||
|
|
682eca2186 | ||
|
|
6affa1c304 | ||
|
|
1d14d9f8b8 | ||
|
|
0abaddc2ef | ||
|
|
57dc93da5d | ||
|
|
21b9453cf4 | ||
|
|
136993ec2b | ||
|
|
63bc4cabe1 | ||
|
|
6a8a6e4ef4 | ||
|
|
9828772890 | ||
|
|
6116573164 | ||
|
|
cab6babd60 | ||
|
|
55399424a1 | ||
|
|
28d3f73c2a | ||
|
|
28a30120dd | ||
|
|
40a0921597 | ||
|
|
7eae86bcb3 | ||
|
|
0b80e4a403 | ||
|
|
b378532ddf | ||
|
|
d419275fb5 | ||
|
|
0fb3a9ca89 | ||
|
|
f43cf185d4 | ||
|
|
5d15955f83 | ||
|
|
2d35e06667 | ||
|
|
d2de6db449 | ||
|
|
a3e78161b5 | ||
|
|
d543665995 | ||
|
|
db7dddf1c5 | ||
|
|
3027a03ad1 | ||
|
|
85e38b7cfd | ||
|
|
9090540ece | ||
|
|
46ef284f6b | ||
|
|
0727dcd963 | ||
|
|
52f8d4f9f0 | ||
|
|
f1fa374ed1 | ||
|
|
6b691eee43 | ||
|
|
be3beabb9b | ||
|
|
1fa00cc25c | ||
|
|
f70943524b | ||
|
|
a67080a291 | ||
|
|
69a99445c9 | ||
|
|
00d8480062 | ||
|
|
7424ba9090 | ||
|
|
ec4d2f97cb | ||
|
|
9d9ac0ec28 | ||
|
|
635e7c26e8 | ||
|
|
c4a4678afb | ||
|
|
a5a91c08a9 | ||
|
|
7db58b482b | ||
|
|
1b914083c8 | ||
|
|
657d14c07b | ||
|
|
fbf8ab72a4 | ||
|
|
997f158149 | ||
|
|
c3be5d1d5e | ||
|
|
250bcd8189 | ||
|
|
a71d37b398 | ||
|
|
5c5523195c | ||
|
|
bff4cf518f | ||
|
|
8015e999cd | ||
|
|
0c905f0da7 | ||
|
|
e691a90a4c | ||
|
|
0b2da4fba7 | ||
|
|
1c6d6788a3 | ||
|
|
ecc7978184 | ||
|
|
1b9ee64a67 | ||
|
|
22b02226c3 | ||
|
|
e4102b88d8 | ||
|
|
a099f55a69 | ||
|
|
1f1445c798 | ||
|
|
741a5e3650 | ||
|
|
365047a3fb | ||
|
|
42c06acd18 | ||
|
|
f2c8ac4a9a | ||
|
|
05e8914db7 | ||
|
|
35191bdd66 | ||
|
|
98890eee1f | ||
|
|
ef43629502 | ||
|
|
c703497924 | ||
|
|
5caad706bb | ||
|
|
aa048d5409 | ||
|
|
aafd538cf8 | ||
|
|
1b42bd207d | ||
|
|
9fac2ef24e |
@@ -1,4 +0,0 @@
|
||||
DATABASE_URI=mongodb://127.0.0.1/payloadtests
|
||||
PAYLOAD_SECRET=laijflieawfjlweifjewalifjwe
|
||||
# PAYLOAD_CONFIG_PATH=MUST BE SET PROGRAMMATICALLY
|
||||
PAYLOAD_DROP_DATABASE=true
|
||||
@@ -1,51 +0,0 @@
|
||||
module.exports = {
|
||||
extends: ['@payloadcms'],
|
||||
overrides: [
|
||||
{
|
||||
files: ['scripts/**'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'no-console': 'off',
|
||||
'perfectionist/sort-object-types': 'off',
|
||||
'perfectionist/sort-objects': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
extends: ['plugin:@typescript-eslint/disable-type-checked'],
|
||||
files: ['*.js', '*.cjs', '*.json', '*.md', '*.yml', '*.yaml'],
|
||||
},
|
||||
{
|
||||
files: ['packages/eslint-config-payload/**'],
|
||||
rules: {
|
||||
'perfectionist/sort-objects': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['package.json', 'tsconfig.json'],
|
||||
rules: {
|
||||
'perfectionist/sort-array-includes': 'off',
|
||||
'perfectionist/sort-astro-attributes': 'off',
|
||||
'perfectionist/sort-classes': 'off',
|
||||
'perfectionist/sort-enums': 'off',
|
||||
'perfectionist/sort-exports': 'off',
|
||||
'perfectionist/sort-imports': 'off',
|
||||
'perfectionist/sort-interfaces': 'off',
|
||||
'perfectionist/sort-jsx-props': 'off',
|
||||
'perfectionist/sort-keys': 'off',
|
||||
'perfectionist/sort-maps': 'off',
|
||||
'perfectionist/sort-named-exports': 'off',
|
||||
'perfectionist/sort-named-imports': 'off',
|
||||
'perfectionist/sort-object-types': 'off',
|
||||
'perfectionist/sort-objects': 'off',
|
||||
'perfectionist/sort-svelte-attributes': 'off',
|
||||
'perfectionist/sort-union-types': 'off',
|
||||
'perfectionist/sort-vue-attributes': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.json'],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
root: true,
|
||||
}
|
||||
@@ -5,6 +5,12 @@ module.exports = {
|
||||
extends: ['plugin:@typescript-eslint/disable-type-checked'],
|
||||
files: ['*.js', '*.cjs', '*.json', '*.md', '*.yml', '*.yaml'],
|
||||
},
|
||||
{
|
||||
files: ['packages/eslint-config-payload/**'],
|
||||
rules: {
|
||||
'perfectionist/sort-objects': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['package.json', 'tsconfig.json'],
|
||||
rules: {
|
||||
@@ -28,9 +34,5 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.json'],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
root: true,
|
||||
}
|
||||
79
.github/workflows/main.yml
vendored
79
.github/workflows/main.yml
vendored
@@ -4,7 +4,7 @@ on:
|
||||
pull_request:
|
||||
types: [ opened, reopened, synchronize ]
|
||||
push:
|
||||
branches: ['main', 'feat/next-poc']
|
||||
branches: [ 'main' ]
|
||||
|
||||
jobs:
|
||||
changes:
|
||||
@@ -71,7 +71,7 @@ jobs:
|
||||
${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
|
||||
- run: pnpm install
|
||||
- run: pnpm run build:core
|
||||
- run: pnpm run build
|
||||
|
||||
- name: Cache build
|
||||
uses: actions/cache@v3
|
||||
@@ -79,44 +79,6 @@ jobs:
|
||||
path: ./*
|
||||
key: ${{ github.sha }}-${{ github.run_number }}
|
||||
|
||||
plugins-build:
|
||||
needs: changes
|
||||
if: ${{ needs.changes.outputs.needs_build == 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 25
|
||||
|
||||
- name: Use Node.js 18
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
shell: bash
|
||||
run: |
|
||||
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/cache@v3
|
||||
name: Setup pnpm cache
|
||||
with:
|
||||
path: ${{ env.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-
|
||||
${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
|
||||
- run: pnpm install
|
||||
- run: pnpm run build:plugins
|
||||
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
needs: core-build
|
||||
@@ -275,6 +237,43 @@ jobs:
|
||||
- name: Generate GraphQL schema file
|
||||
run: pnpm dev:generate-graphql-schema graphql-schema-gen
|
||||
|
||||
build-packages:
|
||||
runs-on: ubuntu-latest
|
||||
needs: core-build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
pkg:
|
||||
- db-mongodb
|
||||
- db-postgres
|
||||
- bundler-webpack
|
||||
- bundler-vite
|
||||
- richtext-slate
|
||||
- richtext-lexical
|
||||
- live-preview
|
||||
- live-preview-react
|
||||
|
||||
steps:
|
||||
- name: Use Node.js 18
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 8
|
||||
run_install: false
|
||||
|
||||
- name: Restore build
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ./*
|
||||
key: ${{ github.sha }}-${{ github.run_number }}
|
||||
|
||||
- name: Build ${{ matrix.pkg }}
|
||||
run: pnpm turbo run build --filter=${{ matrix.pkg }}
|
||||
|
||||
plugins:
|
||||
runs-on: ubuntu-latest
|
||||
needs: core-build
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -8,11 +8,7 @@ test-results
|
||||
.devcontainer
|
||||
.localstack
|
||||
/migrations
|
||||
/media
|
||||
.localstack
|
||||
.turbo
|
||||
|
||||
.turbo
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/node,macos,windows,webstorm,sublimetext,visualstudiocode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node,macos,windows,webstorm,sublimetext,visualstudiocode
|
||||
|
||||
@@ -1 +1 @@
|
||||
v18.19.1
|
||||
v18.17.1
|
||||
|
||||
8
.vscode/launch.json
vendored
8
.vscode/launch.json
vendored
@@ -2,12 +2,6 @@
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
"configurations": [
|
||||
{
|
||||
"command": "pnpm dev",
|
||||
"name": "Run Dev 3.0",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
},
|
||||
{
|
||||
"command": "pnpm run dev _community",
|
||||
"cwd": "${workspaceFolder}",
|
||||
@@ -33,7 +27,7 @@
|
||||
"type": "node-terminal"
|
||||
},
|
||||
{
|
||||
"command": "pnpm run dev:postgres versions",
|
||||
"command": "pnpm run dev:postgres fields",
|
||||
"cwd": "${workspaceFolder}",
|
||||
"name": "Run Dev Postgres",
|
||||
"request": "launch",
|
||||
|
||||
33
.vscode/settings.json
vendored
33
.vscode/settings.json
vendored
@@ -5,21 +5,21 @@
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
"source.fixAll.eslint": true
|
||||
}
|
||||
},
|
||||
"[typescriptreact]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
"source.fixAll.eslint": true
|
||||
}
|
||||
},
|
||||
"[javascript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
"source.fixAll.eslint": true
|
||||
}
|
||||
},
|
||||
"[json]": {
|
||||
@@ -35,30 +35,5 @@
|
||||
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
|
||||
"typescript.tsdk": "node_modules/typescript/lib",
|
||||
// Load .git-blame-ignore-revs file
|
||||
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".git-blame-ignore-revs"],
|
||||
"[javascript][typescript][typescriptreact]": {
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
}
|
||||
},
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#8cb5b6",
|
||||
"activityBar.background": "#8cb5b6",
|
||||
"activityBar.foreground": "#15202b",
|
||||
"activityBar.inactiveForeground": "#15202b99",
|
||||
"activityBarBadge.background": "#9c639b",
|
||||
"activityBarBadge.foreground": "#e7e7e7",
|
||||
"commandCenter.border": "#15202b99",
|
||||
"sash.hoverBorder": "#8cb5b6",
|
||||
"statusBar.background": "#6da1a2",
|
||||
"statusBar.foreground": "#15202b",
|
||||
"statusBarItem.hoverBackground": "#568586",
|
||||
"statusBarItem.remoteBackground": "#6da1a2",
|
||||
"statusBarItem.remoteForeground": "#15202b",
|
||||
"titleBar.activeBackground": "#6da1a2",
|
||||
"titleBar.activeForeground": "#15202b",
|
||||
"titleBar.inactiveBackground": "#6da1a299",
|
||||
"titleBar.inactiveForeground": "#15202b99"
|
||||
},
|
||||
"peacock.color": "#6da1a2"
|
||||
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".git-blame-ignore-revs"]
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import config from '@payload-config'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import { NotFoundView } from '@payloadcms/next/views/NotFound/index'
|
||||
|
||||
type Args = {
|
||||
params: {
|
||||
segments: string[]
|
||||
}
|
||||
searchParams: {
|
||||
[key: string]: string | string[]
|
||||
}
|
||||
}
|
||||
|
||||
const NotFound = ({ params, searchParams }: Args) => NotFoundView({ config, params, searchParams })
|
||||
|
||||
export default NotFound
|
||||
@@ -1,20 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import config from '@payload-config'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import { RootPage, generatePageMetadata } from '@payloadcms/next/views/Root/index'
|
||||
|
||||
type Args = {
|
||||
params: {
|
||||
segments: string[]
|
||||
}
|
||||
searchParams: {
|
||||
[key: string]: string | string[]
|
||||
}
|
||||
}
|
||||
|
||||
export const generateMetadata = ({ params, searchParams }: Args) =>
|
||||
generatePageMetadata({ config, params, searchParams })
|
||||
|
||||
const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })
|
||||
|
||||
export default Page
|
||||
@@ -1,9 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { REST_DELETE, REST_GET, REST_PATCH, REST_POST } from '@payloadcms/next/routes'
|
||||
|
||||
export const GET = REST_GET(config)
|
||||
export const POST = REST_POST(config)
|
||||
export const DELETE = REST_DELETE(config)
|
||||
export const PATCH = REST_PATCH(config)
|
||||
@@ -1,6 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GET_STATIC_FILE } from '@payloadcms/next/routes'
|
||||
|
||||
export const GET = GET_STATIC_FILE(config)
|
||||
@@ -1,6 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes'
|
||||
|
||||
export const GET = GRAPHQL_PLAYGROUND_GET(config)
|
||||
@@ -1,6 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
/* DO NOT MODIFY it because it could be re-written at any time. */
|
||||
import config from '@payload-config'
|
||||
import { GRAPHQL_POST } from '@payloadcms/next/routes'
|
||||
|
||||
export const POST = GRAPHQL_POST(config)
|
||||
@@ -1,15 +0,0 @@
|
||||
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
|
||||
import configPromise from '@payload-config'
|
||||
import { RootLayout } from '@payloadcms/next/layouts/Root/index'
|
||||
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
|
||||
import React from 'react'
|
||||
|
||||
import './custom.scss'
|
||||
|
||||
type Args = {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
const Layout = ({ children }: Args) => <RootLayout config={configPromise}>{children}</RootLayout>
|
||||
|
||||
export default Layout
|
||||
@@ -1,5 +0,0 @@
|
||||
export const GET = () => {
|
||||
return Response.json({
|
||||
hello: 'elliot',
|
||||
})
|
||||
}
|
||||
@@ -11,7 +11,7 @@ keywords: documentation, getting started, guide, Content Management System, cms,
|
||||
Payload requires the following software:
|
||||
|
||||
- Any JavaScript package manager (Yarn, NPM, or pnpm)
|
||||
- Node.js version 18+
|
||||
- Node.js version 16+
|
||||
- Any [compatible database](/docs/database/overview) (MongoDB or Postgres)
|
||||
|
||||
<Banner type="warning">
|
||||
|
||||
@@ -292,13 +292,11 @@ For auth-enabled Collections, this hook runs after successful `forgotPassword` o
|
||||
```ts
|
||||
import { CollectionAfterForgotPasswordHook } from 'payload/types'
|
||||
|
||||
const afterLoginHook: CollectionAfterForgotPasswordHook = async ({
|
||||
req, // full express request
|
||||
user, // user being logged in
|
||||
token, // user token
|
||||
}) => {
|
||||
return user
|
||||
}
|
||||
const afterForgotPasswordHook: CollectionAfterForgotPasswordHook = async ({
|
||||
args, // arguments passed into the operation
|
||||
context,
|
||||
collection, // The collection which this hook is being run on
|
||||
}) => {...}
|
||||
```
|
||||
|
||||
## TypeScript
|
||||
|
||||
@@ -290,5 +290,5 @@ If you've configured tests for your package, integrate them into your workf
|
||||
The best way to share and allow others to use your plugin once it is complete is to publish an NPM package. This process is straightforward and well documented, find out more about [creating and publishing a NPM package here](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages/).
|
||||
##### Add payload-plugin topic tag:
|
||||
Apply the tag **payload-plugin** to your GitHub repository. This will boost the visibility of your plugin and ensure it gets listed with [existing payload plugins](https://github.com/topics/payload-plugin).
|
||||
##### Use [Semantic Versioning](https://semver.org/) (SemVar):
|
||||
With the SemVar system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility.
|
||||
##### Use [Semantic Versioning](https://semver.org/) (SemVer):
|
||||
With the SemVer system you release version numbers that reflect the nature of changes (major, minor, patch). Ensure all major versions reference their Payload compatibility.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.7.0",
|
||||
"@faceless-ui/css-grid": "^1.2.0",
|
||||
"@faceless-ui/modal": "^2.0.2",
|
||||
"@faceless-ui/modal": "^2.0.1",
|
||||
"escape-html": "^1.0.3",
|
||||
"graphql": "^16.8.1",
|
||||
"next": "^13.5.6",
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
"@payloadcms/bundler-webpack": "latest",
|
||||
"@payloadcms/db-mongodb": "latest",
|
||||
"@payloadcms/richtext-slate": "latest",
|
||||
"@faceless-ui/modal": "^2.0.2",
|
||||
"@faceless-ui/modal": "^2.0.1",
|
||||
"@payloadcms/plugin-form-builder": "^1.0.12",
|
||||
"@payloadcms/plugin-seo": "^1.0.8",
|
||||
"dotenv": "^8.2.0",
|
||||
|
||||
@@ -69,7 +69,7 @@ For more details on this, see the [CORS](https://payloadcms.com/docs/production/
|
||||
|
||||
## Front-end
|
||||
|
||||
If you're building a website or other front-end for your tenant, you will need specify the `tenant` in your requests. For example, if you wanted to fetch all pages for the tenant `ABC`, you would make a request to `/api/pages?where[tenant][slug][equals]=abc`.
|
||||
If you're building a website or other front-end for your tenant, you will need specify the `tenant` in your requests. For example, if you wanted to fetch all pages for the tenant `ABC`, you would make a request to `/api/pages?where[tenant.name][equals]=ABC`.
|
||||
|
||||
For a head start on building a website for your tenant(s), check out the official [Website Template](https://github.com/payloadcms/template-website). It includes a page layout builder, preview, SEO, and much more. It is not multi-tenant, though, but you can easily take the concepts from that example and apply them here.
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ app.get('/', (_, res) => {
|
||||
const start = async (): Promise<void> => {
|
||||
await payload.init({
|
||||
secret: process.env.PAYLOAD_SECRET,
|
||||
mongoURL: process.env.MONGODB_URI,
|
||||
express: app,
|
||||
onInit: () => {
|
||||
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"@swc/core": "^1.3.84",
|
||||
"@swc/jest": "^0.2.29",
|
||||
"@types/jest": "^29.5.4",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"mongodb-memory-server": "^8.15.1",
|
||||
"nodemon": "^3.0.1",
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
// const nextJest = require('next/jest.js')
|
||||
|
||||
// const createJestConfig = nextJest({
|
||||
// // Provide the path to your Next.js app to load next.config.js and .env files in your test environment
|
||||
// dir: './',
|
||||
// })
|
||||
|
||||
const customJestConfig = {
|
||||
module.exports = {
|
||||
globalSetup: './test/jest.setup.ts',
|
||||
moduleNameMapper: {
|
||||
'\\.(css|scss)$': '<rootDir>/packages/payload/src/bundlers/mocks/emptyModule.js',
|
||||
@@ -20,6 +13,3 @@ const customJestConfig = {
|
||||
},
|
||||
verbose: true,
|
||||
}
|
||||
|
||||
// module.exports = createJestConfig(customJestConfig)
|
||||
export default customJestConfig
|
||||
|
||||
5
next-env.d.ts
vendored
5
next-env.d.ts
vendored
@@ -1,5 +0,0 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
@@ -1,21 +0,0 @@
|
||||
import withPayload from './packages/next/src/withPayload.js'
|
||||
import bundleAnalyzer from '@next/bundle-analyzer'
|
||||
|
||||
const withBundleAnalyzer = bundleAnalyzer({
|
||||
enabled: process.env.ANALYZE === 'true',
|
||||
})
|
||||
|
||||
export default withBundleAnalyzer(
|
||||
withPayload({
|
||||
reactStrictMode: false,
|
||||
async redirects() {
|
||||
return [
|
||||
{
|
||||
destination: '/admin',
|
||||
permanent: true,
|
||||
source: '/',
|
||||
},
|
||||
]
|
||||
},
|
||||
}),
|
||||
)
|
||||
122
package.json
122
package.json
@@ -1,45 +1,19 @@
|
||||
{
|
||||
"name": "payload-monorepo",
|
||||
"version": "3.0.0-alpha.23",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"workspaces:": [
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "pnpm run build:core",
|
||||
"build": "pnpm --filter payload run build",
|
||||
"build:all": "turbo build",
|
||||
"build:core": "turbo build --filter \"!@payloadcms/plugin-*\"",
|
||||
"build:plugins": "turbo build --filter \"@payloadcms/plugin-*\" --filter \"!@payloadcms/plugin-search\" --filter \"!@payloadcms/plugin-redirects\" --filter \"!@payloadcms/plugin-nested-docs\"",
|
||||
"build:app": "next build",
|
||||
"build:create-payload-app": "turbo build --filter create-payload-app",
|
||||
"build:db-mongodb": "turbo build --filter db-mongodb",
|
||||
"build:db-postgres": "turbo build --filter db-postgres",
|
||||
"build:eslint-config-payload": "turbo build --filter eslint-config-payload",
|
||||
"build:graphql": "turbo build --filter graphql",
|
||||
"build:live-preview": "turbo build --filter live-preview",
|
||||
"build:live-preview-react": "turbo build --filter live-preview-react",
|
||||
"build:next": "turbo build --filter next",
|
||||
"build:payload": "turbo build --filter payload",
|
||||
"build:plugin-cloud": "turbo build --filter plugin-cloud",
|
||||
"build:plugin-cloud-storage": "turbo build --filter plugin-cloud-storage",
|
||||
"build:plugin-form-builder": "turbo build --filter plugin-form-builder",
|
||||
"build:plugin-nested-docs": "turbo build --filter plugin-nested-docs",
|
||||
"build:plugin-redirects": "turbo build --filter plugin-redirects",
|
||||
"build:plugin-search": "turbo build --filter plugin-search",
|
||||
"build:plugin-sentry": "turbo build --filter plugin-sentry",
|
||||
"build:plugin-seo": "turbo build --filter plugin-seo",
|
||||
"build:plugin-stripe": "turbo build --filter plugin-stripe",
|
||||
"build:richtext-lexical": "turbo build --filter richtext-lexical",
|
||||
"build:richtext-slate": "turbo build --filter richtext-slate",
|
||||
"build:translations": "turbo build --filter translations",
|
||||
"build:ui": "turbo build --filter ui",
|
||||
"clean": "turbo clean",
|
||||
"clean:cache": "rimraf node_modules/.cache && rimraf packages/payload/node_modules/.cache && rimraf .next",
|
||||
"clean:all": "find . \\( -type d \\( -name node_modules -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} +",
|
||||
"dev": "cross-env node --no-deprecation ./test/dev.js",
|
||||
"dev:generate-graphql-schema": "NODE_OPTIONS=--no-deprecation ts-node -T ./test/generateGraphQLSchema.ts",
|
||||
"dev:generate-types": "NODE_OPTIONS=--no-deprecation ts-node -T ./test/generateTypes.ts",
|
||||
"clean": "rimraf dist && rimraf packages/payload/dist",
|
||||
"clean:cache": "rimraf node_modules/.cache && rimraf packages/payload/node_modules/.cache",
|
||||
"clean:unix": "find . \\( -type d \\( -name node_modules -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} +",
|
||||
"dev": "nodemon",
|
||||
"dev:generate-graphql-schema": "ts-node -T ./test/generateGraphQLSchema.ts",
|
||||
"dev:generate-types": "ts-node -T ./test/generateTypes.ts",
|
||||
"dev:postgres": "pnpm --filter payload run dev:postgres",
|
||||
"docker:restart": "pnpm docker:stop --remove-orphans && pnpm docker:start",
|
||||
"docker:start": "docker-compose -f packages/plugin-cloud-storage/docker-compose.yml up -d",
|
||||
@@ -49,23 +23,20 @@
|
||||
"lint-staged": "lint-staged",
|
||||
"prepare": "husky install",
|
||||
"pretest": "pnpm build",
|
||||
"reinstall": "pnpm clean:all && pnpm install",
|
||||
"reinstall": "pnpm clean:unix && pnpm install",
|
||||
"script:list-packages": "tsx ./scripts/list-packages.ts",
|
||||
"release:alpha": "tsx ./scripts/release.ts --bump prerelease --tag alpha",
|
||||
"release:beta": "tsx ./scripts/release.ts --bump prerelease --tag beta",
|
||||
"script:release": "tsx ./scripts/release.ts",
|
||||
"test": "pnpm test:int && pnpm test:components && pnpm test:e2e",
|
||||
"test:components": "cross-env NODE_OPTIONS=--no-deprecation jest --config=jest.components.config.js",
|
||||
"test:e2e": "NODE_OPTIONS=--no-deprecation npx playwright install --with-deps chromium && NODE_OPTIONS=--no-deprecation ts-node -T ./test/runE2E.ts",
|
||||
"test:e2e:debug": "cross-env NODE_OPTIONS=--no-deprecation PWDEBUG=1 DISABLE_LOGGING=true playwright test",
|
||||
"test:e2e:headed": "cross-env NODE_OPTIONS=--no-deprecation DISABLE_LOGGING=true playwright test --headed",
|
||||
"test:int:postgres": "cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_DATABASE=postgres DISABLE_LOGGING=true jest --forceExit --detectOpenHandles",
|
||||
"test:int": "cross-env NODE_OPTIONS=--no-deprecation DISABLE_LOGGING=true jest --forceExit --detectOpenHandles",
|
||||
"test:components": "cross-env jest --config=jest.components.config.js",
|
||||
"test:e2e": "npx playwright install --with-deps chromium && ts-node -T ./test/runE2E.ts",
|
||||
"test:e2e:debug": "cross-env PWDEBUG=1 DISABLE_LOGGING=true playwright test",
|
||||
"test:e2e:headed": "cross-env DISABLE_LOGGING=true playwright test --headed",
|
||||
"test:int:postgres": "cross-env PAYLOAD_DATABASE=postgres DISABLE_LOGGING=true jest --forceExit --detectOpenHandles",
|
||||
"test:int": "cross-env DISABLE_LOGGING=true jest --forceExit --detectOpenHandles",
|
||||
"translateNewKeys": "pnpm --filter payload run translateNewKeys"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aws-sdk/client-s3": "^3.142.0",
|
||||
"@next/bundle-analyzer": "^14.1.0",
|
||||
"@octokit/core": "^5.1.0",
|
||||
"@payloadcms/eslint-config": "workspace:*",
|
||||
"@playwright/test": "1.40.1",
|
||||
"@swc/cli": "^0.1.62",
|
||||
@@ -77,7 +48,6 @@
|
||||
"@types/conventional-changelog": "^3.1.4",
|
||||
"@types/conventional-changelog-core": "^4.2.5",
|
||||
"@types/conventional-changelog-preset-loader": "^2.3.4",
|
||||
"@types/conventional-changelog-writer": "^4.0.10",
|
||||
"@types/fs-extra": "^11.0.2",
|
||||
"@types/jest": "29.5.7",
|
||||
"@types/minimist": "1.2.2",
|
||||
@@ -89,66 +59,67 @@
|
||||
"@types/shelljs": "0.8.12",
|
||||
"@types/testing-library__jest-dom": "5.14.8",
|
||||
"add-stream": "^1.0.0",
|
||||
"chalk": "^4.1.2",
|
||||
"comment-json": "^4.2.3",
|
||||
"chalk": "^5.3.0",
|
||||
"chalk-template": "1.1.0",
|
||||
"concat-stream": "^2.0.0",
|
||||
"conventional-changelog": "^5.1.0",
|
||||
"conventional-changelog-conventionalcommits": "^7.0.2",
|
||||
"conventional-changelog-core": "^7.0.0",
|
||||
"conventional-changelog-preset-loader": "^4.1.0",
|
||||
"conventional-changelog-writer": "^7.0.1",
|
||||
"copyfiles": "2.4.1",
|
||||
"cross-env": "7.0.3",
|
||||
"dotenv": "8.6.0",
|
||||
"drizzle-orm": "0.29.4",
|
||||
"execa": "5.1.1",
|
||||
"drizzle-orm": "0.29.3",
|
||||
"express": "4.18.2",
|
||||
"form-data": "3.0.1",
|
||||
"fs-extra": "10.1.0",
|
||||
"get-port": "5.1.1",
|
||||
"get-stream": "6.0.1",
|
||||
"glob": "8.1.0",
|
||||
"graphql-request": "6.1.0",
|
||||
"husky": "^8.0.3",
|
||||
"isomorphic-fetch": "3.0.0",
|
||||
"jest": "29.7.0",
|
||||
"jest-environment-jsdom": "29.7.0",
|
||||
"json5": "^2.2.3",
|
||||
"jwt-decode": "3.1.2",
|
||||
"lexical": "0.13.1",
|
||||
"lint-staged": "^14.0.1",
|
||||
"minimist": "1.2.8",
|
||||
"mongodb-memory-server": "^9",
|
||||
"next": "14.1.2",
|
||||
"node-mocks-http": "^1.14.1",
|
||||
"node-fetch": "2.6.12",
|
||||
"nodemon": "3.0.3",
|
||||
"pino": "8.15.0",
|
||||
"pino-pretty": "10.2.0",
|
||||
"prettier": "^3.0.3",
|
||||
"prompts": "2.4.2",
|
||||
"qs": "6.11.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"read-stream": "^2.1.1",
|
||||
"rimraf": "3.0.2",
|
||||
"semver": "^7.5.4",
|
||||
"sharp": "0.32.6",
|
||||
"shelljs": "0.8.5",
|
||||
"simple-git": "^3.20.0",
|
||||
"slash": "3.0.0",
|
||||
"slate": "0.91.4",
|
||||
"tempfile": "^3.0.0",
|
||||
"ts-node": "10.9.2",
|
||||
"tsx": "^4.7.1",
|
||||
"turbo": "^1.12.4",
|
||||
"turbo": "^1.11.1",
|
||||
"typescript": "5.2.2",
|
||||
"uuid": "^9.0.1",
|
||||
"yocto-queue": "^1.0.0"
|
||||
"uuid": "^9.0.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "18.2.0",
|
||||
"react-i18next": "11.18.6",
|
||||
"react-router-dom": "5.3.4"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"copyfiles": "$copyfiles",
|
||||
"cross-env": "$cross-env",
|
||||
"dotenv": "$dotenv",
|
||||
"drizzle-orm": "$drizzle-orm",
|
||||
"ts-node": "$ts-node",
|
||||
"typescript": "$typescript"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.17.0",
|
||||
"node": ">=14",
|
||||
"pnpm": ">=8"
|
||||
},
|
||||
"lint-staged": {
|
||||
@@ -157,25 +128,6 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@sentry/react": "^7.77.0",
|
||||
"passport-strategy": "1.0.0"
|
||||
},
|
||||
"pnpm": {
|
||||
"overrides": {
|
||||
"copyfiles": "$copyfiles",
|
||||
"cross-env": "$cross-env",
|
||||
"dotenv": "$dotenv",
|
||||
"drizzle-orm": "$drizzle-orm",
|
||||
"graphql": "^16.8.1",
|
||||
"react": "$react",
|
||||
"react-dom": "$react-dom",
|
||||
"ts-node": "$ts-node",
|
||||
"typescript": "$typescript"
|
||||
},
|
||||
"allowedDeprecatedVersions": {
|
||||
"uuid": "3.4.0",
|
||||
"abab": "2",
|
||||
"domexception": "4"
|
||||
}
|
||||
"@sentry/react": "^7.77.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
||||
28
packages/bundler-vite/README.md
Normal file
28
packages/bundler-vite/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Payload Vite Adapter
|
||||
|
||||
Official Vite adapter for [Payload](https://payloadcms.com).
|
||||
|
||||
- [Main Repository](https://github.com/payloadcms/payload)
|
||||
- [Payload Docs](https://payloadcms.com/docs)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @payloadcms/bundler-vite
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { buildConfig } from 'payload/config'
|
||||
import { viteBundler } from '@payloadcms/bundler-vite'
|
||||
|
||||
export default buildConfig({
|
||||
bundler: viteBundler(),
|
||||
// ...rest of config
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
More detailed usage can be found in the [Payload Docs](https://payloadcms.com/docs/configuration/overview).
|
||||
|
||||
3
packages/bundler-vite/mock.js
Normal file
3
packages/bundler-vite/mock.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export const viteBundler = () => {}
|
||||
export const mongooseAdapter = () => ({})
|
||||
export const postgresAdapter = () => ({})
|
||||
51
packages/bundler-vite/package.json
Normal file
51
packages/bundler-vite/package.json
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "@payloadcms/bundler-vite",
|
||||
"version": "0.1.6",
|
||||
"description": "The officially supported Vite bundler adapter for Payload",
|
||||
"repository": "https://github.com/payloadcms/payload",
|
||||
"license": "MIT",
|
||||
"homepage": "https://payloadcms.com",
|
||||
"author": {
|
||||
"email": "info@payloadcms.com",
|
||||
"name": "Payload",
|
||||
"url": "https://payloadcms.com"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types && pnpm copyTsx",
|
||||
"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/",
|
||||
"copyTsx": "copyfiles -u 1 \"src/entry.tsx\" dist/",
|
||||
"prepublishOnly": "pnpm clean && pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@rollup/plugin-image": "^3.0.2",
|
||||
"@vitejs/plugin-react": "^4.0.4",
|
||||
"compression": "1.7.4",
|
||||
"connect-history-api-fallback": "1.6.0",
|
||||
"get-port": "5.1.1",
|
||||
"path-browserify": "1.0.1",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-virtual": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@payloadcms/eslint-config": "workspace:*",
|
||||
"payload": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"payload": "^2.0.0",
|
||||
"react-dom": "18.2.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"main": "./dist/index.js",
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"mock.js"
|
||||
]
|
||||
}
|
||||
157
packages/bundler-vite/src/config.ts
Normal file
157
packages/bundler-vite/src/config.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
// @ts-expect-error
|
||||
import type { InlineConfig } from 'vite'
|
||||
|
||||
import image from '@rollup/plugin-image'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import getPort from 'get-port'
|
||||
import path from 'path'
|
||||
import virtual from 'vite-plugin-virtual'
|
||||
|
||||
const mockModulePath = path.resolve(__dirname, './mocks/emptyModule.js')
|
||||
const mockDotENVPath = path.resolve(__dirname, './mocks/dotENV.js')
|
||||
|
||||
export const getViteConfig = async (payloadConfig: SanitizedConfig): Promise<InlineConfig> => {
|
||||
const { createLogger, searchForWorkspaceRoot } = await import('vite')
|
||||
|
||||
const logger = createLogger('warn', { allowClearScreen: false, prefix: '[VITE-WARNING]' })
|
||||
const originalWarning = logger.warn
|
||||
logger.warn = (msg, options) => {
|
||||
// TODO: fix this? removed these warnings to make debugging easier
|
||||
if (msg.includes('Default and named imports from CSS files are deprecated')) return
|
||||
originalWarning(msg, options)
|
||||
}
|
||||
|
||||
const hmrPort = await getPort()
|
||||
|
||||
const absoluteAliases = {}
|
||||
|
||||
const alias = [
|
||||
{ find: '@payloadcms/bundler-vite', replacement: path.resolve(__dirname, '../mock.js') },
|
||||
{ find: '@payloadcms/db-mongodb', replacement: path.resolve(__dirname, '../mock.js') },
|
||||
{ find: '@payloadcms/db-postgres', replacement: path.resolve(__dirname, '../mock.js') },
|
||||
{ find: 'path', replacement: require.resolve('path-browserify') },
|
||||
{ find: 'payload-config', replacement: payloadConfig.paths.rawConfig },
|
||||
{ find: /payload$/, replacement: mockModulePath },
|
||||
{ find: '~payload-user-css', replacement: payloadConfig.admin.css },
|
||||
{ find: '~react-toastify', replacement: 'react-toastify' },
|
||||
{ find: 'dotenv', replacement: mockDotENVPath },
|
||||
]
|
||||
|
||||
if (payloadConfig.admin.webpack && typeof payloadConfig.admin.webpack === 'function') {
|
||||
const webpackConfig = payloadConfig.admin.webpack({
|
||||
resolve: {
|
||||
alias: {},
|
||||
},
|
||||
})
|
||||
|
||||
if (Object.keys(webpackConfig.resolve.alias).length > 0) {
|
||||
Object.entries(webpackConfig.resolve.alias).forEach(([source, target]) => {
|
||||
if (path.isAbsolute(source)) {
|
||||
absoluteAliases[source] = target
|
||||
} else {
|
||||
alias.push({
|
||||
find: source,
|
||||
replacement: target,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const define = {
|
||||
__dirname: '"/"',
|
||||
'module.hot': 'undefined',
|
||||
'process.argv': '[]',
|
||||
'process.cwd': 'function () { return "/" }',
|
||||
'process?.cwd': 'function () { return "/" }',
|
||||
}
|
||||
|
||||
Object.entries(process.env).forEach(([key, val]) => {
|
||||
if (key.indexOf('PAYLOAD_PUBLIC_') === 0) {
|
||||
define[`process.env.${key}`] = `'${val}'`
|
||||
} else {
|
||||
define[`process.env.${key}`] = `''`
|
||||
}
|
||||
})
|
||||
|
||||
let viteConfig: InlineConfig = {
|
||||
base: payloadConfig.routes.admin,
|
||||
build: {
|
||||
chunkSizeWarningLimit: 4000,
|
||||
emptyOutDir: true,
|
||||
outDir: payloadConfig.admin.buildPath,
|
||||
rollupOptions: {
|
||||
plugins: [image()],
|
||||
treeshake: true,
|
||||
},
|
||||
},
|
||||
customLogger: logger,
|
||||
define,
|
||||
optimizeDeps: {
|
||||
exclude: [
|
||||
// Dependencies that need aliases should be excluded
|
||||
// from pre-bundling
|
||||
'@payloadcms/bundler-vite',
|
||||
'@payloadcms/db-mongodb',
|
||||
'@payloadcms/db-postgres',
|
||||
...(Object.keys(absoluteAliases) || []),
|
||||
],
|
||||
include: ['payload/components/root', 'react-dom/client'],
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
name: 'absolute-aliases',
|
||||
enforce: 'pre',
|
||||
resolveId(source, importer) {
|
||||
let fullSourcePath: string
|
||||
|
||||
// TODO: need to handle this better. This is overly simple.
|
||||
if (source.startsWith('.')) {
|
||||
fullSourcePath = path.resolve(path.dirname(importer), source)
|
||||
|
||||
if (fullSourcePath) {
|
||||
const exactMatch = absoluteAliases[fullSourcePath]
|
||||
if (exactMatch) return exactMatch
|
||||
|
||||
const indexMatch = absoluteAliases[`${fullSourcePath}/index`]
|
||||
if (indexMatch) return indexMatch
|
||||
|
||||
const withoutFileExtensionMatch =
|
||||
absoluteAliases[`${fullSourcePath.replace(/\.[^/.]+$/, '')}`]
|
||||
if (withoutFileExtensionMatch) return withoutFileExtensionMatch
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
},
|
||||
},
|
||||
virtual({
|
||||
crypto: 'export default {}',
|
||||
http: 'export default {}',
|
||||
https: 'export default {}',
|
||||
}),
|
||||
react(),
|
||||
],
|
||||
resolve: {
|
||||
alias,
|
||||
},
|
||||
root: path.resolve(__dirname, './'),
|
||||
server: {
|
||||
fs: {
|
||||
allow: [searchForWorkspaceRoot(process.cwd()), path.resolve(__dirname, '../../../payload')],
|
||||
},
|
||||
hmr: {
|
||||
port: hmrPort,
|
||||
},
|
||||
middlewareMode: true,
|
||||
},
|
||||
}
|
||||
|
||||
if (payloadConfig.admin.vite && typeof payloadConfig.admin.vite === 'function') {
|
||||
viteConfig = payloadConfig.admin.vite(viteConfig)
|
||||
}
|
||||
|
||||
return viteConfig
|
||||
}
|
||||
9
packages/bundler-vite/src/entry.tsx
Normal file
9
packages/bundler-vite/src/entry.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Root } from 'payload/components/root'
|
||||
// @ts-expect-error
|
||||
import config from 'payload-config'
|
||||
import React from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
|
||||
const container = document.getElementById('app')
|
||||
const root = createRoot(container)
|
||||
root.render(<Root config={config} />)
|
||||
14
packages/bundler-vite/src/index.html
Normal file
14
packages/bundler-vite/src/index.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
|
||||
<link rel="icon" href="data:," data-placeholder-favicon />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div id="portal"></div>
|
||||
<script type="module" src="./entry.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
14
packages/bundler-vite/src/index.ts
Normal file
14
packages/bundler-vite/src/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// @ts-expect-error
|
||||
import type { InlineConfig } from 'vite'
|
||||
|
||||
import type { PayloadBundler } from './types'
|
||||
|
||||
import { buildAdmin } from './scripts/build'
|
||||
import { devAdmin } from './scripts/dev'
|
||||
import { serveAdmin } from './scripts/serve'
|
||||
|
||||
export const viteBundler: (viteConfig?: InlineConfig) => PayloadBundler = (viteConfig) => ({
|
||||
build: async (payloadConfig) => buildAdmin({ payloadConfig, viteConfig }),
|
||||
dev: async (payload) => devAdmin({ payload, viteConfig }),
|
||||
serve: async (payload) => serveAdmin({ payload }),
|
||||
})
|
||||
3
packages/bundler-vite/src/mocks/dotENV.js
Normal file
3
packages/bundler-vite/src/mocks/dotENV.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
config: () => null,
|
||||
}
|
||||
1
packages/bundler-vite/src/mocks/emptyModule.js
Normal file
1
packages/bundler-vite/src/mocks/emptyModule.js
Normal file
@@ -0,0 +1 @@
|
||||
export default () => {}
|
||||
1
packages/bundler-vite/src/mocks/fileMock.js
Normal file
1
packages/bundler-vite/src/mocks/fileMock.js
Normal file
@@ -0,0 +1 @@
|
||||
export default 'file-stub'
|
||||
21
packages/bundler-vite/src/scripts/build.ts
Normal file
21
packages/bundler-vite/src/scripts/build.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
// @ts-expect-error
|
||||
import type { InlineConfig } from 'vite'
|
||||
|
||||
import { getViteConfig } from '../config'
|
||||
|
||||
type BuildAdminType = (options: {
|
||||
payloadConfig: SanitizedConfig
|
||||
viteConfig: InlineConfig
|
||||
}) => Promise<void>
|
||||
export const buildAdmin: BuildAdminType = async ({ payloadConfig, viteConfig: viteConfigArg }) => {
|
||||
const vite = await import('vite')
|
||||
const viteConfig = await getViteConfig(payloadConfig)
|
||||
|
||||
try {
|
||||
await vite.build(viteConfig)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
throw new Error('Error: there was an error building the vite prod config.')
|
||||
}
|
||||
}
|
||||
31
packages/bundler-vite/src/scripts/dev.ts
Normal file
31
packages/bundler-vite/src/scripts/dev.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { PayloadHandler } from 'payload/config'
|
||||
// @ts-expect-error
|
||||
import type { InlineConfig } from 'vite'
|
||||
|
||||
import express from 'express'
|
||||
|
||||
import type { Payload } from '../../../payload'
|
||||
|
||||
import { getViteConfig } from '../config'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
type DevAdminType = (options: {
|
||||
payload: Payload
|
||||
viteConfig: InlineConfig
|
||||
}) => Promise<PayloadHandler>
|
||||
export const devAdmin: DevAdminType = async ({ payload, viteConfig: viteConfigArg }) => {
|
||||
const vite = await import('vite')
|
||||
|
||||
try {
|
||||
const viteConfig = await getViteConfig(payload.config)
|
||||
const viteServer = await vite.createServer(viteConfig)
|
||||
|
||||
router.use(viteServer.middlewares)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw new Error('Error: there was an error creating the vite dev server.')
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
28
packages/bundler-vite/src/scripts/serve.ts
Normal file
28
packages/bundler-vite/src/scripts/serve.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { Payload } from 'payload'
|
||||
import type { PayloadHandler } from 'payload/config'
|
||||
|
||||
import compression from 'compression'
|
||||
import history from 'connect-history-api-fallback'
|
||||
import express from 'express'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
type ServeAdminType = (options: { payload: Payload }) => Promise<PayloadHandler>
|
||||
|
||||
export const serveAdmin: ServeAdminType = async ({ payload }) => {
|
||||
router.use(history())
|
||||
|
||||
router.get('*', (req, res, next) => {
|
||||
if (req.path.substr(-1) === '/' && req.path.length > 1) {
|
||||
const query = req.url.slice(req.path.length)
|
||||
res.redirect(301, req.path.slice(0, -1) + query)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
router.use(compression(payload.config.express.compression))
|
||||
router.use(express.static(payload.config.admin.buildPath, { redirect: false }))
|
||||
|
||||
return router
|
||||
}
|
||||
8
packages/bundler-vite/src/types.ts
Normal file
8
packages/bundler-vite/src/types.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { Payload } from 'payload'
|
||||
import type { PayloadHandler, SanitizedConfig } from 'payload/config'
|
||||
|
||||
export interface PayloadBundler {
|
||||
build: (payloadConfig: SanitizedConfig) => Promise<void> // used in `payload build`
|
||||
dev: (payload: Payload) => Promise<PayloadHandler> // this would be a typical Express middleware handler
|
||||
serve: (payload: Payload) => Promise<PayloadHandler> // serve built files in production
|
||||
}
|
||||
@@ -5,21 +5,9 @@
|
||||
"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. */,
|
||||
"allowImportingTsExtensions": true
|
||||
"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"
|
||||
],
|
||||
"exclude": ["dist", "node_modules", ".eslintrc.js"],
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
|
||||
"references": [{ "path": "../payload" }]
|
||||
}
|
||||
10
packages/bundler-webpack/.eslintignore
Normal file
10
packages/bundler-webpack/.eslintignore
Normal file
@@ -0,0 +1,10 @@
|
||||
.tmp
|
||||
**/.git
|
||||
**/.hg
|
||||
**/.pnp.*
|
||||
**/.svn
|
||||
**/.yarn/**
|
||||
**/build
|
||||
**/dist/**
|
||||
**/node_modules
|
||||
**/temp
|
||||
43
packages/bundler-webpack/.eslintrc.js
Normal file
43
packages/bundler-webpack/.eslintrc.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/** @type {import('prettier').Config} */
|
||||
module.exports = {
|
||||
extends: ['@payloadcms'],
|
||||
overrides: [
|
||||
{
|
||||
extends: ['plugin:@typescript-eslint/disable-type-checked'],
|
||||
files: ['*.js', '*.cjs', '*.json', '*.md', '*.yml', '*.yaml'],
|
||||
},
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-redundant-type-constituents': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['package.json', 'tsconfig.json'],
|
||||
rules: {
|
||||
'perfectionist/sort-array-includes': 'off',
|
||||
'perfectionist/sort-astro-attributes': 'off',
|
||||
'perfectionist/sort-classes': 'off',
|
||||
'perfectionist/sort-enums': 'off',
|
||||
'perfectionist/sort-exports': 'off',
|
||||
'perfectionist/sort-imports': 'off',
|
||||
'perfectionist/sort-interfaces': 'off',
|
||||
'perfectionist/sort-jsx-props': 'off',
|
||||
'perfectionist/sort-keys': 'off',
|
||||
'perfectionist/sort-maps': 'off',
|
||||
'perfectionist/sort-named-exports': 'off',
|
||||
'perfectionist/sort-named-imports': 'off',
|
||||
'perfectionist/sort-object-types': 'off',
|
||||
'perfectionist/sort-objects': 'off',
|
||||
'perfectionist/sort-svelte-attributes': 'off',
|
||||
'perfectionist/sort-union-types': 'off',
|
||||
'perfectionist/sort-vue-attributes': 'off',
|
||||
},
|
||||
},
|
||||
],
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.json'],
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
root: true,
|
||||
}
|
||||
10
packages/bundler-webpack/.prettierignore
Normal file
10
packages/bundler-webpack/.prettierignore
Normal file
@@ -0,0 +1,10 @@
|
||||
.tmp
|
||||
**/.git
|
||||
**/.hg
|
||||
**/.pnp.*
|
||||
**/.svn
|
||||
**/.yarn/**
|
||||
**/build
|
||||
**/dist/**
|
||||
**/node_modules
|
||||
**/temp
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
||||
28
packages/bundler-webpack/README.md
Normal file
28
packages/bundler-webpack/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Payload Webpack Adapter
|
||||
|
||||
Official Webpack adapter for [Payload](https://payloadcms.com).
|
||||
|
||||
- [Main Repository](https://github.com/payloadcms/payload)
|
||||
- [Payload Docs](https://payloadcms.com/docs)
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
npm install @payloadcms/bundler-webpack
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { buildConfig } from 'payload/config'
|
||||
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
||||
|
||||
export default buildConfig({
|
||||
bundler: webpackBundler()
|
||||
// ...rest of config
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
More detailed usage can be found in the [Payload Docs](https://payloadcms.com/docs/configuration/overview).
|
||||
|
||||
72
packages/bundler-webpack/package.json
Normal file
72
packages/bundler-webpack/package.json
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "@payloadcms/bundler-webpack",
|
||||
"version": "1.0.6",
|
||||
"description": "The officially supported Webpack bundler adapter for Payload",
|
||||
"repository": "https://github.com/payloadcms/payload",
|
||||
"license": "MIT",
|
||||
"homepage": "https://payloadcms.com",
|
||||
"author": {
|
||||
"email": "info@payloadcms.com",
|
||||
"name": "Payload",
|
||||
"url": "https://payloadcms.com"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "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}",
|
||||
"prepublishOnly": "pnpm clean && pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"compression": "1.7.4",
|
||||
"connect-history-api-fallback": "1.6.0",
|
||||
"css-loader": "5.2.7",
|
||||
"css-minimizer-webpack-plugin": "^5.0.0",
|
||||
"file-loader": "6.2.0",
|
||||
"find-node-modules": "^2.1.3",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"md5": "2.3.0",
|
||||
"mini-css-extract-plugin": "1.6.2",
|
||||
"path-browserify": "1.0.1",
|
||||
"postcss": "8.4.31",
|
||||
"postcss-loader": "6.2.1",
|
||||
"postcss-preset-env": "9.0.0",
|
||||
"process": "0.11.10",
|
||||
"sass-loader": "12.6.0",
|
||||
"style-loader": "^2.0.0",
|
||||
"swc-loader": "^0.2.3",
|
||||
"swc-minify-webpack-plugin": "^2.1.0",
|
||||
"terser-webpack-plugin": "^5.3.6",
|
||||
"url-loader": "4.1.1",
|
||||
"webpack": "^5.78.0",
|
||||
"webpack-bundle-analyzer": "^4.8.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-dev-middleware": "6.0.1",
|
||||
"webpack-hot-middleware": "^2.25.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@payloadcms/eslint-config": "workspace:*",
|
||||
"@types/extract-text-webpack-plugin": "^3.0.7",
|
||||
"@types/find-node-modules": "^2.1.0",
|
||||
"@types/html-webpack-plugin": "^3.2.6",
|
||||
"@types/mini-css-extract-plugin": "^1.4.3",
|
||||
"@types/optimize-css-assets-webpack-plugin": "^5.0.5",
|
||||
"@types/webpack-bundle-analyzer": "^4.6.0",
|
||||
"@types/webpack-env": "^1.18.0",
|
||||
"@types/webpack-hot-middleware": "2.25.6",
|
||||
"payload": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"payload": "^2.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"main": "./dist/index.js",
|
||||
"registry": "https://registry.npmjs.org/",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
105
packages/bundler-webpack/src/configs/base.ts
Normal file
105
packages/bundler-webpack/src/configs/base.ts
Normal file
@@ -0,0 +1,105 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
import type { Configuration } from 'webpack'
|
||||
|
||||
import findNodeModules from 'find-node-modules'
|
||||
import fs from 'fs'
|
||||
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
||||
import path from 'path'
|
||||
import webpack from 'webpack'
|
||||
|
||||
const mockModulePath = path.resolve(__dirname, '../mocks/emptyModule.js')
|
||||
const mockDotENVPath = path.resolve(__dirname, '../mocks/dotENV.js')
|
||||
const mockDBAdapterPath = path.resolve(__dirname, '../mocks/db-adapters.js')
|
||||
|
||||
const nodeModulesPaths = findNodeModules({ cwd: process.cwd(), relative: false })
|
||||
|
||||
export const getBaseConfig = (payloadConfig: SanitizedConfig): Configuration => {
|
||||
let nodeModulesPath = nodeModulesPaths.find((p) => {
|
||||
const guess = path.resolve(p, 'payload/dist/admin')
|
||||
if (fs.existsSync(guess)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
if (!nodeModulesPath) {
|
||||
nodeModulesPath = process.cwd()
|
||||
}
|
||||
|
||||
const adminFolderPath = path.resolve(nodeModulesPath, 'payload/dist/admin')
|
||||
|
||||
const config: Configuration = {
|
||||
entry: {
|
||||
main: [adminFolderPath],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
exclude: /\/node_modules\/(?!.+\.tsx?$).*$/,
|
||||
test: /\.(t|j)sx?$/,
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('swc-loader'),
|
||||
options: {
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: 'typescript',
|
||||
tsx: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
oneOf: [
|
||||
{
|
||||
test: /\.(?:ico|gif|png|jpg|jpeg|woff(2)?|eot|ttf|otf|svg)$/i,
|
||||
type: 'asset/resource',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({ process: require.resolve('process/browser') }),
|
||||
new webpack.DefinePlugin(
|
||||
Object.entries(process.env).reduce((values, [key, val]) => {
|
||||
if (key.indexOf('PAYLOAD_PUBLIC_') === 0) {
|
||||
return {
|
||||
...values,
|
||||
[`process.env.${key}`]: `'${val}'`,
|
||||
}
|
||||
}
|
||||
|
||||
return values
|
||||
}, {}),
|
||||
),
|
||||
new HtmlWebpackPlugin({
|
||||
filename: path.normalize('./index.html'),
|
||||
template: payloadConfig.admin.indexHTML,
|
||||
}),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@payloadcms/bundler-webpack': mockModulePath,
|
||||
'@payloadcms/db-mongodb': mockDBAdapterPath,
|
||||
'@payloadcms/db-postgres': mockDBAdapterPath,
|
||||
dotenv: mockDotENVPath,
|
||||
path: require.resolve('path-browserify'),
|
||||
payload$: mockModulePath,
|
||||
'payload-config': payloadConfig.paths.rawConfig,
|
||||
'payload-user-css': payloadConfig.admin.css,
|
||||
},
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
fallback: {
|
||||
crypto: false,
|
||||
http: false,
|
||||
https: false,
|
||||
},
|
||||
modules: ['node_modules', nodeModulesPath, path.resolve(__dirname, '../../node_modules')],
|
||||
},
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
82
packages/bundler-webpack/src/configs/dev.ts
Normal file
82
packages/bundler-webpack/src/configs/dev.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
import type { Configuration } from 'webpack'
|
||||
|
||||
import md5 from 'md5'
|
||||
import webpack from 'webpack'
|
||||
|
||||
import { getBaseConfig } from './base'
|
||||
|
||||
export const getDevConfig = (payloadConfig: SanitizedConfig): Configuration => {
|
||||
const baseConfig = getBaseConfig(payloadConfig) as any
|
||||
|
||||
let webpackConfig: Configuration = {
|
||||
...baseConfig,
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
// version cache when there are changes to aliases
|
||||
buildDependencies: {
|
||||
config: [__filename],
|
||||
},
|
||||
version: md5(Object.entries(baseConfig.resolve.alias).join()),
|
||||
},
|
||||
devtool: 'inline-source-map',
|
||||
entry: {
|
||||
...baseConfig.entry,
|
||||
main: [
|
||||
`${require.resolve('webpack-hot-middleware/client')}?path=${
|
||||
payloadConfig.routes.admin
|
||||
}/__webpack_hmr`,
|
||||
...(baseConfig.entry.main as string[]),
|
||||
],
|
||||
},
|
||||
mode: 'development',
|
||||
module: {
|
||||
...baseConfig.module,
|
||||
rules: [
|
||||
...baseConfig.module.rules,
|
||||
{
|
||||
sideEffects: true,
|
||||
test: /\.(scss|css)$/,
|
||||
/*
|
||||
* The loaders here are run in reverse order. Here is how your loaders are being processed:
|
||||
* 1. sass-loader: This loader compiles your SCSS into CSS.
|
||||
* 2. postcss-loader: This loader applies postcss transformations (with preset-env plugin in your case).
|
||||
* 3. css-loader: This loader interprets @import and url() like import/require() and will resolve them.
|
||||
* 4. style-loader: This loader injects CSS into the DOM.
|
||||
*/
|
||||
use: [
|
||||
require.resolve('style-loader'),
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
url: (url) => !url.startsWith('/'),
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
postcssOptions: {
|
||||
plugins: [require.resolve('postcss-preset-env')],
|
||||
},
|
||||
},
|
||||
},
|
||||
require.resolve('sass-loader'),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: '/',
|
||||
publicPath: `${payloadConfig.routes.admin}/`,
|
||||
},
|
||||
plugins: [...baseConfig.plugins, new webpack.HotModuleReplacementPlugin()],
|
||||
stats: 'errors-warnings',
|
||||
}
|
||||
|
||||
if (payloadConfig.admin.webpack && typeof payloadConfig.admin.webpack === 'function') {
|
||||
webpackConfig = payloadConfig.admin.webpack(webpackConfig)
|
||||
}
|
||||
|
||||
return webpackConfig
|
||||
}
|
||||
80
packages/bundler-webpack/src/configs/prod.ts
Normal file
80
packages/bundler-webpack/src/configs/prod.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
import type { Configuration } from 'webpack'
|
||||
|
||||
import MiniCSSExtractPlugin from 'mini-css-extract-plugin'
|
||||
import { SwcMinifyWebpackPlugin } from 'swc-minify-webpack-plugin'
|
||||
import { WebpackPluginInstance } from 'webpack'
|
||||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
|
||||
|
||||
import { getBaseConfig } from './base'
|
||||
|
||||
export const getProdConfig = (payloadConfig: SanitizedConfig): Configuration => {
|
||||
const baseConfig = getBaseConfig(payloadConfig) as any
|
||||
|
||||
let webpackConfig: Configuration = {
|
||||
...baseConfig,
|
||||
mode: 'production',
|
||||
module: {
|
||||
...baseConfig.module,
|
||||
rules: [
|
||||
...baseConfig.module.rules,
|
||||
{
|
||||
sideEffects: true,
|
||||
test: /\.(scss|css)$/,
|
||||
use: [
|
||||
MiniCSSExtractPlugin.loader,
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
url: (url) => !url.startsWith('/'),
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
postcssOptions: {
|
||||
plugins: [require.resolve('postcss-preset-env')],
|
||||
},
|
||||
},
|
||||
},
|
||||
require.resolve('sass-loader'),
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
optimization: {
|
||||
minimizer: [new SwcMinifyWebpackPlugin()],
|
||||
splitChunks: {
|
||||
cacheGroups: {
|
||||
styles: {
|
||||
name: 'styles',
|
||||
chunks: 'all',
|
||||
enforce: true,
|
||||
test: /\.(sa|sc|c)ss$/,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
output: {
|
||||
chunkFilename: '[name].[chunkhash].js',
|
||||
filename: '[name].[chunkhash].js',
|
||||
path: payloadConfig.admin.buildPath,
|
||||
publicPath: `${payloadConfig.routes.admin}/`,
|
||||
},
|
||||
plugins: [
|
||||
...baseConfig.plugins,
|
||||
new MiniCSSExtractPlugin({
|
||||
filename: '[name].[contenthash].css',
|
||||
ignoreOrder: true,
|
||||
}),
|
||||
...(process.env.PAYLOAD_ANALYZE_BUNDLE ? [new BundleAnalyzerPlugin()] : []),
|
||||
],
|
||||
stats: 'errors-only',
|
||||
}
|
||||
|
||||
if (payloadConfig.admin.webpack && typeof payloadConfig.admin.webpack === 'function') {
|
||||
webpackConfig = payloadConfig.admin.webpack(webpackConfig)
|
||||
}
|
||||
|
||||
return webpackConfig
|
||||
}
|
||||
12
packages/bundler-webpack/src/index.ts
Normal file
12
packages/bundler-webpack/src/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
import type { PayloadBundler } from '../../payload/dist/bundlers/types'
|
||||
|
||||
import { buildAdmin } from './scripts/build'
|
||||
import { devAdmin } from './scripts/dev'
|
||||
import { serveAdmin } from './scripts/serve'
|
||||
|
||||
export const webpackBundler: () => PayloadBundler = () => ({
|
||||
build: async (payloadConfig) => buildAdmin({ payloadConfig }),
|
||||
dev: async (payload) => devAdmin({ payload }),
|
||||
serve: async (payload) => serveAdmin({ payload }),
|
||||
})
|
||||
2
packages/bundler-webpack/src/mocks/db-adapters.js
Normal file
2
packages/bundler-webpack/src/mocks/db-adapters.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export const mongooseAdapter = () => ({})
|
||||
export const postgresAdapter = () => ({})
|
||||
3
packages/bundler-webpack/src/mocks/dotENV.js
Normal file
3
packages/bundler-webpack/src/mocks/dotENV.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
config: () => null,
|
||||
}
|
||||
3
packages/bundler-webpack/src/mocks/emptyModule.js
Normal file
3
packages/bundler-webpack/src/mocks/emptyModule.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export const webpackBundler = () => {}
|
||||
|
||||
export default () => {}
|
||||
1
packages/bundler-webpack/src/mocks/fileMock.js
Normal file
1
packages/bundler-webpack/src/mocks/fileMock.js
Normal file
@@ -0,0 +1 @@
|
||||
export default 'file-stub'
|
||||
31
packages/bundler-webpack/src/scripts/build.ts
Normal file
31
packages/bundler-webpack/src/scripts/build.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { SanitizedConfig } from 'payload/config'
|
||||
|
||||
import webpack from 'webpack'
|
||||
|
||||
import { getProdConfig } from '../configs/prod'
|
||||
|
||||
type BuildAdminType = (options: { payloadConfig: SanitizedConfig }) => Promise<void>
|
||||
export const buildAdmin: BuildAdminType = async ({ payloadConfig }) => {
|
||||
try {
|
||||
const webpackConfig = getProdConfig(payloadConfig)
|
||||
webpack(webpackConfig, (err, stats) => {
|
||||
if (err || stats.hasErrors()) {
|
||||
// Handle errors here
|
||||
|
||||
if (stats) {
|
||||
console.error(
|
||||
stats.toString({
|
||||
chunks: false,
|
||||
colors: true,
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
console.error(err.message)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw new Error('Error: there was an error building the webpack prod config.')
|
||||
}
|
||||
}
|
||||
35
packages/bundler-webpack/src/scripts/dev.ts
Normal file
35
packages/bundler-webpack/src/scripts/dev.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { Payload } from 'payload'
|
||||
import type { PayloadHandler } from 'payload/config'
|
||||
|
||||
import history from 'connect-history-api-fallback'
|
||||
import express from 'express'
|
||||
import webpack from 'webpack'
|
||||
import webpackDevMiddleware from 'webpack-dev-middleware'
|
||||
import webpackHotMiddleware from 'webpack-hot-middleware'
|
||||
|
||||
import { getDevConfig } from '../configs/dev'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
type DevAdminType = (options: { payload: Payload }) => Promise<PayloadHandler>
|
||||
export const devAdmin: DevAdminType = async ({ payload }) => {
|
||||
router.use(history())
|
||||
|
||||
try {
|
||||
const webpackConfig = getDevConfig(payload.config)
|
||||
const compiler = webpack(webpackConfig)
|
||||
|
||||
router.use(
|
||||
webpackDevMiddleware(compiler, {
|
||||
publicPath: '/',
|
||||
}),
|
||||
)
|
||||
|
||||
router.use(webpackHotMiddleware(compiler))
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw new Error('Error: there was an error creating the webpack dev server.')
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
41
packages/bundler-webpack/src/scripts/serve.ts
Normal file
41
packages/bundler-webpack/src/scripts/serve.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { Payload } from 'payload'
|
||||
import type { PayloadHandler } from 'payload/config'
|
||||
|
||||
import compression from 'compression'
|
||||
import history from 'connect-history-api-fallback'
|
||||
import express from 'express'
|
||||
|
||||
const router = express.Router()
|
||||
|
||||
type ServeAdminType = (options: { payload: Payload }) => Promise<PayloadHandler>
|
||||
|
||||
export const serveAdmin: ServeAdminType = async ({ payload }) => {
|
||||
router.use(history())
|
||||
|
||||
router.get('*', (req, res, next) => {
|
||||
if (req.path.substr(-1) === '/' && req.path.length > 1) {
|
||||
const query = req.url.slice(req.path.length)
|
||||
res.redirect(301, req.path.slice(0, -1) + query)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
router.use(compression(payload.config.express.compression))
|
||||
router.use(
|
||||
express.static(payload.config.admin.buildPath, {
|
||||
redirect: false,
|
||||
setHeaders: (res, path) => {
|
||||
const staticFilesRegex = new RegExp(
|
||||
'.(svg|css|js|jp(e)?g|png|avif|webp|webm|gif|ico|woff|woff2|ttf|otf)$',
|
||||
'i',
|
||||
)
|
||||
if (path.match(staticFilesRegex)) {
|
||||
res.set('Cache-Control', `public, max-age=${60 * 60 * 24 * 365}, immutable`)
|
||||
}
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
return router
|
||||
}
|
||||
@@ -2,14 +2,12 @@
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"composite": true, // Make sure typescript knows that this module depends on their references
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||
"rootDir": "./src",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"noEmit": false /* Do not emit outputs. */,
|
||||
"emitDeclarationOnly": true
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||
"rootDir": "./src" /* Specify the root folder within your source files. */
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.json"],
|
||||
"exclude": ["src/all"]
|
||||
"exclude": ["dist", "node_modules", ".eslintrc.js"],
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
|
||||
"references": [{ "path": "../payload" }]
|
||||
}
|
||||
@@ -6,8 +6,7 @@
|
||||
"create-payload-app": "bin/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "pnpm copyfiles && pnpm build:swc",
|
||||
"copyfiles": "copyfiles -u 2 \"../../app/(payload)/**\" \"dist\"",
|
||||
"build": "pnpm build:swc",
|
||||
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
||||
"clean": "rimraf {dist,*.tsbuildinfo}",
|
||||
"test": "jest",
|
||||
@@ -23,13 +22,10 @@
|
||||
"arg": "^5.0.0",
|
||||
"chalk": "^4.1.0",
|
||||
"command-exists": "^1.2.9",
|
||||
"comment-json": "^4.2.3",
|
||||
"degit": "^2.8.4",
|
||||
"detect-package-manager": "^3.0.1",
|
||||
"execa": "^5.0.0",
|
||||
"figures": "^3.2.0",
|
||||
"fs-extra": "^9.0.1",
|
||||
"globby": "11.1.0",
|
||||
"handlebars": "^4.7.7",
|
||||
"ora": "^5.1.0",
|
||||
"prompts": "^2.4.2",
|
||||
|
||||
@@ -1,219 +0,0 @@
|
||||
import type { CompilerOptions } from 'typescript'
|
||||
|
||||
import chalk from 'chalk'
|
||||
import * as CommentJson from 'comment-json'
|
||||
import { detect } from 'detect-package-manager'
|
||||
import execa from 'execa'
|
||||
import fs from 'fs'
|
||||
import fse from 'fs-extra'
|
||||
import globby from 'globby'
|
||||
import path from 'path'
|
||||
|
||||
import type { CliArgs } from '../types'
|
||||
|
||||
import { copyRecursiveSync } from '../utils/copy-recursive-sync'
|
||||
import { error, info, debug as origDebug, success, warning } from '../utils/log'
|
||||
|
||||
type InitNextArgs = Pick<CliArgs, '--debug'> & {
|
||||
projectDir?: string
|
||||
useDistFiles?: boolean
|
||||
}
|
||||
type InitNextResult = { reason?: string; success: boolean; userAppDir?: string }
|
||||
|
||||
export async function initNext(args: InitNextArgs): Promise<InitNextResult> {
|
||||
args.projectDir = args.projectDir || process.cwd()
|
||||
const { projectDir } = args
|
||||
const templateResult = await applyPayloadTemplateFiles(args)
|
||||
if (!templateResult.success) return templateResult
|
||||
|
||||
const { success: installSuccess } = await installDeps(projectDir)
|
||||
if (!installSuccess) {
|
||||
return { ...templateResult, reason: 'Failed to install dependencies', success: false }
|
||||
}
|
||||
|
||||
// Create or find payload.config.ts
|
||||
const createConfigResult = findOrCreatePayloadConfig(projectDir)
|
||||
if (!createConfigResult.success) {
|
||||
return { ...templateResult, ...createConfigResult }
|
||||
}
|
||||
|
||||
// Add `@payload-config` to tsconfig.json `paths`
|
||||
await addPayloadConfigToTsConfig(projectDir)
|
||||
|
||||
// Output directions for user to update next.config.js
|
||||
const withPayloadMessage = `
|
||||
|
||||
${chalk.bold(`Wrap your existing next.config.js with the withPayload function. Here is an example:`)}
|
||||
|
||||
const { withPayload } = require("@payloadcms/next");
|
||||
|
||||
const nextConfig = {
|
||||
// Your Next.js config
|
||||
};
|
||||
|
||||
module.exports = withPayload(nextConfig);
|
||||
|
||||
`
|
||||
|
||||
console.log(withPayloadMessage)
|
||||
|
||||
return templateResult
|
||||
}
|
||||
|
||||
async function addPayloadConfigToTsConfig(projectDir: string) {
|
||||
const tsConfigPath = path.resolve(projectDir, 'tsconfig.json')
|
||||
const userTsConfigContent = await fse.readFile(tsConfigPath, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
const userTsConfig = CommentJson.parse(userTsConfigContent) as {
|
||||
compilerOptions?: CompilerOptions
|
||||
}
|
||||
if (!userTsConfig.compilerOptions && !('extends' in userTsConfig)) {
|
||||
userTsConfig.compilerOptions = {}
|
||||
}
|
||||
|
||||
if (!userTsConfig.compilerOptions.paths?.['@payload-config']) {
|
||||
userTsConfig.compilerOptions.paths = {
|
||||
...(userTsConfig.compilerOptions.paths || {}),
|
||||
'@payload-config': ['./payload.config.ts'],
|
||||
}
|
||||
await fse.writeFile(tsConfigPath, CommentJson.stringify(userTsConfig, null, 2))
|
||||
}
|
||||
}
|
||||
|
||||
async function applyPayloadTemplateFiles(args: InitNextArgs): Promise<InitNextResult> {
|
||||
const { '--debug': debug, projectDir, useDistFiles } = args
|
||||
|
||||
info('Initializing Payload app in Next.js project', 1)
|
||||
|
||||
const logDebug = (message: string) => {
|
||||
if (debug) origDebug(message)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(projectDir)) {
|
||||
return { reason: `Could not find specified project directory at ${projectDir}`, success: false }
|
||||
}
|
||||
|
||||
// Next.js configs can be next.config.js, next.config.mjs, etc.
|
||||
const foundConfig = (await globby('next.config.*js', { cwd: projectDir }))?.[0]
|
||||
const nextConfigPath = path.resolve(projectDir, foundConfig)
|
||||
if (!fs.existsSync(nextConfigPath)) {
|
||||
return {
|
||||
reason: `No next.config.js found at ${nextConfigPath}. Ensure you are in a Next.js project directory.`,
|
||||
success: false,
|
||||
}
|
||||
} else {
|
||||
if (debug) logDebug(`Found Next config at ${nextConfigPath}`)
|
||||
}
|
||||
|
||||
const templateFilesPath =
|
||||
__dirname.endsWith('dist') || useDistFiles
|
||||
? path.resolve(__dirname, '../..', 'dist/app')
|
||||
: path.resolve(__dirname, '../../../../app')
|
||||
|
||||
if (debug) logDebug(`Using template files from: ${templateFilesPath}`)
|
||||
|
||||
if (!fs.existsSync(templateFilesPath)) {
|
||||
return {
|
||||
reason: `Could not find template source files from ${templateFilesPath}`,
|
||||
success: false,
|
||||
}
|
||||
} else {
|
||||
if (debug) logDebug('Found template source files')
|
||||
}
|
||||
|
||||
// src/app or app
|
||||
const userAppDirGlob = await globby(['**/app'], {
|
||||
cwd: projectDir,
|
||||
onlyDirectories: true,
|
||||
})
|
||||
const userAppDir = path.resolve(projectDir, userAppDirGlob?.[0])
|
||||
if (!fs.existsSync(userAppDir)) {
|
||||
return { reason: `Could not find user app directory inside ${projectDir}`, success: false }
|
||||
} else {
|
||||
logDebug(`Found user app directory: ${userAppDir}`)
|
||||
}
|
||||
|
||||
logDebug(`Copying template files from ${templateFilesPath} to ${userAppDir}`)
|
||||
copyRecursiveSync(templateFilesPath, userAppDir, debug)
|
||||
success('Successfully initialized.')
|
||||
return { success: true, userAppDir }
|
||||
}
|
||||
|
||||
async function installDeps(projectDir: string) {
|
||||
const packageManager = await detect({ cwd: projectDir })
|
||||
if (!packageManager) {
|
||||
throw new Error('Could not detect package manager')
|
||||
}
|
||||
|
||||
info(`Installing dependencies with ${packageManager}`, 1)
|
||||
const packagesToInstall = [
|
||||
'payload',
|
||||
'@payloadcms/db-mongodb',
|
||||
'@payloadcms/next',
|
||||
'@payloadcms/richtext-slate',
|
||||
'@payloadcms/ui',
|
||||
].map((pkg) => `${pkg}@alpha`)
|
||||
|
||||
let exitCode = 0
|
||||
switch (packageManager) {
|
||||
case 'npm': {
|
||||
;({ exitCode } = await execa('npm', ['install', '--save', ...packagesToInstall], {
|
||||
cwd: projectDir,
|
||||
}))
|
||||
break
|
||||
}
|
||||
case 'yarn':
|
||||
case 'pnpm': {
|
||||
;({ exitCode } = await execa(packageManager, ['add', ...packagesToInstall], {
|
||||
cwd: projectDir,
|
||||
}))
|
||||
break
|
||||
}
|
||||
case 'bun': {
|
||||
warning('Bun support is untested.')
|
||||
;({ exitCode } = await execa('bun', ['add', ...packagesToInstall], { cwd: projectDir }))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode !== 0) {
|
||||
error(`Failed to install dependencies with ${packageManager}`)
|
||||
} else {
|
||||
success(`Successfully installed dependencies`)
|
||||
}
|
||||
return { success: exitCode === 0 }
|
||||
}
|
||||
function findOrCreatePayloadConfig(projectDir: string) {
|
||||
const configPath = path.resolve(projectDir, 'payload.config.ts')
|
||||
if (fs.existsSync(configPath)) {
|
||||
return { message: 'Found existing payload.config.ts', success: true }
|
||||
} else {
|
||||
// Create default config
|
||||
// TODO: Pull this from templates
|
||||
const defaultConfig = `import path from "path";
|
||||
|
||||
import { mongooseAdapter } from "@payloadcms/db-mongodb"; // database-adapter-import
|
||||
import { slateEditor } from "@payloadcms/richtext-slate"; // editor-import
|
||||
import { buildConfig } from "payload/config";
|
||||
|
||||
export default buildConfig({
|
||||
editor: slateEditor({}), // editor-config
|
||||
collections: [],
|
||||
secret: "asdfasdf",
|
||||
typescript: {
|
||||
outputFile: path.resolve(__dirname, "payload-types.ts"),
|
||||
},
|
||||
graphQL: {
|
||||
schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
|
||||
},
|
||||
db: mongooseAdapter({
|
||||
url: "mongodb://localhost:27017/next-payload-3",
|
||||
}),
|
||||
});
|
||||
`
|
||||
|
||||
fse.writeFileSync(configPath, defaultConfig)
|
||||
return { message: 'Created default payload.config.ts', success: true }
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,12 @@ import type { CliArgs, PackageManager } from './types'
|
||||
|
||||
import { createProject } from './lib/create-project'
|
||||
import { generateSecret } from './lib/generate-secret'
|
||||
import { initNext } from './lib/init-next'
|
||||
import { parseProjectName } from './lib/parse-project-name'
|
||||
import { parseTemplate } from './lib/parse-template'
|
||||
import { selectDb } from './lib/select-db'
|
||||
import { getValidTemplates, validateTemplate } from './lib/templates'
|
||||
import { writeEnvFile } from './lib/write-env-file'
|
||||
import { error, success } from './utils/log'
|
||||
import { success } from './utils/log'
|
||||
import { helpMessage, successMessage, welcomeMessage } from './utils/messages'
|
||||
|
||||
export class Main {
|
||||
@@ -28,9 +27,6 @@ export class Main {
|
||||
'--secret': String,
|
||||
'--template': String,
|
||||
|
||||
// Next.js
|
||||
'--init-next': Boolean,
|
||||
|
||||
// Package manager
|
||||
'--no-deps': Boolean,
|
||||
'--use-npm': Boolean,
|
||||
@@ -39,7 +35,6 @@ export class Main {
|
||||
|
||||
// Flags
|
||||
'--beta': Boolean,
|
||||
'--debug': Boolean,
|
||||
'--dry-run': Boolean,
|
||||
|
||||
// Aliases
|
||||
@@ -58,17 +53,6 @@ export class Main {
|
||||
console.log(helpMessage())
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
if (this.args['--init-next']) {
|
||||
const result = await initNext(this.args)
|
||||
if (!result.success) {
|
||||
error(result.reason || 'Failed to initialize Payload app in Next.js project')
|
||||
} else {
|
||||
success('Payload app successfully initialized in Next.js project')
|
||||
}
|
||||
process.exit(result.success ? 0 : 1)
|
||||
}
|
||||
|
||||
const templateArg = this.args['--template']
|
||||
if (templateArg) {
|
||||
const valid = validateTemplate(templateArg)
|
||||
|
||||
@@ -3,10 +3,8 @@ import type arg from 'arg'
|
||||
export interface Args extends arg.Spec {
|
||||
'--beta': BooleanConstructor
|
||||
'--db': StringConstructor
|
||||
'--debug': BooleanConstructor
|
||||
'--dry-run': BooleanConstructor
|
||||
'--help': BooleanConstructor
|
||||
'--init-next': BooleanConstructor
|
||||
'--name': StringConstructor
|
||||
'--no-deps': BooleanConstructor
|
||||
'--secret': StringConstructor
|
||||
@@ -14,9 +12,6 @@ export interface Args extends arg.Spec {
|
||||
'--use-npm': BooleanConstructor
|
||||
'--use-pnpm': BooleanConstructor
|
||||
'--use-yarn': BooleanConstructor
|
||||
|
||||
// Aliases
|
||||
|
||||
'-h': string
|
||||
'-n': string
|
||||
'-t': string
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
/**
|
||||
* Recursively copy files from src to dest
|
||||
*/
|
||||
export function copyRecursiveSync(src: string, dest: string, debug?: boolean) {
|
||||
const exists = fs.existsSync(src)
|
||||
const stats = exists && fs.statSync(src)
|
||||
const isDirectory = exists && stats.isDirectory()
|
||||
if (isDirectory) {
|
||||
fs.mkdirSync(dest, { recursive: true })
|
||||
fs.readdirSync(src).forEach((childItemName) => {
|
||||
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))
|
||||
})
|
||||
} else {
|
||||
fs.copyFileSync(src, dest)
|
||||
}
|
||||
}
|
||||
@@ -9,18 +9,10 @@ export const warning = (message: string): void => {
|
||||
console.log(chalk.yellow('? ') + chalk.bold(message))
|
||||
}
|
||||
|
||||
export const info = (message: string, paddingTop?: number): void => {
|
||||
console.log(
|
||||
`${'\n'.repeat(paddingTop || 0)}${chalk.green(figures.pointerSmall)} ${chalk.bold(message)}`,
|
||||
)
|
||||
export const info = (message: string): void => {
|
||||
console.log(`${chalk.yellow(figures.info)} ${chalk.bold(message)}`)
|
||||
}
|
||||
|
||||
export const error = (message: string): void => {
|
||||
console.log(`${chalk.red(figures.cross)} ${chalk.bold(message)}`)
|
||||
}
|
||||
|
||||
export const debug = (message: string): void => {
|
||||
console.log(
|
||||
`${chalk.gray(figures.pointerSmall)} ${chalk.bgGray('[DEBUG]')} ${chalk.gray(message)}`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
{
|
||||
"name": "@payloadcms/db-mongodb",
|
||||
"version": "3.0.0-alpha.23",
|
||||
"description": "The officially supported MongoDB database adapter for Payload - Update 2",
|
||||
"version": "1.4.3",
|
||||
"description": "The officially supported MongoDB database adapter for Payload",
|
||||
"repository": "https://github.com/payloadcms/payload",
|
||||
"license": "MIT",
|
||||
"homepage": "https://payloadcms.com",
|
||||
"type": "module",
|
||||
"author": {
|
||||
"email": "info@payloadcms.com",
|
||||
"name": "Payload",
|
||||
@@ -18,17 +17,17 @@
|
||||
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
||||
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
||||
"clean": "rimraf {dist,*.tsbuildinfo}",
|
||||
"prepublishOnly": "pnpm clean && pnpm turbo build"
|
||||
"prepublishOnly": "pnpm clean && pnpm build"
|
||||
},
|
||||
"dependencies": {
|
||||
"bson-objectid": "2.0.4",
|
||||
"deepmerge": "4.3.1",
|
||||
"get-port": "5.1.1",
|
||||
"http-status": "1.6.2",
|
||||
"mongoose": "6.12.3",
|
||||
"mongoose-aggregate-paginate-v2": "1.0.6",
|
||||
"mongoose-paginate-v2": "1.7.22",
|
||||
"prompts": "2.4.2",
|
||||
"http-status": "1.6.2",
|
||||
"uuid": "9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -39,7 +38,7 @@
|
||||
"payload": "workspace:*"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"payload": "workspace:*"
|
||||
"payload": "^2.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"main": "./dist/index.js",
|
||||
|
||||
@@ -4,26 +4,19 @@ import type { Connect } from 'payload/database'
|
||||
|
||||
import mongoose from 'mongoose'
|
||||
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
|
||||
export const connect: Connect = async function connect(
|
||||
this: MongooseAdapter,
|
||||
options = {
|
||||
hotReload: false,
|
||||
},
|
||||
) {
|
||||
const { hotReload } = options
|
||||
import type { MongooseAdapter } from '.'
|
||||
|
||||
export const connect: Connect = async function connect(this: MongooseAdapter, payload) {
|
||||
if (this.url === false) {
|
||||
return
|
||||
}
|
||||
|
||||
if (typeof this.url !== 'string') {
|
||||
if (!payload.local && typeof this.url !== 'string') {
|
||||
throw new Error('Error: missing MongoDB connection URL.')
|
||||
}
|
||||
|
||||
const urlToConnect = this.url
|
||||
const successfulConnectionMessage = 'Connected to MongoDB server successfully!'
|
||||
let urlToConnect = this.url
|
||||
let successfulConnectionMessage = 'Connected to MongoDB server successfully!'
|
||||
|
||||
const connectionOptions: ConnectOptions & { useFacet: undefined } = {
|
||||
autoIndex: true,
|
||||
@@ -31,7 +24,29 @@ export const connect: Connect = async function connect(
|
||||
useFacet: undefined,
|
||||
}
|
||||
|
||||
if (hotReload) connectionOptions.autoIndex = false
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
if (process.env.PAYLOAD_TEST_MONGO_URL) {
|
||||
urlToConnect = process.env.PAYLOAD_TEST_MONGO_URL
|
||||
} else {
|
||||
connectionOptions.dbName = 'payloadmemory'
|
||||
const { MongoMemoryReplSet } = require('mongodb-memory-server')
|
||||
const getPort = require('get-port')
|
||||
|
||||
const port = await getPort()
|
||||
this.mongoMemoryServer = await MongoMemoryReplSet.create({
|
||||
instance: {
|
||||
dbName: 'payloadmemory',
|
||||
port,
|
||||
},
|
||||
replSet: {
|
||||
count: 3,
|
||||
},
|
||||
})
|
||||
|
||||
urlToConnect = this.mongoMemoryServer.getUri()
|
||||
successfulConnectionMessage = 'Connected to in-memory MongoDB server successfully!'
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.connection = (await mongoose.connect(urlToConnect, connectionOptions)).connection
|
||||
@@ -43,15 +58,12 @@ export const connect: Connect = async function connect(
|
||||
this.beginTransaction = undefined
|
||||
}
|
||||
|
||||
if (!hotReload) {
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----')
|
||||
await mongoose.connection.dropDatabase()
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----')
|
||||
}
|
||||
|
||||
this.payload.logger.info(successfulConnectionMessage)
|
||||
if (process.env.PAYLOAD_DROP_DATABASE === 'true') {
|
||||
this.payload.logger.info('---- DROPPING DATABASE ----')
|
||||
await mongoose.connection.dropDatabase()
|
||||
this.payload.logger.info('---- DROPPED DATABASE ----')
|
||||
}
|
||||
this.payload.logger.info(successfulConnectionMessage)
|
||||
} catch (err) {
|
||||
this.payload.logger.error(`Error: cannot connect to MongoDB. Details: ${err.message}`, err)
|
||||
process.exit(1)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Create } from 'payload/database'
|
||||
import type { Document, PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
import type { MongooseAdapter } from '.'
|
||||
|
||||
import handleError from './utilities/handleError.js'
|
||||
import { withSession } from './withSession.js'
|
||||
import handleError from './utilities/handleError'
|
||||
import { withSession } from './withSession'
|
||||
|
||||
export const create: Create = async function create(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { CreateGlobal } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
import type { MongooseAdapter } from '.'
|
||||
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields.js'
|
||||
import { withSession } from './withSession.js'
|
||||
import sanitizeInternalFields from './utilities/sanitizeInternalFields'
|
||||
import { withSession } from './withSession'
|
||||
|
||||
export const createGlobal: CreateGlobal = async function createGlobal(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { CreateGlobalVersion } from 'payload/database'
|
||||
import type { PayloadRequest } from 'payload/types'
|
||||
import type { Document } from 'payload/types'
|
||||
|
||||
import type { MongooseAdapter } from './index.d.ts'
|
||||
import type { MongooseAdapter } from '.'
|
||||
|
||||
import { withSession } from './withSession.js'
|
||||
import { withSession } from './withSession'
|
||||
|
||||
export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
|
||||
this: MongooseAdapter,
|
||||
|
||||
@@ -41,7 +41,7 @@ export const createMigration: CreateMigration = async function createMigration({
|
||||
|
||||
// Check if predefined migration exists
|
||||
if (fs.existsSync(cleanPath)) {
|
||||
const { down, up } = eval(`require(${cleanPath})`)
|
||||
const { down, up } = require(cleanPath)
|
||||
migrationFileContent = migrationTemplate(up, down)
|
||||
} else {
|
||||
payload.logger.error({
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user