@payloadcms/figma 1.0.0-beta.4 → 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/adapters/asset-collection.d.ts +15 -0
  2. package/dist/adapters/asset-collection.js +51 -45
  3. package/dist/adapters/build-lambda-zip.d.ts +8 -9
  4. package/dist/adapters/build-lambda-zip.js +36 -44
  5. package/dist/adapters/index.d.ts +4 -0
  6. package/dist/adapters/index.js +4 -0
  7. package/dist/adapters/lambdaLimits.d.ts +6 -0
  8. package/dist/adapters/lambdaLimits.js +5 -0
  9. package/dist/adapters/nextjs-assets.d.ts +7 -0
  10. package/dist/adapters/nextjs-assets.js +44 -0
  11. package/dist/adapters/nextjs.d.ts +8 -0
  12. package/dist/adapters/nextjs.js +19 -37
  13. package/dist/adapters/nitro.js +18 -43
  14. package/dist/adapters/omit-optional-sharp.d.ts +22 -0
  15. package/dist/adapters/omit-optional-sharp.js +158 -0
  16. package/dist/adapters/secret-files.js +8 -1
  17. package/dist/adapters/types.d.ts +8 -0
  18. package/dist/adapters/v2/core/build.d.ts +69 -0
  19. package/dist/adapters/v2/core/build.js +183 -0
  20. package/dist/adapters/v2/core/content-type.d.ts +3 -0
  21. package/dist/adapters/v2/core/content-type.js +41 -0
  22. package/dist/adapters/v2/core/getRelativePathError.d.ts +5 -0
  23. package/dist/adapters/v2/core/getRelativePathError.js +21 -0
  24. package/dist/adapters/v2/core/index.d.ts +15 -0
  25. package/dist/adapters/v2/core/index.js +13 -0
  26. package/dist/adapters/v2/core/limits.d.ts +28 -0
  27. package/dist/adapters/v2/core/limits.js +26 -0
  28. package/dist/adapters/v2/core/manifest-version.d.ts +10 -0
  29. package/dist/adapters/v2/core/manifest-version.js +14 -0
  30. package/dist/adapters/v2/core/server-zip.d.ts +58 -0
  31. package/dist/adapters/v2/core/server-zip.js +123 -0
  32. package/dist/adapters/v2/core/services.d.ts +46 -0
  33. package/dist/adapters/v2/core/services.js +202 -0
  34. package/dist/adapters/v2/core/static-path.d.ts +13 -0
  35. package/dist/adapters/v2/core/static-path.js +32 -0
  36. package/dist/adapters/v2/core/static-site.d.ts +26 -0
  37. package/dist/adapters/v2/core/static-site.js +95 -0
  38. package/dist/adapters/v2/core/types.d.ts +128 -0
  39. package/dist/adapters/v2/core/types.js +7 -0
  40. package/dist/adapters/v2/core/upload.d.ts +67 -0
  41. package/dist/adapters/v2/core/upload.js +198 -0
  42. package/dist/adapters/v2/core/validateDeployment/createIssue.d.ts +3 -0
  43. package/dist/adapters/v2/core/validateDeployment/createIssue.js +7 -0
  44. package/dist/adapters/v2/core/validateDeployment/escapePointer.d.ts +2 -0
  45. package/dist/adapters/v2/core/validateDeployment/escapePointer.js +3 -0
  46. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.d.ts +2 -0
  47. package/dist/adapters/v2/core/validateDeployment/singletonHeaders.js +10 -0
  48. package/dist/adapters/v2/core/validateDeployment/types.d.ts +16 -0
  49. package/dist/adapters/v2/core/validateDeployment/types.js +8 -0
  50. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.d.ts +3 -0
  51. package/dist/adapters/v2/core/validateDeployment/validateArtifacts.js +30 -0
  52. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.d.ts +8 -0
  53. package/dist/adapters/v2/core/validateDeployment/validateCachePolicy.js +26 -0
  54. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.d.ts +7 -0
  55. package/dist/adapters/v2/core/validateDeployment/validateCounts/validateCount.js +11 -0
  56. package/dist/adapters/v2/core/validateDeployment/validateCounts.d.ts +3 -0
  57. package/dist/adapters/v2/core/validateDeployment/validateCounts.js +41 -0
  58. package/dist/adapters/v2/core/validateDeployment/validateFallback.d.ts +3 -0
  59. package/dist/adapters/v2/core/validateDeployment/validateFallback.js +21 -0
  60. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.d.ts +6 -0
  61. package/dist/adapters/v2/core/validateDeployment/validateHeaderName.js +13 -0
  62. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.d.ts +2 -0
  63. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp/isReservedRuleHeader.js +13 -0
  64. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.d.ts +11 -0
  65. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules/validateHeaderOp.js +38 -0
  66. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.d.ts +3 -0
  67. package/dist/adapters/v2/core/validateDeployment/validateHeaderRules.js +17 -0
  68. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.d.ts +6 -0
  69. package/dist/adapters/v2/core/validateDeployment/validateHeaderValue.js +24 -0
  70. package/dist/adapters/v2/core/validateDeployment/validateId.d.ts +7 -0
  71. package/dist/adapters/v2/core/validateDeployment/validateId.js +12 -0
  72. package/dist/adapters/v2/core/validateDeployment/validateMatch.d.ts +15 -0
  73. package/dist/adapters/v2/core/validateDeployment/validateMatch.js +74 -0
  74. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.d.ts +7 -0
  75. package/dist/adapters/v2/core/validateDeployment/validatePublicPath.js +21 -0
  76. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.d.ts +3 -0
  77. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList/findRepeatedSingletons.js +16 -0
  78. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.d.ts +11 -0
  79. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateHeaderList.js +48 -0
  80. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.d.ts +10 -0
  81. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseBody.js +16 -0
  82. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.d.ts +8 -0
  83. package/dist/adapters/v2/core/validateDeployment/validateResponses/validateResponseStatus.js +25 -0
  84. package/dist/adapters/v2/core/validateDeployment/validateResponses.d.ts +7 -0
  85. package/dist/adapters/v2/core/validateDeployment/validateResponses.js +59 -0
  86. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.d.ts +10 -0
  87. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateCaptures.js +12 -0
  88. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.d.ts +14 -0
  89. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRedirectAction.js +59 -0
  90. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.d.ts +11 -0
  91. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateRewriteAction.js +20 -0
  92. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.d.ts +11 -0
  93. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateServerAction.js +26 -0
  94. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.d.ts +13 -0
  95. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction/validateStaticAction.js +25 -0
  96. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.d.ts +12 -0
  97. package/dist/adapters/v2/core/validateDeployment/validateRoutes/validateRouteAction.js +35 -0
  98. package/dist/adapters/v2/core/validateDeployment/validateRoutes.d.ts +6 -0
  99. package/dist/adapters/v2/core/validateDeployment/validateRoutes.js +55 -0
  100. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.d.ts +3 -0
  101. package/dist/adapters/v2/core/validateDeployment/validateServers/listReferencedServerIds.js +12 -0
  102. package/dist/adapters/v2/core/validateDeployment/validateServers.d.ts +7 -0
  103. package/dist/adapters/v2/core/validateDeployment/validateServers.js +59 -0
  104. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.d.ts +3 -0
  105. package/dist/adapters/v2/core/validateDeployment/validateStaticMap.js +22 -0
  106. package/dist/adapters/v2/core/validateDeployment.d.ts +7 -0
  107. package/dist/adapters/v2/core/validateDeployment.js +42 -0
  108. package/dist/adapters/v2/core/write.d.ts +21 -0
  109. package/dist/adapters/v2/core/write.js +30 -0
  110. package/dist/adapters/v2/nextjs/coverage.d.ts +45 -0
  111. package/dist/adapters/v2/nextjs/coverage.js +113 -0
  112. package/dist/adapters/v2/nextjs/read-build-output.d.ts +116 -0
  113. package/dist/adapters/v2/nextjs/read-build-output.js +368 -0
  114. package/dist/adapters/v2/nextjs/translate.d.ts +20 -0
  115. package/dist/adapters/v2/nextjs/translate.js +400 -0
  116. package/dist/adapters/vite.d.ts +7 -0
  117. package/dist/adapters/vite.js +47 -0
  118. package/dist/adapters/writeZip.d.ts +20 -0
  119. package/dist/adapters/writeZip.js +28 -0
  120. package/dist/api/control-plane.d.ts +28 -6
  121. package/dist/api/control-plane.js +67 -64
  122. package/dist/auth/cli-build-context.d.ts +3 -0
  123. package/dist/auth/cli-build-context.js +2 -0
  124. package/dist/auth/oauth-flow.d.ts +3 -3
  125. package/dist/auth/oauth-flow.js +13 -3
  126. package/dist/cli.js +15 -0
  127. package/dist/commands/build-manifest.d.ts +49 -0
  128. package/dist/commands/build-manifest.js +111 -0
  129. package/dist/commands/deploy.js +195 -26
  130. package/dist/db-content-api/generated/content-api-types.d.ts +18 -14
  131. package/dist/db-content-api/index.js +4 -1
  132. package/dist/db-content-api/utilities/where.js +2 -6
  133. package/dist/endpoints/client-config.d.ts +3 -0
  134. package/dist/endpoints/client-config.js +87 -0
  135. package/dist/image-transforms/constants.d.ts +8 -0
  136. package/dist/image-transforms/constants.js +26 -0
  137. package/dist/image-transforms/createImageTransformer.d.ts +6 -0
  138. package/dist/image-transforms/createImageTransformer.js +100 -0
  139. package/dist/image-transforms/deliverImageResponse.d.ts +11 -0
  140. package/dist/image-transforms/deliverImageResponse.js +43 -0
  141. package/dist/image-transforms/imageRevision.d.ts +14 -0
  142. package/dist/image-transforms/imageRevision.js +115 -0
  143. package/dist/image-transforms/normalizeMediaType.d.ts +2 -0
  144. package/dist/image-transforms/normalizeMediaType.js +3 -0
  145. package/dist/image-transforms/parseImageOverrides.d.ts +4 -0
  146. package/dist/image-transforms/parseImageOverrides.js +20 -0
  147. package/dist/image-transforms/preserveImageRedirectHeaders.d.ts +2 -0
  148. package/dist/image-transforms/preserveImageRedirectHeaders.js +30 -0
  149. package/dist/image-transforms/preventConflictingImageTransformers.d.ts +9 -0
  150. package/dist/image-transforms/preventConflictingImageTransformers.js +67 -0
  151. package/dist/image-transforms/serveImageRequest.d.ts +6 -0
  152. package/dist/image-transforms/serveImageRequest.js +97 -0
  153. package/dist/image-transforms/storedImage.d.ts +49 -0
  154. package/dist/image-transforms/storedImage.js +84 -0
  155. package/dist/image-transforms/types.d.ts +9 -0
  156. package/dist/image-transforms/types.js +1 -0
  157. package/dist/image-transforms/variantMetadata.d.ts +13 -0
  158. package/dist/image-transforms/variantMetadata.js +164 -0
  159. package/dist/imageSizeOptions.d.ts +8 -8
  160. package/dist/imageSizeOptions.js +0 -2
  161. package/dist/index.d.ts +1 -0
  162. package/dist/plugin/build-config.d.ts +3 -4
  163. package/dist/plugin/build-config.js +32 -16
  164. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +2 -1
  165. package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +2 -1
  166. package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +2 -1
  167. package/dist/storage-content-api/buildMediaResponseHeaders.js +11 -5
  168. package/dist/storage-content-api/isRunningInLambda.d.ts +2 -0
  169. package/dist/storage-content-api/isRunningInLambda.js +3 -0
  170. package/dist/storage-content-api/staticHandler.js +13 -51
  171. package/dist/storage-content-api/streamMediaResponse.d.ts +17 -0
  172. package/dist/storage-content-api/streamMediaResponse.js +96 -0
  173. package/dist/utils/lambda-config.js +1 -1
  174. package/dist/utils/messages.js +8 -0
  175. package/dist/utils/next-image-loader-config.js +43 -6
  176. package/dist/utils/next-image-loader-file.js +8 -0
  177. package/package.json +7 -1
