azure-functions-powershell-worker icon indicating copy to clipboard operation
azure-functions-powershell-worker copied to clipboard

Allow Module Entrypoints in Sub-Files

Open JustinGrote opened this issue 4 years ago • 2 comments

When using the module entrypoint e.g.:

  "scriptFile": "../PowerBot/PowerBot.psm1",
  "entryPoint": "messageHandler",

The function has to be defined in the psm1 file directly, it can't be defined in a sub-file which is the common module development pattern. I assume the parser doesn't actually evaluate the psm1, it just reads that file directly to determine if the functions exist.

Workarounds

Stub Function

Define a "stub" function in the .psm1, and replace it later when it actually gets loaded.

function messages ($Request, $TriggerMetadata) {}

#Dot source my function which will overwrite the stub at runtime. This works fine
. ./Public/messages.ps1

This is kind of an antipattern because you have to keep the parameters in sync between the stub and the actual function.

"Compiled" .psm1

Use a build script to compile a separated function into a .psm1. This is not desirable because you can't test against source using the azure functions core tools, you have to to build it every time.

Alternative Implementations

Allow a host.json setting to override the "function exists" check, since it's not material to the actual config (the config is defined in the function.json). This is not desirable because the safety checks are nice, but easier to implement.

JustinGrote avatar Feb 29 '20 23:02 JustinGrote

Agreed on this. We're bumping into the same thing.

KelvinTegelaar avatar Jun 07 '23 14:06 KelvinTegelaar

This is documented as working yet it is not. Should we then update the docs?

C0smin avatar Sep 04 '23 10:09 C0smin