@payloadcms/figma 0.1.0-internal.10c3b07 → 0.1.0-internal.fbdc0d3
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.
- package/LICENSE.md +1 -1
- package/dist/{utils → adapters}/asset-collection.d.ts +10 -4
- package/dist/{utils → adapters}/asset-collection.js +58 -17
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +4 -2
- package/dist/adapters/build-lambda-zip.js +111 -0
- package/dist/adapters/configureNextjsCache.d.ts +8 -0
- package/dist/adapters/configureNextjsCache.js +55 -0
- package/dist/{utils → adapters}/deploy-output/resolveOutputPath.d.ts +1 -1
- package/dist/adapters/fs-utils.d.ts +39 -0
- package/dist/adapters/fs-utils.js +135 -0
- package/dist/adapters/index.d.ts +4 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.d.ts +40 -0
- package/dist/adapters/lambda-runtime/nextjs-cache.js +174 -0
- package/dist/adapters/nextjs.d.ts +12 -0
- package/dist/adapters/nextjs.js +67 -0
- package/dist/{utils/adapters → adapters}/nitro.d.ts +2 -2
- package/dist/{utils/adapters → adapters}/nitro.js +54 -29
- package/dist/adapters/secret-files.d.ts +25 -0
- package/dist/adapters/secret-files.js +50 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.js +1 -0
- package/dist/{utils/adapters → adapters}/vite.d.ts +1 -1
- package/dist/{utils/adapters → adapters}/vite.js +4 -3
- package/dist/api/control-plane.d.ts +11 -0
- package/dist/api/control-plane.js +26 -0
- package/dist/auth/headless-oauth-flow.js +4 -0
- package/dist/auth/oauth-flow.js +17 -0
- package/dist/auth/refresh.js +12 -12
- package/dist/auth/requested-scopes.d.ts +1 -0
- package/dist/auth/requested-scopes.js +3 -0
- package/dist/auth/token-store.d.ts +16 -0
- package/dist/auth/token-store.js +33 -0
- package/dist/auth/types.d.ts +5 -3
- package/dist/commands/bootstrap.js +3 -0
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/init.js +72 -2
- package/dist/commands/upgrade.js +65 -1
- package/dist/commands/upload-schema.js +3 -4
- package/dist/config/oauth.js +6 -1
- package/dist/constants.d.ts +0 -2
- package/dist/constants.js +0 -3
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/utilities/auth.d.ts +1 -4
- package/dist/db-content-api/utilities/auth.js +1 -1
- package/dist/db-content-api/utilities/data/index.js +8 -2
- package/dist/db-content-api/utilities/data/removeVirtualFields.d.ts +3 -11
- package/dist/db-content-api/utilities/data/removeVirtualFields.js +12 -50
- package/dist/db-content-api/utilities/schema/buildDocumentSchema.js +9 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/next/image-loader.d.ts +6 -0
- package/dist/next/image-loader.js +14 -0
- package/dist/oauth/components/LoginButton/index.js +66 -19
- package/dist/oauth/components/LoginButton/index.scss +121 -15
- package/dist/oauth/defaults.js +4 -1
- package/dist/plugin/build-config.d.ts +13 -3
- package/dist/plugin/build-config.js +198 -59
- package/dist/plugin/cache-revalidation-hooks.d.ts +6 -0
- package/dist/plugin/cache-revalidation-hooks.js +69 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.d.ts +2 -1
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -1
- package/dist/plugin/make-permission-access/make-permission-access.d.ts +8 -0
- package/dist/plugin/make-permission-access/make-permission-access.js +24 -0
- package/dist/storage-content-api/api-types.d.ts +5 -2
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.d.ts +1 -1
- package/dist/storage-content-api/buildBaseMediaResponseHeaders.js +3 -1
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.d.ts +8 -6
- package/dist/storage-content-api/buildClientUploadFetchBackHeaders.js +17 -12
- package/dist/storage-content-api/buildMediaRequestHeaders.d.ts +1 -0
- package/dist/storage-content-api/buildMediaRequestHeaders.js +14 -0
- package/dist/storage-content-api/buildMediaResponseHeaders.d.ts +3 -3
- package/dist/storage-content-api/buildMediaResponseHeaders.js +25 -18
- package/dist/storage-content-api/client-uploads/generate.d.ts +7 -3
- package/dist/storage-content-api/client-uploads/generate.js +22 -21
- package/dist/storage-content-api/client.d.ts +0 -2
- package/dist/storage-content-api/client.js +2 -2
- package/dist/storage-content-api/copyFile.d.ts +16 -0
- package/dist/storage-content-api/copyFile.js +90 -0
- package/dist/storage-content-api/deleteFile.d.ts +8 -0
- package/dist/storage-content-api/deleteFile.js +18 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +33 -0
- package/dist/storage-content-api/getMediaType.d.ts +1 -0
- package/dist/storage-content-api/getMediaType.js +3 -0
- package/dist/storage-content-api/handleUpload.d.ts +1 -2
- package/dist/storage-content-api/handleUpload.js +13 -157
- package/dist/storage-content-api/hasSupportedContentEncoding.d.ts +1 -1
- package/dist/storage-content-api/hasSupportedContentEncoding.js +4 -2
- package/dist/storage-content-api/index.js +17 -8
- package/dist/storage-content-api/mediaErrorResponse.d.ts +1 -1
- package/dist/storage-content-api/mediaErrorResponse.js +2 -2
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/shouldAttachMedia.d.ts +1 -0
- package/dist/storage-content-api/{getInlineContentType.js → shouldAttachMedia.js} +8 -7
- package/dist/storage-content-api/staticHandler.d.ts +2 -1
- package/dist/storage-content-api/staticHandler.js +47 -53
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/storage-content-api/uploadFileData.d.ts +10 -0
- package/dist/storage-content-api/uploadFileData.js +145 -0
- package/dist/utils/build-detection.js +3 -3
- package/dist/utils/cache-bootstrap.js +1 -0
- package/dist/utils/deploy-adapter.d.ts +2 -34
- package/dist/utils/deploy-adapter.js +16 -9
- package/dist/utils/env-management.d.ts +15 -0
- package/dist/utils/env-management.js +47 -0
- package/dist/utils/lambda-config.js +14 -9
- package/dist/utils/load-payload-config.js +1 -6
- package/dist/utils/next-image-loader-config.d.ts +2 -0
- package/dist/utils/next-image-loader-config.js +63 -0
- package/dist/utils/next-image-loader-file.d.ts +2 -0
- package/dist/utils/next-image-loader-file.js +11 -0
- package/dist/utils/payload-config-ast.d.ts +5 -0
- package/dist/utils/payload-config-ast.js +73 -4
- package/dist/utils/payload-config-modifier.js +3 -0
- package/dist/utils/payload-secret.d.ts +28 -0
- package/dist/utils/payload-secret.js +34 -0
- package/package.json +22 -10
- package/dist/storage-content-api/getInlineContentType.d.ts +0 -1
- package/dist/storage-content-api/handleDelete.d.ts +0 -7
- package/dist/storage-content-api/handleDelete.js +0 -15
- package/dist/storage-content-api/utilities/getSafeFilename.d.ts +0 -11
- package/dist/storage-content-api/utilities/getSafeFilename.js +0 -59
- package/dist/storage-content-api/utilities/index.d.ts +0 -2
- package/dist/storage-content-api/utilities/index.js +0 -2
- package/dist/storage-content-api/utilities/parseUploadReference.d.ts +0 -17
- package/dist/storage-content-api/utilities/parseUploadReference.js +0 -27
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -64
- package/dist/utils/build-lambda-zip.js +0 -73
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNextjsOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/inspectNitroOutput.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/isFile.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/readJson.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveNitroOutputLayout.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveOutputPath.js +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.d.ts +0 -0
- /package/dist/{utils → adapters}/deploy-output/resolveWithin.js +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AdapterLogger } from './types.js';
|
|
1
2
|
/**
|
|
2
3
|
* Get file size in bytes
|
|
3
4
|
*
|
|
@@ -14,7 +15,7 @@ export declare function getFileSize(filePath: string): Promise<number>;
|
|
|
14
15
|
* @param projectPath - Path to project root
|
|
15
16
|
* @returns Array of static asset paths (using _next prefix)
|
|
16
17
|
*/
|
|
17
|
-
export declare function collectStaticAssets(projectPath: string, output?: string): Promise<string[]>;
|
|
18
|
+
export declare function collectStaticAssets(projectPath: string, output?: string, logger?: AdapterLogger): Promise<string[]>;
|
|
18
19
|
/**
|
|
19
20
|
* Result from collecting SSG assets
|
|
20
21
|
*/
|
|
@@ -23,14 +24,18 @@ export type SSGAssets = {
|
|
|
23
24
|
keys: string[];
|
|
24
25
|
/** Map of S3 key → relative filesystem path from project root */
|
|
25
26
|
pathMap: Record<string, string>;
|
|
27
|
+
/** Map of page route → S3 keys generated for that page */
|
|
28
|
+
routeAssetMap: Record<string, string[]>;
|
|
26
29
|
};
|
|
30
|
+
type StaticMetadataAssets = Omit<SSGAssets, 'routeAssetMap'>;
|
|
27
31
|
/**
|
|
28
32
|
* Collect SSG asset paths by parsing .next/prerender-manifest.json
|
|
29
33
|
*
|
|
30
|
-
* For each page route in the manifest's `routes` object, collects
|
|
34
|
+
* For each static page route without revalidation in the manifest's `routes` object, collects:
|
|
31
35
|
* - {route}.html (full HTML)
|
|
32
36
|
* - {route}.rsc (React Server Components payload)
|
|
33
37
|
* - {route}.meta (response headers JSON)
|
|
38
|
+
* - Nested `.segment.rsc` files under {route}.segments (segment-prefetch payloads)
|
|
34
39
|
*
|
|
35
40
|
* S3 keys use the route path without leading slash.
|
|
36
41
|
* Filesystem paths point to .next/server/app/{route}.{ext}
|
|
@@ -38,7 +43,7 @@ export type SSGAssets = {
|
|
|
38
43
|
* @param projectPath - Path to project root
|
|
39
44
|
* @returns SSG asset keys and a pathMap for filesystem resolution
|
|
40
45
|
*/
|
|
41
|
-
export declare function collectSSGAssets(projectPath: string, output?: string): Promise<SSGAssets>;
|
|
46
|
+
export declare function collectSSGAssets(projectPath: string, output?: string, logger?: AdapterLogger): Promise<SSGAssets>;
|
|
42
47
|
/**
|
|
43
48
|
* Collect file-based Next.js metadata icons that were prerendered as static route handlers.
|
|
44
49
|
*
|
|
@@ -46,7 +51,7 @@ export declare function collectSSGAssets(projectPath: string, output?: string):
|
|
|
46
51
|
* `.next/server/app/shop/icon1.png.body` output.
|
|
47
52
|
* Documentation: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons
|
|
48
53
|
*/
|
|
49
|
-
export declare function collectStaticMetadataAssets(projectPath: string, output?: string): Promise<
|
|
54
|
+
export declare function collectStaticMetadataAssets(projectPath: string, output?: string): Promise<StaticMetadataAssets>;
|
|
50
55
|
/**
|
|
51
56
|
* Create Lambda deployment zip
|
|
52
57
|
*
|
|
@@ -56,3 +61,4 @@ export declare function collectStaticMetadataAssets(projectPath: string, output?
|
|
|
56
61
|
* @throws Error if build missing or zip creation fails
|
|
57
62
|
*/
|
|
58
63
|
export declare function createLambdaZip(projectPath: string): Promise<void>;
|
|
64
|
+
export {};
|
|
@@ -2,7 +2,6 @@ import fs from 'fs/promises';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { buildLambdaZip } from './build-lambda-zip.js';
|
|
4
4
|
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
5
|
-
import * as log from './log.js';
|
|
6
5
|
// Maximum file size for static assets (S3 limitation)
|
|
7
6
|
const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
8
7
|
;
|
|
@@ -24,7 +23,7 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
24
23
|
* @param dir - Directory to scan
|
|
25
24
|
* @param baseDir - Base directory for relative paths
|
|
26
25
|
* @returns Array of relative file paths
|
|
27
|
-
*/ async function collectFiles(dir, baseDir) {
|
|
26
|
+
*/ async function collectFiles(dir, baseDir, logger) {
|
|
28
27
|
const files = [];
|
|
29
28
|
try {
|
|
30
29
|
const entries = await fs.readdir(dir, {
|
|
@@ -34,7 +33,7 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
34
33
|
const fullPath = path.join(dir, entry.name);
|
|
35
34
|
if (entry.isDirectory()) {
|
|
36
35
|
// Recursively collect from subdirectories
|
|
37
|
-
const subFiles = await collectFiles(fullPath, baseDir);
|
|
36
|
+
const subFiles = await collectFiles(fullPath, baseDir, logger);
|
|
38
37
|
files.push(...subFiles);
|
|
39
38
|
} else if (entry.isFile()) {
|
|
40
39
|
// Check file size before adding
|
|
@@ -47,7 +46,7 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
47
46
|
// Warn user about skipped files
|
|
48
47
|
const sizeMB = (stats.size / (1024 * 1024)).toFixed(2);
|
|
49
48
|
const relativePath = path.relative(baseDir, fullPath);
|
|
50
|
-
|
|
49
|
+
logger?.warning(`Skipping large asset: ${relativePath} (${sizeMB}MB exceeds 50MB limit)`);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -65,10 +64,10 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
65
64
|
*
|
|
66
65
|
* @param projectPath - Path to project root
|
|
67
66
|
* @returns Array of static asset paths (using _next prefix)
|
|
68
|
-
*/ export async function collectStaticAssets(projectPath, output) {
|
|
67
|
+
*/ export async function collectStaticAssets(projectPath, output, logger) {
|
|
69
68
|
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
70
69
|
const staticDir = path.join(outputPath, 'static');
|
|
71
|
-
const files = await collectFiles(staticDir, projectPath);
|
|
70
|
+
const files = await collectFiles(staticDir, projectPath, logger);
|
|
72
71
|
return files.map((file)=>{
|
|
73
72
|
const relativeToStatic = path.relative(staticDir, path.resolve(projectPath, file));
|
|
74
73
|
return `_next/static/${relativeToStatic.split(path.sep).join('/')}`;
|
|
@@ -77,17 +76,18 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
77
76
|
/**
|
|
78
77
|
* Collect SSG asset paths by parsing .next/prerender-manifest.json
|
|
79
78
|
*
|
|
80
|
-
* For each page route in the manifest's `routes` object, collects
|
|
79
|
+
* For each static page route without revalidation in the manifest's `routes` object, collects:
|
|
81
80
|
* - {route}.html (full HTML)
|
|
82
81
|
* - {route}.rsc (React Server Components payload)
|
|
83
82
|
* - {route}.meta (response headers JSON)
|
|
83
|
+
* - Nested `.segment.rsc` files under {route}.segments (segment-prefetch payloads)
|
|
84
84
|
*
|
|
85
85
|
* S3 keys use the route path without leading slash.
|
|
86
86
|
* Filesystem paths point to .next/server/app/{route}.{ext}
|
|
87
87
|
*
|
|
88
88
|
* @param projectPath - Path to project root
|
|
89
89
|
* @returns SSG asset keys and a pathMap for filesystem resolution
|
|
90
|
-
*/ export async function collectSSGAssets(projectPath, output) {
|
|
90
|
+
*/ export async function collectSSGAssets(projectPath, output, logger) {
|
|
91
91
|
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
92
92
|
const manifestPath = path.join(outputPath, 'prerender-manifest.json');
|
|
93
93
|
let manifest;
|
|
@@ -97,22 +97,21 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
97
97
|
} catch {
|
|
98
98
|
return {
|
|
99
99
|
keys: [],
|
|
100
|
-
pathMap: {}
|
|
100
|
+
pathMap: {},
|
|
101
|
+
routeAssetMap: {}
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
if (!manifest.routes || typeof manifest.routes !== 'object') {
|
|
104
105
|
return {
|
|
105
106
|
keys: [],
|
|
106
|
-
pathMap: {}
|
|
107
|
+
pathMap: {},
|
|
108
|
+
routeAssetMap: {}
|
|
107
109
|
};
|
|
108
110
|
}
|
|
109
111
|
const keys = [];
|
|
110
112
|
const pathMap = {};
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
'.rsc',
|
|
114
|
-
'.meta'
|
|
115
|
-
];
|
|
113
|
+
const routeAssetMap = {};
|
|
114
|
+
const appDir = path.join(outputPath, 'server', 'app');
|
|
116
115
|
for (const [routeKey, route] of Object.entries(manifest.routes)){
|
|
117
116
|
// Current manifests classify app pages explicitly. Older App Router manifests
|
|
118
117
|
// can be identified by their RSC data route. Other entries may be route handlers.
|
|
@@ -120,17 +119,59 @@ const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
|
120
119
|
if (!isPageRoute) {
|
|
121
120
|
continue;
|
|
122
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
|
+
}
|
|
123
135
|
// Strip leading slash for S3 key; handle root "/" → "index"
|
|
124
136
|
const stripped = routeKey === '/' ? 'index' : routeKey.replace(/^\//, '');
|
|
137
|
+
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
|
+
const extensions = hasFullRSC ? [
|
|
143
|
+
'.html',
|
|
144
|
+
'.rsc',
|
|
145
|
+
'.meta'
|
|
146
|
+
] : [
|
|
147
|
+
'.html',
|
|
148
|
+
'.meta'
|
|
149
|
+
];
|
|
125
150
|
for (const ext of extensions){
|
|
126
151
|
const s3Key = `${stripped}${ext}`;
|
|
127
152
|
keys.push(s3Key);
|
|
128
|
-
|
|
153
|
+
routeAssets.push(s3Key);
|
|
154
|
+
pathMap[s3Key] = path.relative(projectPath, path.join(appDir, s3Key));
|
|
155
|
+
}
|
|
156
|
+
// Next.js stores segment-prefetch payloads beside each prerendered page in a
|
|
157
|
+
// `<page>.segments` tree. Scan the generated tree instead of reconstructing
|
|
158
|
+
// its opaque, potentially nested segment names from route information.
|
|
159
|
+
const segmentFiles = await collectFiles(path.join(appDir, `${stripped}.segments`), appDir, logger);
|
|
160
|
+
for (const segmentFile of segmentFiles.filter((file)=>file.endsWith('.segment.rsc'))){
|
|
161
|
+
const s3Key = segmentFile.split(path.sep).join('/');
|
|
162
|
+
keys.push(s3Key);
|
|
163
|
+
routeAssets.push(s3Key);
|
|
164
|
+
pathMap[s3Key] = path.relative(projectPath, path.join(appDir, segmentFile));
|
|
129
165
|
}
|
|
166
|
+
// Preserve the manifest route association for the original HTML/RSC/meta
|
|
167
|
+
// files and the new segment files; segment keys cannot be mapped back to a
|
|
168
|
+
// page reliably from their filename in NextjsAdapter.
|
|
169
|
+
routeAssetMap[routeKey] = routeAssets;
|
|
130
170
|
}
|
|
131
171
|
return {
|
|
132
172
|
keys,
|
|
133
|
-
pathMap
|
|
173
|
+
pathMap,
|
|
174
|
+
routeAssetMap
|
|
134
175
|
};
|
|
135
176
|
}
|
|
136
177
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LambdaBundle } from './
|
|
1
|
+
import type { AdapterLogger, LambdaBundle, PrepareLambdaBundleOptions } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped
|
|
4
4
|
* total must be strictly less than this value, so a bundle exactly equal to it is
|
|
@@ -21,4 +21,6 @@ export declare const LAMBDA_MAX_UNZIPPED_BYTES: number;
|
|
|
21
21
|
* @returns The built bundle: its unzipped byte size and the absolute zip path.
|
|
22
22
|
* @throws Error if standalone directory missing or zip creation fails
|
|
23
23
|
*/
|
|
24
|
-
export declare function buildLambdaZip(projectPath: string, output?: string
|
|
24
|
+
export declare function buildLambdaZip(projectPath: string, output?: string, options?: {
|
|
25
|
+
logger?: AdapterLogger;
|
|
26
|
+
} & PrepareLambdaBundleOptions): Promise<LambdaBundle>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import archiver from 'archiver';
|
|
2
|
+
import { createWriteStream } from 'fs';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { configureNextjsCache } from './configureNextjsCache.js';
|
|
6
|
+
import { inspectNextjsOutput } from './deploy-output/inspectNextjsOutput.js';
|
|
7
|
+
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
8
|
+
import { walkBundleFiles } from './fs-utils.js';
|
|
9
|
+
import { isBundlableFile } from './secret-files.js';
|
|
10
|
+
/**
|
|
11
|
+
* AWS Lambda's hard limit on unzipped deployment code size (250 MB). The unzipped
|
|
12
|
+
* total must be strictly less than this value, so a bundle exactly equal to it is
|
|
13
|
+
* rejected. The server enforces this too and now returns a clear message, so a
|
|
14
|
+
* client-side check against this value is an early-exit convenience, not the
|
|
15
|
+
* source of truth.
|
|
16
|
+
*/ export const LAMBDA_MAX_UNZIPPED_BYTES = 250 * 1024 * 1024;
|
|
17
|
+
/**
|
|
18
|
+
* Build Lambda deployment zip using pure Node.js
|
|
19
|
+
*
|
|
20
|
+
* Cross-platform replacement for build_for_lambda.sh:
|
|
21
|
+
* 1. Adds a generated run.sh directly to the archive
|
|
22
|
+
* 2. Creates lambda.zip from the standalone output
|
|
23
|
+
*
|
|
24
|
+
* The output's static/ and the project's public/ directories are not copied into the zip. Those
|
|
25
|
+
* files are uploaded separately and served by Gatekeeper, not the Lambda function.
|
|
26
|
+
*
|
|
27
|
+
* @param projectPath - Path to project root
|
|
28
|
+
* @returns The built bundle: its unzipped byte size and the absolute zip path.
|
|
29
|
+
* @throws Error if standalone directory missing or zip creation fails
|
|
30
|
+
*/ export async function buildLambdaZip(projectPath, output, options = {}) {
|
|
31
|
+
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
32
|
+
const layout = await inspectNextjsOutput(outputPath);
|
|
33
|
+
if (!layout) {
|
|
34
|
+
throw new Error(`Standalone build not found at ${outputPath}`);
|
|
35
|
+
}
|
|
36
|
+
const files = (await walkBundleFiles(layout.standalonePath)).filter((file)=>isBundlableFile(file.relativePath));
|
|
37
|
+
// Override archive entries in memory without changing Next's standalone output.
|
|
38
|
+
const bundleFileOverrides = await createBundleFileOverrides(layout.standalonePath, layout.serverEntryPath, options.logger);
|
|
39
|
+
const artifactDir = options.artifactDir ?? projectPath;
|
|
40
|
+
await fs.mkdir(artifactDir, {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
const zipPath = path.join(artifactDir, 'lambda.zip');
|
|
44
|
+
let unzippedBytes = files.reduce((total, file)=>total + file.size, 0);
|
|
45
|
+
for (const [name, contents] of bundleFileOverrides){
|
|
46
|
+
const existingBytes = files.find((file)=>file.relativePath === name)?.size ?? 0;
|
|
47
|
+
unzippedBytes += contents.byteLength - existingBytes;
|
|
48
|
+
}
|
|
49
|
+
await createZip(files, zipPath, bundleFileOverrides);
|
|
50
|
+
return {
|
|
51
|
+
unzippedBytes,
|
|
52
|
+
zipPath
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns files that replace or extend the standalone output in the Lambda zip:
|
|
57
|
+
* the generated launcher, the cache-configured server entry, and its optional
|
|
58
|
+
* cache handler. All paths are relative to the zip root.
|
|
59
|
+
*/ async function createBundleFileOverrides(standalonePath, serverEntryPath, logger) {
|
|
60
|
+
const serverEntry = path.relative(standalonePath, serverEntryPath).split(path.sep).join('/');
|
|
61
|
+
const cacheConfiguration = await configureNextjsCache(serverEntryPath, logger);
|
|
62
|
+
const bundleFileOverrides = new Map([
|
|
63
|
+
[
|
|
64
|
+
'run.sh',
|
|
65
|
+
Buffer.from(createRunScript(serverEntry))
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
serverEntry,
|
|
69
|
+
Buffer.from(cacheConfiguration.server)
|
|
70
|
+
]
|
|
71
|
+
]);
|
|
72
|
+
if (cacheConfiguration.handler) {
|
|
73
|
+
bundleFileOverrides.set(path.posix.join(path.posix.dirname(serverEntry), cacheConfiguration.handler.name), cacheConfiguration.handler.data);
|
|
74
|
+
}
|
|
75
|
+
return bundleFileOverrides;
|
|
76
|
+
}
|
|
77
|
+
function createRunScript(serverEntry) {
|
|
78
|
+
const escapedEntry = serverEntry.replaceAll("'", "'\\''");
|
|
79
|
+
return `#!/bin/bash -x
|
|
80
|
+
[ ! -d '/tmp/cache' ] && mkdir -p /tmp/cache
|
|
81
|
+
NODE_ENV=production exec node '${escapedEntry}'
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
function createZip(files, zipPath, bundleFileOverrides) {
|
|
85
|
+
return new Promise((resolve, reject)=>{
|
|
86
|
+
const output = createWriteStream(zipPath);
|
|
87
|
+
const archive = archiver('zip', {
|
|
88
|
+
zlib: {
|
|
89
|
+
level: 9
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
output.on('close', ()=>resolve());
|
|
93
|
+
archive.on('error', (err)=>reject(err));
|
|
94
|
+
archive.pipe(output);
|
|
95
|
+
for (const file of files){
|
|
96
|
+
if (bundleFileOverrides.has(file.relativePath)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
archive.file(file.sourcePath, {
|
|
100
|
+
name: file.relativePath
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
for (const [name, contents] of bundleFileOverrides){
|
|
104
|
+
archive.append(contents, {
|
|
105
|
+
name,
|
|
106
|
+
mode: name === 'run.sh' ? 0o755 : 0o644
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
void archive.finalize();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Node, Project } from 'ts-morph';
|
|
4
|
+
import { createNextjsCacheHandlerSource } from './lambda-runtime/nextjs-cache.js';
|
|
5
|
+
const CACHE_HANDLER_FILE = '__figma_nextjs_cache.mjs';
|
|
6
|
+
export async function configureNextjsCache(serverEntryPath, logger) {
|
|
7
|
+
const original = await fs.readFile(serverEntryPath, 'utf8');
|
|
8
|
+
const project = new Project({
|
|
9
|
+
useInMemoryFileSystem: true
|
|
10
|
+
});
|
|
11
|
+
const source = project.createSourceFile('server.js', original);
|
|
12
|
+
const initializer = source.getVariableDeclaration('nextConfig')?.getInitializer();
|
|
13
|
+
if (!initializer || !Node.isObjectLiteralExpression(initializer)) {
|
|
14
|
+
throw new Error('Unsupported Next.js standalone server: expected a nextConfig object');
|
|
15
|
+
}
|
|
16
|
+
// Only accept Next's generated JSON, not arbitrary application code.
|
|
17
|
+
let config;
|
|
18
|
+
try {
|
|
19
|
+
config = JSON.parse(initializer.getText());
|
|
20
|
+
} catch {
|
|
21
|
+
throw new Error('Unsupported Next.js standalone server: expected generated JSON config');
|
|
22
|
+
}
|
|
23
|
+
const experimental = config.experimental;
|
|
24
|
+
// cacheHandler is the stable name; older Next.js builds use the experimental path.
|
|
25
|
+
if (config.cacheHandler || experimental?.incrementalCacheHandlerPath) {
|
|
26
|
+
logger?.info('Using the application cacheHandler; Figma fresh-only caching is not enabled.');
|
|
27
|
+
return {
|
|
28
|
+
server: original
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const reservedPath = path.join(path.dirname(serverEntryPath), CACHE_HANDLER_FILE);
|
|
32
|
+
const exists = await fs.lstat(reservedPath).then(()=>true, (error)=>{
|
|
33
|
+
if (error.code === 'ENOENT') {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
throw error;
|
|
37
|
+
});
|
|
38
|
+
if (exists) {
|
|
39
|
+
throw new Error(`Standalone output contains reserved file ${CACHE_HANDLER_FILE}`);
|
|
40
|
+
}
|
|
41
|
+
initializer.getProperty('"cacheHandler"')?.remove();
|
|
42
|
+
initializer.addPropertyAssignments([
|
|
43
|
+
{
|
|
44
|
+
name: 'cacheHandler',
|
|
45
|
+
initializer: `require.resolve('./${CACHE_HANDLER_FILE}')`
|
|
46
|
+
}
|
|
47
|
+
]);
|
|
48
|
+
return {
|
|
49
|
+
handler: {
|
|
50
|
+
name: CACHE_HANDLER_FILE,
|
|
51
|
+
data: Buffer.from(createNextjsCacheHandlerSource())
|
|
52
|
+
},
|
|
53
|
+
server: source.getFullText()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AdapterName } from '../
|
|
1
|
+
import type { AdapterName } from '../types.js';
|
|
2
2
|
export declare function resolveOutputPath(projectPath: string, adapter: AdapterName, output?: string): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively collect all file paths under a directory,
|
|
3
|
+
* returned as forward-slash-separated paths relative to baseDir.
|
|
4
|
+
*/
|
|
5
|
+
export declare function collectFilesRecursive(dir: string, baseDir: string): Promise<string[]>;
|
|
6
|
+
export declare class EscapingSymlinkError extends Error {
|
|
7
|
+
readonly symlinkPath: string;
|
|
8
|
+
readonly targetPath: string;
|
|
9
|
+
constructor(symlinkPath: string, targetPath: string, root: string);
|
|
10
|
+
}
|
|
11
|
+
export interface BundleFile {
|
|
12
|
+
/** Forward-slash path relative to the walk root; used as the zip entry name. */
|
|
13
|
+
relativePath: string;
|
|
14
|
+
/**
|
|
15
|
+
* Bytes this entry contributes to unzipped size. Regular files use content
|
|
16
|
+
* size; in-tree symlinks use `lstat` size (the stored link path).
|
|
17
|
+
*/
|
|
18
|
+
size: number;
|
|
19
|
+
/** Path passed to the archiver; may be an in-tree symlink. */
|
|
20
|
+
sourcePath: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Recursively list files under `root` for Lambda bundle sizing and archiving.
|
|
24
|
+
*
|
|
25
|
+
* Regular files and directories are included. Symlinks are included (not
|
|
26
|
+
* followed) only when the resolved target stays within `root`; otherwise an
|
|
27
|
+
* {@link EscapingSymlinkError} is thrown. This matches `archiver.directory`,
|
|
28
|
+
* which stores zip symlink entries rather than copying target contents.
|
|
29
|
+
* Broken or unreadable files are skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function walkBundleFiles(root: string): Promise<BundleFile[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Recursively sum the byte size of all files under a directory using the same
|
|
34
|
+
* symlink policy as {@link walkBundleFiles}. Returns 0 for a missing or
|
|
35
|
+
* unreadable directory. Escaping symlinks throw {@link EscapingSymlinkError}.
|
|
36
|
+
* Files that disappear or become unreadable between readdir and stat are
|
|
37
|
+
* skipped (treated as 0 bytes).
|
|
38
|
+
*/
|
|
39
|
+
export declare function getDirectorySize(dir: string): Promise<number>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Recursively collect all file paths under a directory,
|
|
5
|
+
* returned as forward-slash-separated paths relative to baseDir.
|
|
6
|
+
*/ export async function collectFilesRecursive(dir, baseDir) {
|
|
7
|
+
const files = [];
|
|
8
|
+
try {
|
|
9
|
+
const entries = await fs.readdir(dir, {
|
|
10
|
+
withFileTypes: true
|
|
11
|
+
});
|
|
12
|
+
for (const entry of entries){
|
|
13
|
+
const fullPath = path.join(dir, entry.name);
|
|
14
|
+
if (entry.isDirectory()) {
|
|
15
|
+
const subFiles = await collectFilesRecursive(fullPath, baseDir);
|
|
16
|
+
files.push(...subFiles);
|
|
17
|
+
} else if (entry.isFile()) {
|
|
18
|
+
files.push(path.relative(baseDir, fullPath).split(path.sep).join('/'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// Not accessible
|
|
23
|
+
}
|
|
24
|
+
return files;
|
|
25
|
+
}
|
|
26
|
+
export class EscapingSymlinkError extends Error {
|
|
27
|
+
symlinkPath;
|
|
28
|
+
targetPath;
|
|
29
|
+
constructor(symlinkPath, targetPath, root){
|
|
30
|
+
super(`Symlink '${symlinkPath}' points outside ${root} (${targetPath})`), this.symlinkPath = symlinkPath, this.targetPath = targetPath;
|
|
31
|
+
this.name = 'EscapingSymlinkError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Recursively list files under `root` for Lambda bundle sizing and archiving.
|
|
36
|
+
*
|
|
37
|
+
* Regular files and directories are included. Symlinks are included (not
|
|
38
|
+
* followed) only when the resolved target stays within `root`; otherwise an
|
|
39
|
+
* {@link EscapingSymlinkError} is thrown. This matches `archiver.directory`,
|
|
40
|
+
* which stores zip symlink entries rather than copying target contents.
|
|
41
|
+
* Broken or unreadable files are skipped.
|
|
42
|
+
*/ export async function walkBundleFiles(root) {
|
|
43
|
+
const rootReal = await fs.realpath(root);
|
|
44
|
+
const files = [];
|
|
45
|
+
await walkBundleDir(root, root, rootReal, files);
|
|
46
|
+
return files;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Recursively sum the byte size of all files under a directory using the same
|
|
50
|
+
* symlink policy as {@link walkBundleFiles}. Returns 0 for a missing or
|
|
51
|
+
* unreadable directory. Escaping symlinks throw {@link EscapingSymlinkError}.
|
|
52
|
+
* Files that disappear or become unreadable between readdir and stat are
|
|
53
|
+
* skipped (treated as 0 bytes).
|
|
54
|
+
*/ export async function getDirectorySize(dir) {
|
|
55
|
+
try {
|
|
56
|
+
const files = await walkBundleFiles(dir);
|
|
57
|
+
return files.reduce((total, file)=>total + file.size, 0);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof EscapingSymlinkError) {
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function isPathWithin(rootReal, targetReal) {
|
|
66
|
+
const relative = path.relative(rootReal, targetReal);
|
|
67
|
+
return relative === '' || relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
68
|
+
}
|
|
69
|
+
async function walkBundleDir(dir, root, rootReal, files) {
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = await fs.readdir(dir, {
|
|
73
|
+
withFileTypes: true
|
|
74
|
+
});
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
for (const entry of entries){
|
|
79
|
+
const fullPath = path.join(dir, entry.name);
|
|
80
|
+
if (entry.isSymbolicLink()) {
|
|
81
|
+
await addSymlinkEntry(fullPath, root, rootReal, files);
|
|
82
|
+
} else if (entry.isDirectory()) {
|
|
83
|
+
await walkBundleDir(fullPath, root, rootReal, files);
|
|
84
|
+
} else if (entry.isFile()) {
|
|
85
|
+
await addRegularFile(fullPath, root, files);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function addSymlinkEntry(fullPath, root, rootReal, files) {
|
|
90
|
+
const relativePath = toRelativePath(root, fullPath);
|
|
91
|
+
const targetPath = await resolveSymlinkTarget(fullPath);
|
|
92
|
+
if (targetPath === null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!isPathWithin(rootReal, targetPath)) {
|
|
96
|
+
throw new EscapingSymlinkError(relativePath, targetPath, root);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const stats = await fs.lstat(fullPath);
|
|
100
|
+
files.push({
|
|
101
|
+
relativePath,
|
|
102
|
+
size: stats.size,
|
|
103
|
+
sourcePath: fullPath
|
|
104
|
+
});
|
|
105
|
+
} catch {
|
|
106
|
+
// Symlink vanished between readdir and lstat — skip it.
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function resolveSymlinkTarget(fullPath) {
|
|
110
|
+
try {
|
|
111
|
+
return await fs.realpath(fullPath);
|
|
112
|
+
} catch {
|
|
113
|
+
try {
|
|
114
|
+
const link = await fs.readlink(fullPath);
|
|
115
|
+
return path.resolve(path.dirname(fullPath), link);
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function addRegularFile(fullPath, root, files) {
|
|
122
|
+
try {
|
|
123
|
+
const stats = await fs.stat(fullPath);
|
|
124
|
+
files.push({
|
|
125
|
+
relativePath: toRelativePath(root, fullPath),
|
|
126
|
+
size: stats.size,
|
|
127
|
+
sourcePath: fullPath
|
|
128
|
+
});
|
|
129
|
+
} catch {
|
|
130
|
+
// File vanished or is unreadable between readdir and stat — skip it.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function toRelativePath(root, fullPath) {
|
|
134
|
+
return path.relative(root, fullPath).split(path.sep).join('/');
|
|
135
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { NextjsAdapter } from './nextjs.js';
|
|
2
|
+
export { NitroAdapter } from './nitro.js';
|
|
3
|
+
export type { AdapterLogger, AdapterName, AssetCollection, DeployAdapter, LambdaBundle, PageCollection, PrepareLambdaBundleOptions, } from './types.js';
|
|
4
|
+
export { ViteAdapter } from './vite.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function createNextjsCacheHandler(deserializeValue: any, serializeValue: any): {
|
|
2
|
+
new (): {
|
|
3
|
+
tagVersion: number;
|
|
4
|
+
get(key: any, context?: {}): Promise<{
|
|
5
|
+
value: any;
|
|
6
|
+
lastModified: any;
|
|
7
|
+
} | null>;
|
|
8
|
+
set(key: any, value: any, context?: {}): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* The revalidateTag function allows invalidating cached data on-demand based
|
|
11
|
+
* on the specified tags. For our purposes, since we are currently doing a
|
|
12
|
+
* local in-memory, per-process lambda cache, we can just go ahead and clear
|
|
13
|
+
* the cache. Eventually we will want to support doing tag invalidation at the
|
|
14
|
+
* CDN layer.
|
|
15
|
+
*/
|
|
16
|
+
revalidateTag(tags: any, _durations?: {}): Promise<void>;
|
|
17
|
+
resetRequestCache(): void;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export function createNextjsCacheHandlerSource(): string;
|
|
21
|
+
declare const _default: {
|
|
22
|
+
new (): {
|
|
23
|
+
tagVersion: number;
|
|
24
|
+
get(key: any, context?: {}): Promise<{
|
|
25
|
+
value: any;
|
|
26
|
+
lastModified: any;
|
|
27
|
+
} | null>;
|
|
28
|
+
set(key: any, value: any, context?: {}): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* The revalidateTag function allows invalidating cached data on-demand based
|
|
31
|
+
* on the specified tags. For our purposes, since we are currently doing a
|
|
32
|
+
* local in-memory, per-process lambda cache, we can just go ahead and clear
|
|
33
|
+
* the cache. Eventually we will want to support doing tag invalidation at the
|
|
34
|
+
* CDN layer.
|
|
35
|
+
*/
|
|
36
|
+
revalidateTag(tags: any, _durations?: {}): Promise<void>;
|
|
37
|
+
resetRequestCache(): void;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export default _default;
|