Skip to content

Commit

Permalink
fix(layer): make base dir configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Apr 11, 2024
1 parent 4171359 commit efd74cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/packLambdaFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ export const packLambdaFromPath = async (
id: string,
sourceFile: string,
handlerFunction = 'handler',
/**
* @default process.cwd()
*/
baseDir = process.cwd(),
/**
* @default ${baseDir}/dist/lambdas
*/
distDir: string = path.join(process.cwd(), 'dist', 'lambdas'),
): Promise<PackedLambda> => {
try {
await mkdir(path.join(process.cwd(), 'dist', 'lambdas'), {
await mkdir(distDir, {
recursive: true,
})
} catch {
// Directory exists
}
const zipFile = path.join(process.cwd(), 'dist', 'lambdas', `${id}.zip`)
const zipFile = path.join(distDir, `${id}.zip`)
const { handler, hash } = await packLambda({
sourceFile: path.join(baseDir, sourceFile),
zipFile,
Expand Down
20 changes: 16 additions & 4 deletions src/packLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ export type PackedLayer = { layerZipFile: string; hash: string }
export const packLayer = async ({
id,
dependencies,
baseDir,
distDir,
}: {
id: string
dependencies: string[]
/**
* @default process.cwd()
*/
baseDir?: string
/**
* @default ${baseDir}/dist/layers
*/
distDir?: string
}): Promise<PackedLayer> => {
const packageJsonFile = path.join(process.cwd(), 'package.json')
const packageLockJsonFile = path.join(process.cwd(), 'package-lock.json')
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(

Check warning on line 33 in src/packLayer.ts

View workflow job for this annotation

GitHub Actions / tests

Unsafe assignment of an `any` value
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')

try {
Expand Down Expand Up @@ -91,7 +103,7 @@ export const packLayer = async ({
})

const zipFileName = await new Promise<string>((resolve) => {
const zipFileName = path.join(process.cwd(), 'dist', 'layers', `${id}.zip`)
const zipFileName = path.join(base, 'dist', 'layers', `${id}.zip`)
zipfile.outputStream
.pipe(createWriteStream(zipFileName))
.on('close', () => {
Expand Down

0 comments on commit efd74cd

Please sign in to comment.