Skip to content

Commit 254d888

Browse files
authored
docs: add missing types, prefer pnpm, fix various typos, discourage using payload from import (#9847)
- Adds missing types, especially the `Where` type. Will be helpful for people to see that they can type their queries like that - Mention pnpm first and prefer pnpm > npm > yarn throughout docs - Add `payload` to function arguments in examples to discourage people from doing `import payload from 'payload'` - PNPM => pnpm, NPM => npm - Fix some typos
1 parent 36c2714 commit 254d888

File tree

18 files changed

+78
-57
lines changed

18 files changed

+78
-57
lines changed

docs/cloud/projects.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ From there, you are ready to make updates to your project. When you are ready to
9898

9999
Projects generated from a template will come pre-configured with the official Cloud Plugin, but if you are using your own repository you will need to add this into your project. To do so, add the plugin to your Payload Config:
100100

101-
`yarn add @payloadcms/payload-cloud`
101+
`pnpm add @payloadcms/payload-cloud`
102102

103103
```js
104104
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'

docs/getting-started/installation.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords: documentation, getting started, guide, Content Management System, cms,
1010

1111
Payload requires the following software:
1212

13-
- Any JavaScript package manager (Yarn, NPM, or pnpm - pnpm is preferred)
13+
- Any JavaScript package manager (pnpm, npm, or yarn - pnpm is preferred)
1414
- Node.js version 20.9.0+
1515
- Any [compatible database](/docs/database/overview) (MongoDB, Postgres or Sqlite)
1616

@@ -49,7 +49,7 @@ pnpm i payload @payloadcms/next @payloadcms/richtext-lexical sharp graphql
4949

5050
<Banner type="warning">
5151
<strong>Note:</strong>
52-
Swap out `pnpm` for your package manager. If you are using NPM, you might need to install using legacy peer deps: `npm i --legacy-peer-deps`.
52+
Swap out `pnpm` for your package manager. If you are using npm, you might need to install using legacy peer deps: `npm i --legacy-peer-deps`.
5353
</Banner>
5454

5555
Next, install a [Database Adapter](/docs/database/overview). Payload requires a Database Adapter to establish a database connection. Payload works with all types of databases, but the most common are MongoDB and Postgres.
@@ -181,6 +181,6 @@ Once you have a Payload Config, update your `tsconfig` to include a `path` that
181181

182182
#### 5. Fire it up!
183183

184-
After you've reached this point, it's time to boot up Payload. Start your project in your application's folder to get going. By default, the Next.js dev script is `pnpm dev` (or `npm run dev` if using NPM).
184+
After you've reached this point, it's time to boot up Payload. Start your project in your application's folder to get going. By default, the Next.js dev script is `pnpm dev` (or `npm run dev` if using npm).
185185

186186
After it starts, you can go to `http://localhost:3000/admin` to create your first Payload user!

docs/graphql/graphql-schema.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type Collection1 {
6262

6363
The above example outputs all your definitions to a file relative from your payload config as `./graphql/schema.graphql`. By default, the file will be output to your current working directory as `schema.graphql`.
6464

65-
### Adding an NPM script
65+
### Adding an npm script
6666

6767
<Banner type="warning">
6868
<strong>Important</strong>
@@ -72,7 +72,7 @@ The above example outputs all your definitions to a file relative from your payl
7272

7373
Payload will automatically try and locate your config, but might not always be able to find it. For example, if you are working in a `/src` directory or similar, you need to tell Payload where to find your config manually by using an environment variable.
7474

75-
If this applies to you, create an NPM script to make generating types easier:
75+
If this applies to you, create an npm script to make generating types easier:
7676

7777
```json
7878
// package.json

docs/hooks/context.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ To pass data between hooks, you can assign values to context in an earlier hook
2828
For example:
2929

3030
```ts
31+
import type { CollectionConfig } from 'payload'
32+
3133
const Customer: CollectionConfig = {
3234
slug: 'customers',
3335
hooks: {
@@ -43,7 +45,6 @@ const Customer: CollectionConfig = {
4345
},
4446
],
4547
afterChange: [
46-
4748
async ({ context, doc, req }) => {
4849
// use context.customerData without needing to fetch it again
4950
if (context.customerData.contacted === false) {
@@ -65,6 +66,8 @@ Let's say you have an `afterChange` hook, and you want to do a calculation insid
6566
Bad example:
6667

6768
```ts
69+
import type { CollectionConfig } from 'payload'
70+
6871
const Customer: CollectionConfig = {
6972
slug: 'customers',
7073
hooks: {
@@ -92,6 +95,8 @@ Instead of the above, we need to tell the `afterChange` hook to not run again if
9295
Fixed example:
9396

9497
```ts
98+
import type { CollectionConfig } from 'payload'
99+
95100
const MyCollection: CollectionConfig = {
96101
slug: 'slug',
97102
hooks: {
@@ -125,7 +130,7 @@ const MyCollection: CollectionConfig = {
125130

126131
The default TypeScript interface for `context` is `{ [key: string]: unknown }`. If you prefer a more strict typing in your project or when authoring plugins for others, you can override this using the `declare` syntax.
127132

128-
This is known as "type augmentation", a TypeScript feature which allows us to add types to existing objects. Simply put this in any `.ts` or `.d.ts` file:
133+
This is known as "type augmentation", a TypeScript feature which allows us to add types to existing types. Simply put this in any `.ts` or `.d.ts` file:
129134

130135
```ts
131136
import { RequestContext as OriginalRequestContext } from 'payload'

docs/hooks/overview.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Root Hooks are not associated with any specific Collection, Global, or Field. Th
3737
To add Root Hooks, use the `hooks` property in your [Payload Config](/docs/configuration/config):
3838

3939
```ts
40-
import { buildConfig } from 'payload'
40+
import { buildConfig } from 'payload'
4141

4242
export default buildConfig({
4343
// ...
@@ -60,7 +60,7 @@ The following options are available:
6060
The `afterError` Hook is triggered when an error occurs in the Payload application. This can be useful for logging errors to a third-party service, sending an email to the development team, logging the error to Sentry or DataDog, etc. The output can be used to transform the result object / status code.
6161

6262
```ts
63-
import { buildConfig } from 'payload'
63+
import { buildConfig } from 'payload'
6464

6565
export default buildConfig({
6666
// ...

docs/plugins/build-your-own.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ cd dev
8484
npx create-payload-app@latest
8585
```
8686

87-
If you&apos;re using the plugin template, the dev folder is built out for you and the `samplePlugin` has already been installed in `dev/payload.config()`.
87+
If you&apos;re using the plugin template, the dev folder is built out for you and the `samplePlugin` has already been installed in `dev/payload.config.ts`.
8888

8989
```
9090
plugins: [
@@ -95,11 +95,11 @@ If you&apos;re using the plugin template, the dev folder is built out for you an
9595
]
9696
```
9797

98-
You can add to the `dev/payload.config` and build out the dev project as needed to test your plugin.
98+
You can add to the `dev/payload.config.ts` and build out the dev project as needed to test your plugin.
9999

100100
When you&apos;re ready to start development, navigate into this folder with `cd dev`
101101

102-
And then start the project with `yarn dev` and pull up `http://localhost:3000` in your browser.
102+
And then start the project with `pnpm dev` and pull up `http://localhost:3000` in your browser.
103103

104104
## Testing
105105

@@ -112,7 +112,7 @@ Jest organizes tests into test suites and cases. We recommend creating tests bas
112112
The plugin template provides a stubbed out test suite at `dev/plugin.spec.ts` which is ready to go - just add in your own test conditions and you&apos;re all set!
113113

114114
```
115-
import payload from 'payload'
115+
let payload: Payload
116116
117117
describe('Plugin tests', () => {
118118
// Example test to check for seeded data
@@ -245,7 +245,7 @@ config.hooks = {
245245
```
246246

247247
### Extending functions
248-
Function properties cannot use spread syntax. The way to extend them is to execute the existing function if it exists and then run your additional functionality.
248+
Function properties cannot use spread syntax. The way to extend them is to execute the existing function if it exists and then run your additional functionality.
249249

250250
Here is an example extending the `onInit` property:
251251

@@ -285,11 +285,11 @@ For a better user experience, provide a way to disable the plugin without uninst
285285

286286
### Include tests in your GitHub CI workflow
287287

288-
If you&apos;ve configured tests for your package, integrate them into your workflow to run the tests each time you commit to the plugin repository. Learn more about [how to configure tests into your GitHub CI workflow.](https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs)
288+
If you&apos;ve configured tests for your package, integrate them into your workflow to run the tests each time you commit to the plugin repository. Learn more about [how to configure tests into your GitHub CI workflow.](https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs)
289289

290-
### Publish your finished plugin to NPM
290+
### Publish your finished plugin to npm
291291

292-
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/).
292+
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/).
293293

294294
### Add payload-plugin topic tag
295295

docs/plugins/form-builder.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ desc: Easily build and manage forms from the Admin Panel. Send dynamic, personal
66
keywords: plugins, plugin, form, forms, form builder
77
---
88

9-
[![NPM](https://img.shields.io/npm/v/@payloadcms/plugin-form-builder)](https://www.npmjs.com/package/@payloadcms/plugin-form-builder)
9+
[![npm](https://img.shields.io/npm/v/@payloadcms/plugin-form-builder)](https://www.npmjs.com/package/@payloadcms/plugin-form-builder)
1010

1111
This plugin allows you to build and manage custom forms directly within the [Admin Panel](../admin/overview). Instead of hard-coding a new form into your website or application every time you need one, admins can simply define the schema for each form they need on-the-fly, and your front-end can map over this schema, render its own UI components, and match your brand's design system.
1212

@@ -33,7 +33,7 @@ Forms can be as simple or complex as you need, from a basic contact form, to a m
3333

3434
## Installation
3535

36-
Install the plugin using any JavaScript package manager like [Yarn](https://yarnpkg.com), [NPM](https://npmjs.com), or [PNPM](https://pnpm.io):
36+
Install the plugin using any JavaScript package manager like [pnpm](https://pnpm.io), [npm](https://npmjs.com), or [Yarn](https://yarnpkg.com):
3737

3838
```bash
3939
pnpm add @payloadcms/plugin-form-builder

docs/plugins/nested-docs.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ desc: Nested documents in a parent, child, and sibling relationship.
66
keywords: plugins, nested, documents, parent, child, sibling, relationship
77
---
88

9-
[![NPM](https://img.shields.io/npm/v/@payloadcms/plugin-nested-docs)](https://www.npmjs.com/package/@payloadcms/plugin-nested-docs)
9+
[![npm](https://img.shields.io/npm/v/@payloadcms/plugin-nested-docs)](https://www.npmjs.com/package/@payloadcms/plugin-nested-docs)
1010

1111
This plugin allows you to easily nest the documents of your application inside of one another. It does so by adding a
1212
new `parent` field onto each of your documents that, when selected, attaches itself to the parent's tree. When you edit
@@ -44,8 +44,7 @@ but different parents.
4444

4545
## Installation
4646

47-
Install the plugin using any JavaScript package manager like [Yarn](https://yarnpkg.com), [NPM](https://npmjs.com),
48-
or [PNPM](https://pnpm.io):
47+
Install the plugin using any JavaScript package manager like [pnpm](https://pnpm.io), [npm](https://npmjs.com), or [Yarn](https://yarnpkg.com):
4948

5049
```bash
5150
pnpm add @payloadcms/plugin-nested-docs

docs/plugins/redirects.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ desc: Automatically create redirects for your Payload application
66
keywords: plugins, redirects, redirect, plugin, payload, cms, seo, indexing, search, search engine
77
---
88

9-
[![NPM](https://img.shields.io/npm/v/@payloadcms/plugin-redirects)](https://www.npmjs.com/package/@payloadcms/plugin-redirects)
9+
[![npm](https://img.shields.io/npm/v/@payloadcms/plugin-redirects)](https://www.npmjs.com/package/@payloadcms/plugin-redirects)
1010

1111
This plugin allows you to easily manage redirects for your application from within your [Admin Panel](../admin/overview). It does so by adding a `redirects` collection to your config that allows you specify a redirect from one URL to another. Your front-end application can use this data to automatically redirect users to the correct page using proper HTTP status codes. This is useful for SEO, indexing, and search engine ranking when re-platforming or when changing your URL structure.
1212

@@ -29,7 +29,7 @@ For example, if you have a page at `/about` and you want to change it to `/about
2929

3030
## Installation
3131

32-
Install the plugin using any JavaScript package manager like [Yarn](https://yarnpkg.com), [NPM](https://npmjs.com), or [PNPM](https://pnpm.io):
32+
Install the plugin using any JavaScript package manager like [pnpm](https://pnpm.io), [npm](https://npmjs.com), or [Yarn](https://yarnpkg.com):
3333

3434
```bash
3535
pnpm add @payloadcms/plugin-redirects

docs/plugins/search.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ desc: Generates records of your documents that are extremely fast to search on.
66
keywords: plugins, search, search plugin, search engine, search index, search results, search bar, search box, search field, search form, search input
77
---
88

9-
[![NPM](https://img.shields.io/npm/v/@payloadcms/plugin-search)](https://www.npmjs.com/package/@payloadcms/plugin-search)
9+
[![npm](https://img.shields.io/npm/v/@payloadcms/plugin-search)](https://www.npmjs.com/package/@payloadcms/plugin-search)
1010

1111
This plugin generates records of your documents that are extremely fast to search on. It does so by creating a new `search` collection that is indexed in the database then saving a static copy of each of your documents using only search-critical data. Search records are automatically created, synced, and deleted behind-the-scenes as you manage your application's documents.
1212

@@ -37,7 +37,7 @@ This plugin is a great way to implement a fast, immersive search experience such
3737

3838
## Installation
3939

40-
Install the plugin using any JavaScript package manager like [Yarn](https://yarnpkg.com), [NPM](https://npmjs.com), or [PNPM](https://pnpm.io):
40+
Install the plugin using any JavaScript package manager like [pnpm](https://pnpm.io), [npm](https://npmjs.com), or [Yarn](https://yarnpkg.com):
4141

4242
```bash
4343
pnpm add @payloadcms/plugin-search

0 commit comments

Comments
 (0)