eta-dev / eta

Embedded JS template engine for Node, Deno, and the browser. Lighweight, fast, and pluggable. Written in TypeScript
https://eta.js.org
MIT License
1.41k stars 65 forks source link

fix: add support for Bun #250

Closed muan closed 1 year ago

muan commented 1 year ago

Ref: #181

Minimum test file:

// test.js
import { Eta } from 'eta'
const eta = new Eta({ views: 'views' })
console.log(eta.render('index'))
// views/index.eta
hello

When running with Node node test.js

hello

When running with Bun bun run test.js

2 |         var r = [null];
43 |         r.push.apply(r, e);
44 |         var a = new (Function.bind.apply(t, r));
45 |         return n && i(a, n.prototype), a;
46 | 
47 |       }, a.apply(null, arguments);
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ^
Eta Error: Failed to get template 'index'
      at a (/Users/muan/Code/testz/node_modules/eta/dist/browser.umd.js:1:1170)
      at n (/Users/muan/Code/testz/node_modules/eta/dist/browser.umd.js:1:1523)
      at new e (/Users/muan/Code/testz/node_modules/eta/dist/browser.umd.js:1:2051)
      at F (/Users/muan/Code/testz/node_modules/eta/dist/browser.umd.js:1:7263)
      at O (/Users/muan/Code/testz/node_modules/eta/dist/browser.umd.js:1:7464)
      at /Users/muan/Code/testz/test.js:3:12

Note the /dist/browser.umd.js. This is due to how bun resolves files. It's simply by the order of exports keys and it's only if exports does not exist does it fallback to module.

I can't seem to track down a relevant issue in Bun so this is the best I can come up with for now. 🤷🏻‍♀️ Tracked https://github.com/oven-sh/bun/issues/2357.

With this fix direct applied inside of node_modules/eta, the template file resolution is fixed.

nebrelbug commented 1 year ago

@muan wow, this is a fascinating issue! Thank you for contributing a fix.

Will you amend your last commit message or create a new commit message to align with the Commitizen spec? i.e., fix: remove bun as a key and reorder instead or feat: add Bun support. This is required for the build to pass.

I'll then be happy to merge this!

muan commented 1 year ago

I've squashed them and amended the commit message. 👍🏻 Thanks for the quick turnaround.

nebrelbug commented 1 year ago

@muan thank you! Just merged and will release a new minor version.