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

ESM related fixes #897

Merged
merged 7 commits into from
Oct 11, 2024
Merged

ESM related fixes #897

merged 7 commits into from
Oct 11, 2024

Conversation

haZya
Copy link
Contributor

@haZya haZya commented Oct 10, 2024

Pull Request

Related issue

Fixes #863, fixes #876

What does this PR do?

This fixes some issues related to ESM bundling.

  • Vite (rollup) had an issue with variables in dynamic import paths, where it complains Dynamic import cannot be analyzed by Vite. This could be fixed by using a plugin like vite-plugin-dynamic-import. But since this can also be fixed from within the NSFWJS package, I've decided to explicitly pre-define the import paths instead of resolving them at runtime using variables.
  • Added nested package.json with "type": "module" and "type": "commonjs" in dist/esm and dist/cjs directories respectively to correctly define the scope for both CJS and ESM. This fixes Cannot use import statement outside a module #876.
  • Added ESM version of the model files using esbuild and import conditionally based on the environment.
  • Added getGlobal function to access the global object in an environment-agnostic way.

haZya added 7 commits October 2, 2024 21:00
+ Added "type": "commonjs" explicitly.
Added ESM version of the model files using esbuild and import conditionally based on the environment.
…s with their weight files

+ Updated bundle-model.mjs to generate model files in esm and cjs directories.
+ Updated imports with new paths.
Copy link
Contributor

@mazenchami mazenchami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haZya great work on this! thank you very much for putting the time into it. I'll be merging this and putting out a release soon

@mazenchami mazenchami merged commit 2f60c4e into infinitered:master Oct 11, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants