Skip to content

Commit

Permalink
Allow ESBuild rules to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshay committed Oct 28, 2022
1 parent 3c13f14 commit bc7b57a
Show file tree
Hide file tree
Showing 34 changed files with 242 additions and 397 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-knives-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astro-aws/adapter": patch
---

Allow override of certain ESBuild options
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ jobs:
- yarn test
- yarn constraints
- yarn changeset status --since=main
node_version:
- 14
- 16
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- uses: actions/setup-node@v3
with:
node-version: "16"
node-version: ${{ matrix.node_version }}
cache: "yarn"
- run: git fetch origin main:main
- run: yarn install --mode=skip-build && ${{ matrix.script }}
9 changes: 0 additions & 9 deletions apps/cli/src/cmds/build/index.ts

This file was deleted.

91 changes: 0 additions & 91 deletions apps/cli/src/cmds/build/package.ts

This file was deleted.

9 changes: 0 additions & 9 deletions apps/cli/src/utils/swc-util.ts

This file was deleted.

28 changes: 0 additions & 28 deletions apps/cli/src/utils/ts-util.ts

This file was deleted.

6 changes: 0 additions & 6 deletions apps/cli/tsconfig.json

This file was deleted.

13 changes: 0 additions & 13 deletions apps/infra/bin/infra.ts

This file was deleted.

8 changes: 4 additions & 4 deletions apps/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"dist"
],
"scripts": {
"build": "yarn clean && tsc -p tsconfig.build.json",
"clean": "rimraf dist cdk.out",
"build": "scripts build --skip-tsc",
"deploy": "cdk deploy --all --require-approval never",
"invalidate": "./scripts/invalidate-cloudfront-cache.sh",
"synth": "cdk synth"
},
"eslintConfig": {
Expand All @@ -34,13 +34,13 @@
"constructs": "^10.1.139",
"eslint": "^8.26.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"typescript": "^4.8.4"
},
"devDependencies": {
"@astro-aws/scripts": "workspace:^",
"eslint-config-get-off-my-lawn": "^7.1.0"
},
"engines": {
"node": ">=16.0.0"
"node": "14.x || 16.x"
}
}
13 changes: 13 additions & 0 deletions apps/infra/scripts/invalidate-cloudfront-cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

AWS_ACCOUNT="$(aws sts get-caller-identity --query Account --output text ${@})"
AWS_REGION="$(aws configure get region ${@})"

DISTIRBUTION_ID="$(aws cloudformation describe-stacks --stack-name "AstroAWSStack-${AWS_ACCOUNT}-${AWS_REGION}" --query "Stacks[0].Outputs[?OutputKey=='CloudFrontDistributionId'].OutputValue" --output text ${@})"
PATHS="$(jq -r ". | join(\" \")" ../www/dist/invalidationPaths.json)"

echo "Invalidating CloudFront distribution ${DISTIRBUTION_ID}: ${PATHS}"

aws cloudfront create-invalidation --distribution-id "${DISTIRBUTION_ID}" --paths ${PATHS} ${@}
20 changes: 20 additions & 0 deletions apps/infra/src/bin/infra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as process from "node:process";

import { App, Tags } from "aws-cdk-lib";

import { AstroAWSStack } from "../lib/stacks/astro-aws-stack.js";

const app = new App();

const env = {
account: process.env.AWS_ACCOUNT ?? String(process.env.CDK_DEFAULT_ACCOUNT),
region: process.env.AWS_REGION ?? String(process.env.CDK_DEFAULT_REGION),
};

const stack = new AstroAWSStack(app, `AstroAWSStack-${env.account}-${env.region}`, {
domainName: "astro-aws.lshay.dev",
env,
});

