Skip to content

Work with Monorepo mode #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
daniloraisi opened this issue May 27, 2020 · 10 comments
Closed

Work with Monorepo mode #265

daniloraisi opened this issue May 27, 2020 · 10 comments

Comments

@daniloraisi
Copy link
Contributor

I'm submitting a...

[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

On Monorepo project, I can't create multiple functions based on my apps.

Expected behavior

Ability to use azure-http-func on Monorepo Mode projects to create multiple functions.

Minimal reproduction of the problem with instructions

  1. Create a new NestJS project using CLI nest new my-project

  2. Create a Monorepo adding new app with nest g app my-app

  3. Add azure-http-func to the first app: nest add @nestjs/azure-func-http --rootDir apps/my-project/src.
    3.1. Select my-project project to add library to.

    At this point everything works fine.

  4. Try add azure-http-func to the second app: nest add @nestjs/azure-func-http --rootDir apps/my-app/src.
    4.1. Select my-app project to add library to.

We are presented the following error:

❯ nest add @nestjs/azure-func-http --rootDir apps/my-app/src
✔ Package installation in progress... ☕
? Which project would you like to add the library to? my-app
Starting library setup...
ERROR! .funcignore already exists.
ERROR! host.json already exists.
ERROR! local.settings.json already exists.
ERROR! proxies.json already exists.
ERROR! main/function.json already exists.
ERROR! main/index.ts already exists.
ERROR! main/sample.dat already exists.
The Schematic workflow failed. See above.

Failed to execute command: "/home/danilo/Projects/my-project/node_modules/.bin/schematics" @nestjs/azure-func-http:nest-add --sourceRoot="apps/my-app/src" --rootDir apps/my-app/src

What is the motivation / use case for changing the behavior?

I want to create a Monorepo with multiple apps and split my API into separated Azure Functions.

Environment

Nest version: 7.2.0
 
For Tooling issues:
- Node version: v12.17.0
- Platform: Linux
@kamilmysliwiec
Copy link
Member

@Jefiozie have you encountered such an issue before?

@Jefiozie
Copy link
Contributor

hi @kamilmysliwiec, I've not seen this. I think the main reason that I've not seen this is that I've used the introduced --project flag when switching to the monorepo setup.

@daniloraisi I think you could setup our your project by using the following steps:

  1. Create a new NestJS project using CLI nest new my-project
  2. Create a Monorepo adding new app with nest g app my-app
  3. Add azure-http-func to the first app: nest add @nestjs/azure-func-http --project my-project
  4. Try add azure-http-func to the second app: nest add @nestjs/azure-func-http --project my-app
  5. Navigate to apps/my-app/src
  6. run npx func host start

Let us know if this worked out for you or if this is not working for your use case.

@pawelbart
Copy link

@Jefiozie Thanks for your solution. Locally its work well but what is the proper way to publish function?
I built app by nest built app and publish by func azure functionapp publish but App Service doesn't contain any function.

@Jefiozie
Copy link
Contributor

Hi @pawelbart, did you already seen the blog here they use a extension in vscode. I don't know the exact commands for publishing them with the func cmdline tool. Is this related to this issue or is it a other issue you are experiencing?

@daniloraisi
Copy link
Contributor Author

@Jefiozie it works, but there are some caveats:

  1. Function files are generated per app basis, but nest build will generate everything into dist folder. So, as @pawelbart pointed, we have problems publishing them.

  2. nest-cli.json is altered with webpack: true and webpackConfig:... on a project basis, but if I try a default build executing just nest build it uses NestJS default webpack.

  3. Script start:azure generated on package.json will not work, since all function files are available only on each app directory.

I know that probably this is kind an edge case, but it's interesting to talk about.

@pawelbart
Copy link

@Jefiozie Yes, I read the blog article and everything works for me for standard app (without monorepo structure).

VSCode extension Azure Functions under the hood calls the following sequence:
npm install, npm run build, npm prune --production, func azure functionapp publish <app-name>

For monorepo nest build generates path dist/apps/api/main.js. Because function.json has "scriptFile": "../../../../dist/apps/<app-name>/main/index.js" I run nest build <app-name>, which generates such path.

I noticed that during deployment there are uploaded only files from apps/<app-name>/src (excluding files from .funcignore) instead of the entire project. That's why dist/apps/<app-name>/main/index.js does't exist in wwwroot folder on Azure Storage account.

I'm looking for the best way to send the entire project to Azure. Maybe it is possible to set project root path in function.json or somewhere else?

I agree with @daniloraisi that this is an interesting topic. Thanks for your help.

@daniloraisi
Copy link
Contributor Author

@Jefiozie I forked the project and modified some behaviours so it can work as expected.

Can I do a Pull Request to integrate?

daniloraisi pushed a commit to daniloraisi/azure-func-http that referenced this issue May 28, 2020
@kamilmysliwiec
Copy link
Member

@daniloraisi PRs are more than welcome!

@daniloraisi daniloraisi mentioned this issue May 29, 2020
3 tasks
@daniloraisi
Copy link
Contributor Author

Some news @kamilmysliwiec?

@kamilmysliwiec
Copy link
Member

Just merged your PR and published as 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants