Skip to content

Commit

Permalink
removed powertools
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Nov 17, 2023
1 parent 17223c7 commit 2f4c125
Show file tree
Hide file tree
Showing 19 changed files with 3,198 additions and 6,934 deletions.
5 changes: 0 additions & 5 deletions .changeset/few-pets-live.md

This file was deleted.

10 changes: 5 additions & 5 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
"start": "astro dev"
},
"dependencies": {
"@astrojs/starlight": "^0.11.0",
"astro": "^3.2.4",
"@astrojs/starlight": "^0.12.0",
"astro": "^3.5.5",
"sharp": "^0.32.6"
},
"devDependencies": {
"@astro-aws/adapter": "workspace:^",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"rimraf": "^5.0.5"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
}
}
12 changes: 6 additions & 6 deletions apps/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@
"dependencies": {
"@astro-aws/constructs": "workspace:^",
"@astro-aws/docs": "workspace:^",
"aws-cdk": "^2.100.0",
"aws-cdk-lib": "^2.100.0",
"aws-cdk": "^2.109.0",
"aws-cdk-lib": "^2.109.0",
"constructs": "^10.3.0",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"workspace-tools": "^0.35.2"
"workspace-tools": "^0.36.3"
},
"devDependencies": {
"@astro-aws/scripts": "workspace:^",
"@types/node": "^18.18.0",
"eslint-config-get-off-my-lawn": "^7.2.0"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
},
"cli": {
"clean": [
Expand Down
24 changes: 20 additions & 4 deletions apps/infra/src/bin/infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import { GitHubUsersStack } from "../lib/stacks/github-users-stack.js"

const app = new App()

const createStackName = (environment: string, stack: string, mode?: string) =>
["AstroAWS", environment, stack, mode].filter(Boolean).join("-")
const createStackName = (
environment: string,
stack: string,
runtime?: string,
mode?: string,
) => ["AstroAWS", environment, stack, runtime, mode].filter(Boolean).join("-")

Object.entries(ENVIRONMENT_PROPS).forEach(([environment, environmentProps]) => {
const monitoringStack = new MonitoringStack(
Expand All @@ -25,10 +29,22 @@ Object.entries(ENVIRONMENT_PROPS).forEach(([environment, environmentProps]) => {
environmentProps.websites.forEach((websiteProps) => {
let certificateStack: CertificateStack | undefined

if (environment === Environments.DEV) {
// eslint-disable-next-line no-param-reassign
delete websiteProps.hostedZoneName
// eslint-disable-next-line no-param-reassign
delete websiteProps.aliases
}

if (websiteProps.hostedZoneName && websiteProps.aliases) {
certificateStack = new CertificateStack(
app,
createStackName(environment, "Certificate", websiteProps.mode),
createStackName(
environment,
"Certificate",
"nodejs18",
websiteProps.mode,
),
{
...environmentProps,
aliases: websiteProps.aliases,
Expand All @@ -39,7 +55,7 @@ Object.entries(ENVIRONMENT_PROPS).forEach(([environment, environmentProps]) => {

new WebsiteStack(
app,
createStackName(environment, "Website", websiteProps.mode),
createStackName(environment, "Website", "nodejs18", websiteProps.mode),
{
...environmentProps,
...websiteProps,
Expand Down
5 changes: 4 additions & 1 deletion apps/infra/src/lib/stacks/website-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PriceClass,
ResponseHeadersPolicy,
} from "aws-cdk-lib/aws-cloudfront"
import { Architecture, Tracing } from "aws-cdk-lib/aws-lambda"
import { Architecture, Runtime, Tracing } from "aws-cdk-lib/aws-lambda"
import type { Construct } from "constructs"
import { AstroAWS } from "@astro-aws/constructs"
import { LogQueryWidget } from "aws-cdk-lib/aws-cloudwatch"
Expand All @@ -32,6 +32,7 @@ type StaticWebsiteStackProps = {
aliases?: readonly [string, ...string[]]
mode: string
hostedZoneName?: string
runtime?: string
package: string
}

Expand All @@ -56,6 +57,7 @@ class WebsiteStack extends Stack {
environment,
hostedZone,
hostedZoneName,
runtime = "nodejs18",
} = props

const distDir = mode === "static" ? "dist" : `dist/${mode}`
Expand Down Expand Up @@ -117,6 +119,7 @@ class WebsiteStack extends Stack {
environment: {
DOMAIN: String(domainNames?.[0]),
},
runtime: new Runtime(`${runtime}.x`),
tracing: Tracing.ACTIVE,
},
s3Bucket: {
Expand Down
18 changes: 9 additions & 9 deletions examples/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@
},
"dependencies": {
"@astrojs/tailwind": "^5.0.2",
"@faker-js/faker": "^8.1.0",
"@middy/core": "^4.6.5",
"astro": "^3.2.4",
"daisyui": "^3.9.2",
"@faker-js/faker": "^8.3.1",
"@middy/core": "^5.0.1",
"astro": "^3.5.5",
"daisyui": "^4.1.1",
"http-status-codes": "^2.3.0",
"tailwindcss": "^3.3.3"
"tailwindcss": "^3.3.5"
},
"devDependencies": {
"@astro-aws/adapter": "workspace:^",
"@astrojs/check": "^0.2.0",
"eslint": "^8.51.0",
"@astrojs/check": "^0.3.1",
"eslint": "^8.53.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"prettier": "^3.1.0",
"rimraf": "^5.0.5",
"typescript": "^5.2.2"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
}
}
5 changes: 2 additions & 3 deletions examples/base/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// eslint-disable-next-line import/no-unresolved
import { defineMiddleware } from "astro:middleware"
import { logger } from "@astro-aws/adapter/powertools"
import { StatusCodes } from "http-status-codes"

export const onRequest = defineMiddleware(async ({ locals, url }, next) => {
logger.info("Running middleware for base")
console.log("Running middleware for base")

// eslint-disable-next-line no-param-reassign
locals.title = "Example"
Expand All @@ -20,7 +19,7 @@ export const onRequest = defineMiddleware(async ({ locals, url }, next) => {
import.meta.env.DOMAIN,
)

logger.info(`Redirecting to ${redirectUrl.toString()}`)
console.log(`Redirecting to ${redirectUrl.toString()}`)

return Response.redirect(redirectUrl, StatusCodes.PERMANENT_REDIRECT)
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"@lshay/eslint-config": "^0.2.5",
"@lshay/prettier-config": "^0.6.1",
"@rushstack/eslint-patch": "^1.5.1",
"eslint": "^8.51.0",
"eslint": "^8.53.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"prettier": "^3.0.3",
"turbo": "^1.10.15",
"eslint-plugin-import": "^2.29.0",
"prettier": "^3.1.0",
"turbo": "^1.10.16",
"typescript": "^5.2.2"
},
"engines": {
Expand Down
22 changes: 9 additions & 13 deletions packages/adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,29 @@
},
"dependencies": {
"@astrojs/webapi": "^2.2.0",
"@aws-lambda-powertools/commons": "^1.14.0",
"@aws-lambda-powertools/logger": "^1.14.0",
"@aws-lambda-powertools/metrics": "^1.14.0",
"@aws-lambda-powertools/tracer": "^1.14.0",
"@middy/core": "^4.6.5",
"esbuild": "^0.19.4",
"@middy/core": "^5.0.1",
"esbuild": "^0.19.5",
"http-status-codes": "^2.3.0",
"merge-anything": "^5.1.7",
"pino": "^8.16.0"
"pino": "^8.16.2"
},
"devDependencies": {
"@astro-aws/scripts": "workspace:^",
"@faker-js/faker": "^8.1.0",
"@types/aws-lambda": "^8.10.124",
"@faker-js/faker": "^8.3.1",
"@types/aws-lambda": "^8.10.126",
"@types/node": "^18.18.0",
"astro": "^3.2.4",
"astro": "^3.5.5",
"aws-lambda": "^1.0.7",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"eslint": "^8.53.0",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"peerDependencies": {
"astro": ">=1"
},
"engines": {
"node": "18.x"
"node": "18.x || 20.x"
},
"publishConfig": {
"access": "public"
Expand Down
26 changes: 3 additions & 23 deletions packages/adapter/src/args.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import { type ConstructorOptions as LoggerConstructorOptions } from "@aws-lambda-powertools/logger/lib/types"
import {
type MetricsOptions,
type ExtraOptions,
} from "@aws-lambda-powertools/metrics/lib/types"
import { type TracerOptions } from "@aws-lambda-powertools/tracer/lib/types"
import type { BuildOptions } from "esbuild"

import {
type WithLoggerOptions,
type WithTracerOptions,
} from "./lambda/middleware.js"
import { type WithLoggerOptions } from "./lambda/middleware.js"

type EsBuildOptions = Omit<
BuildOptions,
Expand All @@ -25,19 +16,8 @@ type Args = {
locals: object
/** Specifies where you want your app deployed to. */
mode: "edge" | "ssr-stream" | "ssr"
/** Configuration for powertools. */
powertools?: {
middleware?: {
logger?: WithLoggerOptions
metrics?: ExtraOptions
tracer?: WithTracerOptions
}
options?: {
logger?: LoggerConstructorOptions
metrics?: MetricsOptions
tracer?: TracerOptions
}
}
/** Settings for logging. */
logger?: WithLoggerOptions
}

export { type EsBuildOptions, type Args }
23 changes: 2 additions & 21 deletions packages/adapter/src/lambda/handlers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ import type {
CloudFrontResponseResult,
} from "aws-lambda"
import { type SSRManifest } from "astro"
import { Logger } from "@aws-lambda-powertools/logger"
import { Metrics } from "@aws-lambda-powertools/metrics"
import { Tracer } from "@aws-lambda-powertools/tracer"
import { polyfill } from "@astrojs/webapi"

import type { Args } from "../../args.js"
import { setLogger, setMetrics, setTracer } from "../../powertools.js"
import { createRequestBody, parseContentType } from "../helpers.js"
import {
DISALLOWED_EDGE_HEADERS,
KNOWN_BINARY_MEDIA_TYPES,
} from "../constants.js"
import { withLogger, withTracer } from "../middleware.js"
import { withLogger } from "../middleware.js"

polyfill(globalThis, {
exclude: "window document",
Expand Down Expand Up @@ -87,18 +83,6 @@ const createExports = (
...args.binaryMediaTypes,
])

if (args.powertools?.options?.logger) {
setLogger(new Logger(args.powertools.options.logger))
}

if (args.powertools?.options?.metrics) {
setMetrics(new Metrics(args.powertools.options.metrics))
}

if (args.powertools?.options?.tracer) {
setTracer(new Tracer(args.powertools.options.tracer))
}

const handleRequest = async (
request: Request,
matchNotFound: boolean,
Expand Down Expand Up @@ -179,10 +163,7 @@ const createExports = (
}

return {
handler: withLogger(
args.powertools?.middleware?.logger,
withTracer(args.powertools?.middleware?.tracer, handler),
),
handler: withLogger(args.logger, handler),
}
}

Expand Down
23 changes: 2 additions & 21 deletions packages/adapter/src/lambda/handlers/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ import type {
} from "aws-lambda"
import middy from "@middy/core"
import { type SSRManifest } from "astro"
import { Logger } from "@aws-lambda-powertools/logger"
import { Metrics } from "@aws-lambda-powertools/metrics"
import { Tracer } from "@aws-lambda-powertools/tracer"
import { polyfill } from "@astrojs/webapi"

import type { Args } from "../../args.js"
import { setLogger, setMetrics, setTracer } from "../../powertools.js"
import {
createReadableStream,
createRequestBody,
parseContentType,
} from "../helpers.js"
import { withLogger, withTracer } from "../middleware.js"
import { withLogger } from "../middleware.js"
import { KNOWN_BINARY_MEDIA_TYPES } from "../constants.js"
import { type CloudfrontResult } from "../types.js"

Expand Down Expand Up @@ -103,18 +99,6 @@ const createExports = (
...args.binaryMediaTypes,
])

if (args.powertools?.options?.logger) {
setLogger(new Logger(args.powertools.options.logger))
}

if (args.powertools?.options?.metrics) {
setMetrics(new Metrics(args.powertools.options.metrics))
}

if (args.powertools?.options?.tracer) {
setTracer(new Tracer(args.powertools.options.tracer))
}

const handler: APIGatewayProxyHandlerV2<CloudfrontResult> = async (
event: APIGatewayProxyEventV2,
) => {
Expand Down Expand Up @@ -185,10 +169,7 @@ const createExports = (

return {
handler: middy({ streamifyResponse: shouldStream }).handler(
withLogger(
args.powertools?.middleware?.logger,
withTracer(args.powertools?.middleware?.tracer, handler),
),
withLogger(args.logger, handler),
),
}
}
Expand Down
Loading

0 comments on commit 2f4c125

Please sign in to comment.