Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
| return | ||
| } | ||
|
|
||
| const alreadyImported = existing |
There was a problem hiding this comment.
This check treats import { sharpTransformer as st } as an available sharpTransformer binding. The codemod later emits sharpTransformer(...), which is undefined. Use the local alias or add an unaliased import before generating the call.
| // Remove `sharp` before extracting collection entries — later removals | ||
| // shift node positions, and ts-morph node references taken before a | ||
| // sibling removal can go stale. | ||
| sharpProp?.remove() |
There was a problem hiding this comment.
The codemod removes sharp and collection image settings before it confirms that it can add sharpTransformer. Non-inline transformer settings and upload spreads then produce output without image processing. Remove the old settings only after the replacement call is registered.
| * @returns Built and sanitized Payload Config | ||
| */ | ||
| export async function buildConfig(config: Config): Promise<SanitizedConfig> { | ||
| assertNoLegacySharpConfig({ config }) |
There was a problem hiding this comment.
This check runs before plugins. A plugin can add removed Sharp settings, and Payload then starts without processing them. Run this validation after plugins and before transformer initialisation.
| uploadConfig.formatOptions || | ||
| uploadConfig.trimOptions || | ||
| uploadConfig.constructorOptions || | ||
| uploadConfig.hasImageAdjustments || |
There was a problem hiding this comment.
This check does not consider registered transformFile transformers. Direct-to-cloud uploads can provide no bytes or only header bytes, so custom transformers do not run. Add a transformer content requirement or fetch the full file for each matching transformer.
| return finalizeFileResponse({ collection, req, response: currentResponse! }) | ||
| } | ||
| } | ||
| } catch (err) { |
There was a problem hiding this comment.
If a transformer gets the source and then throws, this path leaves the response body open. Repeated failures can retain file handles or storage connections. Cancel unused response bodies and close the underlying stream in this error path.
# Conflicts: # templates/_template/package.json # templates/blank-tanstack/package.json # templates/blank/package.json # templates/with-postgres/package.json
| * The local binding `sharpTransformer` is imported under in this file, honoring an alias such as | ||
| * `import { sharpTransformer as st }`. Falls back to `sharpTransformer` when it isn't imported yet. | ||
| */ | ||
| function getSharpTransformerLocalName(sourceFile: SourceFile): string { |
There was a problem hiding this comment.
The fallback name matches unrelated local functions named sharpTransformer. The codemod then changes their imageSizes properties to variants. Resolve the imported symbol and choose a collision-free name before changing calls. Add tests for local name collisions.
| req, | ||
| uploadReference, | ||
| useCompositePrefixes = false, | ||
| }: GetFileArgs): Promise<Response> { |
There was a problem hiding this comment.
This transform path reuses a Web stream that does not implement cancel() or destroy file.createReadStream(). A failed transform can leave the GCS download active. Retain the Node stream, destroy it on cancellation, connect req.signal, and add a cancellation test.
| see the main file must not be combined with Sharp for image uploads. | ||
| </Banner> | ||
|
|
||
| Transformers only run on uploads whose full bytes are available. When a client uploads directly to cloud storage (`clientUploads`) on a collection with `disableLocalStorage`, Payload downloads the whole file only when `upload.mimeTypes` restricts the allowed types, the request carries a crop or resize edit, the file is an animated image, or the collection has Sharp `variants` or image adjustments (`resizeOptions`, `formatOptions`, and so on). Otherwise the upload is saved without running any transformer. |
There was a problem hiding this comment.
Eligible custom transformFile stages now require full content for direct client uploads. This paragraph omits that case and says no transformer runs otherwise. Update it to match hasTransformFileStages.
| const VARIANTS_KEY = 'variants' | ||
|
|
||
| const IDENTIFIER_PATTERN = /^[A-Z_$][\w$]*$/i | ||
| const RESERVED_WORDS = new Set([ |
There was a problem hiding this comment.
Is this really needed? Seems a bit excessive
Note
Part 2 of 3 in a stacked PR. See #17827 for the full description, breaking changes and migration.
@payloadcms/transformer-sharp, its README, workspace registration and lockfileScope
payload:upload.transformerspipeline, dynamic file requests behindaccess.read/req.fileTransform,generatePayloadFileURL, removal of the built-in Sharp processing and Sharp-specific config/types@payloadcms/ui: upload and file manager updatesplugin-cloud-storage: internaltransformfile-handler operation@payloadcms/codemod:migrate-sharp-to-transformercreate-payload-appand templates: migrated tosharpTransformerupload/transformers.mdx, upload and storage adapter docs, v4 migration guide