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

Generate ESM functions for Netlify #6666

Merged
merged 7 commits into from
Sep 12, 2022

Conversation

eduardoboucas
Copy link
Contributor

Netlify currently transpiles serverless functions with ESM syntax down to CJS, which is causing problems such as #6462.

We've started to address that in netlify/zip-it-and-ship-it#1198, which emits ESM files for functions with a .mjs extension. Because this is technically a breaking change, we're rolling it out gradually, but we've created a configuration property that allows frameworks like SvelteKit to opt-in to this behaviour straight away. This is done with a per-function configuration file introduced in netlify/zip-it-and-ship-it#1030.

With that in place, this PR has the following changes:

  • The conditional logic that decided whether to create CJS or ESM functions was removed, and it now generates ESM only
  • The generated function files use the .mjs extension
  • There's an additional file generated for each function, containing the configuration property mentioned above

We're in the final stages of rolling out this functionality to all customers, but wanted to get the PR in front of you sooner rather than later to gather any feedback and improve the experience for SvelteKit users as soon as possible.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Sep 8, 2022

⚠️ No Changeset found

Latest commit: 4424940

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Thank you! THANK YOU!

The generated function files use the .mjs extension

Is it necessary to use the .mjs extension if a user has "type": "module" in their package.json? (which all SvelteKit users will have)

We're in the final stages of rolling out this functionality to all customers, but wanted to get the PR in front of you sooner rather than later to gather any feedback and improve the experience for SvelteKit users as soon as possible.

To clarify, would it be okay if we merge this PR and roll it out to our users now or do we need to wait for something on your side still?

packages/adapter-netlify/index.js Show resolved Hide resolved
packages/adapter-netlify/index.js Outdated Show resolved Hide resolved
packages/adapter-netlify/index.js Outdated Show resolved Hide resolved
packages/adapter-netlify/index.js Outdated Show resolved Hide resolved
eduardoboucas and others added 3 commits September 9, 2022 10:00
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@eduardoboucas
Copy link
Contributor Author

Is it necessary to use the .mjs extension if a user has "type": "module" in their package.json? (which all SvelteKit users will have)

For now, yes. We'll gradually roll out ESM support for .js files, but using .mjs allows you to opt-in to this behaviour straight away.

To clarify, would it be okay if we merge this PR and roll it out to our users now or do we need to wait for something on your side still?

We need to update our CLI with this change, which we'll do today. I'll keep this thread updated and let you know once it's good to merge.

@ascorbic
Copy link
Contributor

ascorbic commented Sep 9, 2022

Does this work properly if somebody has manually set their bundler to esbuild?

@eduardoboucas
Copy link
Contributor Author

Does this work properly if somebody has manually set their bundler to esbuild?

Yes, esbuild will respect these settings.

@eduardoboucas
Copy link
Contributor Author

We've released CLI v11.7.1 with support for these changes. I still want to do a couple of end-to-end tests, but I'm not sure I'll be able to do that today. It's on the top of my list for Monday, though!

@eduardoboucas
Copy link
Contributor Author

This is all good to go from our side. Let me know if there's anything else that I need to do to get this merged and released.

Thanks! 🙌🏻

@benmccann
Copy link
Member

Awesome!! Thank you so much!

@benmccann benmccann merged commit 40e5647 into sveltejs:master Sep 12, 2022
geoffrich added a commit that referenced this pull request Sep 12, 2022
@geoffrich geoffrich mentioned this pull request Sep 12, 2022
5 tasks
benmccann pushed a commit that referenced this pull request Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants