-
Notifications
You must be signed in to change notification settings - Fork 35
Detect functions with ES Modules #617
Comments
POC for possible module detection: #625 |
(Adding some loose thoughts here.) My main concern with this feature is the performance implications of doing an additional parse of each function just to determine whether it uses ESM or not. When using the legacy bundler, we're already parsing files with This feels particularly wasteful when processing functions generated dynamically by build plugins (e.g. Essential Next.js). Plugin authors (i.e. Netlify, in the case of Essential plugins) are in control of the format used in these functions, so it feels redundant to be detecting it by performing an expensive operation. If plugins want to generate JavaScript functions that use ESM, they can simply generate These functions are loaded from an internal functions directory (i.e. |
💯 on what @eduardoboucas is saying about the performance cost of parsing or lexing JavaScript for every build with functions. I am wondering if a solution based on string search might be good enough for 99% of cases (while still imperfect)? Something like:
This does feel rough and improper compared to using a lexer (even if implemented in WebAssembly). However, it might be much faster. Also, we want to switch to |
@eduardoboucas @ehmicky perf is the concern I had in mind when I introduced https://github.com/guybedford/es-module-lexer in my draft PR, since it runs inline wasm and claims to be highly performant at just doing its one task. If adding any checks is still a concern, though, I can shelf my POC work. |
Thanks for that additional context, @charliegroll. If that library brings considerable performance improvements over Let's not shelve your PoC! I think we should continue exploring our options here. This is a sensitive change because it touches the happy path of the vast majority of functions users, so we need to tread carefully (for example, we would want to put this behind a feature flag). It'd be good to get the PR in a mergeable state (I think some tests are failing at the moment) and then run some benchmarks to have a sense of the impact this change would have on projects of different sizes. |
Currently, functions with ES Modules are supported only when using esbuild. It would be great if zip-it-and-ship-it could detect when a function uses ES Modules and automatically use esbuild to bundle it, just like what happens with TypeScript.
The text was updated successfully, but these errors were encountered: