serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 161 forks source link

Opt in to use locally installed Azure Functions Core Tools, instead of node_modules/.bin tools. #667

Open BartInTheField opened 1 year ago

BartInTheField commented 1 year ago

This is a Feature Proposal

Description

Right now in the utils used for sls offline, node_modules/.bin of the serverless instance it self are used to spawn azure functions. As a user I would like to opt in to use self installed Azure Functions Core Tools, in practice this means just running func.

Why?

In the case of using a monorepo like NX or Lerna, node_modules are stored in the root of a project. The current implementation searches for azure functions tools in a path that does not exist in these monorepo's.

Also, when the user has worked previously with Azure Functions Core Tools or also uses Azure functions outside of serverless, it would be beneficial to used there own locally installed tools.

How?

I have written my own patch to support this behaviour. But it would be better to have some command line arguments to opt in to this behaviour without writing a patch.

--- a/node_modules/serverless-azure-functions/lib/shared/utils.js
+++ b/node_modules/serverless-azure-functions/lib/shared/utils.js
@@ -282,8 +282,7 @@ var Utils = /** @class */ (function () {
      */
     Utils.spawnLocal = function (options) {
         var serverless = options.serverless, command = options.command;
-        var localCommand = path_1.join(serverless.config.servicePath, "node_modules", ".bin", command);
-        return this.spawn(__assign({}, options, { command: localCommand, commandName: command }));
+        return this.spawn(__assign({}, options, { commandName: command }));
     };
     // public static spawn()
     Utils.spawn = function (options) {