Skip to content

Commit 98e4db0

Browse files
authored
fix(plugin-cloud-storage): ensure client handlers are added to import map regardless of enabled state (#11880)
There are cases when a storage plugin is disabled during development and enabled in production. This will result in import maps that differ depending on if they're generated during development or production. In a lot of cases, those import maps are generated during development-only. During production, we just re-use what was generated locally. This will cause missing import map entries for those plugins that are disabled during development. This PR ensures the import map entries are added regardless of the enabled state of those plugins. This is necessary for our generate-templates script to not omit the vercel blob storage import map entry.
1 parent 6b56343 commit 98e4db0

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

packages/payload/src/bin/generateImportMap/iterateConfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export function iterateConfig({
9595
}
9696

9797
if (config?.admin?.dependencies) {
98-
for (const key in config.admin.dependencies) {
99-
const dependency = config.admin.dependencies[key]
98+
for (const dependency of Object.values(config.admin.dependencies)) {
10099
addToImportMap(dependency.path)
101100
}
102101
}

packages/payload/src/config/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,7 @@ export type Config = {
793793
/** Global date format that will be used for all dates in the Admin panel. Any valid date-fns format pattern can be used. */
794794
dateFormat?: string
795795
/**
796-
* Each entry in this map generates an entry in the importMap,
797-
* as well as an entry in the componentMap if the type of the
798-
* dependency is 'component'
796+
* Each entry in this map generates an entry in the importMap.
799797
*/
800798
dependencies?: AdminDependencies
801799
/**

packages/plugin-cloud-storage/src/utilities/initClientUploads.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export const initClientUploads = <ExtraProps extends Record<string, unknown>, T>
5353
config.admin = {}
5454
}
5555

56+
if (!config.admin.dependencies) {
57+
config.admin.dependencies = {}
58+
}
59+
// Ensure client handler is always part of the import map, to avoid
60+
// import map discrepancies between dev and prod
61+
config.admin.dependencies[clientHandler] = {
62+
type: 'function',
63+
path: clientHandler,
64+
}
65+
5666
if (!config.admin.components) {
5767
config.admin.components = {}
5868
}

0 commit comments

Comments
 (0)