@payloadcms/figma 0.1.0-alpha.1 → 0.1.0-alpha.10
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 +17 -3
- package/dist/adapters/asset-collection.js +242 -0
- package/dist/{utils → adapters}/build-lambda-zip.d.ts +8 -7
- 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/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.d.ts +1 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput/getNextRelativeAppDir.js +15 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.d.ts +12 -0
- package/dist/adapters/deploy-output/inspectNextjsOutput.js +28 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.d.ts +9 -0
- package/dist/adapters/deploy-output/inspectNitroOutput.js +13 -0
- package/dist/adapters/deploy-output/isFile.d.ts +1 -0
- package/dist/adapters/deploy-output/isFile.js +4 -0
- package/dist/adapters/deploy-output/readJson.d.ts +1 -0
- package/dist/adapters/deploy-output/readJson.js +9 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.d.ts +8 -0
- package/dist/adapters/deploy-output/resolveNitroOutputLayout.js +16 -0
- package/dist/adapters/deploy-output/resolveOutputPath.d.ts +2 -0
- package/dist/adapters/deploy-output/resolveOutputPath.js +9 -0
- package/dist/adapters/deploy-output/resolveWithin.d.ts +1 -0
- package/dist/adapters/deploy-output/resolveWithin.js +12 -0
- 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/adapters/nitro.d.ts +8 -0
- package/dist/adapters/nitro.js +193 -0
- 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 +2 -2
- package/dist/adapters/vite.js +33 -0
- package/dist/api/check-project-subdomain-availability.d.ts +12 -0
- package/dist/api/check-project-subdomain-availability.js +32 -0
- package/dist/api/control-plane-error.d.ts +6 -0
- package/dist/api/control-plane-error.js +8 -0
- package/dist/api/control-plane-fetch.d.ts +7 -0
- package/dist/api/control-plane-fetch.js +37 -0
- package/dist/api/control-plane.d.ts +1 -9
- package/dist/api/control-plane.js +2 -48
- package/dist/api/create-project.d.ts +18 -0
- package/dist/api/create-project.js +37 -0
- package/dist/api/list-project-workspaces.d.ts +8 -0
- package/dist/api/list-project-workspaces.js +28 -0
- package/dist/api/project-resource-type.d.ts +1 -0
- package/dist/api/project-resource-type.js +1 -0
- package/dist/auth/headless-oauth-flow.d.ts +23 -0
- package/dist/auth/headless-oauth-flow.js +69 -0
- package/dist/auth/oauth-flow.d.ts +2 -0
- package/dist/auth/oauth-flow.js +13 -8
- package/dist/auth/token-store.d.ts +4 -1
- package/dist/auth/token-store.js +14 -0
- package/dist/auth/types.d.ts +12 -0
- package/dist/cli.d.ts +39 -0
- package/dist/cli.js +71 -36
- package/dist/commands/bootstrap.js +2 -1
- package/dist/commands/build-lambda-zip.js +1 -1
- package/dist/commands/deploy.d.ts +12 -0
- package/dist/commands/deploy.js +63 -25
- package/dist/commands/detect-project-resource-type.d.ts +3 -0
- package/dist/commands/detect-project-resource-type.js +28 -0
- package/dist/commands/init.d.ts +2 -2
- package/dist/commands/init.js +164 -79
- package/dist/commands/login.d.ts +11 -1
- package/dist/commands/login.js +66 -4
- package/dist/commands/prompt-to-create-project/format-project-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-project-subdomain.js +3 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/format-unavailable-subdomain-reason.js +7 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/get-default-project-name.js +13 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.d.ts +7 -0
- package/dist/commands/prompt-to-create-project/prompt-for-available-subdomain.js +32 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.d.ts +8 -0
- package/dist/commands/prompt-to-create-project/resolve-project-region.js +27 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-project-subdomain.js +54 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.d.ts +9 -0
- package/dist/commands/prompt-to-create-project/resolve-text-input.js +23 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.d.ts +12 -0
- package/dist/commands/prompt-to-create-project/resolve-workspace-plan-key.js +36 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.d.ts +1 -0
- package/dist/commands/prompt-to-create-project/validate-subdomain.js +9 -0
- package/dist/commands/prompt-to-create-project.d.ts +24 -0
- package/dist/commands/prompt-to-create-project.js +69 -0
- package/dist/commands/setup-agent.d.ts +12 -0
- package/dist/commands/setup-agent.js +123 -0
- package/dist/commands/write-project-configuration.d.ts +12 -0
- package/dist/commands/write-project-configuration.js +16 -0
- package/dist/db-content-api/generated/content-api-types.d.ts +6 -2
- package/dist/db-content-api/index.d.ts +1 -1
- package/dist/db-content-api/index.js +121 -72
- package/dist/db-content-api/utilities/data/index.js +2 -2
- package/dist/db-content-api/utilities/data/injectGlobalType.d.ts +6 -0
- package/dist/db-content-api/utilities/data/injectGlobalType.js +11 -0
- 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/isRecord.d.ts +9 -0
- package/dist/db-content-api/utilities/isRecord.js +19 -0
- package/dist/db-content-api/utilities/joins.js +5 -1
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.d.ts +10 -0
- package/dist/db-content-api/utilities/meta/resolvesToRelationshipValue.js +95 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.d.ts +9 -0
- package/dist/db-content-api/utilities/meta/stringifyIdsInWhere.js +112 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.d.ts +3 -0
- package/dist/db-content-api/utilities/schema/getDocumentSchema.js +24 -0
- package/dist/db-content-api/utilities/where.d.ts +2 -6
- package/dist/db-content-api/utilities/where.js +20 -9
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.js +2 -0
- package/dist/exports/views.d.ts +1 -0
- package/dist/exports/views.js +1 -0
- package/dist/imageSizeOptions.d.ts +23 -0
- package/dist/imageSizeOptions.js +26 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/write-agent-config.d.ts +12 -0
- package/dist/lib/write-agent-config.js +52 -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/oauth/endpoints/getLoginEndpoint.js +5 -2
- package/dist/oauth/index.js +8 -7
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +1 -1
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +5 -1
- package/dist/plugin/build-config.d.ts +4 -2
- package/dist/plugin/build-config.js +95 -31
- 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 +8 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +66 -0
- package/dist/plugin/cloud-limits/CloudLimitModal/index.scss +56 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/CloudLimitProvider/index.js +110 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.css +14 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.d.ts +4 -0
- package/dist/plugin/cloud-limits/LimitReachedView/index.js +52 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.d.ts +7 -0
- package/dist/plugin/cloud-limits/SlugRegistryContext/index.js +3 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.d.ts +1 -0
- package/dist/plugin/cloud-limits/SlugTracker/index.js +27 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.d.ts +2 -0
- package/dist/plugin/cloud-limits/icons/ExternalLinkIcon.js +30 -0
- package/dist/plugin/cloud-limits/routes.d.ts +2 -0
- package/dist/plugin/cloud-limits/routes.js +4 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.d.ts +9 -0
- package/dist/plugin/cloud-limits/server/redirectInitialAutosaveCreate.js +28 -0
- package/dist/plugin/cloud-limits/shared.d.ts +10 -0
- package/dist/plugin/cloud-limits/shared.js +52 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.d.ts +2 -0
- package/dist/plugin/cloud-limits/utilities/cloudLimitInterceptor.js +134 -0
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +4 -0
- package/dist/plugin/cloud-limits/utilities/toasts.js +19 -0
- 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/plugin/sandbox-upload-fetch.d.ts +32 -0
- package/dist/plugin/sandbox-upload-fetch.js +53 -0
- package/dist/skills/deploy-to-figma/SKILL.md +234 -0
- package/dist/skills/deploy-to-figma/references/cli-reference.md +146 -0
- package/dist/storage-content-api/client-uploads/generate.js +2 -1
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.d.ts +11 -0
- package/dist/storage-content-api/getDownloadResponseHeaderPolicy.js +27 -0
- package/dist/storage-content-api/index.js +1 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.d.ts +5 -0
- package/dist/storage-content-api/resolveDownloadResponseHeaders.js +13 -0
- package/dist/storage-content-api/staticHandler.js +2 -1
- package/dist/storage-content-api/types.d.ts +4 -1
- package/dist/translations/ar.d.ts +12 -0
- package/dist/translations/ar.js +12 -0
- package/dist/translations/az.d.ts +12 -0
- package/dist/translations/az.js +12 -0
- package/dist/translations/bg.d.ts +12 -0
- package/dist/translations/bg.js +12 -0
- package/dist/translations/bnBd.d.ts +12 -0
- package/dist/translations/bnBd.js +12 -0
- package/dist/translations/bnIn.d.ts +12 -0
- package/dist/translations/bnIn.js +12 -0
- package/dist/translations/ca.d.ts +12 -0
- package/dist/translations/ca.js +12 -0
- package/dist/translations/cs.d.ts +12 -0
- package/dist/translations/cs.js +12 -0
- package/dist/translations/da.d.ts +12 -0
- package/dist/translations/da.js +12 -0
- package/dist/translations/de.d.ts +12 -0
- package/dist/translations/de.js +12 -0
- package/dist/translations/en.d.ts +12 -0
- package/dist/translations/en.js +12 -0
- package/dist/translations/es.d.ts +12 -0
- package/dist/translations/es.js +12 -0
- package/dist/translations/et.d.ts +12 -0
- package/dist/translations/et.js +12 -0
- package/dist/translations/fa.d.ts +12 -0
- package/dist/translations/fa.js +12 -0
- package/dist/translations/fr.d.ts +12 -0
- package/dist/translations/fr.js +12 -0
- package/dist/translations/he.d.ts +12 -0
- package/dist/translations/he.js +12 -0
- package/dist/translations/hr.d.ts +12 -0
- package/dist/translations/hr.js +12 -0
- package/dist/translations/hu.d.ts +12 -0
- package/dist/translations/hu.js +12 -0
- package/dist/translations/hy.d.ts +12 -0
- package/dist/translations/hy.js +12 -0
- package/dist/translations/id.d.ts +12 -0
- package/dist/translations/id.js +12 -0
- package/dist/translations/index.d.ts +533 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/is.d.ts +12 -0
- package/dist/translations/is.js +12 -0
- package/dist/translations/it.d.ts +12 -0
- package/dist/translations/it.js +12 -0
- package/dist/translations/ja.d.ts +12 -0
- package/dist/translations/ja.js +12 -0
- package/dist/translations/ko.d.ts +12 -0
- package/dist/translations/ko.js +12 -0
- package/dist/translations/lt.d.ts +12 -0
- package/dist/translations/lt.js +12 -0
- package/dist/translations/lv.d.ts +12 -0
- package/dist/translations/lv.js +12 -0
- package/dist/translations/my.d.ts +12 -0
- package/dist/translations/my.js +12 -0
- package/dist/translations/nb.d.ts +12 -0
- package/dist/translations/nb.js +12 -0
- package/dist/translations/nl.d.ts +12 -0
- package/dist/translations/nl.js +12 -0
- package/dist/translations/pl.d.ts +12 -0
- package/dist/translations/pl.js +12 -0
- package/dist/translations/pt.d.ts +12 -0
- package/dist/translations/pt.js +12 -0
- package/dist/translations/ro.d.ts +12 -0
- package/dist/translations/ro.js +12 -0
- package/dist/translations/rs.d.ts +12 -0
- package/dist/translations/rs.js +12 -0
- package/dist/translations/rsLatin.d.ts +12 -0
- package/dist/translations/rsLatin.js +12 -0
- package/dist/translations/ru.d.ts +12 -0
- package/dist/translations/ru.js +12 -0
- package/dist/translations/sk.d.ts +12 -0
- package/dist/translations/sk.js +12 -0
- package/dist/translations/sl.d.ts +12 -0
- package/dist/translations/sl.js +12 -0
- package/dist/translations/sv.d.ts +12 -0
- package/dist/translations/sv.js +12 -0
- package/dist/translations/ta.d.ts +12 -0
- package/dist/translations/ta.js +12 -0
- package/dist/translations/th.d.ts +12 -0
- package/dist/translations/th.js +12 -0
- package/dist/translations/tr.d.ts +12 -0
- package/dist/translations/tr.js +12 -0
- package/dist/translations/uk.d.ts +12 -0
- package/dist/translations/uk.js +12 -0
- package/dist/translations/vi.d.ts +12 -0
- package/dist/translations/vi.js +12 -0
- package/dist/translations/zh.d.ts +12 -0
- package/dist/translations/zh.js +12 -0
- package/dist/translations/zhTw.d.ts +12 -0
- package/dist/translations/zhTw.js +12 -0
- package/dist/types.d.ts +11 -0
- package/dist/utils/assert-never.d.ts +1 -0
- package/dist/utils/assert-never.js +3 -0
- package/dist/utils/build-detection.d.ts +6 -1
- package/dist/utils/build-detection.js +68 -89
- package/dist/utils/deploy-adapter.d.ts +3 -35
- package/dist/utils/deploy-adapter.js +25 -14
- package/dist/utils/lambda-config.js +18 -23
- package/dist/utils/messages.js +24 -3
- 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-generate.d.ts +10 -0
- package/dist/utils/payload-generate.js +59 -0
- package/dist/utils/pnpm-builds.d.ts +14 -0
- package/dist/utils/pnpm-builds.js +125 -0
- package/dist/utils/s3-upload.js +4 -1
- package/package.json +31 -7
- package/dist/lib/download-skill.d.ts +0 -12
- package/dist/lib/download-skill.js +0 -77
- package/dist/utils/adapters/nextjs.d.ts +0 -8
- package/dist/utils/adapters/nextjs.js +0 -61
- package/dist/utils/adapters/nitro.d.ts +0 -8
- package/dist/utils/adapters/nitro.js +0 -172
- package/dist/utils/adapters/vite.js +0 -31
- package/dist/utils/asset-collection.js +0 -144
- package/dist/utils/build-lambda-zip.js +0 -90
- package/dist/utils/fs-utils.d.ts +0 -12
- package/dist/utils/fs-utils.js +0 -55
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): 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 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,15 @@ 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): Promise<SSGAssets>;
|
|
46
|
+
export declare function collectSSGAssets(projectPath: string, output?: string, logger?: AdapterLogger): Promise<SSGAssets>;
|
|
47
|
+
/**
|
|
48
|
+
* Collect file-based Next.js metadata icons that were prerendered as static route handlers.
|
|
49
|
+
*
|
|
50
|
+
* Maps public asset keys such as `shop/icon1.png` to their raw
|
|
51
|
+
* `.next/server/app/shop/icon1.png.body` output.
|
|
52
|
+
* Documentation: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons
|
|
53
|
+
*/
|
|
54
|
+
export declare function collectStaticMetadataAssets(projectPath: string, output?: string): Promise<StaticMetadataAssets>;
|
|
42
55
|
/**
|
|
43
56
|
* Create Lambda deployment zip
|
|
44
57
|
*
|
|
@@ -48,3 +61,4 @@ export declare function collectSSGAssets(projectPath: string): Promise<SSGAssets
|
|
|
48
61
|
* @throws Error if build missing or zip creation fails
|
|
49
62
|
*/
|
|
50
63
|
export declare function createLambdaZip(projectPath: string): Promise<void>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { buildLambdaZip } from './build-lambda-zip.js';
|
|
4
|
+
import { resolveOutputPath } from './deploy-output/resolveOutputPath.js';
|
|
5
|
+
// Maximum file size for static assets (S3 limitation)
|
|
6
|
+
const MAX_ASSET_SIZE = 50 * 1024 * 1024 // 50MB
|
|
7
|
+
;
|
|
8
|
+
/**
|
|
9
|
+
* Get file size in bytes
|
|
10
|
+
*
|
|
11
|
+
* @param filePath - Absolute path to file
|
|
12
|
+
* @returns File size in bytes
|
|
13
|
+
*/ export async function getFileSize(filePath) {
|
|
14
|
+
const stats = await fs.stat(filePath);
|
|
15
|
+
return stats.size;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Recursively collect files from a directory
|
|
19
|
+
*
|
|
20
|
+
* Excludes files larger than 50MB (S3 limitation).
|
|
21
|
+
* Warns user when files are excluded due to size.
|
|
22
|
+
*
|
|
23
|
+
* @param dir - Directory to scan
|
|
24
|
+
* @param baseDir - Base directory for relative paths
|
|
25
|
+
* @returns Array of relative file paths
|
|
26
|
+
*/ async function collectFiles(dir, baseDir, logger) {
|
|
27
|
+
const files = [];
|
|
28
|
+
try {
|
|
29
|
+
const entries = await fs.readdir(dir, {
|
|
30
|
+
withFileTypes: true
|
|
31
|
+
});
|
|
32
|
+
for (const entry of entries){
|
|
33
|
+
const fullPath = path.join(dir, entry.name);
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
// Recursively collect from subdirectories
|
|
36
|
+
const subFiles = await collectFiles(fullPath, baseDir, logger);
|
|
37
|
+
files.push(...subFiles);
|
|
38
|
+
} else if (entry.isFile()) {
|
|
39
|
+
// Check file size before adding
|
|
40
|
+
const stats = await fs.stat(fullPath);
|
|
41
|
+
if (stats.size <= MAX_ASSET_SIZE) {
|
|
42
|
+
// Add relative path from base directory
|
|
43
|
+
const relativePath = path.relative(baseDir, fullPath);
|
|
44
|
+
files.push(relativePath);
|
|
45
|
+
} else {
|
|
46
|
+
// Warn user about skipped files
|
|
47
|
+
const sizeMB = (stats.size / (1024 * 1024)).toFixed(2);
|
|
48
|
+
const relativePath = path.relative(baseDir, fullPath);
|
|
49
|
+
logger?.warning(`Skipping large asset: ${relativePath} (${sizeMB}MB exceeds 50MB limit)`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
// Directory doesn't exist or not accessible
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return files;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Collect all static asset paths from .next/static
|
|
61
|
+
*
|
|
62
|
+
* Returns paths relative to project root, formatted for S3:
|
|
63
|
+
* - `.next/static/chunks/main.js` → `_next/static/chunks/main.js`
|
|
64
|
+
*
|
|
65
|
+
* @param projectPath - Path to project root
|
|
66
|
+
* @returns Array of static asset paths (using _next prefix)
|
|
67
|
+
*/ export async function collectStaticAssets(projectPath, output, logger) {
|
|
68
|
+
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
69
|
+
const staticDir = path.join(outputPath, 'static');
|
|
70
|
+
const files = await collectFiles(staticDir, projectPath, logger);
|
|
71
|
+
return files.map((file)=>{
|
|
72
|
+
const relativeToStatic = path.relative(staticDir, path.resolve(projectPath, file));
|
|
73
|
+
return `_next/static/${relativeToStatic.split(path.sep).join('/')}`;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Collect SSG asset paths by parsing .next/prerender-manifest.json
|
|
78
|
+
*
|
|
79
|
+
* For each static page route without revalidation in the manifest's `routes` object, collects:
|
|
80
|
+
* - {route}.html (full HTML)
|
|
81
|
+
* - {route}.rsc (React Server Components payload)
|
|
82
|
+
* - {route}.meta (response headers JSON)
|
|
83
|
+
* - Nested `.segment.rsc` files under {route}.segments (segment-prefetch payloads)
|
|
84
|
+
*
|
|
85
|
+
* S3 keys use the route path without leading slash.
|
|
86
|
+
* Filesystem paths point to .next/server/app/{route}.{ext}
|
|
87
|
+
*
|
|
88
|
+
* @param projectPath - Path to project root
|
|
89
|
+
* @returns SSG asset keys and a pathMap for filesystem resolution
|
|
90
|
+
*/ export async function collectSSGAssets(projectPath, output, logger) {
|
|
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
|
+
}
|
|
111
|
+
const keys = [];
|
|
112
|
+
const pathMap = {};
|
|
113
|
+
const routeAssetMap = {};
|
|
114
|
+
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(/^\//, '');
|
|
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
|
+
];
|
|
150
|
+
for (const ext of extensions){
|
|
151
|
+
const s3Key = `${stripped}${ext}`;
|
|
152
|
+
keys.push(s3Key);
|
|
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));
|
|
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;
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
keys,
|
|
173
|
+
pathMap,
|
|
174
|
+
routeAssetMap
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Collect file-based Next.js metadata icons that were prerendered as static route handlers.
|
|
179
|
+
*
|
|
180
|
+
* Maps public asset keys such as `shop/icon1.png` to their raw
|
|
181
|
+
* `.next/server/app/shop/icon1.png.body` output.
|
|
182
|
+
* Documentation: https://nextjs.org/docs/app/api-reference/file-conventions/metadata/app-icons
|
|
183
|
+
*/ export async function collectStaticMetadataAssets(projectPath, output) {
|
|
184
|
+
const outputPath = resolveOutputPath(projectPath, 'nextjs', output);
|
|
185
|
+
const manifestPath = path.join(outputPath, 'prerender-manifest.json');
|
|
186
|
+
let manifest;
|
|
187
|
+
try {
|
|
188
|
+
const raw = await fs.readFile(manifestPath, 'utf-8');
|
|
189
|
+
manifest = JSON.parse(raw);
|
|
190
|
+
} catch {
|
|
191
|
+
return {
|
|
192
|
+
keys: [],
|
|
193
|
+
pathMap: {}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
if (!manifest.routes || typeof manifest.routes !== 'object') {
|
|
197
|
+
return {
|
|
198
|
+
keys: [],
|
|
199
|
+
pathMap: {}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const keys = [];
|
|
203
|
+
const pathMap = {};
|
|
204
|
+
for (const [routeKey, route] of Object.entries(manifest.routes)){
|
|
205
|
+
if (route.routeType !== 'route' || route.compute !== 'static' || route.response !== 'complete' || !isFileBasedMetadataIconRoute(routeKey)) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const assetKey = routeKey.replace(/^\/+/, '');
|
|
209
|
+
const bodyPath = path.join(outputPath, 'server', 'app', `${assetKey}.body`);
|
|
210
|
+
try {
|
|
211
|
+
const bodyStat = await fs.stat(bodyPath);
|
|
212
|
+
if (!bodyStat.isFile()) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
keys.push(assetKey);
|
|
219
|
+
pathMap[assetKey] = path.relative(projectPath, bodyPath);
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
keys,
|
|
223
|
+
pathMap
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create Lambda deployment zip
|
|
228
|
+
*
|
|
229
|
+
* Uses cross-platform Node.js implementation instead of shell script.
|
|
230
|
+
*
|
|
231
|
+
* @param projectPath - Path to project root
|
|
232
|
+
* @throws Error if build missing or zip creation fails
|
|
233
|
+
*/ export async function createLambdaZip(projectPath) {
|
|
234
|
+
await buildLambdaZip(projectPath);
|
|
235
|
+
}
|
|
236
|
+
function isFileBasedMetadataIconRoute(routeKey) {
|
|
237
|
+
const basename = path.posix.basename(routeKey);
|
|
238
|
+
if (routeKey === '/favicon.ico') {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return /^icon\d*(?:-[0-9a-z]{6})?\.(?:ico|jpe?g|png|svg)$/.test(basename) || /^apple-icon\d*(?:-[0-9a-z]{6})?\.(?:jpe?g|png)$/.test(basename);
|
|
242
|
+
}
|
|
@@ -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
|
|
@@ -11,15 +11,16 @@ export declare const LAMBDA_MAX_UNZIPPED_BYTES: number;
|
|
|
11
11
|
* Build Lambda deployment zip using pure Node.js
|
|
12
12
|
*
|
|
13
13
|
* Cross-platform replacement for build_for_lambda.sh:
|
|
14
|
-
* 1.
|
|
15
|
-
* 2.
|
|
16
|
-
* 3. Creates lambda.zip from .next/standalone/
|
|
14
|
+
* 1. Adds a generated run.sh directly to the archive
|
|
15
|
+
* 2. Creates lambda.zip from the standalone output
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* The output's static/ and the project's public/ directories are not copied into the zip. Those
|
|
18
|
+
* files are uploaded separately and served by Gatekeeper, not the Lambda function.
|
|
20
19
|
*
|
|
21
20
|
* @param projectPath - Path to project root
|
|
22
21
|
* @returns The built bundle: its unzipped byte size and the absolute zip path.
|
|
23
22
|
* @throws Error if standalone directory missing or zip creation fails
|
|
24
23
|
*/
|
|
25
|
-
export declare function buildLambdaZip(projectPath: 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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getNextRelativeAppDir(manifest: null | Record<string, unknown>): null | string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export function getNextRelativeAppDir(manifest) {
|
|
3
|
+
if (typeof manifest?.relativeAppDir === 'string') {
|
|
4
|
+
return manifest.relativeAppDir;
|
|
5
|
+
}
|
|
6
|
+
if (typeof manifest?.appDir !== 'string') {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const config = manifest.config;
|
|
10
|
+
if (config === null || typeof config !== 'object' || Array.isArray(config)) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const tracingRoot = config.outputFileTracingRoot;
|
|
14
|
+
return typeof tracingRoot === 'string' ? path.relative(tracingRoot, manifest.appDir) : null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface NextjsOutputLayout {
|
|
2
|
+
buildId: string;
|
|
3
|
+
outputPath: string;
|
|
4
|
+
serverEntryPath: string;
|
|
5
|
+
standalonePath: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Inspects a resolved Next.js output directory, typically `<project>/.next`.
|
|
9
|
+
* Returns its build ID and standalone paths, or null when required files are missing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function inspectNextjsOutput(outputPath: string): Promise<NextjsOutputLayout | null>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getNextRelativeAppDir } from './inspectNextjsOutput/getNextRelativeAppDir.js';
|
|
4
|
+
import { isFile } from './isFile.js';
|
|
5
|
+
import { readJson } from './readJson.js';
|
|
6
|
+
import { resolveWithin } from './resolveWithin.js';
|
|
7
|
+
/**
|
|
8
|
+
* Inspects a resolved Next.js output directory, typically `<project>/.next`.
|
|
9
|
+
* Returns its build ID and standalone paths, or null when required files are missing.
|
|
10
|
+
*/ export async function inspectNextjsOutput(outputPath) {
|
|
11
|
+
const buildId = await fs.readFile(path.join(outputPath, 'BUILD_ID'), 'utf8').then((value)=>value.trim()).catch(()=>null);
|
|
12
|
+
if (!buildId) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const standalonePath = path.join(outputPath, 'standalone');
|
|
16
|
+
const manifest = await readJson(path.join(outputPath, 'required-server-files.json'));
|
|
17
|
+
const relativeAppDir = getNextRelativeAppDir(manifest);
|
|
18
|
+
const serverEntryPath = relativeAppDir === null ? path.join(standalonePath, 'server.js') : resolveWithin(standalonePath, path.join(relativeAppDir, 'server.js'), 'relativeAppDir');
|
|
19
|
+
if (!await isFile(serverEntryPath)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
buildId,
|
|
24
|
+
outputPath,
|
|
25
|
+
serverEntryPath,
|
|
26
|
+
standalonePath
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { resolveNitroOutputLayout } from './resolveNitroOutputLayout.js';
|
|
2
|
+
type NitroOutputLayout = Awaited<ReturnType<typeof resolveNitroOutputLayout>>;
|
|
3
|
+
/**
|
|
4
|
+
* Inspects a resolved Nitro output directory, typically `<project>/.output`.
|
|
5
|
+
* Returns its server and public paths, or null when the server entry is missing. The build ID is
|
|
6
|
+
* Nitro's manifest date when available; legacy outputs without a manifest omit it.
|
|
7
|
+
*/
|
|
8
|
+
export declare function inspectNitroOutput(outputPath: string): Promise<NitroOutputLayout | null>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isFile } from './isFile.js';
|
|
2
|
+
import { resolveNitroOutputLayout } from './resolveNitroOutputLayout.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inspects a resolved Nitro output directory, typically `<project>/.output`.
|
|
5
|
+
* Returns its server and public paths, or null when the server entry is missing. The build ID is
|
|
6
|
+
* Nitro's manifest date when available; legacy outputs without a manifest omit it.
|
|
7
|
+
*/ export async function inspectNitroOutput(outputPath) {
|
|
8
|
+
const layout = await resolveNitroOutputLayout(outputPath);
|
|
9
|
+
if (!await isFile(layout.serverEntryPath)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return layout;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isFile(filePath: string): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readJson(filePath: string): Promise<null | Record<string, unknown>>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
export async function readJson(filePath) {
|
|
3
|
+
try {
|
|
4
|
+
const value = JSON.parse(await fs.readFile(filePath, 'utf8'));
|
|
5
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
6
|
+
} catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { readJson } from './readJson.js';
|
|
3
|
+
import { resolveWithin } from './resolveWithin.js';
|
|
4
|
+
const DEFAULT_PUBLIC_DIR = 'public';
|
|
5
|
+
const DEFAULT_SERVER_ENTRY = 'server/index.mjs';
|
|
6
|
+
export async function resolveNitroOutputLayout(outputPath) {
|
|
7
|
+
const manifest = await readJson(path.join(outputPath, 'nitro.json'));
|
|
8
|
+
const serverEntry = typeof manifest?.serverEntry === 'string' ? manifest.serverEntry : DEFAULT_SERVER_ENTRY;
|
|
9
|
+
const publicDir = typeof manifest?.publicDir === 'string' ? manifest.publicDir : DEFAULT_PUBLIC_DIR;
|
|
10
|
+
return {
|
|
11
|
+
buildId: typeof manifest?.date === 'string' ? manifest.date : undefined,
|
|
12
|
+
outputPath,
|
|
13
|
+
publicPath: resolveWithin(outputPath, publicDir, 'publicDir'),
|
|
14
|
+
serverEntryPath: resolveWithin(outputPath, serverEntry, 'serverEntry')
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
const DEFAULT_OUTPUT_DIRS = {
|
|
3
|
+
nextjs: '.next',
|
|
4
|
+
nitro: '.output',
|
|
5
|
+
vite: 'dist'
|
|
6
|
+
};
|
|
7
|
+
export function resolveOutputPath(projectPath, adapter, output) {
|
|
8
|
+
return output ? path.resolve(projectPath, output) : path.join(projectPath, DEFAULT_OUTPUT_DIRS[adapter]);
|
|
9
|
+
}
|