improving the dependencies for publishing - again, switching away from needing serverless.js

This commit is contained in:
Egor 2020-07-16 00:58:43 -07:00
parent 3c1b8816ef
commit 85c9df0a63
39 changed files with 177 additions and 234 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ node_modules
.vscode .vscode
dist dist
yarn-error.log yarn-error.log
*.tgz

View file

@ -1,13 +1,13 @@
.github .github
.vscode .vscode
lerna.json lerna.json
babel.config.js
tsconfig.json tsconfig.json
babel.config.js .babelrc.json
CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md
.prettierrc .prettierrc
.eslintrc.js .eslintrc.json
.yarnignore .yarnignore
*.tgz
src src
tsconfig.build.json tsconfig.build.json
examples examples

View file

@ -5,6 +5,7 @@ Effortless deployment for Next.js apps 🚀
## Table of Contents ## Table of Contents
- [Getting Started](#Getting-Started) - [Getting Started](#Getting-Started)
- [Features](#Features)
- [Background](#Background) - [Background](#Background)
- [CLI](#CLI) - [CLI](#CLI)
- [Environment](#Environment) - [Environment](#Environment)
@ -14,7 +15,8 @@ Effortless deployment for Next.js apps 🚀
- [Base Options](#Base-Options) - [Base Options](#Base-Options)
- [GitHub Options](#GitHub-Options) - [GitHub Options](#GitHub-Options)
- [AWS Options](#AWS-Options) - [AWS Options](#AWS-Options)
- [Advanced Configuration](#Advanced-Configuration) - [Advanced Usage](#Advanced-Usage)
- [Persisting Deployment State](#Persisting-State)
- [CI/CD](#CICD) - [CI/CD](#CICD)
## Getting Started ## Getting Started
@ -30,9 +32,13 @@ Optionally you can also add and run `next deploy` from your Next.js app:
- `yarn add --dev next-deploy` - `yarn add --dev next-deploy`
- `yarn next-deploy` - `yarn next-deploy`
## Features
TODO
## Background ## Background
Next Deploy was created to deploy web applications built using the wonderful [Next.js](https://nextjs.org/) framework. It allows teams to easily integrate with our supported engines (AWS, GitHub Pages) and keep the entirety of their code in source control; from frontend, to backend, to the deployment logic. Next Deploy was created to deploy web applications built using the wonderful [Next.js](https://nextjs.org/) framework. It allows teams to easily integrate with the supported engines (AWS, GitHub Pages) and keep the entirety of their code in source control. From frontend, to backend, to the deployment logic.
Next Deploy started as a fork of [serverless-next.js](https://github.com/serverless-nextjs/serverless-next.js) which itself is an orchestrator of various orphaned [serverless-components](https://github.com/serverless-components/). Next Deploy was created out of a need for a better, strongly typed codebase and an ability to provide more advanced functionality without the [influence of corporate backers](https://opencollective.com/goserverless#section-contributions). Next Deploy started as a fork of [serverless-next.js](https://github.com/serverless-nextjs/serverless-next.js) which itself is an orchestrator of various orphaned [serverless-components](https://github.com/serverless-components/). Next Deploy was created out of a need for a better, strongly typed codebase and an ability to provide more advanced functionality without the [influence of corporate backers](https://opencollective.com/goserverless#section-contributions).
@ -73,7 +79,8 @@ You will need the following permissions:
<details> <details>
<summary>Click to view</summary> <summary>Click to view</summary>
``` ```javascript
[
'acm:DescribeCertificate', // only for custom domains 'acm:DescribeCertificate', // only for custom domains
'acm:ListCertificates', // only for custom domains 'acm:ListCertificates', // only for custom domains
'acm:RequestCertificate', // only for custom domains 'acm:RequestCertificate', // only for custom domains
@ -115,7 +122,8 @@ You will need the following permissions:
's3:ListBucket', 's3:ListBucket',
's3:PutAccelerateConfiguration', 's3:PutAccelerateConfiguration',
's3:PutBucketPolicy', 's3:PutBucketPolicy',
's3:PutObject'; 's3:PutObject',
];
``` ```
</details> </details>
@ -212,12 +220,28 @@ All engines support the basic options:
| ------------------ | ------------------------------------------ | ------- | ----------------------------------------------------------------------- | | ------------------ | ------------------------------------------ | ------- | ----------------------------------------------------------------------- |
| _cloudfront event_ | `string\|{arn:string,includeBody:boolean}` | `null` | The customization for a new CloudFront event handler (lambda function). | | _cloudfront event_ | `string\|{arn:string,includeBody:boolean}` | `null` | The customization for a new CloudFront event handler (lambda function). |
### Advanced Configuration ## Advanced Usage
Environment variables may be substituted from `process.env` to allow for more flexibility. ### Persisting State
TODO TODO
### CI/CD ### CI/CD
Implement [CI/CD](#https://en.wikipedia.org/wiki/CI/CD) in your workflow with Next Deploy by substituting environment variables into your `next-deploy.config.js`.
As an example:
```javascript
module.exports = {
bucketName: process.env.MY_APP_BUCKET_NAME,
description: process.env.MY_APP_LAMBDA_DESCRIPTION,
name: {
requestLambda: process.env.MY_APP_REQUEST_LAMBDA_NAME,
},
domain: [process.env.MY_APP_SUBDOMAIN, process.env.MY_APP_DOMAIN],
debug: true,
};
```
TODO TODO

View file

@ -1,11 +1,5 @@
{ {
"version": "independent", "version": "independent",
"npmClient": "yarn", "npmClient": "yarn",
"command": {
"publish": {
"ignoreChanges": ["*.md"],
"message": "chore(release): publish"
}
},
"packages": ["packages/*"] "packages": ["packages/*"]
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "next-deploy", "name": "next-deploy",
"version": "0.2.0-alpha-1", "version": "0.2.0",
"description": "Effortless deployment for Next.js apps 🚀", "description": "Effortless deployment for Next.js apps 🚀",
"author": "Nidratech Ltd. <egor@nidratech.com>", "author": "Nidratech Ltd. <egor@nidratech.com>",
"keywords": [ "keywords": [
@ -17,8 +17,8 @@
"dev": "lerna run --parallel build:watch", "dev": "lerna run --parallel build:watch",
"build": "lerna run build", "build": "lerna run build",
"clean": "lerna run clean", "clean": "lerna run clean",
"setup": "yarn && lerna exec -- yarn", "prepack": "yarn build",
"prepack": "yarn build" "postinstall": "cd packages/aws-component && npx yarn && cd ../aws-domain && npx yarn && cd ../aws-lambda && npx yarn && cd ../aws-lambda-builder && npx yarn && cd ../cli && npx yarn"
}, },
"bin": { "bin": {
"next-deploy": "./packages/cli/dist/index.js" "next-deploy": "./packages/cli/dist/index.js"
@ -33,13 +33,6 @@
}, },
"homepage": "https://github.com/nidratech/next-deploy#readme", "homepage": "https://github.com/nidratech/next-deploy#readme",
"dependencies": { "dependencies": {
"@next-deploy/aws-cloudfront": "link:node_modules/next-deploy/packages/aws-cloudfront",
"@next-deploy/aws-component": "link:node_modules/next-deploy/packages/aws-component",
"@next-deploy/aws-domain": "link:node_modules/next-deploy/packages/aws-domain",
"@next-deploy/aws-lambda": "link:node_modules/next-deploy/packages/aws-lambda",
"@next-deploy/aws-lambda-builder": "link:node_modules/next-deploy/packages/aws-lambda-builder",
"@next-deploy/aws-s3": "link:node_modules/next-deploy/packages/aws-s3",
"@next-deploy/github": "link:node_modules/next-deploy/packages/github",
"@serverless/aws-iam-role": "^1.0.0", "@serverless/aws-iam-role": "^1.0.0",
"@serverless/aws-lambda-layer": "^1.0.0", "@serverless/aws-lambda-layer": "^1.0.0",
"@serverless/core": "^1.1.2", "@serverless/core": "^1.1.2",

View file

@ -1,16 +1,13 @@
{ {
"name": "@next-deploy/aws-cloudfront", "name": "@next-deploy/aws-cloudfront",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
"build:watch": "yarn compile -w", "build:watch": "yarn compile -w",
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -2,7 +2,3 @@
# yarn lockfile v1 # yarn lockfile v1
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,8 +1,8 @@
{ {
"name": "@next-deploy/aws-component", "name": "@next-deploy/aws-component",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
@ -10,12 +10,11 @@
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
}, },
"devDependencies": { "dependencies": {
"@next-deploy/aws-cloudfront": "link:../aws-cloudfront", "@next-deploy/aws-cloudfront": "link:../aws-cloudfront",
"@next-deploy/aws-domain": "link:../aws-domain", "@next-deploy/aws-domain": "link:../aws-domain",
"@next-deploy/aws-lambda": "link:../aws-lambda", "@next-deploy/aws-lambda": "link:../aws-lambda",
"@next-deploy/aws-lambda-builder": "link:../aws-lambda-builder", "@next-deploy/aws-lambda-builder": "link:../aws-lambda-builder",
"@next-deploy/aws-s3": "link:../aws-s3", "@next-deploy/aws-s3": "link:../aws-s3"
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -5,11 +5,15 @@ import { resolve, join } from 'path';
import Builder from '@next-deploy/aws-lambda-builder'; import Builder from '@next-deploy/aws-lambda-builder';
import AwsS3 from '@next-deploy/aws-s3'; import AwsS3 from '@next-deploy/aws-s3';
import AwsCloudFront from '@next-deploy/aws-cloudfront'; import AwsCloudFront from '@next-deploy/aws-cloudfront';
import AwsDomain from '@next-deploy/aws-domain';
import { SubDomain } from '@next-deploy/aws-domain/types';
import AwsLambda from '@next-deploy/aws-lambda';
import { AwsLambdaInputs } from '@next-deploy/aws-lambda/types';
import { OriginRequestHandlerManifest as BuildManifest } from '@next-deploy/aws-lambda-builder/types'; import { OriginRequestHandlerManifest as BuildManifest } from '@next-deploy/aws-lambda-builder/types';
import { PathPatternConfig } from '@next-deploy/aws-cloudfront/types'; import { PathPatternConfig } from '@next-deploy/aws-cloudfront/types';
import { Origin } from '@next-deploy/aws-cloudfront/types'; import { Origin } from '@next-deploy/aws-cloudfront/types';
import { getDomains } from './utils'; import { getDomains, load } from './utils';
import { DeploymentResult, AwsComponentInputs, LambdaType, LambdaInput } from '../types'; import { DeploymentResult, AwsComponentInputs, LambdaType } from '../types';
export const BUILD_DIR = '.next-deploy-build'; export const BUILD_DIR = '.next-deploy-build';
export const REQUEST_LAMBDA_CODE_DIR = `${BUILD_DIR}/request-lambda`; export const REQUEST_LAMBDA_CODE_DIR = `${BUILD_DIR}/request-lambda`;
@ -103,6 +107,8 @@ class AwsComponent extends Component {
} }
async build({ build, nextConfigDir }: AwsComponentInputs = {}): Promise<void> { async build({ build, nextConfigDir }: AwsComponentInputs = {}): Promise<void> {
this.context.status('Building');
const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd(); const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd();
const builder = new Builder(nextConfigPath, join(nextConfigPath, BUILD_DIR), { const builder = new Builder(nextConfigPath, join(nextConfigPath, BUILD_DIR), {
cmd: build?.cmd || 'node_modules/.bin/next', cmd: build?.cmd || 'node_modules/.bin/next',
@ -110,8 +116,6 @@ class AwsComponent extends Component {
args: build?.args || ['build'], args: build?.args || ['build'],
}); });
this.context.instance.metrics.status.message = 'Building';
await builder.build(this.context.instance.debugMode ? this.context.debug : undefined); await builder.build(this.context.instance.debugMode ? this.context.debug : undefined);
} }
@ -120,33 +124,33 @@ class AwsComponent extends Component {
nextStaticDir, nextStaticDir,
bucketRegion, bucketRegion,
bucketName, bucketName,
cloudfront, cloudfront: cloudfrontInput,
policy, policy,
publicDirectoryCache, publicDirectoryCache,
domain, domain,
domainType, domainType,
...inputs ...inputs
}: AwsComponentInputs = {}): Promise<DeploymentResult> { }: AwsComponentInputs = {}): Promise<DeploymentResult> {
this.context.instance.metrics.status.message = 'Deploying'; this.context.status('Deploying');
const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd(); const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd();
const nextStaticPath = nextStaticDir ? resolve(nextStaticDir) : nextConfigPath; const nextStaticPath = nextStaticDir ? resolve(nextStaticDir) : nextConfigPath;
const customCloudFrontConfig: Record<string, any> = cloudfront || {}; const customCloudFrontConfig: Record<string, any> = cloudfrontInput || {};
const calculatedBucketRegion = bucketRegion || 'us-east-1'; const calculatedBucketRegion = bucketRegion || 'us-east-1';
const [defaultBuildManifest] = await Promise.all([ const [defaultBuildManifest] = await Promise.all([
this.readRequestLambdaBuildManifest(nextConfigPath), this.readRequestLambdaBuildManifest(nextConfigPath),
]); ]);
const [bucket, cloudFront, requestEdgeLambda] = await Promise.all([ const [bucket, cloudfront, requestEdgeLambda] = await Promise.all([
this.load('@next-deploy/aws-s3'), load<AwsS3>('@next-deploy/aws-s3', this),
this.load('@next-deploy/aws-cloudfront'), load<AwsCloudFront>('@next-deploy/aws-cloudfront', this),
this.load('@next-deploy/aws-lambda', 'requestEdgeLambda'), load<AwsLambda>('@next-deploy/aws-lambda', this, 'requestEdgeLambda'),
]); ]);
const bucketOutputs = await bucket({ const bucketOutputs = await bucket.default({
accelerated: true, accelerated: true,
name: bucketName, name: bucketName,
region: calculatedBucketRegion, region: calculatedBucketRegion,
@ -180,10 +184,10 @@ class AwsComponent extends Component {
// parse origins from inputs // parse origins from inputs
let inputOrigins: any = []; let inputOrigins: any = [];
if (cloudfront?.origins) { if (cloudfrontInput?.origins) {
const origins = cloudfront.origins as string[]; const origins = cloudfrontInput.origins as string[];
inputOrigins = origins.map(expandRelativeUrls); inputOrigins = origins.map(expandRelativeUrls);
delete cloudfront.origins; delete cloudfrontInput.origins;
} }
const cloudFrontOrigins = [ const cloudFrontOrigins = [
@ -228,7 +232,7 @@ class AwsComponent extends Component {
return inputValue[lambdaType] || defaultValue; return inputValue[lambdaType] || defaultValue;
}; };
const defaultEdgeLambdaInput: LambdaInput = { const defaultEdgeLambdaInput: Partial<AwsLambdaInputs> = {
handler: 'index.handler', handler: 'index.handler',
code: join(nextConfigPath, REQUEST_LAMBDA_CODE_DIR), code: join(nextConfigPath, REQUEST_LAMBDA_CODE_DIR),
role: { role: {
@ -248,15 +252,15 @@ class AwsComponent extends Component {
) as string, ) as string,
}; };
const requestEdgeLambdaOutputs = await requestEdgeLambda(defaultEdgeLambdaInput); const requestEdgeLambdaOutputs = await requestEdgeLambda.default(defaultEdgeLambdaInput);
const requestEdgeLambdaPublishOutputs = await requestEdgeLambda.publishVersion(); const requestEdgeLambdaPublishOutputs = await requestEdgeLambda.publishVersion();
let defaultCloudfrontInputs = {} as PathPatternConfig; let defaultCloudfrontInputs = {} as PathPatternConfig;
if (cloudfront && cloudfront.defaults) { if (cloudfrontInput && cloudfrontInput.defaults) {
defaultCloudfrontInputs = cloudfront.defaults; defaultCloudfrontInputs = cloudfrontInput.defaults;
delete cloudfront.defaults; delete cloudfrontInput.defaults;
} }
// validate that the custom config paths match generated paths in the manifest // validate that the custom config paths match generated paths in the manifest
@ -269,12 +273,7 @@ class AwsComponent extends Component {
...(config['lambda@edge'] || {}), ...(config['lambda@edge'] || {}),
}; };
// here we are removing configs that cannot be overridden if (!['static/*', '_next/*'].includes(path)) {
if (path === 'api/*') {
// for "api/*" we need to make sure we aren't overriding the predefined lambda handler
// delete is idempotent so it's safe
delete edgeConfig['origin-request'];
} else if (!['static/*', '_next/*'].includes(path)) {
// for everything but static/* and _next/* we want to ensure that they are pointing at our lambda // for everything but static/* and _next/* we want to ensure that they are pointing at our lambda
edgeConfig[ edgeConfig[
'origin-request' 'origin-request'
@ -312,7 +311,7 @@ class AwsComponent extends Component {
const defaultLambdaAtEdgeConfig = { const defaultLambdaAtEdgeConfig = {
...(defaultCloudfrontInputs['lambda@edge'] || {}), ...(defaultCloudfrontInputs['lambda@edge'] || {}),
}; };
const cloudFrontOutputs = await cloudFront({ const cloudFrontOutputs = await cloudfront.default({
defaults: { defaults: {
ttl: 0, ttl: 0,
...defaultCloudfrontInputs, ...defaultCloudfrontInputs,
@ -341,12 +340,12 @@ class AwsComponent extends Component {
const { domain: calculatedDomain, subdomain } = getDomains(domain); const { domain: calculatedDomain, subdomain } = getDomains(domain);
if (calculatedDomain && subdomain) { if (calculatedDomain && subdomain) {
const domainComponent = await this.load('@next-deploy/aws-domain'); const domainComponent = await load<AwsDomain>('@next-deploy/aws-domain', this);
const domainOutputs = await domainComponent({ const domainOutputs = await domainComponent.default({
privateZone: false, privateZone: false,
domain: calculatedDomain, domain: calculatedDomain,
subdomains: { subdomains: {
[subdomain]: cloudFrontOutputs, [subdomain]: cloudFrontOutputs as SubDomain,
}, },
domainType: domainType || 'both', domainType: domainType || 'both',
defaultCloudfrontInputs, defaultCloudfrontInputs,
@ -362,9 +361,9 @@ class AwsComponent extends Component {
async remove(): Promise<void> { async remove(): Promise<void> {
const [bucket, cloudfront, domain] = await Promise.all([ const [bucket, cloudfront, domain] = await Promise.all([
this.load('@next-deploy/aws-s3'), load<AwsS3>('@next-deploy/aws-s3', this),
this.load('@next-deploy/aws-cloudfront'), load<AwsCloudFront>('@next-deploy/aws-cloudfront', this),
this.load('@next-deploy/aws-domain'), load<AwsDomain>('@next-deploy/aws-domain', this),
]); ]);
await Promise.all([bucket.remove(), cloudfront.remove(), domain.remove()]); await Promise.all([bucket.remove(), cloudfront.remove(), domain.remove()]);

View file

@ -14,3 +14,18 @@ export const getDomains = (
return { domain: undefined, subdomain: undefined }; return { domain: undefined, subdomain: undefined };
}; };
export const load = async <T>(path: string, that: any, name?: string): Promise<T> => {
const EngineComponent = await import(path);
const component = new EngineComponent.default(
`${that.id}.${name || EngineComponent.default.name}`,
that.context.instance
);
await component.init();
component.context.log = () => ({});
component.context.status = () => ({});
component.context.output = () => ({});
return component;
};

View file

@ -19,17 +19,6 @@ type AwsComponentInputs = BaseDeploymentOptions & {
type LambdaType = 'requestLambda' | 'responseLambda'; type LambdaType = 'requestLambda' | 'responseLambda';
type LambdaInput = {
description: string;
handler: string;
code: string;
role: Record<string, unknown>;
memory: number;
timeout: number;
runtime: string;
name?: string;
};
type DeploymentResult = { type DeploymentResult = {
appUrl: string; appUrl: string;
bucketName: string; bucketName: string;

View file

@ -21,8 +21,3 @@
"@next-deploy/aws-s3@link:../aws-s3": "@next-deploy/aws-s3@link:../aws-s3":
version "0.0.0" version "0.0.0"
uid "" uid ""
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,8 +1,8 @@
{ {
"name": "@next-deploy/aws-domain", "name": "@next-deploy/aws-domain",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
@ -10,8 +10,7 @@
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
}, },
"devDependencies": { "dependencies": {
"@next-deploy/aws-cloudfront": "link:../aws-cloudfront", "@next-deploy/aws-cloudfront": "link:../aws-cloudfront"
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -6,7 +6,7 @@ type AwsDomainInputs = {
privateZone?: boolean; privateZone?: boolean;
domainType?: DomainType; domainType?: DomainType;
defaultCloudfrontInputs?: PathPatternConfig; defaultCloudfrontInputs?: PathPatternConfig;
subdomains: SubDomain[]; subdomains: Record<string, SubDomain>;
}; };
type SubDomain = { type SubDomain = {

View file

@ -5,8 +5,3 @@
"@next-deploy/aws-cloudfront@link:../aws-cloudfront": "@next-deploy/aws-cloudfront@link:../aws-cloudfront":
version "0.0.0" version "0.0.0"
uid "" uid ""
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,6 +1,6 @@
{ {
"name": "@next-deploy/aws-lambda-builder", "name": "@next-deploy/aws-lambda-builder",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
@ -11,7 +11,6 @@
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
}, },
"devDependencies": { "devDependencies": {
"@next-deploy/aws-lambda-builder": "link:../aws-lambda-builder", "@next-deploy/aws-lambda-builder": "link:../aws-lambda-builder"
"typescript": "^3.9.6"
} }
} }

View file

@ -135,7 +135,7 @@ const handler = ({
} as CloudFrontResultResponse; } as CloudFrontResultResponse;
const newStream = new Stream.Readable(); const newStream = new Stream.Readable();
const req = { ...newStream, ...IncomingMessage.prototype } as IncomingMessage; const req = Object.assign(newStream, IncomingMessage.prototype);
req.url = request.uri; req.url = request.uri;
req.method = request.method; req.method = request.method;
req.rawHeaders = []; req.rawHeaders = [];
@ -158,6 +158,16 @@ const handler = ({
req.headers[lowercaseKey] = headerKeyValPairs[0].value; req.headers[lowercaseKey] = headerKeyValPairs[0].value;
} }
// @ts-ignore
req.getHeader = (name: string) => req.headers[name.toLowerCase()];
// @ts-ignore
req.getHeaders = () => req.headers;
if (request.body && request.body.data) {
req.push(request.body.data, request.body.encoding ? 'base64' : undefined);
}
req.push(null); req.push(null);
const res = new Stream() as PrivateServerResponse; const res = new Stream() as PrivateServerResponse;
@ -175,14 +185,12 @@ const handler = ({
res.headers = {}; res.headers = {};
//@ts-ignore //@ts-ignore
res.writeHead = (status: number, headers: OutgoingHttpHeaders) => { res.writeHead = (status, headers: OutgoingHttpHeaders) => {
response.status = status.toString(); response.status = status;
if (headers) { if (headers) {
res.headers = { ...res.headers, ...headers }; res.headers = Object.assign(res.headers, headers);
} }
return res;
}; };
res.write = (chunk: any) => { res.write = (chunk: any) => {
if (!response.body) { if (!response.body) {

View file

@ -17,12 +17,10 @@ import { OriginRequestEvent, OriginRequestHandlerManifest } from '../types';
const addS3HostHeader = (req: CloudFrontRequest, s3DomainName: string): void => { const addS3HostHeader = (req: CloudFrontRequest, s3DomainName: string): void => {
req.headers['host'] = [{ key: 'host', value: s3DomainName }]; req.headers['host'] = [{ key: 'host', value: s3DomainName }];
}; };
const isDataRequest = (uri: string): boolean => uri.startsWith('/_next/data'); const isDataRequest = (uri: string): boolean => uri.startsWith('/_next/data');
const isApiRequest = (uri: string): boolean => uri.startsWith('/api'); const isApiRequest = (uri: string): boolean => uri.startsWith('/api');
const normaliseUri = (uri: string): string => (uri === '/' ? '/index' : uri); const normalizeUri = (uri: string): string => (uri === '/' ? '/index' : uri);
const normalizeS3OriginDomain = (s3Origin: CloudFrontS3Origin): string => {
const normaliseS3OriginDomain = (s3Origin: CloudFrontS3Origin): string => {
if (s3Origin.region === 'us-east-1') { if (s3Origin.region === 'us-east-1') {
return s3Origin.domainName; return s3Origin.domainName;
} }
@ -45,14 +43,14 @@ const router = (manifest: OriginRequestHandlerManifest): ((uri: string) => strin
const allDynamicRoutes = { ...ssr.dynamic, ...html.dynamic, ...apis.dynamic }; const allDynamicRoutes = { ...ssr.dynamic, ...html.dynamic, ...apis.dynamic };
return (uri: string): string | null => { return (uri: string): string | null => {
let normalizedUri = uri; const normalizedUri = isDataRequest(uri)
? uri.replace(`/_next/data/${manifest.buildId}`, '').replace('.json', '')
if (isDataRequest(uri)) { : uri;
normalizedUri = uri.replace(`/_next/data/${manifest.buildId}`, '').replace('.json', '');
}
if (ssr.nonDynamic[normalizedUri]) { if (ssr.nonDynamic[normalizedUri]) {
return ssr.nonDynamic[normalizedUri]; return ssr.nonDynamic[normalizedUri];
} else if (apis.nonDynamic[normalizedUri]) {
return apis.nonDynamic[normalizedUri];
} }
for (const route in allDynamicRoutes) { for (const route in allDynamicRoutes) {
@ -68,10 +66,7 @@ const router = (manifest: OriginRequestHandlerManifest): ((uri: string) => strin
if (isApiRequest(uri)) { if (isApiRequest(uri)) {
return null; return null;
} } else if (html.nonDynamic['/404'] !== undefined) {
// only use the 404 page if the project exports it
if (html.nonDynamic['/404'] !== undefined) {
return 'pages/404.html'; return 'pages/404.html';
} }
@ -83,7 +78,7 @@ export const handler = async (
event: OriginRequestEvent event: OriginRequestEvent
): Promise<CloudFrontResultResponse | CloudFrontRequest> => { ): Promise<CloudFrontResultResponse | CloudFrontRequest> => {
const { request } = event.Records[0].cf; const { request } = event.Records[0].cf;
const uri = normaliseUri(request.uri); const uri = normalizeUri(request.uri);
const manifest: OriginRequestHandlerManifest = Manifest; const manifest: OriginRequestHandlerManifest = Manifest;
const prerenderManifest: PrerenderManifestType = PrerenderManifest; const prerenderManifest: PrerenderManifestType = PrerenderManifest;
const { pages, publicFiles } = manifest; const { pages, publicFiles } = manifest;
@ -93,7 +88,7 @@ export const handler = async (
const origin = request.origin as CloudFrontOrigin; const origin = request.origin as CloudFrontOrigin;
const s3Origin = origin.s3 as CloudFrontS3Origin; const s3Origin = origin.s3 as CloudFrontS3Origin;
const isHTMLPage = isStaticPage || isPrerenderedPage; const isHTMLPage = isStaticPage || isPrerenderedPage;
const normalizedS3DomainName = normaliseS3OriginDomain(s3Origin); const normalizedS3DomainName = normalizeS3OriginDomain(s3Origin);
s3Origin.domainName = normalizedS3DomainName; s3Origin.domainName = normalizedS3DomainName;

View file

@ -5,8 +5,3 @@
"@next-deploy/aws-lambda-builder@link:.": "@next-deploy/aws-lambda-builder@link:.":
version "0.0.0" version "0.0.0"
uid "" uid ""
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,8 +1,8 @@
{ {
"name": "@next-deploy/aws-lambda", "name": "@next-deploy/aws-lambda",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
@ -10,8 +10,7 @@
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
}, },
"devDependencies": { "dependencies": {
"@next-deploy/aws-s3": "link:../aws-s3", "@next-deploy/aws-s3": "link:../aws-s3"
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -50,7 +50,7 @@ const defaults: Partial<AwsLambdaInputs> = {
class LambdaComponent extends Component { class LambdaComponent extends Component {
async default(inputs: Partial<AwsLambdaInputs> = {}) { async default(inputs: Partial<AwsLambdaInputs> = {}) {
this.context.status(`Deploying`); this.context.status('Deploying');
const config = mergeDeepRight(defaults, inputs) as AwsLambdaInputs; const config = mergeDeepRight(defaults, inputs) as AwsLambdaInputs;

View file

@ -94,7 +94,7 @@ export const createLambda = async ({
Handler: handler, Handler: handler,
MemorySize: memory, MemorySize: memory,
Publish: true, Publish: true,
Role: role.arn, Role: role.arn as string,
Runtime: runtime, Runtime: runtime,
Timeout: timeout, Timeout: timeout,
Environment: { Environment: {

View file

@ -21,5 +21,9 @@ export type AwsLambdaInputs = {
}; };
type Resource = { type Resource = {
policy?: {
arn: string; arn: string;
}; };
service?: string[];
arn?: string;
};

View file

@ -5,8 +5,3 @@
"@next-deploy/aws-s3@link:../aws-s3": "@next-deploy/aws-s3@link:../aws-s3":
version "0.0.0" version "0.0.0"
uid "" uid ""
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,16 +1,13 @@
{ {
"name": "@next-deploy/aws-s3", "name": "@next-deploy/aws-s3",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
"build:watch": "yarn compile -w", "build:watch": "yarn compile -w",
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -7,6 +7,7 @@ type AwsS3Inputs = {
dir?: string; dir?: string;
key?: string; key?: string;
zip?: string; zip?: string;
accelerated?: boolean;
cacheControl?: S3.CacheControl; cacheControl?: S3.CacheControl;
keyPrefix?: string; keyPrefix?: string;
cors?: S3.CORSConfiguration; cors?: S3.CORSConfiguration;

View file

@ -2,7 +2,3 @@
# yarn lockfile v1 # yarn lockfile v1
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,6 +1,6 @@
{ {
"name": "@next-deploy/cli", "name": "@next-deploy/cli",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
@ -10,9 +10,8 @@
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
}, },
"devDependencies": { "dependencies": {
"@next-deploy/aws-component": "link:../aws-component", "@next-deploy/aws-component": "link:../aws-component",
"@next-deploy/github": "link:../github", "@next-deploy/github": "link:../github"
"typescript": "^3.9.6"
} }
} }

View file

@ -2,15 +2,30 @@
# yarn lockfile v1 # yarn lockfile v1
"@next-deploy/aws-cloudfront@link:../aws-cloudfront":
version "0.0.0"
uid ""
"@next-deploy/aws-component@link:../aws-component": "@next-deploy/aws-component@link:../aws-component":
version "0.0.0" version "0.0.0"
uid "" uid ""
"@next-deploy/aws-domain@link:../aws-domain":
version "0.0.0"
uid ""
"@next-deploy/aws-lambda-builder@link:../aws-lambda-builder":
version "0.0.0"
uid ""
"@next-deploy/aws-lambda@link:../aws-lambda":
version "0.0.0"
uid ""
"@next-deploy/aws-s3@link:../aws-s3":
version "0.0.0"
uid ""
"@next-deploy/github@link:../github": "@next-deploy/github@link:../github":
version "0.0.0" version "0.0.0"
uid "" uid ""
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1,16 +1,13 @@
{ {
"name": "@next-deploy/github", "name": "@next-deploy/github",
"version": "0.0.0", "version": "4.2.0",
"license": "MIT", "license": "MIT",
"main": "serverless.js", "main": "dist/component.js",
"types": "dist/component.d.ts", "types": "dist/component.d.ts",
"scripts": { "scripts": {
"build": "yarn clean && yarn compile", "build": "yarn clean && yarn compile",
"build:watch": "yarn compile -w", "build:watch": "yarn compile -w",
"clean": "rm -rf ./dist", "clean": "rm -rf ./dist",
"compile": "tsc -p tsconfig.build.json" "compile": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"typescript": "^3.9.6"
} }
} }

View file

@ -1 +0,0 @@
module.exports = require('./dist/component.js').default;

View file

@ -14,7 +14,7 @@ class GithubComponent extends Component {
} }
async build({ build, nextConfigDir, domain }: GithubInputs = {}): Promise<void> { async build({ build, nextConfigDir, domain }: GithubInputs = {}): Promise<void> {
this.context.instance.metrics.status.message = 'Building'; this.context.status('Building');
const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd(); const nextConfigPath = nextConfigDir ? resolve(nextConfigDir) : process.cwd();
@ -37,9 +37,9 @@ class GithubComponent extends Component {
} }
async deploy({ domain, publish: publishOptions }: GithubInputs = {}): Promise<DeploymentResult> { async deploy({ domain, publish: publishOptions }: GithubInputs = {}): Promise<DeploymentResult> {
this.context.instance.metrics.status.message = 'Deploying'; this.context.status('Deploying');
let outputs: DeploymentResult = {}; const outputs: DeploymentResult = {};
if (domain?.length) { if (domain?.length) {
const computedDomain = getComputedDomain(domain); const computedDomain = getComputedDomain(domain);

View file

@ -2,7 +2,3 @@
# yarn lockfile v1 # yarn lockfile v1
typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

View file

@ -1873,34 +1873,6 @@
call-me-maybe "^1.0.1" call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0" glob-to-regexp "^0.3.0"
"@next-deploy/aws-cloudfront@link:node_modules/next-deploy/packages/aws-cloudfront":
version "0.0.0"
uid ""
"@next-deploy/aws-component@link:node_modules/next-deploy/packages/aws-component":
version "0.0.0"
uid ""
"@next-deploy/aws-domain@link:node_modules/next-deploy/packages/aws-domain":
version "0.0.0"
uid ""
"@next-deploy/aws-lambda-builder@link:node_modules/next-deploy/packages/aws-lambda-builder":
version "0.0.0"
uid ""
"@next-deploy/aws-lambda@link:node_modules/next-deploy/packages/aws-lambda":
version "0.0.0"
uid ""
"@next-deploy/aws-s3@link:node_modules/next-deploy/packages/aws-s3":
version "0.0.0"
uid ""
"@next-deploy/github@link:node_modules/next-deploy/packages/github":
version "0.0.0"
uid ""
"@next/react-dev-overlay@9.4.4": "@next/react-dev-overlay@9.4.4":
version "9.4.4" version "9.4.4"
resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-9.4.4.tgz#4ae03ac839ff022b3ce5c695bd24b179d4ef459d" resolved "https://registry.yarnpkg.com/@next/react-dev-overlay/-/react-dev-overlay-9.4.4.tgz#4ae03ac839ff022b3ce5c695bd24b179d4ef459d"
@ -2051,9 +2023,9 @@
"@types/node" ">= 8" "@types/node" ">= 8"
"@octokit/types@^5.0.0", "@octokit/types@^5.0.1": "@octokit/types@^5.0.0", "@octokit/types@^5.0.1":
version "5.0.1" version "5.1.0"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-5.0.1.tgz#5459e9a5e9df8565dcc62c17a34491904d71971e" resolved "https://registry.yarnpkg.com/@octokit/types/-/types-5.1.0.tgz#4377a3f39edad3e60753fb5c3c310756f1ded57f"
integrity sha512-GorvORVwp244fGKEt3cgt/P+M0MGy4xEDbckw+K5ojEezxyMDgCaYPKVct+/eWQfZXOT7uq0xRpmrl/+hliabA== integrity sha512-OFxUBgrEllAbdEmWp/wNmKIu5EuumKHG4sgy56vjZ8lXPgMhF05c76hmulfOdFHHYRpPj49ygOZJ8wgVsPecuA==
dependencies: dependencies:
"@types/node" ">= 8" "@types/node" ">= 8"
@ -2994,22 +2966,7 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9" resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg== integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
aws-sdk@^2.387.0, aws-sdk@^2.488.0: aws-sdk@^2.387.0, aws-sdk@^2.488.0, aws-sdk@^2.714.0:
version "2.713.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.713.0.tgz#e87404ddcba093d36afafb48f119ec66f654a83f"
integrity sha512-axR1eOVn134KXJc1IT+Au2TXcK6oswY+4nvGe5GfU3pXeehhe0xNeP9Bw9yF36TRBxuvu4IJ2hRHDKma05smgA==
dependencies:
buffer "4.9.2"
events "1.1.1"
ieee754 "1.1.13"
jmespath "0.15.0"
querystring "0.2.0"
sax "1.2.1"
url "0.10.3"
uuid "3.3.2"
xml2js "0.4.19"
aws-sdk@^2.714.0:
version "2.714.0" version "2.714.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.714.0.tgz#b248ecd68f0f8061dc95b6919ff64cc7ae1e8c97" resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.714.0.tgz#b248ecd68f0f8061dc95b6919ff64cc7ae1e8c97"
integrity sha512-5wtzueYdq8nj/7TgW64kfVUJC2lXSMb+0Iv3F4tBqzdZMAjbva82qnGGkWRFmy1jqq9Zll0tJsR1tnskkuK67g== integrity sha512-5wtzueYdq8nj/7TgW64kfVUJC2lXSMb+0Iv3F4tBqzdZMAjbva82qnGGkWRFmy1jqq9Zll0tJsR1tnskkuK67g==
@ -3567,9 +3524,9 @@ chokidar@2.1.8, chokidar@^2.1.8:
fsevents "^1.2.7" fsevents "^1.2.7"
chokidar@^3.3.0, chokidar@^3.4.0: chokidar@^3.3.0, chokidar@^3.4.0:
version "3.4.0" version "3.4.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.0.tgz#b30611423ce376357c765b9b8f904b9fba3c0be8" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.4.1.tgz#e905bdecf10eaa0a0b1db0c664481cc4cbc22ba1"
integrity sha512-aXAaho2VJtisB/1fg1+3nlLJqGOuewTzQpd/Tz0yTg2R0e4IGtshYvtjowyEumcBv2z+y4+kc75Mz7j5xJskcQ== integrity sha512-TQTJyr2stihpC4Sya9hs2Xh+O2wf+igjL36Y75xx2WdHuiICcn/XJza46Jwt0eT5hVpQOzo3FpY3cj3RVYLX0g==
dependencies: dependencies:
anymatch "~3.1.1" anymatch "~3.1.1"
braces "~3.0.2" braces "~3.0.2"
@ -10224,9 +10181,9 @@ ts-pnp@^1.1.6:
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw== integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
ts-toolbelt@^6.3.3: ts-toolbelt@^6.3.3:
version "6.13.2" version "6.13.6"
resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-6.13.2.tgz#15bbbae972102c379681d133fd342cfdd49692db" resolved "https://registry.yarnpkg.com/ts-toolbelt/-/ts-toolbelt-6.13.6.tgz#4c9fad69bb3389323fe60982f18cd06b72f7d42a"
integrity sha512-8wnAjhOgsE80qOo3dC6jmIXeQzSlqV1J7AqQxIkY4J00ckyPvvmjXg/TkuDOMrRpV0roLtO76i/4leZbi++9/w== integrity sha512-qqIexrhqCNOuSRCrJMOKor8UJxA4DYMB6fNpBmRAKJgmLXNj8TAiuCrs7Nm08fva+MEdQhEXmsnjBQarNSIWZg==
tslib@^1.8.1, tslib@^1.9.0: tslib@^1.8.1, tslib@^1.9.0:
version "1.13.0" version "1.13.0"