Skip to content

Commit

Permalink
fix(cpa): install db adapter in package.json (#5921)
Browse files Browse the repository at this point in the history
  • Loading branch information
denolfe committed Apr 23, 2024
1 parent d01fcb9 commit 51f7351
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/create-payload-app/src/lib/configure-payload-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import fse from 'fs-extra'
import globby from 'globby'
import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

import type { DbDetails } from '../types.js'

Expand All @@ -15,6 +19,34 @@ export async function configurePayloadConfig(args: {
return
}

// Update package.json
const packageJsonPath =
'projectDir' in args.projectDirOrConfigPath &&
path.resolve(args.projectDirOrConfigPath.projectDir, 'package.json')

if (packageJsonPath && fse.existsSync(packageJsonPath)) {
try {
const packageObj = await fse.readJson(packageJsonPath)

const dbPackage = dbReplacements[args.dbDetails.type]

// Delete all other db adapters
Object.values(dbReplacements).forEach((p) => {
if (p.packageName !== dbPackage.packageName) {
delete packageObj.dependencies[p.packageName]
}
})

// Set version of db adapter to match payload version
packageObj.dependencies[dbPackage.packageName] = packageObj.dependencies['payload']

await fse.writeJson(packageJsonPath, packageObj, { spaces: 2 })
} catch (err: unknown) {
warning(`Unable to configure Payload in package.json`)
warning(err instanceof Error ? err.message : '')
}
}

try {
let payloadConfigPath: string | undefined
if (!('payloadConfigPath' in args.projectDirOrConfigPath)) {
Expand Down

0 comments on commit 51f7351

Please sign in to comment.