@@ -44,6 +44,21 @@ type StaticMetadataAssets = Omit<SSGAssets, 'routeAssetMap'>;
44
44
  * @returns SSG asset keys and a pathMap for filesystem resolution
45
45
  */
46
46
  export declare function collectSSGAssets(projectPath: string, output?: string, logger?: AdapterLogger): Promise<SSGAssets>;
47
+ /** An App Router page Next.js fully prerendered, so its files can be served without the server. */
48
+ export interface StaticPrerenderedPage {
49
+ /** File name stem under `server/app`, such as `index` for `/` or `blog/a` for `/blog/a`. */
50
+ fileStem: string;
51
+ /** Whether the build emitted a complete `.rsc` payload for the page. */
52
+ hasFullRSC: boolean;
53
+ /** The page's public path from `prerender-manifest.json`. */
54
+ routeKey: string;
55
+ }
56
+ /**
57
+ * Lists the pages in `<outputPath>/prerender-manifest.json` that are safe to serve from storage:
58
+ * App Router pages with static computation and no ISR. Returns an empty list when the manifest is
59
+ * missing or unreadable.
60
+ */
61
+ export declare function listStaticPrerenderedPages(outputPath: string): Promise<StaticPrerenderedPage[]>;
47
62
  /**
48
63
  * Collect file-based Next.js metadata icons that were prerendered as static route handlers.
49
64
  *
@@ -89,56 +89,13 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
89
89
  * @returns SSG asset keys and a pathMap for filesystem resolution
90
90
  */ export async function collectSSGAssets(projectPath, output, logger) {
91
91
  const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
92
- const manifestPath = path.join(outputPath, 'prerender-manifest.json');
93
- let manifest;
94
- try {
95
- const raw = await fs.readFile(manifestPath, 'utf-8');
96
- manifest = JSON.parse(raw);
97
- } catch {
98
- return {
99
- keys: [],
100
- pathMap: {},
101
- routeAssetMap: {}
102
- };
103
- }
104
- if (!manifest.routes || typeof manifest.routes !== 'object') {
105
- return {
106
- keys: [],
107
- pathMap: {},
108
- routeAssetMap: {}
109
- };
110
- }
92
+ const pages = await listStaticPrerenderedPages(outputPath);
111
93
  const keys = [];
112
94
  const pathMap = {};
113
95
  const routeAssetMap = {};
114
96
  const appDir = path.join(outputPath, 'server', 'app');
115
- for (const [routeKey, route] of Object.entries(manifest.routes)){
116
- // Current manifests classify app pages explicitly. Older App Router manifests
117
- // can be identified by their RSC data route. Other entries may be route handlers.
118
- const isPageRoute = route.routeType === 'page' || route.routeType === undefined && typeof route.dataRoute === 'string' && route.dataRoute.endsWith('.rsc');
119
- if (!isPageRoute) {
120
- continue;
121
- }
122
- // ISR prerenders are seeds for the Next.js runtime, not permanent S3 pages.
123
- // Keep legacy manifests without this field; only false explicitly disables revalidation.
124
- if (route.initialRevalidateSeconds !== undefined && route.initialRevalidateSeconds !== false) {
125
- continue;
126
- }
127
- // SSR and PPR can also disable revalidation. Only static computation can be
128
- // served from S3; an initial response is safe for a static CSR shell.
129
- const hasStaticRendering = route.compute === 'static' && (route.response === 'complete' || route.response === 'initial');
130
- // Older SSG entries omit these fields. Ambiguous PPR entries must use Lambda.
131
- const hasLegacyStaticRendering = route.compute === undefined && route.response === undefined && (route.renderingMode === undefined || route.renderingMode === 'STATIC');
132
- if (!hasStaticRendering && !hasLegacyStaticRendering) {
133
- continue;
134
- }
135
- // Strip leading slash for S3 key; handle root "/" → "index"
136
- const stripped = routeKey === '/' ? 'index' : routeKey.replace(/^\//, '');
97
+ for (const { fileStem: stripped, hasFullRSC, routeKey } of pages){
137
98
  const routeAssets = [];
138
- // For partially static routes, dataRoute can name a runtime endpoint even
139
- // when the build has no full RSC file. Next.js sets prefetchDataRoute only
140
- // when it emits that static payload.
141
- const hasFullRSC = route.renderingMode !== 'PARTIALLY_STATIC' || typeof route.prefetchDataRoute === 'string';
142
99
  const extensions = hasFullRSC ? [
143
100
  '.html',
144
101
  '.rsc',
@@ -174,6 +131,55 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
174
131
  routeAssetMap
175
132
  };
176
133
  }
134
+ /**
135
+ * Lists the pages in `<outputPath>/prerender-manifest.json` that are safe to serve from storage:
136
+ * App Router pages with static computation and no ISR. Returns an empty list when the manifest is
137
+ * missing or unreadable.
138
+ */ export async function listStaticPrerenderedPages(outputPath) {
139
+ const manifestPath = path.join(outputPath, 'prerender-manifest.json');
140
+ let manifest;
141
+ try {
142
+ const raw = await fs.readFile(manifestPath, 'utf-8');
143
+ manifest = JSON.parse(raw);
144
+ } catch {
145
+ return [];
146
+ }
147
+ if (!manifest.routes || typeof manifest.routes !== 'object') {
148
+ return [];
149
+ }
150
+ const pages = [];
151
+ for (const [routeKey, route] of Object.entries(manifest.routes)){
152
+ // Current manifests classify app pages explicitly. Older App Router manifests
153
+ // can be identified by their RSC data route. Other entries may be route handlers.
154
+ const isPageRoute = route.routeType === 'page' || route.routeType === undefined && typeof route.dataRoute === 'string' && route.dataRoute.endsWith('.rsc');
155
+ if (!isPageRoute) {
156
+ continue;
157
+ }
158
+ // ISR prerenders are seeds for the Next.js runtime, not permanent S3 pages.
159
+ // Keep legacy manifests without this field; only false explicitly disables revalidation.
160
+ if (route.initialRevalidateSeconds !== undefined && route.initialRevalidateSeconds !== false) {
161
+ continue;
162
+ }
163
+ // SSR and PPR can also disable revalidation. Only static computation can be
164
+ // served from S3; an initial response is safe for a static CSR shell.
165
+ const hasStaticRendering = route.compute === 'static' && (route.response === 'complete' || route.response === 'initial');
166
+ // Older SSG entries omit these fields. Ambiguous PPR entries must use Lambda.
167
+ const hasLegacyStaticRendering = route.compute === undefined && route.response === undefined && (route.renderingMode === undefined || route.renderingMode === 'STATIC');
168
+ if (!hasStaticRendering && !hasLegacyStaticRendering) {
169
+ continue;
170
+ }
171
+ pages.push({
172
+ // Strip leading slash for the file stem; handle root "/" → "index"
173
+ fileStem: routeKey === '/' ? 'index' : routeKey.replace(/^\//, ''),
174
+ // For partially static routes, dataRoute can name a runtime endpoint even
175
+ // when the build has no full RSC file. Next.js sets prefetchDataRoute only
176
+ // when it emits that static payload.
177
+ hasFullRSC: route.renderingMode !== 'PARTIALLY_STATIC' || typeof route.prefetchDataRoute === 'string',
178
+ routeKey
179
+ });
180
+ }
181
+ return pages;
182
+ }
177
183
  /**
178
184
  * Collect file-based Next.js metadata icons that were prerendered as static route handlers.
179
185
  *
@@ -1,18 +1,11 @@
1
1
  import type { AdapterLogger, LambdaBundle, PrepareLambdaBundleOptions } from './types.js';
2
- /**
3
- * AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped
4
- * total must be strictly less than this value, so a bundle exactly equal to it is
5
- * rejected. The server enforces this too and now returns a clear message, so a
6
- * client-side check against this value is an early-exit convenience, not the
7
- * source of truth.
8
- */
9
- export declare const LAMBDA_MAX_UNZIPPED_BYTES: number;
10
2
  /**
11
3
  * Build Lambda deployment zip using pure Node.js
12
4
  *
13
5
  * Cross-platform replacement for build_for_lambda.sh:
14
6
  * 1. Adds a generated run.sh directly to the archive
15
- * 2. Creates lambda.zip from the standalone output
7
+ * 2. Creates lambda.zip from the standalone output, leaving out Sharp when only
8
+ * Next's optional dependency put it there (see {@link omitOptionalSharp})
16
9
  *
17
10
  * The output's static/ and the project's public/ directories are not copied into the zip. Those
18
11
  * files are uploaded separately and served by Gatekeeper, not the Lambda function.
@@ -25,3 +18,9 @@ export declare const LAMBDA_MAX_UNZIPPED_BYTES: number;
25
18
  export declare function buildLambdaZip(projectPath: string, output?: string, options?: {
26
19
  logger?: AdapterLogger;
27
20
  } & PrepareLambdaBundleOptions): Promise<LambdaBundle>;
21
+ /**
22
+ * Returns the files that replace or extend Next.js's standalone output in a server bundle: the
23
+ * cache-configured server entry and its optional cache handler, keyed by path relative to
24
+ * `standalonePath`. Shared by v1 Lambda bundles and manifest v2 server ZIPs.
25
+ */
26
+ export declare function createNextjsServerFiles(standalonePath: string, serverEntryPath: string, logger?: AdapterLogger): Promise<Map<string, Buffer>>;
@@ -1,5 +1,3 @@
1
- import archiver from 'archiver';
2
- import { createWriteStream } from 'fs';
3
1
  import fs from 'fs/promises';
4
2
  import path from 'path';
5
3
  import { configureNextjsCache } from './configureNextjsCache.js';
@@ -7,20 +5,16 @@ import { assertDeployableServerActionsKey } from './deploy-output/assertDeployab
7
5
  import { inspectNextjsOutput } from './deploy-output/inspectNextjsOutput.js';
8
6
  import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
9
7
  import { walkBundleFiles } from './fs-utils.js';
8
+ import { omitOptionalSharp } from './omit-optional-sharp.js';
10
9
  import { isBundlableFile } from './secret-files.js';
11
- /**
12
- * AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped
13
- * total must be strictly less than this value, so a bundle exactly equal to it is
14
- * rejected. The server enforces this too and now returns a clear message, so a
15
- * client-side check against this value is an early-exit convenience, not the
16
- * source of truth.
17
- */ export const LAMBDA_MAX_UNZIPPED_BYTES = 250 * 1024 * 1024;
10
+ import { writeZip } from './writeZip.js';
18
11
  /**
19
12
  * Build Lambda deployment zip using pure Node.js
20
13
  *
21
14
  * Cross-platform replacement for build_for_lambda.sh:
22
15
  * 1. Adds a generated run.sh directly to the archive
23
- * 2. Creates lambda.zip from the standalone output
16
+ * 2. Creates lambda.zip from the standalone output, leaving out Sharp when only
17
+ * Next's optional dependency put it there (see {@link omitOptionalSharp})
24
18
  *
25
19
  * The output's static/ and the project's public/ directories are not copied into the zip. Those
26
20
  * files are uploaded separately and served by Gatekeeper, not the Lambda function.
@@ -36,7 +30,8 @@ import { isBundlableFile } from './secret-files.js';
36
30
  throw new Error(`Standalone build not found at ${outputPath}`);
37
31
  }
38
32
  await assertDeployableServerActionsKey(outputPath);
39
- const files = (await walkBundleFiles(layout.standalonePath)).filter((file)=>isBundlableFile(file.relativePath));
33
+ const bundlableFiles = (await walkBundleFiles(layout.standalonePath)).filter((file)=>isBundlableFile(file.relativePath));
34
+ const files = await omitOptionalSharp(projectPath, outputPath, bundlableFiles, options.logger);
40
35
  // Override archive entries in memory without changing Next's standalone output.
41
36
  const bundleFileOverrides = await createBundleFileOverrides(layout.standalonePath, layout.serverEntryPath, options.logger);
42
37
  const artifactDir = options.artifactDir ?? projectPath;
@@ -49,7 +44,22 @@ import { isBundlableFile } from './secret-files.js';
49
44
  const existingBytes = files.find((file)=>file.relativePath === name)?.size ?? 0;
50
45
  unzippedBytes += contents.byteLength - existingBytes;
51
46
  }
52
- await createZip(files, zipPath, bundleFileOverrides);
47
+ await writeZip({
48
+ entries: [
49
+ ...files.filter((file)=>!bundleFileOverrides.has(file.relativePath)).map((file)=>({
50
+ name: file.relativePath,
51
+ sourcePath: file.sourcePath
52
+ })),
53
+ ...[
54
+ ...bundleFileOverrides
55
+ ].map(([name, contents])=>({
56
+ name,
57
+ contents,
58
+ mode: name === 'run.sh' ? 0o755 : 0o644
59
+ }))
60
+ ],
61
+ zipPath
62
+ });
53
63
  return {
54
64
  unzippedBytes,
55
65
  zipPath
@@ -61,21 +71,31 @@ import { isBundlableFile } from './secret-files.js';
61
71
  * cache handler. All paths are relative to the zip root.
62
72
  */ async function createBundleFileOverrides(standalonePath, serverEntryPath, logger) {
63
73
  const serverEntry = path.relative(standalonePath, serverEntryPath).split(path.sep).join('/');
64
- const cacheConfiguration = await configureNextjsCache(serverEntryPath, logger);
65
- const bundleFileOverrides = new Map([
74
+ return new Map([
66
75
  [
67
76
  'run.sh',
68
77
  Buffer.from(createRunScript(serverEntry))
69
78
  ],
79
+ ...await createNextjsServerFiles(standalonePath, serverEntryPath, logger)
80
+ ]);
81
+ }
82
+ /**
83
+ * Returns the files that replace or extend Next.js's standalone output in a server bundle: the
84
+ * cache-configured server entry and its optional cache handler, keyed by path relative to
85
+ * `standalonePath`. Shared by v1 Lambda bundles and manifest v2 server ZIPs.
86
+ */ export async function createNextjsServerFiles(standalonePath, serverEntryPath, logger) {
87
+ const serverEntry = path.relative(standalonePath, serverEntryPath).split(path.sep).join('/');
88
+ const cacheConfiguration = await configureNextjsCache(serverEntryPath, logger);
89
+ const files = new Map([
70
90
  [
71
91
  serverEntry,
72
92
  Buffer.from(cacheConfiguration.server)
73
93
  ]
74
94
  ]);
75
95
  if (cacheConfiguration.handler) {
76
- bundleFileOverrides.set(path.posix.join(path.posix.dirname(serverEntry), cacheConfiguration.handler.name), cacheConfiguration.handler.data);
96
+ files.set(path.posix.join(path.posix.dirname(serverEntry), cacheConfiguration.handler.name), cacheConfiguration.handler.data);
77
97
  }
78
- return bundleFileOverrides;
98
+ return files;
79
99
  }
80
100
  function createRunScript(serverEntry) {
81
101
  const escapedEntry = serverEntry.replaceAll("'", "'\\''");
@@ -84,31 +104,3 @@ function createRunScript(serverEntry) {
84
104
  NODE_ENV=production exec node '${escapedEntry}'
85
105
  `;
86
106
  }
87
- function createZip(files, zipPath, bundleFileOverrides) {
88
- return new Promise((resolve, reject)=>{
89
- const output = createWriteStream(zipPath);
90
- const archive = archiver('zip', {
91
- zlib: {
92
- level: 9
93
- }
94
- });
95
- output.on('close', ()=>resolve());
96
- archive.on('error', (err)=>reject(err));
97
- archive.pipe(output);
98
- for (const file of files){
99
- if (bundleFileOverrides.has(file.relativePath)) {
100
- continue;
101
- }
102
- archive.file(file.sourcePath, {
103
- name: file.relativePath
104
- });
105
- }
106
- for (const [name, contents] of bundleFileOverrides){
107
- archive.append(contents, {
108
- name,
109
- mode: name === 'run.sh' ? 0o755 : 0o644
110
- });
111
- }
112
- void archive.finalize();
113
- });
114
- }
@@ -1,4 +1,8 @@
1
+ export { inspectNextjsOutput } from './deploy-output/inspectNextjsOutput.js';
2
+ export { inspectNitroOutput } from './deploy-output/inspectNitroOutput.js';
3
+ export { LAMBDA_MAX_UNZIPPED_BYTES } from './lambdaLimits.js';
1
4
  export { NextjsAdapter } from './nextjs.js';
2
5
  export { NitroAdapter } from './nitro.js';
3
6
  export type { AdapterLogger, AdapterName, AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions, } from './types.js';
7
+ export * from './v2/core/index.js';
4
8
  export { ViteAdapter } from './vite.js';
@@ -1,3 +1,7 @@
1
+ export { inspectNextjsOutput } from './deploy-output/inspectNextjsOutput.js';
2
+ export { inspectNitroOutput } from './deploy-output/inspectNitroOutput.js';
3
+ export { LAMBDA_MAX_UNZIPPED_BYTES } from './lambdaLimits.js';
1
4
  export { NextjsAdapter } from './nextjs.js';
2
5
  export { NitroAdapter } from './nitro.js';
6
+ export * from './v2/core/index.js';
3
7
  export { ViteAdapter } from './vite.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped total must be
3
+ * strictly less than this value, so a bundle exactly equal to it is rejected. The server enforces
4
+ * this too, so a client-side check is an early exit, not the source of truth.
5
+ */
6
+ export declare const LAMBDA_MAX_UNZIPPED_BYTES: number;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped total must be
3
+ * strictly less than this value, so a bundle exactly equal to it is rejected. The server enforces
4
+ * this too, so a client-side check is an early exit, not the source of truth.
5
+ */ export const LAMBDA_MAX_UNZIPPED_BYTES = 250 * 1024 * 1024;
@@ -0,0 +1,7 @@
1
+ import type { AdapterLogger, AssetCollection } from './types.js';
2
+ /**
3
+ * Collects the files a Next.js build serves unchanged: `.next/static` as `_next/static/*`, the
4
+ * public folder, and prerendered metadata icons. Keys are public paths without a leading slash;
5
+ * `pathMap` values are relative to the project root.
6
+ */
7
+ export declare function collectNextjsAssets(projectPath: string, output?: string, logger?: AdapterLogger): Promise<AssetCollection>;
@@ -0,0 +1,44 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import { collectStaticAssets, collectStaticMetadataAssets } from './asset-collection.js';
4
+ import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
5
+ import { collectFilesRecursive } from './fs-utils.js';
6
+ import { isPublishableAsset } from './secret-files.js';
7
+ /**
8
+ * Collects the files a Next.js build serves unchanged: `.next/static` as `_next/static/*`, the
9
+ * public folder, and prerendered metadata icons. Keys are public paths without a leading slash;
10
+ * `pathMap` values are relative to the project root.
11
+ */ export async function collectNextjsAssets(projectPath, output, logger) {
12
+ // Bundle assets: .next/static/ → _next/static/
13
+ const staticAssets = (await collectStaticAssets(projectPath, output, logger)).filter(isPublishableAsset);
14
+ const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
15
+ // A normal Next build keeps public/ beside .next. A prebuilt artifact can
16
+ // instead include it in the supplied output directory, which is necessary
17
+ // when the artifact is isolated from the source project (for example Bazel).
18
+ const artifactPublicDir = path.join(outputPath, 'public');
19
+ const publicDir = await fs.stat(artifactPublicDir).then((stat)=>stat.isDirectory()).catch(()=>false) ? artifactPublicDir : path.join(projectPath, 'public');
20
+ let publicAssets = [];
21
+ try {
22
+ await fs.stat(publicDir);
23
+ publicAssets = (await collectFilesRecursive(publicDir, publicDir)).filter(isPublishableAsset);
24
+ } catch {
25
+ // No public directory
26
+ }
27
+ const metadataAssets = await collectStaticMetadataAssets(projectPath, output);
28
+ const pathMap = {};
29
+ for (const key of staticAssets){
30
+ pathMap[key] = path.relative(projectPath, path.join(outputPath, key.replace(/^_next\//, '')));
31
+ }
32
+ for (const key of publicAssets){
33
+ pathMap[key] = path.relative(projectPath, path.join(publicDir, key));
34
+ }
35
+ for (const key of metadataAssets.keys.filter(isPublishableAsset)){
36
+ pathMap[key] = metadataAssets.pathMap[key];
37
+ }
38
+ const uploadKeys = Object.keys(pathMap);
39
+ return {
40
+ pathMap,
41
+ routes: uploadKeys.map((key)=>`/${key}`),
42
+ uploadKeys
43
+ };
44
+ }
@@ -1,4 +1,5 @@
1
1
  import type { AdapterLogger, AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions } from './types.js';
2
+ import type { DeploymentInput } from './v2/core/build.js';
2
3
  export declare class NextjsAdapter implements DeployAdapter {
3
4
  private readonly logger?;
4
5
  name: "nextjs";
@@ -7,6 +8,13 @@ export declare class NextjsAdapter implements DeployAdapter {
7
8
  });
8
9
  collectAssets(projectPath: string, output?: string): Promise<AssetCollection>;
9
10
  collectPages(projectPath: string, output?: string): Promise<PageCollection>;
11
+ /**
12
+ * Translates a standalone build's output into manifest v2 input, with the server ZIP written to
13
+ * `artifactDir` (a new temporary directory when omitted).
14
+ */
15
+ createManifestV2Input(projectPath: string, output?: string, options?: {
16
+ artifactDir: string;
17
+ }): Promise<DeploymentInput>;
10
18
  prepareLambdaBundle(projectPath: string, output?: string, options?: PrepareLambdaBundleOptions): Promise<LambdaBundle>;
11
19
  }
12
20
  export declare const nextjsAdapter: NextjsAdapter;
@@ -1,49 +1,19 @@
1
1
  import fs from 'fs/promises';
2
+ import os from 'os';
2
3
  import path from 'path';
3
- import { collectSSGAssets, collectStaticAssets, collectStaticMetadataAssets } from './asset-collection.js';
4
+ import { collectSSGAssets } from './asset-collection.js';
4
5
  import { buildLambdaZip } from './build-lambda-zip.js';
5
- import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
6
- import { collectFilesRecursive } from './fs-utils.js';
7
- import { isPublishableAsset } from './secret-files.js';
6
+ import { collectNextjsAssets } from './nextjs-assets.js';
7
+ import { readNextBuildOutput } from './v2/nextjs/read-build-output.js';
8
+ import { toManifestV2Input } from './v2/nextjs/translate.js';
8
9
  export class NextjsAdapter {
9
10
  logger;
10
11
  name = 'nextjs';
11
12
  constructor(options = {}){
12
13
  this.logger = options.logger;
13
14
  }
14
- async collectAssets(projectPath, output) {
15
- // Bundle assets: .next/static/ → _next/static/
16
- const staticAssets = (await collectStaticAssets(projectPath, output, this.logger)).filter(isPublishableAsset);
17
- const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
18
- // A normal Next build keeps public/ beside .next. A prebuilt artifact can
19
- // instead include it in the supplied output directory, which is necessary
20
- // when the artifact is isolated from the source project (for example Bazel).
21
- const artifactPublicDir = path.join(outputPath, 'public');
22
- const publicDir = await fs.stat(artifactPublicDir).then((stat)=>stat.isDirectory()).catch(()=>false) ? artifactPublicDir : path.join(projectPath, 'public');
23
- let publicAssets = [];
24
- try {
25
- await fs.stat(publicDir);
26
- publicAssets = (await collectFilesRecursive(publicDir, publicDir)).filter(isPublishableAsset);
27
- } catch {
28
- // No public directory
29
- }
30
- const metadataAssets = await collectStaticMetadataAssets(projectPath, output);
31
- const pathMap = {};
32
- for (const key of staticAssets){
33
- pathMap[key] = path.relative(projectPath, path.join(outputPath, key.replace(/^_next\//, '')));
34
- }
35
- for (const key of publicAssets){
36
- pathMap[key] = path.relative(projectPath, path.join(publicDir, key));
37
- }
38
- for (const key of metadataAssets.keys.filter(isPublishableAsset)){
39
- pathMap[key] = metadataAssets.pathMap[key];
40
- }
41
- const uploadKeys = Object.keys(pathMap);
42
- return {
43
- pathMap,
44
- routes: uploadKeys.map((key)=>`/${key}`),
45
- uploadKeys
46
- };
15
+ collectAssets(projectPath, output) {
16
+ return collectNextjsAssets(projectPath, output, this.logger);
47
17
  }
48
18
  async collectPages(projectPath, output) {
49
19
  const ssg = await collectSSGAssets(projectPath, output, this.logger);
@@ -57,6 +27,18 @@ export class NextjsAdapter {
57
27
  uploadKeys: ssg.keys
58
28
  };
59
29
  }
30
+ /**
31
+ * Translates a standalone build's output into manifest v2 input, with the server ZIP written to
32
+ * `artifactDir` (a new temporary directory when omitted).
33
+ */ async createManifestV2Input(projectPath, output, options) {
34
+ const model = await readNextBuildOutput(projectPath, output);
35
+ const artifactDir = options?.artifactDir ?? await fs.mkdtemp(path.join(os.tmpdir(), 'figma-nextjs-v2-'));
36
+ return toManifestV2Input(model, {
37
+ artifactDir,
38
+ logger: this.logger,
39
+ projectPath
40
+ });
41
+ }
60
42
  async prepareLambdaBundle(projectPath, output, options) {
61
43
  return buildLambdaZip(projectPath, output, {
62
44
  ...options,
@@ -1,11 +1,10 @@
1
- import archiver from 'archiver';
2
- import { createWriteStream } from 'fs';
3
1
  import fs from 'fs/promises';
4
2
  import path from 'path';
5
3
  import { resolveNitroOutputLayout } from './deploy-output/resolveNitroOutputLayout.js';
6
4
  import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
7
5
  import { collectFilesRecursive, EscapingSymlinkError, walkBundleFiles } from './fs-utils.js';
8
6
  import { isBundlableFile, isPublishableAsset } from './secret-files.js';
7
+ import { writeZip } from './writeZip.js';
9
8
  /** Framework asset directories that are not pre-rendered pages. */ const NON_PAGE_DIRS = new Set([
10
9
  '_build',
11
10
  '_nuxt',
@@ -78,26 +77,23 @@ export class NitroAdapter {
78
77
  ]);
79
78
  const bundlableServerFiles = allServerFiles.filter((file)=>isBundlableFile(file.relativePath));
80
79
  const unzippedBytes = bundlableServerFiles.reduce((total, file)=>total + file.size, 0) + publicFiles.reduce((total, file)=>total + file.size, 0) + runShStat.size;
81
- await createZip(zipPath, [
82
- {
83
- files: bundlableServerFiles,
84
- prefix: serverPrefix
85
- },
86
- {
87
- files: publicFiles,
88
- prefix: publicPrefix
89
- },
90
- {
91
- files: [
92
- {
93
- relativePath: 'run.sh',
94
- size: runShStat.size,
95
- sourcePath: runShPath
96
- }
97
- ],
98
- prefix: ''
99
- }
100
- ]);
80
+ await writeZip({
81
+ entries: [
82
+ ...bundlableServerFiles.map((file)=>({
83
+ name: serverPrefix + file.relativePath,
84
+ sourcePath: file.sourcePath
85
+ })),
86
+ ...publicFiles.map((file)=>({
87
+ name: publicPrefix + file.relativePath,
88
+ sourcePath: file.sourcePath
89
+ })),
90
+ {
91
+ name: 'run.sh',
92
+ sourcePath: runShPath
93
+ }
94
+ ],
95
+ zipPath
96
+ });
101
97
  return {
102
98
  unzippedBytes,
103
99
  zipPath
@@ -170,24 +166,3 @@ async function walkPublicBundleFiles(publicPath) {
170
166
  return [];
171
167
  }
172
168
  }
173
- async function createZip(zipPath, entries) {
174
- return new Promise((resolve, reject)=>{
175
- const output = createWriteStream(zipPath);
176
- const archive = archiver('zip', {
177
- zlib: {
178
- level: 9
179
- }
180
- });
181
- output.on('close', ()=>resolve());
182
- archive.on('error', (err)=>reject(err));
183
- archive.pipe(output);
184
- for (const entry of entries){
185
- for (const file of entry.files){
186
- archive.file(file.sourcePath, {
187
- name: entry.prefix + file.relativePath
188
- });
189
- }
190
- }
191
- void archive.finalize();
192
- });
193
- }
@@ -0,0 +1,22 @@
1
+ import type { BundleFile } from './fs-utils.js';
2
+ import type { AdapterLogger } from './types.js';
3
+ /**
4
+ * Returns the Lambda bundle files without Sharp when the app holds Sharp only
5
+ * because Next.js optionally depends on it.
6
+ *
7
+ * Next's output tracing copies Sharp and its native binaries (about 40 MB) into
8
+ * standalone output for two optional uses:
9
+ * - Next's built-in image optimizer, which is off when the app uses a custom
10
+ * image loader or `images.unoptimized`.
11
+ * - `next/og`, which tries to import Sharp and otherwise renders with its
12
+ * bundled WebAssembly renderer. Payload's API routes import `next/og`, so
13
+ * their route traces list Sharp even when the app never uses it.
14
+ *
15
+ * Because those traces list Sharp either way, they cannot show whether an app
16
+ * needs it. Code that imports Sharp must declare it, though, so Sharp stays
17
+ * whenever the app or a package it depends on, other than Next, declares it,
18
+ * such as `@payloadcms/transformer-sharp`. The standalone output cannot answer
19
+ * that: Next bundles most dependencies into server chunks and leaves their
20
+ * package.json files out, so this reads the app's installed dependencies.
21
+ */
22
+ export declare function omitOptionalSharp(projectPath: string, outputPath: string, files: BundleFile[], logger: AdapterLogger | undefined): Promise<BundleFile[]>;