Skip to content

Commit

Permalink
Suggestions to the "BSON v6 upgrade" (#6618)
Browse files Browse the repository at this point in the history
* Fixed a warning in the realm-web Rollup config

* Moved typescript and commonjs plugin down and stripping comments to lower IIFE bundle size

* Adding an alias for "bson" pointing to the .cjs bundle

* Upgrading ts-loader in the realm-web integration tests

* Updating tsconfigs in the realm web integration tests

* Using ESM when importing realm-web integration test files
  • Loading branch information
kraenhansen committed Apr 17, 2024
1 parent e76e2fb commit a4a54eb
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 26 deletions.
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"dependencies": {
"@react-native/eslint-config": "0.73.2",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-web-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"html-webpack-plugin": "^5.5.0",
"mongodb-realm-cli": "^1.3.2",
"source-map-loader": "^5.0.0",
"ts-loader": "^9.3.0",
"ts-loader": "^9.5.1",
"webpack-cli": "^5.1.4"
}
}
24 changes: 12 additions & 12 deletions packages/realm-web-integration-tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ if (location.pathname.endsWith("-callback")) {
Realm.handleAuthRedirect();
} else if (location.pathname.endsWith("/google-login")) {
console.log("Hello to Google Login ...");
require("./google-login");
await import("./google-login");
} else {
new MochaRemoteClient({
tests: () => {
async tests() {
beforeEach(function () {
this.slow(1000);
this.timeout(10000);
});

require("./environment.test");
require("./app.test");
require("./credentials.test");
require("./user.test");
require("./functions.test");
require("./services.test");
require("./api-key-auth.test");
require("./email-password-auth.test");
require("./iife.test");
require("./bson.test");
await import("./environment.test");
await import("./app.test");
await import("./credentials.test");
await import("./user.test");
await import("./functions.test");
await import("./services.test");
await import("./api-key-auth.test");
await import("./email-password-auth.test");
await import("./iife.test");
await import("./bson.test");
},
});
}
6 changes: 2 additions & 4 deletions packages/realm-web-integration-tests/src/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@
//
////////////////////////////////////////////////////////////////////////////

describe("App services", () => {
require("./remote-mongodb-service.test");
require("./http-service.test");
});
import "./remote-mongodb-service.test";
import "./http-service.test";
7 changes: 4 additions & 3 deletions packages/realm-web-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"compilerOptions": {
"strict": true,
"sourceMap": true,
"module": "commonjs",
"target": "ES2019",
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "Bundler",
"lib": [
"ES2019",
"ES2022",
"DOM"
],
"types": [
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-web-integration-tests/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"mocha-remote-client"
],
"lib": [
"ES2020",
"ES2022",
"DOM"
]
},
Expand Down
26 changes: 22 additions & 4 deletions packages/realm-web/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
//
////////////////////////////////////////////////////////////////////////////

import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import nodeResolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import dts from "rollup-plugin-dts";

import { createRequire } from "node:module";
const require = createRequire(import.meta.url);

import pkg from "./package.json" assert { type: "json" };

const replacer = replace({
__SDK_VERSION__: JSON.stringify(pkg.version),
preventAssignment: true,
values: {
__SDK_VERSION__: JSON.stringify(pkg.version),
},
});

export default [
Expand Down Expand Up @@ -97,16 +104,27 @@ export default [
},
],
plugins: [
commonjs(),
typescript({
tsconfig: "src/dom/tsconfig.json",
// Providing an alias for the "bson" package
// See https://github.com/mongodb/js-bson/pull/669#pullrequestreview-1994786536 for more context
alias({
entries: [
{
find: "bson",
replacement: require.resolve("bson"),
},
],
}),
nodeResolve({
mainFields: ["browser", "module", "main"],
exportConditions: ["browser", "module", "main"],
modulesOnly: true,
preferBuiltins: false,
}),
commonjs(),
typescript({
tsconfig: "src/dom/tsconfig.json",
removeComments: true,
}),
replacer,
],
},
Expand Down

0 comments on commit a4a54eb

Please sign in to comment.