Azure / Azure/azure-functions-nodejs-library

How to support monorepo

Open
#260 22 comments 6 reactions 0 assignees View on GitHub
area:nodejs-functions Needs: Attention :wave:
Dominant language
TypeScript
Stars
70
Forks
35
Avg merge
4d 18h
Merged PRs (30d)
6

Description

_Originally posted by @mildronize in https://github.com/Azure/azure-functions-nodejs-library/issues/201#issuecomment-2110788561_

I've been stuck many kind of monorepo tools such as Nx, or pnpm workspace, or even npm/yarn workspace as well, bundling code with esbuild make the error when deploying into the Azure Functions on Azure.

Let's say for most cases of monorepo and bundling @ejizba, you just simple setup the basic monorepo calling the library across the project you will got the error without sending the issue, in the other hands, if it already support monorepo or bundling code, could you please give me some example how to make it possible?

In my experience, Azure Functions Node.js Runtime is hardest project to setup monorepo,

## Without bundling in the monrepo

Deploying Azure Functions without bundling in the monrepo, you need some extra script to move the packages in the node_modules when you deploy from the subdirectory of the monrepo, for example, you need some extra script to copy from node_modules from the root project into `azure-func-project-1` or `azure-func-project-2`, this structure come from Nx Integrated monorepo feature,

```
| node_modules
| apps
| - azure-func-project-1
| - azure-func-project-2
| libs
| - my-shared-libs
```

for most common monorepo pattern, they most use pnpm/npm/yarn workspaces, you need to prevent linked mode in the monorepo tool for workspace because modern monorepo tool mostly use the linked to safe space in the machine, I'm don't familiar with workspace configuration, i've tried many options but it's won't work. Another problem when `azure-func-project-1` want to call `my-shared-libs`, you need to bundling the lib and copy into the node_modules, and when your monorepo go large, it quite complex task to maintain build process.

or if you want deploy it from the root of the project you'll also need multiple `package.json` file that has `main` field which located in the entrypoint of each project in the same monorepo, For examples, you will need to handle the complexity of node_modules above method and setup `package.json` separately in the root of the monorepo

```
| node_modules
| apps
| - azure-func-project-1
| - azure-func-project-2
| libs
| - my-shared-libs
| - package.project-1.json
| - package.project-2.json
```

However, I've never do following my thought, my guess is quite challenge to setup monorepo without custom magic script.

## With Bundling
Another way using bundling like `esbuild`, I've already added the package suggested above `@azure/functions-core`, as the external dependency, however, deploying to Azure, it'still got the error, I don't have any error right now, or you can see in issue https://github.com/Azure/azure-functions-nodejs-library/issues/256#issue-2292563826

I've give up on monorepo or bunding Azure Function node.js runtime. so, if someone has error message please provide some error, it might be benefit.

I don't know the direction of the Azure Functions (Node.js Runtime), that's I've been stuck this issue so long, so, I've decided the moved out from the node.js runtime to custom handler instead, which is I've try to proof of concept in [Nammatham v3](https://github.com/thaitype/nammatham/wiki/V3-Roadmap)

## for now, in my design

I can build, bundling with monorepo and deploy successfully result below:

- [X] Use Azure Custom Handler
- [X] Support Node.js and Bun.js on [Hono](https://hono.dev/) Framework.
- [X] E2E Test for Node.js with Github Actions
- [X] Build on Linux and deploy to Azure
- [X] Build on Windows and deploy to Azure
- [X] Build on Mac only
- [X] E2E Test for Bun with Github Actions
- [X] Build on Linux and deploy to Azure
- [X] Build on Windows and deploy to Azure
- [X] Build on Mac only
- [X] Support bundle and monorepo code

Github Actions E2E Results
- https://github.com/thaitype/nammatham/actions/runs/9042196321

However, if the Azure Functions Node.js runtime has decided the too fix this issue, I hope it most benefit for community. and that's I don't have any reason to continue develop Nammatham v3

_Originally posted by @mildronize in https://github.com/Azure/azure-functions-nodejs-library/issues/201#issuecomment-2110788561_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.