Skip to content

Commit ff615d3

Browse files
authored
fix(plugin-import-export): incorrect config extension of jobs (#12730)
### What? In a project that has `jobs` configured and the import/export plugin will error on start: `payload-jobs validation failed: taskSlug: createCollectionExport is not a valid enum value for path taskSlug.` ### Why? The plugin was not properly extending the jobs configuration. ### How? Properly extend existing config.jobs to add the `createCollectionExport` task. Fixes #
1 parent 9fbc3f6 commit ff615d3

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

packages/plugin-import-export/src/export/createExport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getCustomFieldFunctions } from './getCustomFieldFunctions.js'
1010
import { getFilename } from './getFilename.js'
1111
import { getSelect } from './getSelect.js'
1212

13-
type Export = {
13+
export type Export = {
1414
collectionSlug: string
1515
/**
1616
* If true, enables debug logging

packages/plugin-import-export/src/export/getCreateExportCollectionTask.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import type { Config, TaskHandler, User } from 'payload'
1+
import type { Config, TaskConfig, User } from 'payload'
22

3-
import type { CreateExportArgs } from './createExport.js'
3+
import type { CreateExportArgs, Export } from './createExport.js'
44

55
import { createExport } from './createExport.js'
66
import { getFields } from './getFields.js'
77

8-
export const getCreateCollectionExportTask = (config: Config): TaskHandler<any, string> => {
8+
export const getCreateCollectionExportTask = (
9+
config: Config,
10+
): TaskConfig<{
11+
input: Export
12+
output: object
13+
}> => {
914
const inputSchema = getFields(config).concat(
1015
{
1116
name: 'user',
@@ -22,7 +27,6 @@ export const getCreateCollectionExportTask = (config: Config): TaskHandler<any,
2227
)
2328

2429
return {
25-
// @ts-expect-error plugin tasks cannot have predefined type slug
2630
slug: 'createCollectionExport',
2731
handler: async ({ input, req }: CreateExportArgs) => {
2832
let user: undefined | User
@@ -41,15 +45,9 @@ export const getCreateCollectionExportTask = (config: Config): TaskHandler<any,
4145
await createExport({ input, req, user })
4246

4347
return {
44-
success: true,
48+
output: {},
4549
}
4650
},
4751
inputSchema,
48-
outputSchema: [
49-
{
50-
name: 'success',
51-
type: 'checkbox',
52-
},
53-
],
5452
}
5553
}

packages/plugin-import-export/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ export const importExportPlugin =
2828
)
2929

3030
// inject the createExport job into the config
31-
config.jobs =
32-
config.jobs ||
33-
({
34-
tasks: [getCreateCollectionExportTask(config)],
35-
} as unknown as JobsConfig) // cannot type jobs config inside of plugins
31+
;((config.jobs ??= {}).tasks ??= []).push(getCreateCollectionExportTask(config))
3632

3733
let collectionsToUpdate = config.collections
3834

0 commit comments

Comments
 (0)