KusStar / vite-bundle-visualizer

CLI for visualizing your vite project bundle.
MIT License
321 stars 7 forks source link

fix: temporary fix cannot import vite in Yarn PnP #18

Closed nix6839 closed 7 months ago

nix6839 commented 7 months ago

Temporary fix #15

List

Details

async function importVite() {
  /** @type {import('vite')} */
  let vite = await importFrom.silent(process.cwd(), 'vite');
  try {
    vite ??= await import(import.meta.resolve('vite'));
  } catch {}
  return vite;
}

In other than Yarn PnP, the importFrom.silet() successfully makes an assignment and then skips the next assignment. Yarn PnP seems to fail on the first assignment but works on the second dynamic import. I'll need to test it after the release and yarn dlx vite-bundle-visualizer, but for now, it seems to properly import vite from the executed project when run through yarn in PnP mode. (I have no idea why).

There are precaution to note:

KusStar commented 7 months ago

LGTM, nice work!