Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add baseDir and resolve build options to serverless-trace #779

Merged
merged 7 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/libs/lambda-at-edge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"@aws-sdk/client-s3": "1.0.0-rc.3",
"@zeit/node-file-trace": "^0.6.5",
"@vercel/nft": "^0.9.3",
"cookie": "^0.4.1",
"execa": "^4.0.2",
"fs-extra": "^9.0.1",
Expand Down
33 changes: 25 additions & 8 deletions packages/libs/lambda-at-edge/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import nodeFileTrace, { NodeFileTraceReasons } from "@zeit/node-file-trace";
import { nodeFileTrace, NodeFileTraceReasons } from "@vercel/nft";
import execa from "execa";
import fse from "fs-extra";
import { join } from "path";
Expand All @@ -21,6 +21,7 @@ import readDirectoryFiles from "./lib/readDirectoryFiles";
import filterOutDirectories from "./lib/filterOutDirectories";
import { PrerenderManifest } from "next/dist/build";
import { Item } from "klaw";
import { Job } from "@vercel/nft/out/node-file-trace";

export const DEFAULT_LAMBDA_CODE_DIR = "default-lambda";
export const API_LAMBDA_CODE_DIR = "api-lambda";
Expand All @@ -38,6 +39,13 @@ type BuildOptions = {
enableHTTPCompression?: boolean;
handler?: string;
authentication?: { username: string; password: string } | undefined;
resolve?: (
id: string,
parent: string,
job: Job,
cjsResolve: boolean
) => string | string[];
baseDir?: string;
};

const defaultBuildOptions = {
Expand All @@ -50,7 +58,9 @@ const defaultBuildOptions = {
domainRedirects: {},
minifyHandlers: false,
enableHTTPCompression: true,
authentication: undefined
authentication: undefined,
resolve: undefined,
baseDir: process.cwd()
};

class Builder {
Expand Down Expand Up @@ -127,7 +137,8 @@ class Builder {
copyLambdaHandlerDependencies(
fileList: string[],
reasons: NodeFileTraceReasons,
handlerDirectory: string
handlerDirectory: string,
base: string
): Promise<void>[] {
return fileList
.filter((file) => {
Expand All @@ -146,7 +157,7 @@ class Builder {
);
})
.map((filePath: string) => {
const resolvedFilePath = path.resolve(filePath);
const resolvedFilePath = path.resolve(join(base, filePath));
const dst = normalizeNodeModules(
path.relative(this.serverlessDir, resolvedFilePath)
);
Expand Down Expand Up @@ -248,14 +259,17 @@ class Builder {
path.join(this.serverlessDir, pageFile)
);

const base = this.buildOptions.baseDir || process.cwd();
const { fileList, reasons } = await nodeFileTrace(ssrPages, {
base: process.cwd()
base,
resolve: this.buildOptions.resolve
});

copyTraces = this.copyLambdaHandlerDependencies(
fileList,
reasons,
DEFAULT_LAMBDA_CODE_DIR
DEFAULT_LAMBDA_CODE_DIR,
base
);
}

Expand Down Expand Up @@ -347,14 +361,17 @@ class Builder {
path.join(this.serverlessDir, pageFile)
);

const base = this.buildOptions.baseDir || process.cwd();
const { fileList, reasons } = await nodeFileTrace(apiPages, {
base: process.cwd()
base,
resolve: this.buildOptions.resolve
});

copyTraces = this.copyLambdaHandlerDependencies(
fileList,
reasons,
API_LAMBDA_CODE_DIR
API_LAMBDA_CODE_DIR,
base
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "serverless-trace-with-dynamic-import-typescript-fixture",
"version": "1.0.0",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "serverless-trace-with-dynamic-import-fixture",
"version": "1.0.0",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "serverless-trace-fixture",
"version": "1.0.0",
"dependencies": {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Serverless Trace", () => {
let fseRemoveSpy: jest.SpyInstance;

beforeEach(async () => {
outputDir = os.tmpdir();
outputDir = path.join(os.tmpdir(), `${Date.now()}`);

fseRemoveSpy = jest.spyOn(fse, "remove").mockImplementation(() => {
return;
Expand Down
12 changes: 6 additions & 6 deletions packages/libs/lambda-at-edge/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@
dependencies:
"@types/node" "*"

"@zeit/node-file-trace@^0.6.5":
version "0.6.5"
resolved "https://registry.yarnpkg.com/@zeit/node-file-trace/-/node-file-trace-0.6.5.tgz#ffd443e4648eb88591c53b1a871a47bff651b62e"
integrity sha512-PbxtiZBU+axKtR9dU2/iQgK9+aP/ip94SqI/FCMWppmFPGlxGKHf8UnJZskFuqLZeWWzL+L+8SeipsNHATO9nw==
"@vercel/nft@^0.9.3":
version "0.9.3"
resolved "https://registry.yarnpkg.com/@vercel/nft/-/nft-0.9.3.tgz#d27d6173a9036d37a497511d84273fcb03d6c483"
integrity sha512-hbRTSKzHt6fTzTKDjZR5fXNMIOAS3/Ffhw96RM4M5+ZnDkxb+OFr6lNIhFibLxxvp27aCh/r/RqPZqj2EBgrlg==
dependencies:
acorn "^7.1.1"
acorn-class-fields "^0.3.2"
Expand All @@ -779,7 +779,7 @@
acorn-numeric-separator "^0.3.0"
acorn-static-class-features "^0.2.1"
bindings "^1.4.0"
estree-walker "^0.6.0"
estree-walker "^0.6.1"
glob "^7.1.3"
graceful-fs "^4.1.15"
micromatch "^4.0.2"
Expand Down Expand Up @@ -1052,7 +1052,7 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=

estree-walker@^0.6.0, estree-walker@^0.6.1:
estree-walker@^0.6.1:
version "0.6.1"
resolved "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz#53049143f40c6eb918b23671d1fe3219f3a1b362"
integrity sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==
Expand Down
Loading