diff --git a/.changeset/shaggy-ravens-bow.md b/.changeset/shaggy-ravens-bow.md new file mode 100644 index 0000000..b538ad3 --- /dev/null +++ b/.changeset/shaggy-ravens-bow.md @@ -0,0 +1,5 @@ +--- +"@astro-aws/adapter": patch +--- + +Set supported features diff --git a/.vscode/settings.json b/.vscode/settings.json index bdf71d2..5fc268a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,14 +1,12 @@ { "cSpell.words": ["astro"], - "eslint.nodePath": ".yarn/sdks", "files.associations": { "*.mdx": "markdown" }, - "prettier.prettierPath": ".yarn/sdks/prettier/index.js", "search.exclude": { "**/.yarn": true, "**/.pnp.*": true }, "typescript.enablePromptUseWorkspaceTsdk": true, - "typescript.tsdk": ".yarn/sdks/typescript/lib" + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/package.json b/package.json index 4a5bafe..796075c 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "turbo": "^1.10.14", "typescript": "^5.2.2" }, - "packageManager": "pnpm@8.7.6", "engines": { "node": "18.x" }, diff --git a/packages/adapter/src/__tests__/index.test.ts b/packages/adapter/src/__tests__/index.test.ts index 603f423..4f254a2 100644 --- a/packages/adapter/src/__tests__/index.test.ts +++ b/packages/adapter/src/__tests__/index.test.ts @@ -1,4 +1,5 @@ import { URL, fileURLToPath } from "node:url" +import { writeFile } from "node:fs/promises" import { afterEach, beforeEach, describe, expect, test, vi } from "vitest" import { faker } from "@faker-js/faker" @@ -9,6 +10,10 @@ import { ADAPTER_NAME } from "../constants.js" import { astroAWSFunctions, getAdapter } from "../index.js" import * as shared from "../shared.js" +vi.mock("node:fs/promises", () => ({ + writeFile: vi.fn(), +})) + describe("index.ts", () => { afterEach(() => { vi.clearAllMocks() @@ -16,7 +21,7 @@ describe("index.ts", () => { describe("getAdapter", () => { const args: Args = { - binaryMediaTypes: [faker.datatype.string()], + binaryMediaTypes: [faker.string.sample()], } describe("when there are arguments", () => { @@ -24,10 +29,24 @@ describe("index.ts", () => { const result = getAdapter(args) expect(result).toStrictEqual({ + adapterFeatures: { + edgeMiddleware: false, + functionPerRoute: false, + }, args, exports: ["handler"], name: ADAPTER_NAME, serverEntrypoint: `${ADAPTER_NAME}/lambda/index.js`, + supportedAstroFeatures: { + assets: { + isSharpCompatible: false, + isSquooshCompatible: false, + supportKind: "stable", + }, + hybridOutput: "stable", + serverOutput: "stable", + staticOutput: "unsupported", + }, }) }) }) @@ -37,10 +56,24 @@ describe("index.ts", () => { const result = getAdapter() expect(result).toStrictEqual({ + adapterFeatures: { + edgeMiddleware: false, + functionPerRoute: false, + }, args: {}, exports: ["handler"], name: ADAPTER_NAME, serverEntrypoint: `${ADAPTER_NAME}/lambda/index.js`, + supportedAstroFeatures: { + assets: { + isSharpCompatible: false, + isSquooshCompatible: false, + supportKind: "stable", + }, + hybridOutput: "stable", + serverOutput: "stable", + staticOutput: "unsupported", + }, }) }) }) @@ -48,7 +81,7 @@ describe("index.ts", () => { describe("astroAWSFunctions", () => { const args: Args = { - binaryMediaTypes: [faker.datatype.string()], + binaryMediaTypes: [faker.string.sample()], } describe("always", () => { @@ -92,13 +125,13 @@ describe("index.ts", () => { } as unknown as AstroConfig routes = [ { - route: faker.datatype.string(), + route: faker.string.sample(), } as unknown as RouteData, { - route: faker.datatype.string(), + route: faker.string.sample(), } as unknown as RouteData, { - route: faker.datatype.string(), + route: faker.string.sample(), } as unknown as RouteData, ] @@ -157,6 +190,13 @@ describe("index.ts", () => { routes, } as unknown as Parameters[0]) + expect(writeFile).toHaveBeenCalledTimes(1) + expect(writeFile).toHaveBeenCalledWith( + fileURLToPath(new URL("metadata.json", config.outDir)), + JSON.stringify({ + routes, + }), + ) expect(bundleEntry).toHaveBeenCalledTimes(1) expect(bundleEntry).toHaveBeenCalledWith( fileURLToPath( diff --git a/packages/adapter/src/index.ts b/packages/adapter/src/index.ts index b29f8dc..e8e9db5 100644 --- a/packages/adapter/src/index.ts +++ b/packages/adapter/src/index.ts @@ -1,4 +1,5 @@ import { fileURLToPath } from "node:url" +import { writeFile } from "node:fs/promises" import type { AstroAdapter, AstroConfig, AstroIntegration } from "astro" @@ -8,10 +9,24 @@ import { ADAPTER_NAME } from "./constants.js" import { warn } from "./log.js" const getAdapter = (args: Args = {}): AstroAdapter => ({ + adapterFeatures: { + edgeMiddleware: false, + functionPerRoute: false, + }, args, exports: ["handler"], name: ADAPTER_NAME, serverEntrypoint: `${ADAPTER_NAME}/lambda/index.js`, + supportedAstroFeatures: { + assets: { + isSharpCompatible: false, + isSquooshCompatible: false, + supportKind: "stable", + }, + hybridOutput: "stable", + serverOutput: "stable", + staticOutput: "unsupported", + }, }) const astroAWSFunctions = (args: Args = {}): AstroIntegration => { @@ -42,7 +57,12 @@ const astroAWSFunctions = (args: Args = {}): AstroIntegration => { ) } }, - "astro:build:done": async () => { + "astro:build:done": async (options) => { + await writeFile( + fileURLToPath(new URL("metadata.json", astroConfig.outDir)), + JSON.stringify(options), + ) + await bundleEntry( fileURLToPath( new URL(astroConfig.build.serverEntry, astroConfig.build.server), diff --git a/packages/adapter/src/lambda/__tests__/helpers.test.ts b/packages/adapter/src/lambda/__tests__/helpers.test.ts index cc04deb..b89effd 100644 --- a/packages/adapter/src/lambda/__tests__/helpers.test.ts +++ b/packages/adapter/src/lambda/__tests__/helpers.test.ts @@ -18,7 +18,7 @@ describe("helpers", () => { headers: Record beforeEach(async () => { - body = faker.datatype.string() + body = faker.string.sample() headers = { "content-type": "text/plain", } @@ -61,7 +61,7 @@ describe("helpers", () => { headers: Record beforeEach(async () => { - body = faker.datatype.string() + body = faker.string.sample() headers = { "content-type": "text/plain", }