Tags.of(app).add("Project", "AstroAWS");
Tags.of(stack).add("Project", "AstroAWS");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as cdk from "aws-cdk-lib";
import type { StackProps } from "aws-cdk-lib";
import { CfnOutput, StackProps } from "aws-cdk-lib";
import { Duration } from "aws-cdk-lib";
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
import {
Expand All @@ -14,6 +14,7 @@ import { AstroAWSConstruct } from "@astro-aws/constructs";

export type AstroAWSProps = StackProps & {
domainName: string;
env: StackProps["env"];
};

export class AstroAWSStack extends cdk.Stack {
Expand All @@ -26,12 +27,12 @@ export class AstroAWSStack extends cdk.Stack {
domainName,
});

new AstroAWSConstruct(this, "AstroAWSConstruct", {
const astroAwsConstruct = new AstroAWSConstruct(this, "AstroAWSConstruct", {
distributionProps: {
certificate,
defaultBehavior: {
cachePolicy: new CachePolicy(this, "CachePolicy", {
cachePolicyName: "AstroAwsCachePolicy",
cachePolicyName: `${id}-CachePolicy`,
cookieBehavior: CacheCookieBehavior.all(),
defaultTtl: Duration.days(1),
enableAcceptEncodingBrotli: true,
Expand All @@ -50,5 +51,13 @@ export class AstroAWSStack extends cdk.Stack {
},
websitePath: "../www",
});

new CfnOutput(this, "CloudFrontDistributionId", {
value: astroAwsConstruct.distribution.distributionId,
});

new CfnOutput(this, "CloudFrontDomainName", {
value: astroAwsConstruct.distribution.distributionDomainName,
});
}
}
2 changes: 1 addition & 1 deletion apps/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
"prettier": "^2.7.1"
},
"engines": {
"node": ">=16.0.0"
"node": "14.x || 16.x"
}
}
Binary file added apps/www/public/images/astro-aws.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added apps/www/public/images/astro-aws.webp
Binary file not shown.
2 changes: 1 addition & 1 deletion constraints.pro
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gen_enforced_dependency(WorkspaceCwd, DependencyIdent, 'workspace:^', Dependency

% This rule will enforce that all packages must have an correct engines.node field
% Keep in sync with the range inside packages/yarnpkg-cli/sources/main.ts
gen_enforced_field(WorkspaceCwd, 'engines.node', '>=16.0.0').
gen_enforced_field(WorkspaceCwd, 'engines.node', '14.x || 16.x').

% Required to make the package work with the GitHub Package Registry
gen_enforced_field(WorkspaceCwd, 'repository.type', 'git').
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"license": "MIT",
"workspaces": [
"packages/*",
"apps/*"
"apps/*",
"scripts"
],
"scripts": {
"lint": "eslint .",
Expand Down Expand Up @@ -42,6 +43,6 @@
},
"packageManager": "[email protected]",
"engines": {
"node": ">=16.0.0"
"node": "14.x || 16.x"
}
}
9 changes: 5 additions & 4 deletions packages/astro-aws-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dist"
],
"scripts": {
"build": "aac build package"
"build": "scripts build"
},
"eslintConfig": {
"extends": [
Expand All @@ -43,10 +43,11 @@
"dependencies": {
"@astrojs/webapi": "^1.1.0",
"astro": "^1.5.2",
"esbuild": "^0.15.12"
"esbuild": "^0.15.12",
"merge-anything": "^5.0.4"
},
"devDependencies": {
"@astro-aws/cli": "workspace:^",
"@astro-aws/scripts": "workspace:^",
"@types/aws-lambda": "^8.10.108",
"@types/node": "^16.0.0",
"aws-lambda": "^1.0.7",
Expand All @@ -55,7 +56,7 @@
"typescript": "^4.8.4"
},
"engines": {
"node": ">=16.0.0"
"node": "14.x || 16.x"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 3 additions & 0 deletions packages/astro-aws-adapter/src/args.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { BuildOptions } from "esbuild";

export type Args = {
binaryMediaTypes?: string[];
esBuildOptions?: Omit<BuildOptions, "bundle" | "entryPoints" | "outdir" | "platform">;
};
1 change: 1 addition & 0 deletions packages/astro-aws-adapter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const astroAWSFunctions = (args: Args = {}): AstroIntegration => {
await bundleEntry(
fileURLToPath(new URL(astroConfig.build.serverEntry, astroConfig.build.server)),
fileURLToPath(astroConfig.build.server).replace("/server", "/lambda"),
args,
);
},
},
Expand Down
Loading

0 comments on commit bc7b57a

Please sign in to comment.