Eliminate the export default app convention
sam-goodwin opened this issue · comments
The convention to export default app
is flakey.
When trying to add snapshot tests, the process.mainModule!.filename
call breaks - it is too dependent on how the node process is executed.
punchcard/packages/punchcard/lib/compute/lambda/function.ts
Lines 205 to 298 in 7a46089
A punchcard app should ideally be no different than a CDK app.
Is there anything we can do in the CDK to aid?
I don't think it can help eliminate the export default app
, but it could certainly help identify the entry-point JS file. E.g. cdk deploy -a ./index.js
<- I need to find the path to this file. Is there an environment or context value I can use to discover this? Or, is there at least a way for me to determine if the app was run by the CDK CLI? This would at least allow punchcard to work in unit test environments.
The only other solution I can think of is something like Pulumi's closure serializer. I think it works from within the node environment by access the V8 compiler context. Although I need to dive deeper.
Hmm, I'm being dumb. If we just assume that if process.mainModule.filename
is null, then it wasn't run by the CDK CLI. This heuristic would at least unblock unit testing.
I think the best approach is to do closure serialization. It cleans up the API and better isolates runtime from infrastructure code. This should be a requirement of 1.0.