Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Mar 14, 2024
Merged

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

merged 5 commits into from
Mar 14, 2024

Conversation

nix6839
Copy link
Contributor

@nix6839 nix6839 commented Mar 13, 2024

Temporary fix #15

List

  • Fix cannot import vite in Yarn PnP
  • Set the node engines range to include versions that import.meta.resolve() is unflagged.
  • Add tests for Vite3, Vite4 and yarn-pnp
  • Add github action for test

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:

  • To run vite-bundle-visualizer in a Yarn PnP project, it must be executed only through the project's yarn commands. Examples include:
    • yarn dlx vite-bundle-visualizer in project
    • yarn add -D vite-bundle-visualizer && yarn vite-bundle-visualizer in project
    • ...

@nix6839 nix6839 marked this pull request as draft March 13, 2024 13:36
@nix6839 nix6839 marked this pull request as ready for review March 13, 2024 14:31
@nix6839 nix6839 changed the title fix: fix cannot import vite in Yarn PnP fix: temporary fix cannot import vite in Yarn PnP Mar 13, 2024
nix6839 added 2 commits March 14, 2024 00:17
They are unflagged `import.meta.resolve()`.
@KusStar
Copy link
Owner

KusStar commented Mar 14, 2024

LGTM, nice work!

@KusStar KusStar merged commit b42592b into KusStar:main Mar 14, 2024
@nix6839 nix6839 deleted the hack-import branch March 14, 2024 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1.0.0 fails in Yarn projects with Plug'n'Play
2 participants