{
  "version": 3,
  "sources": ["../../src/aws-lambda/esbuild-bundling.ts"],
  "sourcesContent": ["import path from \"node:path\";\n\nimport * as cdk from \"aws-cdk-lib\";\nimport { AssetCode, Code } from \"aws-cdk-lib/aws-lambda\";\nimport * as esbuild from \"esbuild\";\nimport { findUpSync } from \"find-up\";\n\nconst findDepsLockFilePath = (input: string) => {\n  const lockFilePath = findUpSync(\n    [\"package-lock.json\", \"yarn.lock\", \"pnpm-lock.yaml\"],\n    {\n      cwd: input,\n    },\n  );\n\n  if (!lockFilePath) {\n    throw new Error(\n      \"Couldn't find a lock file (package-lock.json or yarn.lock)\",\n    );\n  }\n\n  return lockFilePath;\n};\n\n// /**\n//  * Converts a Lambda runtime to an esbuild node target.\n//  */\n// function toTarget(runtime: Runtime): string {\n//   const match = runtime.name.match(/nodejs(\\d+)/)\n\n//   if (!match) throw new Error(\"Cannot extract version from runtime.\")\n\n//   return `node${match[1]}`\n// }\n\nexport interface EsbuildBundlingProps {\n  // input: string\n  // stdin: esbuild.StdinOptions\n  stdin: {\n    contents: string;\n    resolveDir: string;\n  };\n  // runtime: Runtime\n  external?: string[];\n  define?: {\n    [key: string]: string;\n  };\n}\n\nexport class EsbuildBundling {\n  public static bundle(options: EsbuildBundlingProps): AssetCode {\n    // const depsLockFilePath = findDepsLockFilePath(options.input)\n    const depsLockFilePath = findDepsLockFilePath(options.stdin.resolveDir);\n    // console.log({ depsLockFilePath })\n\n    return Code.fromAsset(path.dirname(depsLockFilePath), {\n      assetHashType: cdk.AssetHashType.OUTPUT,\n      bundling: new EsbuildBundling(options),\n    });\n  }\n\n  public readonly image: cdk.DockerImage;\n\n  public readonly local: cdk.ILocalBundling;\n\n  constructor(private readonly properties: EsbuildBundlingProps) {\n    this.image = cdk.DockerImage.fromRegistry(\"dummy\");\n    this.local = {\n      tryBundle(outputDirectory) {\n        // console.log({ outputDir: outputDirectory, input: properties.input })\n        esbuild.buildSync({\n          // entryPoints: [properties.input],\n          stdin: properties.stdin,\n          bundle: true,\n          platform: \"node\",\n          format: \"cjs\",\n          mainFields: [\"module\", \"main\"],\n          // target: toTarget(properties.runtime),\n          target: \"node18\",\n          outfile: `${outputDirectory}/index.js`,\n          external: [\n            \"aws-sdk\",\n            // \"@aws-sdk/*\",\n            // \"@smithy/*\",\n            ...(properties.external ?? []),\n          ],\n          define: properties.define,\n          // minify: true,\n        });\n        return true;\n      },\n    };\n  }\n}\n"],
  "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiB,0BAEjBC,EAAqB,4BACrBC,EAAgC,kCAChCC,EAAyB,wBACzBC,EAA2B,mBAE3B,MAAMC,EAAwBC,GAAkB,CAC9C,MAAMC,KAAe,cACnB,CAAC,oBAAqB,YAAa,gBAAgB,EACnD,CACE,IAAKD,CACP,CACF,EAEA,GAAI,CAACC,EACH,MAAM,IAAI,MACR,4DACF,EAGF,OAAOA,CACT,EA2BO,MAAMT,CAAgB,CAgB3B,YAA6BU,EAAkC,CAAlC,gBAAAA,EAC3B,KAAK,MAAQP,EAAI,YAAY,aAAa,OAAO,EACjD,KAAK,MAAQ,CACX,UAAUQ,EAAiB,CAEzB,OAAAN,EAAQ,UAAU,CAEhB,MAAOK,EAAW,MAClB,OAAQ,GACR,SAAU,OACV,OAAQ,MACR,WAAY,CAAC,SAAU,MAAM,EAE7B,OAAQ,SACR,QAAS,GAAGC,CAAe,YAC3B,SAAU,CACR,UAGA,GAAID,EAAW,UAAY,CAAC,CAC9B,EACA,OAAQA,EAAW,MAErB,CAAC,EACM,EACT,CACF,CACF,CA1CA,OAAc,OAAOE,EAA0C,CAE7D,MAAMC,EAAmBN,EAAqBK,EAAQ,MAAM,UAAU,EAGtE,OAAO,OAAK,UAAU,EAAAE,QAAK,QAAQD,CAAgB,EAAG,CACpD,cAAeV,EAAI,cAAc,OACjC,SAAU,IAAIH,EAAgBY,CAAO,CACvC,CAAC,CACH,CAkCF",
  "names": ["esbuild_bundling_exports", "__export", "EsbuildBundling", "__toCommonJS", "import_node_path", "cdk", "import_aws_lambda", "esbuild", "import_find_up", "findDepsLockFilePath", "input", "lockFilePath", "properties", "outputDirectory", "options", "depsLockFilePath", "path"]
}
