From de7f1ce1fbcd931ead28a0b1fb7dd32284607a0f Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Wed, 4 Nov 2020 09:42:01 +0100 Subject: [PATCH 1/2] fix(esbuild): use absolute path for esbuild entry --- src/function.ts | 2 +- tests/function.test.ts | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/function.ts b/src/function.ts index 4c25e4d..58727fb 100644 --- a/src/function.ts +++ b/src/function.ts @@ -42,7 +42,7 @@ export class NodejsFunction extends lambda.Function { es.buildSync({ ...buildOptions, external: union(exclude, buildOptions.external || []), - entryPoints: [entry], + entryPoints: [path.join(projectRoot, entry)], outdir: path.join(projectRoot, BUILD_FOLDER, path.dirname(entry)), platform: 'node', }); diff --git a/tests/function.test.ts b/tests/function.test.ts index ee1def2..a530795 100644 --- a/tests/function.test.ts +++ b/tests/function.test.ts @@ -7,9 +7,10 @@ import { Runtime, RuntimeFamily } from '@aws-cdk/aws-lambda'; import { Stack } from '@aws-cdk/core'; import { buildSync } from 'esbuild'; import mockfs from 'mock-fs'; -import path from 'path'; +import path, { join } from 'path'; import { NodejsFunction } from '../src'; +import { findProjectRoot } from '../src/utils'; describe('NodejsFunction tests', () => { @@ -50,10 +51,10 @@ describe('NodejsFunction tests', () => { it.each` handler | entry - ${null} | ${'index.ts'} - ${'source/index.handler'} | ${'source/index.ts'} - ${'main.func'} | ${'main.ts'} - ${'a/b/c.h'} | ${'a/b/c.ts'} + ${null} | ${join(findProjectRoot() ?? '', 'index.ts')} + ${'source/index.handler'} | ${join(findProjectRoot() ?? '', 'source/index.ts')} + ${'main.func'} | ${join(findProjectRoot() ?? '', 'main.ts')} + ${'a/b/c.h'} | ${join(findProjectRoot() ?? '', 'a/b/c.ts')} `('Should be valid entry with default rootDir', ({ handler, entry }) => { new NodejsFunction(new Stack(), 'lambda-function', { handler }); expect(buildSync).toHaveBeenCalledWith(expect.objectContaining({ entryPoints: [entry] })); From 75150237742cae00e350a88514a79c07d4ebfa16 Mon Sep 17 00:00:00 2001 From: Victor Korzunin Date: Thu, 5 Nov 2020 00:17:00 +0100 Subject: [PATCH 2/2] test: fix unit test --- tests/function.test.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/function.test.ts b/tests/function.test.ts index a530795..13ec852 100644 --- a/tests/function.test.ts +++ b/tests/function.test.ts @@ -10,7 +10,6 @@ import mockfs from 'mock-fs'; import path, { join } from 'path'; import { NodejsFunction } from '../src'; -import { findProjectRoot } from '../src/utils'; describe('NodejsFunction tests', () => { @@ -51,13 +50,13 @@ describe('NodejsFunction tests', () => { it.each` handler | entry - ${null} | ${join(findProjectRoot() ?? '', 'index.ts')} - ${'source/index.handler'} | ${join(findProjectRoot() ?? '', 'source/index.ts')} - ${'main.func'} | ${join(findProjectRoot() ?? '', 'main.ts')} - ${'a/b/c.h'} | ${join(findProjectRoot() ?? '', 'a/b/c.ts')} + ${null} | ${'index.ts'} + ${'source/index.handler'} | ${'source/index.ts'} + ${'main.func'} | ${'main.ts'} + ${'a/b/c.h'} | ${'a/b/c.ts'} `('Should be valid entry with default rootDir', ({ handler, entry }) => { new NodejsFunction(new Stack(), 'lambda-function', { handler }); - expect(buildSync).toHaveBeenCalledWith(expect.objectContaining({ entryPoints: [entry] })); + expect(buildSync).toHaveBeenCalledWith(expect.objectContaining({ entryPoints: [join(process.cwd(), entry)] })); }); it('Should be valid outdir with custom rootDir', () => {