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

feat(validation): make validation ESM/CJS package [WIP] #479

Closed
wants to merge 1 commit into from

Conversation

f1ames
Copy link
Contributor

@f1ames f1ames commented Aug 11, 2023

This PR makes validation package a hybrid ESM/CJS one.

It started with VSCode extension not really supporting ESM-only packages. Such can be only imported with dynamic import which has a number of limitations AFAIU, see kubeshop/vscode-monokle#8. And then it seems VSC team does not have any timeline or clear incentive to support such - you can read the discussion here microsoft/vscode#130367.

It was okeyish for validation import only, but the same issue happens with new synchronizer package. And since synchronizer depends on validation package (well, for types import only but still) both needs to be CJS.

Based on https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html.

This is WIP as I still need to test if it works with VSC and Cloud correctly without breaking anything, I'm still not sure if other dependencies won't cause issues too. See #479 (comment).

Changes

  • Reworked how package is build to expose both ESM and CJS versions.

Fixes

  • None.

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

@f1ames
Copy link
Contributor Author

f1ames commented Aug 14, 2023

This is WIP as I still need to test if it works wit VSC and Cloud correctly without breaking anything, I'm still not sure if other dependencies won't cause issues too.

Well, tested it and it doesn't seem to be helping 🤔 I played with require vs import and tsconfig options. Even if it compiles, when running the extension, VSCode will still complain:

Activating extension 'Kubeshop.monokle' failed: require() of ES Module /monokle-core/packages/validation/lib/mjs/node.js from /monokle-vsc/out/utils/validation.js not supported. Instead change the require of node.js in/monokle-vsc/out/utils/validation.js to a dynamic import() which is available in all CommonJS modules.

This requires more in-depth investigation. I can get back to this in some time if we have enough time.

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