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: cjs imports from marko files in dev #50

Merged
merged 7 commits into from
Apr 13, 2023
Merged

fix: cjs imports from marko files in dev #50

merged 7 commits into from
Apr 13, 2023

Conversation

rturnq
Copy link
Contributor

@rturnq rturnq commented Apr 5, 2023

Description

In dev mode, .marko files with CommonJS dependencies will fail in SSR because Vite loads them in ESM context.

This PR attempts to handle this case by wrapping them in module that requires it using createRequire. This causes the marko file to be loaded using Marko's require hook in a CommonJS context.

  • The mechanism is only used in dev
  • A heuristic is used to test if the module is likely CommonJS and only these files are wrapped

Motivation and Context

Screenshots (if appropriate):

Checklist:

  • I have updated/added documentation affected by my changes.
  • I have added tests to cover my changes.

@changeset-bot
Copy link

changeset-bot bot commented Apr 5, 2023

🦋 Changeset detected

Latest commit: 8e748a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@marko/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Patch coverage: 89.39% and project coverage change: +0.13 🎉

Comparison is base (597770a) 86.40% compared to head (4a97488) 86.53%.

❗ Current head 4a97488 differs from pull request most recent head 8e748a4. Consider uploading reports for the commit 8e748a4 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #50      +/-   ##
==========================================
+ Coverage   86.40%   86.53%   +0.13%     
==========================================
  Files           9        9              
  Lines         456      520      +64     
  Branches      112      130      +18     
==========================================
+ Hits          394      450      +56     
- Misses         54       61       +7     
- Partials        8        9       +1     
Impacted Files Coverage Δ
src/index.ts 88.13% <89.39%> (-0.15%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rturnq rturnq merged commit e014eb9 into main Apr 13, 2023
@rturnq rturnq deleted the cjs-deps branch April 13, 2023 17:27
@github-actions github-actions bot mentioned this pull request Apr 13, 2023
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.

1 participant