Compare commits

..

41 Commits

Author SHA1 Message Date
Elliot DeNolf
4962f6c926 chore(release): v3.0.0-alpha.58 [skip ci] 2024-04-08 10:52:04 -04:00
James Mikrut
50f0e9298c chore: adds upload export back (#5722) 2024-04-08 10:47:10 -04:00
James
89efcc5db1 chore: adds upload export back 2024-04-08 10:46:41 -04:00
Elliot DeNolf
c3119a5632 chore(release): v3.0.0-alpha.57 [skip ci] 2024-04-08 10:29:26 -04:00
James Mikrut
069bbd92b0 Feat/bulletproof loader (#5721) 2024-04-08 10:18:38 -04:00
James
c4422a2593 chore: improves logic of loader 2024-04-08 10:17:18 -04:00
James
3aab9d368e chore: working loader 2024-04-08 10:07:55 -04:00
Elliot DeNolf
b6afab63b2 chore(cpa): remove test from prepublishOnly 2024-04-08 09:34:52 -04:00
Alessio Gravili
b93f5e9c44 feat!: pass in req to access.admin, to match 2.0 behavior, and strongly type it (#5712) 2024-04-07 22:22:48 -04:00
James
630082035f chore: sets up test environment for loader 2024-04-07 19:48:42 -04:00
Elliot DeNolf
c74e41fc76 chore(release): v3.0.0-alpha.56 [skip ci] 2024-04-07 13:53:49 -04:00
Alessio Gravili
08ce7c58b5 chore: upgrade playwright & TS, and hide deprecation warnings (#5708) 2024-04-06 17:15:02 -04:00
Alessio Gravili
1853fde379 chore: upgrade typescript and "@types/"-prefixed packages 2024-04-06 15:35:09 -04:00
Alessio Gravili
f29d22ca95 chore: ensure node deprecation warnings stay hidden during e2e test runs 2024-04-06 15:06:04 -04:00
Alessio Gravili
5ea5f928ab chore: upgrade playwright from 1.42.1 to 1.43.0 and update patches 2024-04-06 15:05:27 -04:00
James Mikrut
efd6d35eb3 Fix/live preview flake (#5707) 2024-04-06 14:31:19 -04:00
James
2b2538f13a chore: removes old bin 2024-04-06 14:31:02 -04:00
James
9375dae179 Merge branch 'alpha' of github.com:payloadcms/payload into fix/live-preview-flake 2024-04-06 14:22:50 -04:00
James
674bb3758d chore: reduces parallel creates in live preview seed 2024-04-06 14:22:43 -04:00
James Mikrut
cedf9a2eb8 chore: pre-builds in CI (#5690) 2024-04-06 14:10:25 -04:00
James
7d2dc5b6c6 chore: adds more tests to loader int suite 2024-04-06 14:07:17 -04:00
James
9d2aad7bf9 chore: lockfile 2024-04-06 14:01:16 -04:00
James
f085d7609b chore: cleanup 2024-04-06 13:59:29 -04:00
James
a49243a42a chore: cleanup 2024-04-06 13:58:05 -04:00
James
e79f431f14 chore: cleans up tsconfigs 2024-04-06 13:40:30 -04:00
James
38e5b6e8e3 chore: temp disables fields 2024-04-06 13:38:14 -04:00
James
35bdb785c4 Merge branch 'chore/pre-build-e2e' of github.com:payloadcms/payload into chore/pre-build-e2e 2024-04-06 13:35:35 -04:00
James
25cb146fde feat: moduleResolution: bundler in config loaders 2024-04-06 13:35:09 -04:00
Jarrod Flesch
c10f0f4a9e chore: fix sort header route replace 2024-04-05 22:34:04 -04:00
Elliot DeNolf
3a3a7f6e16 ci(scripts): remove p-map 2024-04-05 17:48:21 -04:00
Jarrod Flesch
684c4d2113 chore: fix admin sort flake, fix console warning for test package.json 2024-04-05 16:39:13 -04:00
James
31502d2da3 chore: attempts to de-flake admin 2024-04-05 16:12:49 -04:00
James
3ee39ecca3 chore: increases timeout for fields prebuild 2024-04-05 16:06:00 -04:00
James
60dd71c59e chore: sets longer timeout for prebuild in admin and fields 2024-04-05 15:49:12 -04:00
James
0936f77930 Merge branch 'alpha' of github.com:payloadcms/payload into chore/pre-build-e2e 2024-04-05 15:25:41 -04:00
James
3c09b95a8c chore: builds in child process for e2e 2024-04-05 15:23:07 -04:00
James
9147d30152 Merge branch 'chore/green-ci' of github.com:payloadcms/payload into chore/pre-build-e2e 2024-04-05 14:13:28 -04:00
James
6217c70fb5 chore: prebuilds fields and admin in ci 2024-04-05 14:13:14 -04:00
James
3bd455ced2 chore: pre-builds in CI 2024-04-05 11:46:02 -04:00
James
0c45d5773a chore: brings back admin and fields 2024-04-04 21:02:31 -04:00
James
f48335444b chore: flake 2024-04-04 21:01:38 -04:00
171 changed files with 1023 additions and 1112 deletions

View File

@@ -250,7 +250,7 @@ jobs:
suite:
- _community
- access-control
# - admin
- admin
- auth
- email
- field-error-states

11
.vscode/launch.json vendored
View File

@@ -23,6 +23,17 @@
"request": "launch",
"type": "node-terminal"
},
{
"command": "node --no-deprecation test/loader/init.js",
"cwd": "${workspaceFolder}",
"name": "Run Loader",
"request": "launch",
"type": "node-terminal",
"env": {
"LOADER_TEST_FILE_PATH": "./dependency-test.js"
// "LOADER_TEST_FILE_PATH": "../fields/config.ts"
}
},
{
"command": "node --no-deprecation test/dev.js admin",
"cwd": "${workspaceFolder}",

View File

@@ -14,8 +14,8 @@ type Args = {
}
}
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params, searchParams })
export const generateMetadata = ({ params }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params })
const NotFound = ({ params, searchParams }: Args) => NotFoundPage({ config, params, searchParams })

View File

@@ -1,35 +0,0 @@
import QueryString from 'qs'
import { PAYLOAD_SERVER_URL } from './serverURL.js'
export const fetchDoc = async <T>(args: {
collection: string
depth?: number
id?: string
slug?: string
}): Promise<T> => {
const { id, slug, collection, depth = 2 } = args || {}
const queryString = QueryString.stringify(
{
...(slug ? { 'where[slug][equals]': slug } : {}),
...(depth ? { depth } : {}),
},
{ addQueryPrefix: true },
)
const doc: T = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}${queryString}`, {
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
?.then((res) => res.json())
?.then((res) => {
if (res.errors) throw new Error(res?.errors?.[0]?.message ?? 'Error fetching doc')
return res?.docs?.[0]
})
return doc
}

View File

@@ -1,19 +0,0 @@
import { PAYLOAD_SERVER_URL } from './serverURL.js'
export const fetchDocs = async <T>(collection: string): Promise<T[]> => {
const docs: T[] = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}?depth=0&limit=100`, {
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
?.then((res) => res.json())
?.then((res) => {
if (res.errors) throw new Error(res?.errors?.[0]?.message ?? 'Error fetching docs')
return res?.docs
})
return docs
}

View File

@@ -1,25 +0,0 @@
import type { Footer } from '../../../test/live-preview/payload-types.js'
import { PAYLOAD_SERVER_URL } from './serverURL.js'
export async function fetchFooter(): Promise<Footer> {
if (!PAYLOAD_SERVER_URL) throw new Error('PAYLOAD_SERVER_URL not found')
const footer = await fetch(`${PAYLOAD_SERVER_URL}/api/globals/footer`, {
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
.then((res) => {
if (!res.ok) throw new Error('Error fetching doc')
return res.json()
})
?.then((res) => {
if (res?.errors) throw new Error(res?.errors[0]?.message || 'Error fetching footer')
return res
})
return footer
}

View File

@@ -1,25 +0,0 @@
import type { Header } from '../../../test/live-preview/payload-types.js'
import { PAYLOAD_SERVER_URL } from './serverURL.js'
export async function fetchHeader(): Promise<Header> {
if (!PAYLOAD_SERVER_URL) throw new Error('PAYLOAD_SERVER_URL not found')
const header = await fetch(`${PAYLOAD_SERVER_URL}/api/globals/header`, {
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
method: 'GET',
})
?.then((res) => {
if (!res.ok) throw new Error('Error fetching doc')
return res.json()
})
?.then((res) => {
if (res?.errors) throw new Error(res?.errors[0]?.message || 'Error fetching header')
return res
})
return header
}

View File

@@ -10,6 +10,12 @@ const withBundleAnalyzer = bundleAnalyzer({
export default withBundleAnalyzer(
withPayload({
reactStrictMode: false,
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
async redirects() {
return [
{

View File

@@ -1,6 +1,6 @@
{
"name": "payload-monorepo",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"private": true,
"type": "module",
"workspaces:": [
@@ -76,7 +76,7 @@
"@octokit/core": "^5.1.0",
"@payloadcms/eslint-config": "workspace:*",
"@payloadcms/live-preview-react": "workspace:*",
"@playwright/test": "^1.42.1",
"@playwright/test": "1.43.0",
"@swc/cli": "^0.1.62",
"@swc/jest": "0.2.36",
"@testing-library/jest-dom": "6.4.2",
@@ -88,13 +88,13 @@
"@types/conventional-changelog-writer": "^4.0.10",
"@types/fs-extra": "^11.0.2",
"@types/jest": "29.5.12",
"@types/minimist": "1.2.2",
"@types/node": "20.11.28",
"@types/minimist": "1.2.5",
"@types/node": "20.12.5",
"@types/prompts": "^2.4.5",
"@types/qs": "6.9.7",
"@types/react": "18.2.15",
"@types/qs": "6.9.14",
"@types/react": "18.2.74",
"@types/semver": "^7.5.3",
"@types/shelljs": "0.8.12",
"@types/shelljs": "0.8.15",
"add-stream": "^1.0.0",
"chalk": "^4.1.2",
"comment-json": "^4.2.3",
@@ -131,10 +131,11 @@
"node-mocks-http": "^1.14.1",
"nodemon": "3.0.3",
"open": "^10.1.0",
"p-limit": "^5.0.0",
"pino": "8.15.0",
"pino-pretty": "10.2.0",
"playwright": "^1.42.1",
"playwright-core": "^1.42.1",
"playwright": "1.43.0",
"playwright-core": "1.43.0",
"prettier": "^3.0.3",
"prompts": "2.4.2",
"qs": "6.11.2",
@@ -154,7 +155,7 @@
"ts-node": "10.9.1",
"tsx": "^4.7.1",
"turbo": "^1.13.2",
"typescript": "5.4.2",
"typescript": "5.4.4",
"uuid": "^9.0.1",
"yocto-queue": "^1.0.0"
},
@@ -194,8 +195,7 @@
"domexception": "4"
},
"patchedDependencies": {
"playwright@1.42.1": "patches/playwright@1.42.1.patch"
"playwright@1.43.0": "patches/playwright@1.43.0.patch"
}
},
"packageManager": "pnpm@8.15.4+sha256.cea6d0bdf2de3a0549582da3983c70c92ffc577ff4410cbf190817ddc35137c2"
}
}

View File

@@ -19,7 +19,7 @@
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
"clean": "rimraf {dist,*.tsbuildinfo}",
"test": "jest",
"prepublishOnly": "pnpm test && pnpm clean && pnpm build"
"prepublishOnly": "pnpm clean && pnpm build"
},
"files": [
"package.json",
@@ -48,7 +48,7 @@
"@types/esprima": "^4.0.6",
"@types/fs-extra": "^9.0.12",
"@types/jest": "^27.0.3",
"@types/node": "^16.6.2"
"@types/node": "20.12.5"
},
"exports": {
"./commands": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-mongodb",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "The officially supported MongoDB database adapter for Payload",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/db-postgres",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "The officially supported Postgres database adapter for Payload",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/graphql",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"main": "./src/index.ts",
"types": "./src/index.d.ts",
"type": "module",

View File

@@ -26,7 +26,7 @@
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/react": "^18.2.0",
"@types/react": "18.2.74",
"payload": "workspace:*"
},
"peerDependencies": {

View File

@@ -1,54 +0,0 @@
import path from 'path'
import fs from 'fs'
import { copyRecursiveSync } from './utilities/copyRecursiveSync'
import { copyFile } from './utilities/copyFile'
const install = () => {
const useSrc = fs.existsSync(path.resolve(process.cwd(), './src'))
const hasAppFolder = fs.existsSync(path.resolve(process.cwd(), `./${useSrc ? 'src/' : 'app'}`))
if (!hasAppFolder) {
console.error(
`You need to have a ${
useSrc ? 'src/' : 'app/'
} folder in your project before running this command.`,
)
process.exit(1)
}
const basePath = useSrc ? './src' : '.'
// Copy handlers into /api
copyRecursiveSync(
path.resolve(__dirname, './templates/pages/api'),
path.resolve(process.cwd(), `${basePath}/pages/api`),
)
// Copy admin into /app
copyRecursiveSync(
path.resolve(__dirname, './templates/app'),
path.resolve(process.cwd(), `${basePath}/app`),
)
const payloadConfigPath = path.resolve(process.cwd(), `${basePath}/payload`)
if (!fs.existsSync(payloadConfigPath)) {
fs.mkdirSync(payloadConfigPath)
}
// Copy payload initialization
copyFile(
path.resolve(__dirname, './templates/payloadClient.ts'),
path.resolve(process.cwd(), `${basePath}/payload/payloadClient.ts`),
)
// Copy base payload config
copyFile(
path.resolve(__dirname, './templates/payload.config.ts'),
path.resolve(process.cwd(), `${basePath}/payload/payload.config.ts`),
)
process.exit(0)
}
export default install()

View File

@@ -1,7 +0,0 @@
import fs from 'fs'
export const copyFile = (source, target) => {
if (!fs.existsSync(target)) {
fs.writeFileSync(target, fs.readFileSync(source))
}
}

View File

@@ -1,16 +0,0 @@
import fs from 'fs'
import path from 'path'
export function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src)
var stats = exists && fs.statSync(src)
var isDirectory = exists && stats && stats.isDirectory()
if (isDirectory) {
fs.mkdirSync(dest, { recursive: true })
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName))
})
} else {
fs.copyFileSync(src, dest)
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/next",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"main": "./src/index.js",
"types": "./src/index.js",
"type": "module",
@@ -10,9 +10,6 @@
"url": "https://github.com/payloadcms/payload.git",
"directory": "packages/next"
},
"bin": {
"@payloadcms/next": "./dist/bin/index.js"
},
"scripts": {
"build": "pnpm copyfiles && pnpm build:swc && pnpm build:types && pnpm build:webpack && rm dist/prod/index.js",
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
@@ -39,8 +36,8 @@
"devDependencies": {
"@next/eslint-plugin-next": "^14.1.0",
"@payloadcms/eslint-config": "workspace:*",
"@types/react": "18.2.15",
"@types/react-dom": "18.2.7",
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"@types/ws": "^8.5.10",
"css-loader": "^6.10.0",
"css-minimizer-webpack-plugin": "^6.0.0",

View File

@@ -46,7 +46,7 @@ export const buildFormState = async ({ req }: { req: PayloadRequest }) => {
// Run the admin access function from the config if it exists
if (adminAccessFunction) {
const canAccessAdmin = await adminAccessFunction(req)
const canAccessAdmin = await adminAccessFunction({ req })
if (!canAccessAdmin) {
return Response.json(null, {

View File

@@ -6,11 +6,12 @@ import './index.scss'
const baseClass = 'live-preview-iframe'
export const IFrame: React.FC<{
ref: React.Ref<HTMLIFrameElement>
type Props = {
setIframeHasLoaded: (value: boolean) => void
url: string
}> = forwardRef((props, ref) => {
}
export const IFrame = forwardRef<HTMLIFrameElement, Props>((props, ref) => {
const { setIframeHasLoaded, url } = props
const { zoom } = useLivePreviewContext()

View File

@@ -2,6 +2,7 @@ import type { I18n } from '@payloadcms/translations'
import type { Metadata } from 'next'
import type { SanitizedConfig } from 'payload/types'
import { getNextI18n } from '@payloadcms/next/utilities/getNextI18n.js'
import { HydrateClientUser } from '@payloadcms/ui/elements/HydrateClientUser'
import { DefaultTemplate } from '@payloadcms/ui/templates/Default'
import React, { Fragment } from 'react'
@@ -10,13 +11,18 @@ import { initPage } from '../../utilities/initPage.js'
import { NotFoundClient } from './index.client.js'
export const generatePageMetadata = async ({
i18n,
config: configPromise,
}: {
config: SanitizedConfig
i18n: I18n
config: Promise<SanitizedConfig> | SanitizedConfig
params?: { [key: string]: string | string[] }
//eslint-disable-next-line @typescript-eslint/require-await
}): Promise<Metadata> => {
const config = await configPromise
const i18n = getNextI18n({
config,
})
return {
title: i18n.t('general:notFound'),
}

View File

@@ -49,7 +49,7 @@ export const generatePageMetadata = async ({ config: configPromise, params }: Ar
const isGlobal = segmentOne === 'globals'
const isCollection = segmentOne === 'collections'
const i18n = await getNextI18n({
const i18n = getNextI18n({
config,
})

View File

@@ -12,7 +12,7 @@ if (process.env.DISABLE_SWC !== 'true') {
const dirname = path.dirname(filename)
const url = pathToFileURL(dirname).toString() + '/'
register('./dist/bin/register/index.js', url)
register('./dist/bin/loader/index.js', url)
}
bin()

View File

@@ -1,6 +1,6 @@
{
"name": "payload",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "Node, React and MongoDB Headless CMS and Application Framework",
"license": "MIT",
"main": "./src/index.ts",
@@ -61,7 +61,6 @@
"nodemailer": "6.9.10",
"pino": "8.15.0",
"pino-pretty": "10.2.0",
"pirates": "^4.0.6",
"pluralize": "8.0.0",
"probe-image-size": "^7.2.3",
"sanitize-filename": "1.6.3",

View File

@@ -19,10 +19,7 @@ export async function getAccessResults({ req }: GetAccessResultsArgs): Promise<P
if (userCollectionConfig) {
results.canAccessAdmin = userCollectionConfig.access.admin
? await userCollectionConfig.access.admin({
payload,
user,
})
? await userCollectionConfig.access.admin({ req })
: isLoggedIn
} else {
results.canAccessAdmin = false

View File

@@ -0,0 +1,40 @@
import type * as ts from 'typescript'
import { transform } from '@swc-node/core'
import { SourcemapMap } from '@swc-node/sourcemap-support'
import { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js'
const injectInlineSourceMap = ({
code,
filename,
map,
}: {
code: string
filename: string
map: string | undefined
}): string => {
if (map) {
SourcemapMap.set(filename, map)
const base64Map = Buffer.from(map, 'utf8').toString('base64')
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`
return `${code}\n${sourceMapContent}`
}
return code
}
export async function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
): Promise<string> {
if (filename.endsWith('.d.ts')) {
return ''
}
const swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename)
return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map }) => {
return injectInlineSourceMap({ code, filename, map })
})
}

View File

@@ -5,7 +5,7 @@ import ts from 'typescript'
import { fileURLToPath, pathToFileURL } from 'url'
import { CLIENT_EXTENSIONS } from './clientExtensions.js'
import { compile } from './register.js'
import { compile } from './compile.js'
interface ResolveContext {
conditions: string[]
@@ -26,6 +26,8 @@ type ResolveFn = (...args: Required<ResolveArgs>) => Promise<ResolveResult>
const locatedConfig = getTsconfig()
const tsconfig = locatedConfig.config.compilerOptions as unknown as ts.CompilerOptions
// Don't resolve d.ts files, because we aren't type-checking
tsconfig.noDtsResolution = true
tsconfig.module = ts.ModuleKind.ESNext
tsconfig.moduleResolution = ts.ModuleResolutionKind.NodeNext
@@ -38,18 +40,25 @@ const host: ts.ModuleResolutionHost = {
fileExists: ts.sys.fileExists,
readFile: ts.sys.readFile,
}
const EXTENSIONS: string[] = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Dts, ts.Extension.Mts]
const TS_EXTENSIONS: string[] = [
ts.Extension.Ts,
ts.Extension.Tsx,
ts.Extension.Dts,
ts.Extension.Mts,
]
export const resolve: ResolveFn = async (specifier, context, nextResolve) => {
const isTS = EXTENSIONS.some((ext) => specifier.endsWith(ext))
const isTS = TS_EXTENSIONS.some((ext) => specifier.endsWith(ext))
const isClient = CLIENT_EXTENSIONS.some((ext) => specifier.endsWith(ext))
// If a client file is resolved, we'll set `format: client`
// and short circuit, so the load step
// will return source code of empty object
if (isClient) {
const nextResult = await nextResolve(specifier, context, nextResolve)
const specifierSegments = specifier.split('.')
return {
format: '.' + specifierSegments[specifierSegments.length - 1],
format: 'client',
shortCircuit: true,
url: nextResult.url,
}
@@ -64,9 +73,28 @@ export const resolve: ResolveFn = async (specifier, context, nextResolve) => {
}
}
// import/require from external library
if (context.parentURL.includes('/node_modules/') && !isTS) {
return nextResolve(specifier)
// Try and resolve normally
// This could fail, so we need to swallow that error
// and keep going
let nextResult: ResolveResult
// First, try to
if (!isTS) {
try {
nextResult = await nextResolve(specifier, context, nextResolve)
} catch (_) {
// swallow error
}
}
if (nextResult) {
const nextResultIsTS = TS_EXTENSIONS.some((ext) => nextResult.url.endsWith(ext))
return {
...nextResult,
format: nextResultIsTS ? 'ts' : nextResult.format,
shortCircuit: true,
}
}
const { resolvedModule } = ts.resolveModuleName(
@@ -77,14 +105,11 @@ export const resolve: ResolveFn = async (specifier, context, nextResolve) => {
moduleResolutionCache,
)
// import from local project to local project TS file
if (
resolvedModule &&
!resolvedModule.resolvedFileName.includes('/node_modules/') &&
EXTENSIONS.includes(resolvedModule.extension)
) {
if (resolvedModule) {
const resolvedIsTS = TS_EXTENSIONS.includes(resolvedModule.extension)
return {
format: 'ts',
format: resolvedIsTS ? 'ts' : undefined,
shortCircuit: true,
url: pathToFileURL(resolvedModule.resolvedFileName).href,
}
@@ -92,9 +117,8 @@ export const resolve: ResolveFn = async (specifier, context, nextResolve) => {
// import from local project to either:
// - something TS couldn't resolve
// - external library
// - local project non-TS file
return nextResolve(specifier)
return nextResolve(specifier, context, nextResolve)
}
interface LoadContext {
@@ -127,11 +151,11 @@ if (tsconfig.paths) {
}
export const load: LoadFn = async (url, context, nextLoad) => {
if (CLIENT_EXTENSIONS.some((e) => context.format === e)) {
const rawSource = '{}'
if (context.format === 'client') {
const rawSource = 'export default {}'
return {
format: 'json',
format: 'module',
shortCircuit: true,
source: rawSource,
}
@@ -140,7 +164,7 @@ export const load: LoadFn = async (url, context, nextLoad) => {
if (context.format === 'ts') {
const { source } = await nextLoad(url, context)
const code = typeof source === 'string' ? source : Buffer.from(source).toString()
const compiled = await compile(code, fileURLToPath(url), swcOptions, true)
const compiled = await compile(code, fileURLToPath(url), swcOptions)
return {
format: 'module',
shortCircuit: true,

View File

@@ -1,125 +0,0 @@
import type { Options } from '@swc-node/core'
import { transform, transformSync } from '@swc-node/core'
import { SourcemapMap, installSourceMapSupport } from '@swc-node/sourcemap-support'
import { getTsconfig } from 'get-tsconfig'
import { platform } from 'os'
import { resolve } from 'path'
import { addHook } from 'pirates'
import * as ts from 'typescript'
import { tsCompilerOptionsToSwcConfig } from './read-default-tsconfig.js'
const DEFAULT_EXTENSIONS = ['.js', '.jsx', '.es6', '.es', '.mjs', '.ts', '.tsx']
const PLATFORM = platform()
const injectInlineSourceMap = ({
code,
filename,
map,
}: {
code: string
filename: string
map: string | undefined
}): string => {
if (map) {
SourcemapMap.set(filename, map)
const base64Map = Buffer.from(map, 'utf8').toString('base64')
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`
return `${code}\n${sourceMapContent}`
}
return code
}
export function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
): string
export function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
async: false,
): string
export function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
async: true,
): Promise<string>
export function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
async: boolean,
): Promise<string> | string
export function compile(
sourcecode: string,
filename: string,
options: ts.CompilerOptions & { fallbackToTs?: (filename: string) => boolean },
async = false,
) {
if (filename.endsWith('.d.ts')) {
return ''
}
if (options.files && (options.files as string[]).length) {
if (
PLATFORM === 'win32' &&
(options.files as string[]).every((file) => filename !== resolve(process.cwd(), file))
) {
return sourcecode
}
if (
PLATFORM !== 'win32' &&
(options.files as string[]).every((file) => !filename.endsWith(file))
) {
return sourcecode
}
}
if (options && typeof options.fallbackToTs === 'function' && options.fallbackToTs(filename)) {
delete options.fallbackToTs
const { outputText, sourceMapText } = ts.transpileModule(sourcecode, {
compilerOptions: options,
fileName: filename,
})
return injectInlineSourceMap({ code: outputText, filename, map: sourceMapText })
}
let swcRegisterConfig: Options
if (process.env.SWCRC) {
// when SWCRC environment variable is set to true it will use swcrc file
swcRegisterConfig = {
swc: {
swcrc: true,
},
}
} else {
swcRegisterConfig = tsCompilerOptionsToSwcConfig(options, filename)
}
if (async) {
return transform(sourcecode, filename, swcRegisterConfig).then(({ code, map }) => {
return injectInlineSourceMap({ code, filename, map })
})
} else {
const { code, map } = transformSync(sourcecode, filename, swcRegisterConfig)
return injectInlineSourceMap({ code, filename, map })
}
}
export function register(options: Partial<ts.CompilerOptions> = {}, hookOpts = {}) {
const locatedConfig = getTsconfig()
const tsconfig = locatedConfig.config.compilerOptions as unknown as ts.CompilerOptions
options = tsconfig
// options.module = ts.ModuleKind.CommonJS
installSourceMapSupport()
return addHook((code, filename) => compile(code, filename, options), {
exts: DEFAULT_EXTENSIONS,
...hookOpts,
})
}

View File

@@ -293,7 +293,7 @@ export type CollectionConfig = {
* Access control
*/
access?: {
admin?: (args?: any) => Promise<boolean> | boolean
admin?: ({ req }: { req: PayloadRequest }) => Promise<boolean> | boolean
create?: Access
delete?: Access
read?: Access

View File

@@ -1,44 +0,0 @@
import type pino from 'pino'
import { createRequire } from 'module'
import path from 'path'
import type { SanitizedConfig } from './types.js'
import { CLIENT_EXTENSIONS } from '../bin/register/clientExtensions.js'
import Logger from '../utilities/logger.js'
import { findConfig } from './find.js'
import { validateSchema } from './validate.js'
const require = createRequire(import.meta.url)
const loadConfig = async (logger?: pino.Logger): Promise<SanitizedConfig> => {
const localLogger = logger ?? Logger()
const configPath = findConfig()
CLIENT_EXTENSIONS.forEach((ext) => {
require.extensions[ext] = () => null
})
const configPromise = await import(configPath)
let config = await configPromise
if ('default' in config) config = await config.default
if (process.env.NODE_ENV !== 'production') {
config = validateSchema(config, localLogger)
}
return {
...config,
paths: {
config: configPath,
configDir: path.dirname(configPath),
rawConfig: configPath,
},
}
}
export default loadConfig

View File

@@ -1,3 +1 @@
export { getFileByPath } from '../uploads/getFileByPath.js'
export { importConfig } from '../utilities/importConfig.js'
export { importWithoutClientFiles } from '../utilities/importWithoutClientFiles.js'
export { importConfig, importWithoutClientFiles } from '../utilities/importWithoutClientFiles.js'

View File

@@ -0,0 +1 @@
export { getFileByPath } from '../uploads/getFileByPath.js'

View File

@@ -1,41 +0,0 @@
import path from 'node:path'
import type { SanitizedConfig } from '../config/types.js'
import { importWithoutClientFiles } from './importWithoutClientFiles.js'
/**
* Resolve and load Payload config from either a relative or absolute path
*/
export const importConfig = async (configPath: string) => {
const isAbsolutePath = path.isAbsolute(configPath)
if (isAbsolutePath) {
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(configPath)
return await config.default
}
const callerDir = path.dirname(getCallerInfo()[1].getFileName()).replace('file://', '')
const fullConfigPath = path.resolve(callerDir, configPath)
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(
fullConfigPath,
)
return await config.default
}
const getCallerInfo = () => {
const _prepareStackTrace = Error.prepareStackTrace
try {
let result = []
Error.prepareStackTrace = (_, callSites) => {
const callSitesWithoutCurrent = callSites.slice(1)
result = callSitesWithoutCurrent
return callSitesWithoutCurrent
}
new Error().stack
return result
} finally {
Error.prepareStackTrace = _prepareStackTrace
}
}

View File

@@ -2,13 +2,51 @@ import { register } from 'node:module'
import { fileURLToPath, pathToFileURL } from 'node:url'
import path from 'path'
import type { SanitizedConfig } from '../config/types.js'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export const importWithoutClientFiles = async <T = unknown>(filePath: string) => {
const url = pathToFileURL(filePath).toString()
register(path.resolve(dirname, '../../dist/bin/register/index.js'), url)
register(path.resolve(dirname, '../../dist/bin/loader/index.js'), url)
const result = await import(filePath)
return result as T
}
/**
* Resolve and load Payload config from either a relative or absolute path
*/
export const importConfig = async (configPath: string) => {
const isAbsolutePath = path.isAbsolute(configPath)
if (isAbsolutePath) {
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(configPath)
return await config.default
}
const callerDir = path.dirname(getCallerInfo()[1].getFileName()).replace('file://', '')
const fullConfigPath = path.resolve(callerDir, configPath)
const config = await importWithoutClientFiles<{ default: Promise<SanitizedConfig> }>(
fullConfigPath,
)
return await config.default
}
const getCallerInfo = () => {
const _prepareStackTrace = Error.prepareStackTrace
try {
let result = []
Error.prepareStackTrace = (_, callSites) => {
const callSitesWithoutCurrent = callSites.slice(1)
result = callSitesWithoutCurrent
return callSitesWithoutCurrent
}
new Error().stack
return result
} finally {
Error.prepareStackTrace = _prepareStackTrace
}
}

2
packages/payload/uploads.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export { getFileByPath } from './dist/uploads/getFileByPath.js'
//# sourceMappingURL=uploads.d.ts.map

View File

@@ -0,0 +1,3 @@
export { getFileByPath } from './dist/uploads/getFileByPath.js'
//# sourceMappingURL=uploads.js.map

View File

@@ -1,7 +1,7 @@
{
"name": "@payloadcms/plugin-cloud-storage",
"description": "The official cloud storage plugin for Payload CMS",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"main": "./src/index.ts",
"types": "./src/index.ts",
"type": "module",

View File

@@ -1,7 +1,7 @@
{
"name": "@payloadcms/plugin-cloud",
"description": "The official Payload Cloud plugin",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"main": "./src/index.ts",
"types": "./src/index.ts",
"license": "MIT",

View File

@@ -1,7 +1,7 @@
{
"name": "@payloadcms/plugin-form-builder",
"description": "Form builder plugin for Payload CMS",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"homepage:": "https://payloadcms.com",
"repository": {
"type": "git",
@@ -34,7 +34,7 @@
"@payloadcms/eslint-config": "workspace:*",
"@types/escape-html": "^1.0.4",
"@types/express": "^4.17.21",
"@types/react": "18.2.15",
"@types/react": "18.2.74",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"nodemon": "3.0.3",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-nested-docs",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "The official Nested Docs plugin for Payload",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-redirects",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"homepage:": "https://payloadcms.com",
"repository": {
"type": "git",
@@ -36,7 +36,7 @@
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/express": "^4.17.9",
"@types/react": "18.0.21",
"@types/react": "18.2.74",
"payload": "workspace:*",
"react": "^18.0.0"
},

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-search",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"homepage:": "https://payloadcms.com",
"repository": {
"type": "git",
@@ -41,7 +41,7 @@
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/express": "^4.17.9",
"@types/react": "18.0.21",
"@types/react": "18.2.74",
"payload": "workspace:*",
"react": "^18.0.0"
},

View File

@@ -44,8 +44,8 @@
"@payloadcms/eslint-config": "workspace:*",
"@types/express": "^4.17.9",
"@types/jest": "^29.5.2",
"@types/node": "18.11.3",
"@types/react": "18.0.21",
"@types/node": "20.12.5",
"@types/react": "18.2.74",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"dotenv": "^8.2.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/plugin-seo",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"homepage:": "https://payloadcms.com",
"repository": {
"type": "git",
@@ -40,7 +40,7 @@
},
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/react": "18.2.15",
"@types/react": "18.2.74",
"payload": "workspace:*",
"@payloadcms/translations": "workspace:*",
"@payloadcms/ui": "workspace:*",

View File

@@ -45,7 +45,7 @@
"@payloadcms/eslint-config": "workspace:*",
"@types/express": "^4.17.9",
"@types/lodash.get": "^4.4.7",
"@types/react": "18.0.21",
"@types/react": "18.2.74",
"@types/uuid": "^9.0.0",
"payload": "workspace:*",
"prettier": "^2.7.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/richtext-lexical",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "The officially supported Lexical richtext adapter for Payload",
"repository": {
"type": "git",
@@ -47,9 +47,9 @@
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@types/json-schema": "7.0.15",
"@types/node": "20.6.2",
"@types/react": "18.2.15",
"@types/react-dom": "18.2.7",
"@types/node": "20.12.5",
"@types/react": "18.2.74",
"@types/react-dom": "18.2.24",
"payload": "workspace:*",
"@payloadcms/translations": "workspace:*",
"@payloadcms/ui": "workspace:*",

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/richtext-slate",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"description": "The officially supported Slate richtext adapter for Payload",
"repository": {
"type": "git",
@@ -33,8 +33,8 @@
"devDependencies": {
"@payloadcms/ui": "workspace:*",
"@payloadcms/eslint-config": "workspace:*",
"@types/node": "20.5.7",
"@types/react": "18.2.15",
"@types/node": "20.12.5",
"@types/react": "18.2.74",
"payload": "workspace:*"
},
"peerDependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/translations",
"version": "3.0.0-alpha.54",
"version": "3.0.0-alpha.58",
"main": "./src/exports/index.ts",
"types": "./src/types.ts",
"type": "module",
@@ -56,8 +56,8 @@
"devDependencies": {
"@payloadcms/eslint-config": "workspace:*",
"@swc/core": "^1.3.102",
"@types/react": "^18",
"typescript": "5.4.2"
"@types/react": "18.2.74",
"typescript": "5.4.4"
},
"files": [
"dist"

View File

@@ -1,6 +1,6 @@
{
"name": "@payloadcms/ui",
"version": "3.0.0-alpha.55",
"version": "3.0.0-alpha.58",
"type": "module",
"homepage": "https://payloadcms.com",
"repository": {
@@ -174,9 +174,9 @@
"@payloadcms/eslint-config": "workspace:*",
"@types/body-scroll-lock": "^3.1.0",
"@types/qs": "6.9.7",
"@types/react": "18.2.15",
"@types/react": "18.2.74",
"@types/react-datepicker": "4.11.2",
"@types/react-dom": "18.2.7",
"@types/react-dom": "18.2.24",
"@types/uuid": "8.3.4",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^9.5.0",

View File

@@ -1,5 +1,3 @@
import type { Ref } from 'react'
import React, { forwardRef } from 'react'
import './index.scss'
@@ -10,43 +8,40 @@ export type GutterProps = {
left?: boolean
negativeLeft?: boolean
negativeRight?: boolean
ref?: Ref<HTMLDivElement>
right?: boolean
}
const baseClass = 'gutter'
export const Gutter: React.FC<GutterProps> = forwardRef<HTMLDivElement, GutterProps>(
(props, ref) => {
const {
children,
className,
left = true,
negativeLeft = false,
negativeRight = false,
right = true,
} = props
export const Gutter = forwardRef<HTMLDivElement, GutterProps>((props, ref) => {
const {
children,
className,
left = true,
negativeLeft = false,
negativeRight = false,
right = true,
} = props
const shouldPadLeft = left && !negativeLeft
const shouldPadRight = right && !negativeRight
const shouldPadLeft = left && !negativeLeft
const shouldPadRight = right && !negativeRight
return (
<div
className={[
shouldPadLeft && `${baseClass}--left`,
shouldPadRight && `${baseClass}--right`,
negativeLeft && `${baseClass}--negative-left`,
negativeRight && `${baseClass}--negative-right`,
className,
]
.filter(Boolean)
.join(' ')}
ref={ref}
>
{children}
</div>
)
},
)
return (
<div
className={[
shouldPadLeft && `${baseClass}--left`,
shouldPadRight && `${baseClass}--right`,
negativeLeft && `${baseClass}--negative-left`,
negativeRight && `${baseClass}--negative-right`,
className,
]
.filter(Boolean)
.join(' ')}
ref={ref}
>
{children}
</div>
)
})
Gutter.displayName = 'Gutter'

View File

@@ -1,7 +1,6 @@
'use client'
// TODO: abstract the `next/navigation` dependency out from this component
import { usePathname, useRouter } from 'next/navigation.js'
import queryString from 'qs'
import { useRouter } from 'next/navigation.js'
import React, { useCallback } from 'react'
export type SortColumnProps = {
@@ -22,9 +21,8 @@ const baseClass = 'sort-column'
export const SortColumn: React.FC<SortColumnProps> = (props) => {
const { name, Label, disable = false, label } = props
const { searchParams } = useSearchParams()
const { searchParams, stringifyParams } = useSearchParams()
const router = useRouter()
const pathname = usePathname()
const { t } = useTranslation()
const { sort } = searchParams
@@ -40,17 +38,16 @@ export const SortColumn: React.FC<SortColumnProps> = (props) => {
const setSort = useCallback(
(newSort) => {
const search = queryString.stringify(
{
...searchParams,
sort: newSort,
},
{ addQueryPrefix: true },
router.replace(
stringifyParams({
params: {
sort: newSort,
},
replace: true,
}),
)
router.replace(`${pathname}?${search}`)
},
[searchParams, pathname, router],
[router, stringifyParams],
)
return (

View File

@@ -1,42 +1,33 @@
diff --git a/index.mjs b/index.mjs
index c736e9d13ad09e54ee6f1fe000a9c8d8aa853f40..92ca367464c3d582b7496fd57d59d2ff5849e398 100644
index c736e9d13ad09e54ee6f1fe000a9c8d8aa853f40..54f9db62354009d5c34673876d73fbee1f648a19 100644
--- a/index.mjs
+++ b/index.mjs
@@ -16,3 +16,6 @@
@@ -16,3 +16,5 @@
export * from 'playwright-core';
import playwright from 'playwright-core';
export default playwright;
+
+
+export function createElement() {} // https://github.com/microsoft/playwright/issues/26824 TODO: Maybe create proxy which returns this from react instead? It should be React.createElement
\ No newline at end of file
diff --git a/lib/transform/esmLoader.js b/lib/transform/esmLoader.js
index 80073de7dfc269c6f838e685850b9f32ea0c1f9a..be536bc0dd0969d692c58e4ca0b99f424bdc88a1 100644
index 80073de7dfc269c6f838e685850b9f32ea0c1f9a..76e59df1c543fb47735ef68654bec5d3b24cc07c 100644
--- a/lib/transform/esmLoader.js
+++ b/lib/transform/esmLoader.js
@@ -5,7 +5,17 @@ var _url = _interopRequireDefault(require("url"));
@@ -5,6 +5,10 @@ var _url = _interopRequireDefault(require("url"));
var _compilationCache = require("./compilationCache");
var _transform = require("./transform");
var _portTransport = require("./portTransport");
+
+
+const fs2 = require('node:fs/promises')
+const { fileURLToPath } = require('node:url')
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+
+const endsWith = ['scss', 'css', 'svg', 'png', 'jpg', 'eot', 'ttf', 'woff', 'woff2'];
+
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) Microsoft Corporation.
*
@@ -25,6 +35,27 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
@@ -25,6 +29,25 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
// Node < 18.6: defaultResolve takes 3 arguments.
// Node >= 18.6: nextResolve from the chain takes 2 arguments.
async function resolve(specifier, context, defaultResolve) {
+
+ if(specifier?.endsWith('/node_modules/playwright')) {
+ specifier = specifier.replace('/node_modules/playwright', '/node_modules/playwright/index.mjs')
+ }
@@ -55,12 +46,11 @@ index 80073de7dfc269c6f838e685850b9f32ea0c1f9a..be536bc0dd0969d692c58e4ca0b99f42
+ url: nextResult.url,
+ }
+ }
+
+
var _currentFileDepsColle;
if (context.parentURL && context.parentURL.startsWith('file://')) {
const filename = _url.default.fileURLToPath(context.parentURL);
@@ -41,6 +72,20 @@ async function resolve(specifier, context, defaultResolve) {
@@ -41,6 +64,18 @@ async function resolve(specifier, context, defaultResolve) {
// Node < 18.6: defaultLoad takes 3 arguments.
// Node >= 18.6: nextLoad from the chain takes 2 arguments.
async function load(moduleUrl, context, defaultLoad) {
@@ -75,8 +65,6 @@ index 80073de7dfc269c6f838e685850b9f32ea0c1f9a..be536bc0dd0969d692c58e4ca0b99f42
+ source: JSON.stringify(rawSource),
+ }
+ }
+
+
+
var _transport;
// Bail out for wasm, json, etc.

710
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ import { updateChangelog } from './utils/updateChangelog.js'
// Update this list with any packages to publish
const packageWhitelist = [
'payload',
'translations',
// 'translations',
'ui',
'next',
'graphql',
@@ -27,7 +27,7 @@ const packageWhitelist = [
'richtext-slate',
'richtext-lexical',
'create-payload-app',
// 'create-payload-app',
// Plugins
'plugin-cloud',
@@ -210,9 +210,8 @@ async function main() {
}
// Publish
const results: { name: string; success: boolean; details?: string }[] = await pMap(
packageDetails,
async (pkg) => {
const results: { name: string; success: boolean; details?: string }[] = await Promise.all(
packageDetails.map(async (pkg) => {
try {
console.log(logPrefix, chalk.bold(`🚀 ${pkg.name} publishing...`))
const cmdArgs = ['publish', '-C', pkg.packagePath, '--no-git-checks', '--tag', tag]
@@ -238,8 +237,7 @@ async function main() {
console.error(chalk.bold.red(`\n\n❌ ${pkg.name} ERROR: ${error.message}\n\n`))
return { name: pkg.name, success: false }
}
},
{ concurrency: 5 },
}),
)
console.log(chalk.bold.green(`\n\nResults:\n`))

View File

@@ -1,5 +1,5 @@
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'

View File

@@ -72,9 +72,16 @@ describe('admin', () => {
let disableDuplicateURL: AdminUrlUtil
let serverURL: string
beforeAll(async ({ browser }) => {
beforeAll(async ({ browser }, testInfo) => {
const prebuild = Boolean(process.env.CI)
if (prebuild) testInfo.setTimeout(testInfo.timeout * 2)
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({ dirname }))
;({ payload, serverURL } = await initPayloadE2ENoConfig<Config>({
dirname,
prebuild,
}))
geoUrl = new AdminUrlUtil(serverURL, geoCollectionSlug)
postsUrl = new AdminUrlUtil(serverURL, postsCollectionSlug)
customViewsURL = new AdminUrlUtil(serverURL, customViews2CollectionSlug)
@@ -1271,10 +1278,14 @@ describe('admin', () => {
const downChevron = page.locator('#heading-number .sort-column__desc')
await upChevron.click()
await page.waitForURL(/sort=number/)
await expect(page.locator('.row-1 .cell-number')).toHaveText('1')
await expect(page.locator('.row-2 .cell-number')).toHaveText('2')
await downChevron.click()
await page.waitForURL(/sort=-number/)
await expect(page.locator('.row-1 .cell-number')).toHaveText('2')
await expect(page.locator('.row-2 .cell-number')).toHaveText('1')
})

View File

@@ -1,15 +1,11 @@
import minimist from 'minimist'
import { MongoMemoryReplSet } from 'mongodb-memory-server'
import { nextDev } from 'next/dist/cli/next-dev.js'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import open, { openApp, apps } from 'open'
import open from 'open'
import { getNextJSRootDir } from './helpers/getNextJSRootDir.js'
import { createTestHooks } from './testHooks.js'
const _filename = fileURLToPath(import.meta.url)
const _dirname = dirname(_filename)
process.env.PAYLOAD_DROP_DATABASE = 'true'
const {
@@ -26,7 +22,7 @@ process.env.PAYLOAD_DROP_DATABASE = 'true'
const { afterTest, beforeTest } = await createTestHooks(testSuiteArg)
await beforeTest()
const rootDir = resolve(_dirname, '../')
const rootDir = getNextJSRootDir(testSuiteArg)
// Open the admin if the -o flag is passed
if (args.o) {

View File

@@ -1,5 +1,5 @@
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'

View File

@@ -42,9 +42,16 @@ let serverURL: string
// If we want to make this run in parallel: test.describe.configure({ mode: 'parallel' })
describe('fields', () => {
beforeAll(async ({ browser }) => {
beforeAll(async ({ browser }, testInfo) => {
const prebuild = Boolean(process.env.CI)
if (prebuild) testInfo.setTimeout(testInfo.timeout * 3)
process.env.SEED_IN_CONFIG_ONINIT = 'false' // Makes it so the payload config onInit seed is not run. Otherwise, the seed would be run unnecessarily twice for the initial test run - once for beforeEach and once for onInit
;({ payload, serverURL } = await initPayloadE2ENoConfig({ dirname }))
;({ payload, serverURL } = await initPayloadE2ENoConfig({
dirname,
prebuild,
}))
const context = await browser.newContext()
page = await context.newPage()
@@ -696,6 +703,8 @@ describe('fields', () => {
'#field-customBlocks input[name="customBlocks.0.block1Title"]',
)
await page.mouse.wheel(0, 1750)
await customBlocks.scrollIntoViewIfNeeded()
await expect(customBlocks).toHaveValue('Block 1: Prefilled Title')
@@ -775,6 +784,7 @@ describe('fields', () => {
const assertText3 = 'array row 3'
const assertGroupText3 = 'text in group in row 3'
await page.goto(url.create)
await page.mouse.wheel(0, 1750)
await page.locator('#field-potentiallyEmptyArray').scrollIntoViewIfNeeded()
await wait(300)

View File

@@ -1,7 +1,7 @@
import type { Payload } from 'payload'
import path from 'path'
import { getFileByPath } from 'payload/node'
import { getFileByPath } from 'payload/uploads'
import { fileURLToPath } from 'url'
import { devUser } from '../credentials.js'

7
test/helpers/build.js Normal file
View File

@@ -0,0 +1,7 @@
import nextBuild from 'next/dist/build/index.js'
const build = async () => {
await nextBuild.default(process.env.NEXTJS_DIR, false, false, false, true, true, false, 'default')
}
build()

View File

@@ -0,0 +1,25 @@
import fs from 'fs'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
const _filename = fileURLToPath(import.meta.url)
const _dirname = dirname(_filename)
export const getNextJSRootDir = (testSuite) => {
const testSuiteDir = resolve(_dirname, `../${testSuite}`)
let hasNextConfig = false
try {
fs.accessSync(`${testSuiteDir}/next.config.mjs`, fs.constants.F_OK)
hasNextConfig = true
} catch (err) {
// Swallow err - no config found
}
if (hasNextConfig) return testSuiteDir
// If no next config found in test suite,
// return monorepo root dir
return resolve(_dirname, '../../')
}

View File

@@ -1,17 +1,24 @@
import { createServer } from 'http'
import nextImport from 'next'
import path from 'path'
import { spawn } from 'node:child_process'
import { dirname, resolve } from 'path'
import { wait } from 'payload/utilities'
import { parse } from 'url'
import { fileURLToPath } from 'url'
import type { GeneratedTypes } from './sdk/types.js'
import { createTestHooks } from '../testHooks.js'
import { getNextJSRootDir } from './getNextJSRootDir.js'
import { PayloadTestSDK } from './sdk/index.js'
import startMemoryDB from './startMemoryDB.js'
const _filename = fileURLToPath(import.meta.url)
const _dirname = dirname(_filename)
type Args = {
dirname: string
prebuild?: boolean
}
type Result<T extends GeneratedTypes<T>> = {
@@ -21,6 +28,7 @@ type Result<T extends GeneratedTypes<T>> = {
export async function initPayloadE2ENoConfig<T extends GeneratedTypes<T>>({
dirname,
prebuild,
}: Args): Promise<Result<T>> {
const testSuiteName = dirname.split('/').pop()
const { beforeTest } = await createTestHooks(testSuiteName)
@@ -32,12 +40,36 @@ export async function initPayloadE2ENoConfig<T extends GeneratedTypes<T>>({
await startMemoryDB()
const dir = getNextJSRootDir(testSuiteName)
if (prebuild) {
await new Promise<void>((res, rej) => {
const buildArgs = ['--max-old-space-size=8192', resolve(_dirname, 'build.js')]
const childProcess = spawn('node', buildArgs, {
stdio: 'inherit',
env: {
PATH: process.env.PATH,
NODE_ENV: 'production',
NEXTJS_DIR: dir,
},
})
childProcess.on('close', (code) => {
if (code === 0) res()
rej()
})
})
}
process.env.NODE_OPTIONS = '--max-old-space-size=8192 --no-deprecation'
// @ts-expect-error
const app = nextImport({
dev: true,
dev: !prebuild,
hostname: 'localhost',
port,
dir: path.resolve(dirname, '../../'),
dir,
})
const handle = app.getRequestHandler()

View File

@@ -22,7 +22,5 @@ export default async () => {
global._mongoMemoryServer = db
process.env.MONGODB_MEMORY_SERVER_URI = `${global._mongoMemoryServer.getUri()}&retryWrites=true`
console.log(process.env.MONGODB_MEMORY_SERVER_URI)
}
}

View File

@@ -0,0 +1,22 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import type { Metadata } from 'next'
import config from '@payload-config'
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import { NotFoundPage, generatePageMetadata } from '@payloadcms/next/views/NotFound/index.js'
type Args = {
params: {
segments: string[]
}
searchParams: {
[key: string]: string | string[]
}
}
export const generateMetadata = ({ params }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params })
const NotFound = ({ params, searchParams }: Args) => NotFoundPage({ config, params, searchParams })
export default NotFound

View File

@@ -0,0 +1,22 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import type { Metadata } from 'next'
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.js'
type Args = {
params: {
segments: string[]
}
searchParams: {
[key: string]: string | string[]
}
}
export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params, searchParams })
const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })
export default Page

View File

@@ -0,0 +1,9 @@
/* 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/index.js'
export const GET = REST_GET(config)
export const POST = REST_POST(config)
export const DELETE = REST_DELETE(config)
export const PATCH = REST_PATCH(config)

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 config from '@payload-config'
import { GRAPHQL_PLAYGROUND_GET } from '@payloadcms/next/routes/index.js'
export const GET = GRAPHQL_PLAYGROUND_GET(config)

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 config from '@payload-config'
import { GRAPHQL_POST } from '@payloadcms/next/routes/index.js'
export const POST = GRAPHQL_POST(config)

View File

@@ -0,0 +1,8 @@
#custom-css {
font-family: monospace;
background-image: url('/placeholder.png');
}
#custom-css::after {
content: 'custom-css';
}

View File

@@ -0,0 +1,15 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import configPromise from '@payload-config'
import { RootLayout } from '@payloadcms/next/layouts/Root/index.js'
/* 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

View File

@@ -3,7 +3,7 @@
import { useLivePreview } from '@payloadcms/live-preview-react'
import React from 'react'
import type { Post as PostType } from '../../../../../test/live-preview/payload-types.js'
import type { Post as PostType } from '../../../../../payload-types.js'
import { PAYLOAD_SERVER_URL } from '../../../_api/serverURL.js'
import { Blocks } from '../../../_components/Blocks/index.js'

View File

@@ -1,7 +1,7 @@
import { notFound } from 'next/navigation.js'
import React from 'react'
import type { Post } from '../../../../../test/live-preview/payload-types.js'
import type { Post } from '../../../../../payload-types.js'
import { fetchDoc } from '../../../_api/fetchDoc.js'
import { fetchDocs } from '../../../_api/fetchDocs.js'

View File

@@ -0,0 +1,35 @@
import type { Where } from 'payload/types'
import config from '@payload-config'
import { getPayloadHMR } from '@payloadcms/next/utilities/getPayloadHMR.js'
export const fetchDoc = async <T>(args: {
collection: string
depth?: number
slug?: string
}): Promise<T> => {
const payload = await getPayloadHMR({ config })
const { slug, collection, depth = 2 } = args || {}
const where: Where = {}
if (slug) {
where.slug = {
equals: slug,
}
}
try {
const { docs } = await payload.find({
collection,
depth,
where,
})
if (docs[0]) return docs[0] as T
} catch (err) {
console.log('Error fetching doc', err)
}
throw new Error('Error fetching doc')
}

View File

@@ -0,0 +1,20 @@
import config from '@payload-config'
import { getPayloadHMR } from '@payloadcms/next/utilities/getPayloadHMR.js'
export const fetchDocs = async <T>(collection: string): Promise<T[]> => {
const payload = await getPayloadHMR({ config })
try {
const { docs } = await payload.find({
collection,
depth: 0,
limit: 100,
})
return docs as T[]
} catch (err) {
console.error(err)
}
throw new Error('Error fetching docs')
}

View File

@@ -0,0 +1,20 @@
import config from '@payload-config'
import { getPayloadHMR } from '@payloadcms/next/utilities/getPayloadHMR.js'
import type { Footer } from '../../../payload-types.js'
export async function fetchFooter(): Promise<Footer> {
const payload = await getPayloadHMR({ config })
try {
const footer = await payload.findGlobal({
slug: 'footer',
})
return footer as Footer
} catch (err) {
console.error(err)
}
throw new Error('Error fetching footer.')
}

View File

@@ -0,0 +1,20 @@
import config from '@payload-config'
import { getPayloadHMR } from '@payloadcms/next/utilities/getPayloadHMR.js'
import type { Header } from '../../../payload-types.js'
export async function fetchHeader(): Promise<Header> {
const payload = await getPayloadHMR({ config })
try {
const header = await payload.findGlobal({
slug: 'header',
})
return header as Header
} catch (err) {
console.error(err)
}
throw new Error('Error fetching header.')
}

View File

@@ -1,4 +1,4 @@
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
export type ArchiveBlockProps = Extract<
Exclude<Page['layout'], undefined>[0],

View File

@@ -1,6 +1,6 @@
import React from 'react'
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
import { Gutter } from '../../_components/Gutter/index.js'
import { CMSLink } from '../../_components/Link/index.js'

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react'
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
import { Gutter } from '../../_components/Gutter/index.js'
import { CMSLink } from '../../_components/Link/index.js'

View File

@@ -2,7 +2,7 @@ import type { StaticImageData } from 'next/image.js'
import React from 'react'
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
import { Gutter } from '../../_components/Gutter/index.js'
import { Media } from '../../_components/Media/index.js'

View File

@@ -1,6 +1,6 @@
import React from 'react'
import type { Post } from '../../../../test/live-preview/payload-types.js'
import type { Post } from '../../../../payload-types.js'
import { Card } from '../../_components/Card/index.js'
import { Gutter } from '../../_components/Gutter/index.js'

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react'
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
import { Gutter } from '../../_components/Gutter/index.js'
import RichText from '../../_components/RichText/index.js'

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react'
import type { Page } from '../../../../test/live-preview/payload-types.js'
import type { Page } from '../../../../payload-types.js'
import type { RelationshipsBlockProps } from '../../_blocks/Relationships/index.js'
import type { VerticalPaddingOptions } from '../VerticalPadding/index.js'

Some files were not shown because too many files have changed in this diff Show More