PepsRyuu / nollup

Rollup compatible development bundler for fast rebuilds and HMR.
MIT License
488 stars 28 forks source link

Dynamic import does translate correctly in some cases (0.18.1) #209

Closed charlag closed 3 years ago

charlag commented 3 years ago

Hi again!

We have such a piece of code generated now:

__e__('createDropdown', function () { return createDropdown });function createAsyncDropdown(lazyButtons, width = 200) {
  // not all browsers have the actual button as e.currentTarget, but all of them send it as a second argument (see https://github.com/tutao/tutanota/issues/1110)
  return (e, dom) => {
    let originalButtons = lazyButtons();
    let buttons = originalButtons;
    // If the promise is pending and does not resolve in 100ms, show progress dialog
    if (originalButtons.isPending()) {
      buttons = Promise.race([
      originalButtons,
      Promise.all([
      Promise.delay(100),
      require.dynamic('/home/ivk/dev/repositories/tutanota-3/src/gui/dialogs/ProgressDialog.js')]).
      then(([_, module]) => {
        if (originalButtons.isPending()) {
          return module.showProgressDialog("loading_msg", originalButtons);
        } else {
          return originalButtons;
        }
      })]);

    }
    buttons.then((buttons) => {
      let dropdown = new DropdownN(() => buttons, width);
      dropdown.setOrigin(dom.getBoundingClientRect());
      modal.displayUnique(dropdown, false);
    });
  };
};

It fails on require.dynamic() because require() is not defined (it's not in the scope I think). Maybe another hoisting issue? Thanks!

PepsRyuu commented 3 years ago

Nice catch! That definitely is an oversight for the reason you stated. Should be an easy fix, will have a look!

PepsRyuu commented 3 years ago

I seem to have having lots of difficulty getting Tutanota to work properly and can't easily debug it. I'd appreciate it if you could try the latest version of the master branch and let me know if it solves your problem.

charlag commented 3 years ago

Just tried it out on master, it seems to work, thanks!

Generally it's enough to

npm ci
node make prod
python3 -m http.server
firefox http://localhost:9000/build
PepsRyuu commented 3 years ago

Great! Will release later today. 🙂

PepsRyuu commented 3 years ago

Released in 0.18.2!