From 7e358daed53cba07001f2ec9ed2281bea603f17c Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Thu, 5 Nov 2020 00:22:48 +0100 Subject: [PATCH] fix(esbuild): use absolute path for esbuild entry (#4) * fix(esbuild): use absolute path for esbuild entry * test: fix unit test Co-authored-by: Victor Korzunin --- src/function.ts | 2 +- tests/function.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/function.ts b/src/function.ts index 6c16b41..0201a8c 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..13ec852 100644 --- a/tests/function.test.ts +++ b/tests/function.test.ts @@ -7,7 +7,7 @@ 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'; @@ -56,7 +56,7 @@ describe('NodejsFunction tests', () => { ${'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', () => {