Skip to content
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

Support new Node.js Programming Model #3285

Closed
ejizba opened this issue Aug 15, 2022 · 1 comment · Fixed by #3456
Closed

Support new Node.js Programming Model #3285

ejizba opened this issue Aug 15, 2022 · 1 comment · Fixed by #3456
Assignees
Labels
Milestone

Comments

@ejizba
Copy link
Contributor

ejizba commented Aug 15, 2022

Related to Azure/azure-functions-nodejs-worker#480

We will basically want the same functionality as the new Python programming model work Phil is doing in #3235

Quick summary:

  1. There will be new templates for projects/functions. The biggest highlight is there will be no more "function.json" file
  2. Because there are no "function.json" files, a few features will have to change like listing functions in the UI
@MicroFish91 MicroFish91 added this to the 1.9.0 milestone Aug 25, 2022
@ejizba
Copy link
Contributor Author

ejizba commented Sep 10, 2022

A few updates. First this wiki has background and instructions for trying out the new model: https://aka.ms/AzFuncNodeV4

Now here is a tiny spec on how I see these features working:

Create project

Here are the key differences from old projects:

  • The @azure/functions package needs to be in the dependencies section of package.json (not devDependencies) and reference ^4.0.0-alpha.2 as the version
  • The "main" field needs to be set in package.json. There's a lot of options for this, but I propose dist/src/functions/*.js for TypeScript and src/functions/*.js for JavaScript. That will allow us to create a new file for each function which simplifies some of the tooling logic and IMO is a more realistic folder structure for an app than say putting everything in one file. Open to suggestions on this
  • @types/node should reference v18
  • In host.json the bundle should be "version": "[3.15.0, 4.0.0)"

Create function

I have a first draft of templates here based on this branch. The new templates are suffixed with "-4.x" in the id. Unlike Python, this is essentially the 4th version of our programming model - it just happens that the first 3 didn't have any major changes that would've affected tooling templates. Just like Python, I think this needs to be hard-coded into the extension for now because it may take us time to decide on an official new schema for these models.

The existing wizard should remain the exact same. However, the result will be different

  • The function name should be used to replace the %functionName% string in both the file name and file contents
  • The binding parameters (for example "connection" or "queueName") should replace the relevant string (%connection% or %queueName%) in the file contents
  • The file should be put in the src/functions folder. This assumes a project setup like above. I think this is fine for public preview, but we could try and parse the users "package.json" "main" field if we want this to be smarter

One last note, I added a "triggerType" property to the metadata for each template because you no longer have a function.json and you need to know the trigger type when getting the user prompted settings here.

cc @hossam-nasr @lilyjma

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

Successfully merging a pull request may close this issue.

3 participants