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

Only export a CJS bundle (using rollup) #5882

Merged
merged 10 commits into from
Jun 12, 2023
Merged

Conversation

kraenhansen
Copy link
Member

What, How & Why?

This supersedes #5853 and fixes #5857 by removing the ESM exports from the rollup config and adding CJS entrypoint files which export via module.exports = assignments as our v11 SDK does as well.

☑️ ToDos

  • 📝 Changelog entry
  • 🚦 Tests
  • 📝 Public documentation PR created or is not necessary
  • 💥 Breaking label has been applied or is not necessary

/* eslint-disable @typescript-eslint/no-var-requires -- We're exporting using CJS assignment */
/* eslint-env commonjs */

module.exports = require("./dist/bundle.node").Realm;
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't love it, but it works 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

At least we have proper entry points set for node and React Native. Let's break everything in v13 💣

Copy link
Contributor

@takameyer takameyer left a comment

Choose a reason for hiding this comment

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

Can't wait for v13! 🧼

@@ -84,4 +85,13 @@ describe("Enums", function () {
});
});
});
describe("WaitForSync", function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this part of CJS?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is me forgetting to add this enum test when doing the Flx Sync v2 PR 😉

Comment on lines +21 to +30
module.exports = function (request, options) {
if (request === "react-native") {
// Ensure that "react-native" always resolve relative to the rootDir
options.basedir = options.rootDir;
} else if (request === "realm") {
// Ensure the node binding is used when testing with Jest on node
options.conditions = ["require", "default", "node"];
}
return options.defaultResolver(request, options);
};
Copy link
Member Author

Choose a reason for hiding this comment

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

@takameyer to be honest, I don't understand why this worked before.

  • The first branch will ensure "react-native" from @realm/react is loaded, instead of the peer dependency of realm(realm/node_modules/react-native), as that yielded Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules errors
  • The second branch is to ensure the Node.js version of the SDK is loaded. If I didn't do this, I would be getting TypeError: Cannot read properties of undefined (reading 'Helpers_get_table') errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I've never seen those issues before. Why would this happen with cjs?

Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

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

I believe these (in packages/realm/src/tests) also need to be updated:

Other than that, LGTM 👍

@@ -84,4 +85,13 @@ describe("Enums", function () {
});
});
});
describe("WaitForSync", function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is me forgetting to add this enum test when doing the Flx Sync v2 PR 😉

@kraenhansen
Copy link
Member Author

I believe these (in packages/realm/src/tests) also need to be updated:

@elle-j these are importing directly from source, so they don't need an update 👍

@kraenhansen kraenhansen merged commit fb70261 into main Jun 12, 2023
@kraenhansen kraenhansen deleted the kh/cjs-bundle-rollup branch June 12, 2023 15:41
papafe added a commit that referenced this pull request Jun 14, 2023
* main:
  Update main to core v13.13.0 (#5873)
  Only export a CJS bundle (using rollup) (#5882)
  Overhaul SDK metrics (#5830)

# Conflicts:
#	packages/realm/bindgen/vendor/realm-core
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export only a CommonJS entrypoint
3 participants