Skip to content

Commit

Permalink
fix: build payload without initializing (payloadcms#4028)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrodMFlesch authored Jan 11, 2024
1 parent 53e8690 commit 1115387
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 117 deletions.
2 changes: 2 additions & 0 deletions packages/bundler-vite/mock.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export const viteBundler = () => {}
export const mongooseAdapter = () => ({})
export const postgresAdapter = () => ({})
4 changes: 4 additions & 0 deletions packages/bundler-vite/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const getViteConfig = async (payloadConfig: SanitizedConfig): Promise<Inl

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 },
Expand Down Expand Up @@ -92,6 +94,8 @@ export const getViteConfig = async (payloadConfig: SanitizedConfig): Promise<Inl
// 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'],
Expand Down
3 changes: 3 additions & 0 deletions packages/bundler-webpack/src/configs/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 })

Expand Down Expand Up @@ -82,6 +83,8 @@ export const getBaseConfig = (payloadConfig: SanitizedConfig): Configuration =>
resolve: {
alias: {
'@payloadcms/bundler-webpack': mockModulePath,
'@payloadcms/db-mongodb': mockDBAdapterPath,
'@payloadcms/db-postgres': mockDBAdapterPath,
dotenv: mockDotENVPath,
path: require.resolve('path-browserify'),
payload$: mockModulePath,
Expand Down
2 changes: 2 additions & 0 deletions packages/bundler-webpack/src/mocks/db-adapters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const mongooseAdapter = () => ({})
export const postgresAdapter = () => ({})
19 changes: 0 additions & 19 deletions packages/db-mongodb/src/extendViteConfig.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/db-mongodb/src/extendWebpackConfig.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/db-mongodb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { deleteMany } from './deleteMany'
import { deleteOne } from './deleteOne'
import { deleteVersions } from './deleteVersions'
import { destroy } from './destroy'
import { extendViteConfig } from './extendViteConfig'
import { extendWebpackConfig } from './extendWebpackConfig'
import { find } from './find'
import { findGlobal } from './findGlobal'
import { findGlobalVersions } from './findGlobalVersions'
Expand Down Expand Up @@ -103,9 +101,6 @@ export function mongooseAdapter({
let beginTransactionFunction = beginTransaction
mongoose.set('strictQuery', false)

extendWebpackConfig(payload.config)
extendViteConfig(payload.config)

if (transactionOptions === false) {
beginTransactionFunction = () => null
}
Expand Down
19 changes: 0 additions & 19 deletions packages/db-postgres/src/extendViteConfig.ts

This file was deleted.

28 changes: 0 additions & 28 deletions packages/db-postgres/src/extendWebpackConfig.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/db-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import { deleteMany } from './deleteMany'
import { deleteOne } from './deleteOne'
import { deleteVersions } from './deleteVersions'
import { destroy } from './destroy'
import { extendViteConfig } from './extendViteConfig'
import { extendWebpackConfig } from './extendWebpackConfig'
import { find } from './find'
import { findGlobal } from './findGlobal'
import { findGlobalVersions } from './findGlobalVersions'
Expand Down Expand Up @@ -45,9 +43,6 @@ export function postgresAdapter(args: Args): PostgresAdapterResult {
function adapter({ payload }: { payload: Payload }) {
const migrationDir = findMigrationDir(args.migrationDir)

extendWebpackConfig(payload.config)
extendViteConfig(payload.config)

return createDatabaseAdapter<PostgresAdapter>({
name: 'postgres',

Expand Down
10 changes: 3 additions & 7 deletions packages/payload/src/bin/build.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import payload from '..'
import loadConfig from '../config/load'

export const build = async (): Promise<void> => {
await payload.init({
disableDBConnect: true,
disableOnInit: true,
local: true,
secret: '--unused--',
})
const config = await loadConfig() // Will throw its own error if it fails

await payload.config.admin.bundler.build(payload.config)
await payload.config.admin.bundler.build(config)
}

// when build.js is launched directly
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/plugin-redirects/types.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/types';
export * from './dist/types'
2 changes: 1 addition & 1 deletion packages/plugin-redirects/types.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/types');
module.exports = require('./dist/types')
2 changes: 1 addition & 1 deletion packages/plugin-seo/types.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/types';
export * from './dist/types'
2 changes: 1 addition & 1 deletion packages/plugin-seo/types.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/types');
module.exports = require('./dist/types')
4 changes: 2 additions & 2 deletions test/buildConfigWithDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export function buildConfigWithDefaults(testConfig?: Partial<Config>): Promise<S
),
[path.resolve(__dirname, '../packages/db-mongodb/src/index')]: path.resolve(
__dirname,
'../packages/db-mongodb/mock.js',
'../packages/payload/src/bundlers/mocks/db-mongodb.js',
),
[path.resolve(__dirname, '../packages/db-postgres/src/index')]: path.resolve(
__dirname,
'../packages/db-postgres/mock.js',
'../packages/payload/src/bundlers/mocks/db-postgres.js',
),
react: path.resolve(__dirname, '../packages/payload/node_modules/react'),
},
Expand Down

0 comments on commit 1115387

Please sign in to comment.