Allow Edge handlers directories
ehmicky opened this issue · 2 comments
At the moment, Edge handlers must be single regular files ending with .js or .ts. Would it be a good idea to allow them to be also a directory with an index.js or index.ts main file?
This is an interesting idea, if we have this structure, would we want users to have separate package.json files for each handler with dependencies specific to it instead of having dependencies live in the main project's package.json?
On one hand, some users like to split their dependencies into several package.json in a monorepo-like setup.
On the other hand, this requires our platform to perform npm install on each package.json, which creates many problems:
npm installis slow. Running it several times instead of once makes it even slower.- Our platform will need to cache each
node_modulesindependently, which we currently don't. - Users will want to use Yarn. Or pnpm. Or specify CLI flags for those. And so on. We currently handle some of those features as part of the build-image main logic for npm/yarn. However this logic is currently only available for the Site main
package.json(or mainbasedirectory), not several subdirectories. Also, it is lacking many features and several users are rather unhappy about it. - Errors during
npm install(oryarn, etc.) are very common, and it is often hard for us to know whether the problem comes from the user, us or npm. Extending the logic to more subdirectories would expand that problem. - This is inconsistent with other parts of the platform (Netlify Functions)
Based on this, in Netlify Functions, we opted for: a single package.json for both the Site and the Netlify Functions. There is an optional core plugin that installs Functions dependencies but it is undocumented and not completely stable.
Note that adding support for multiple package.json per Edge handler would also add more work for the beta, and it is a decision harder to reverse (we won't be able to remove that feature) than the opposite (we can always add that feature in the future).
In my opinion, we should stick with a single package.json for the time being.