@bifravst/aws-cdk-lambda-helpers
Advanced tools
Comparing version 1.3.1 to 1.3.2
import { type PackedLambda } from './packLambda.js'; | ||
export declare const packLambdaFromPath: (id: string, sourceFile: string, handlerFunction?: string, baseDir?: string) => Promise<PackedLambda>; | ||
export declare const packLambdaFromPath: (id: string, sourceFile: string, handlerFunction?: string, baseDir?: string, distDir?: string) => Promise<PackedLambda>; |
import { mkdir } from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import { packLambda } from './packLambda.js'; | ||
export const packLambdaFromPath = async (id, sourceFile, handlerFunction = 'handler', baseDir = process.cwd()) => { | ||
export const packLambdaFromPath = async (id, sourceFile, handlerFunction = 'handler', | ||
/** | ||
* @default process.cwd() | ||
*/ | ||
baseDir = process.cwd(), | ||
/** | ||
* @default ${baseDir}/dist/lambdas | ||
*/ | ||
distDir = path.join(process.cwd(), 'dist', 'lambdas')) => { | ||
try { | ||
await mkdir(path.join(process.cwd(), 'dist', 'lambdas'), { | ||
await mkdir(distDir, { | ||
recursive: true, | ||
@@ -13,3 +21,3 @@ }); | ||
} | ||
const zipFile = path.join(process.cwd(), 'dist', 'lambdas', `${id}.zip`); | ||
const zipFile = path.join(distDir, `${id}.zip`); | ||
const { handler, hash } = await packLambda({ | ||
@@ -16,0 +24,0 @@ sourceFile: path.join(baseDir, sourceFile), |
@@ -5,5 +5,13 @@ export type PackedLayer = { | ||
}; | ||
export declare const packLayer: ({ id, dependencies, }: { | ||
export declare const packLayer: ({ id, dependencies, baseDir, distDir, }: { | ||
id: string; | ||
dependencies: string[]; | ||
/** | ||
* @default process.cwd() | ||
*/ | ||
baseDir?: string; | ||
/** | ||
* @default ${baseDir}/dist/layers | ||
*/ | ||
distDir?: string; | ||
}) => Promise<PackedLayer>; |
@@ -9,7 +9,9 @@ import { spawn } from 'child_process'; | ||
import { fileURLToPath } from 'node:url'; | ||
export const packLayer = async ({ id, dependencies, }) => { | ||
const packageJsonFile = path.join(process.cwd(), 'package.json'); | ||
const packageLockJsonFile = path.join(process.cwd(), 'package-lock.json'); | ||
export const packLayer = async ({ id, dependencies, baseDir, distDir, }) => { | ||
const base = baseDir ?? process.cwd(); | ||
const dist = distDir ?? path.join(base, 'dist', 'layers'); | ||
const packageJsonFile = path.join(base, 'package.json'); | ||
const packageLockJsonFile = path.join(base, 'package-lock.json'); | ||
const { dependencies: deps, devDependencies: devDeps } = JSON.parse(await readFile(packageJsonFile, 'utf-8')); | ||
const layerDir = path.join(process.cwd(), 'dist', 'layers', id); | ||
const layerDir = path.join(dist, id); | ||
const nodejsDir = path.join(layerDir, 'nodejs'); | ||
@@ -66,3 +68,3 @@ try { | ||
const zipFileName = await new Promise((resolve) => { | ||
const zipFileName = path.join(process.cwd(), 'dist', 'layers', `${id}.zip`); | ||
const zipFileName = path.join(base, 'dist', 'layers', `${id}.zip`); | ||
zipfile.outputStream | ||
@@ -69,0 +71,0 @@ .pipe(createWriteStream(zipFileName)) |
{ | ||
"name": "@bifravst/aws-cdk-lambda-helpers", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Helper functions which simplify working with TypeScript lambdas for AWS CDK.", | ||
@@ -5,0 +5,0 @@ "exports": { |
26298
523