Skip to content

chrisrichie25/compass

 
 

Repository files navigation

MongoDB Compass Monorepo

This repository contains the source code and build tooling used in MongoDB Compass.

Aggregation Pipeline Builder Tab in Compass

Packages Overview

Compass Plugins

Shared Libraries and Build Tools

Working With the Monorepo

You'll need node ^12.9.0 and npm 7 installed on your machine to work with the repository locally. After your environment is ready, navigate to the repository and run npm run bootstrap, this will install dependencies and will compile all packages.

After bootstrap is finished, you should be able to run npm run start and see Compass application running locally.

This monorepo is powered by npm workspaces an lerna, although not necessary, it might be helpful to have a high level understanding of those tools.

Working on Plugins

Most of the plugins have their own development environment so you can work on them in isolation. If you want to work on a plugin without running the whole Compass application, you can run npm run start in the plugin directory (such as at the top of the compass/packages/compass-connect directory), either with the help of lerna or npm workspaces. For example, to start compass-connect plugin locally, you can either run npm run start --workspace @mongodb-js/compass-connect from the top of compass directory, run npx lerna run start --scope @mongodb-js/compass-connect --stream from anywhere in the compass directory, or run npm run start from the top of the compass/packages/compass-connect directory. Same approaches will work for any other workspace-specific script. If you want to run commands like test or check only for one specific workspace in the repository, you can use any of the methods described above. As an example, to run all tests in one plugin that you are working on such as the compass-connect plugin, you can run npm run test from the top of the compass/packages/compass-connect directory.

If you want to see your changes applied in Compass, you might need to rebuild plugins that you changed with the compile command. Instead of manually writing out the scope you might want to use lerna --since filter to rebuild everything since your local or origin HEAD of the git history: npx lerna run compile --stream --since origin/HEAD. Restarting or hard-reloading (Shift+CMD+R) Compass after compilation is finished should apply your changes.

In addition to running lerna commands directly, there are a few convenient npm scripts for working with packages:

  • npm run compile-changed will compile all plugins and their dependants changed since origin/HEAD
  • npm run test-changed will run tests in all packages and their dependants changed since origin/HEAD.
  • npm run check-changed will run eslint and depcheck validation in all packages (ignoring dependants) changed since origin/HEAD

Building Compass Locally

To build compass you can run package-compass script in the scope of mongodb-compass workspace:

npm run package-compass --workspace mongodb-compass

This command requires a bunch of environment variables provided (HADRON_PRODUCT, HADRON_PRODUCT_NAME, HADRON_DISTRIBUTION, etc) so for your convenience there is a script provided that sets all those vars to some default values and will take care of generating a required package-lock.json file for the compass workspace

npm run test-package-compass

To speed up the process you might want to disable creating installer for the application. To do that you can set HADRON_SKIP_INSTALLER environmental variable to true when running the script

HADRON_SKIP_INSTALLER=true npm run test-package-compass

Caveats

hdiutil: couldn't unmount "diskn" - Resource busy or Similar hdiutil Errors

Sometimes when trying to package compass on macOS you can run into the said error. There doesn't seems to be any common solution to it and the reasons are probably related to the outdated versions of some electron packages we are currently using (but will eventually update). If you are running into that issue, you can disable creating an installer during the packaging process by setting HADRON_SKIP_INSTALLER env variable to true:

HADRON_SKIP_INSTALLER=true npm run test-package-compass

Module did not self-register or Module '<path>' was compiled against a different Node.js version Errors

When running Compass application or tests suites locally, you might run into errors like the following:

Error: Module did not self-register: '/path/to/native/module.node'.
Error: The module '/path/to/native/module.node' was compiled against a different Node.js version using NODE_MODULE_VERSION $XYZ. This version of Node.js requires NODE_MODULE_VERSION $ABC.

The root cause is native modules compiled for a different version of the runtime (either Node.js or Electron) that tries to import the module. In our case this is usually caused by combination of two things:

  1. Modules have to be recompiled for the runtime they will be used in
  2. Due to npm workspaces hoisting all shared dependencies to the very root of the monorepo, all packages use the same modules imported from the same location

This means that if you e.g., start Compass application locally it will recompile all native modules to work in Electron runtime, if you would try to run tests for mongodb-connection-model library right after that, tests would fail due to keytar library not being compatible with Node.js environment that the tests are running in.

If you run into this issue, make sure that native modules are rebuilt for whatever runtime you are planning to use at the moment. To help with that we provide two npm scripts: npm run electron-rebuild will recompile native modules to work with Electron and npm run node-rebuild will recompile them to work with Node.js.

Publishing Packages

For package changes to be applied in Compass beta or GA releases they need to be published first. The whole publish process happens from the main branch with the following command in order:

  1. npm run packages-version [semver bump]: updates package versions for everything that was changed since the last release, updates package-lock file at the root of the repository, commits and tags the changes. See lerna docs to learn more about optional semver bump argument.
  2. npm run packages-publish: publishes packages to the registry, if your npm account uses OTP publishing protection get ready to enter the code a few times, as an alternative you might want to use npm automation authorization tokens locally if OTP gets in the way too much (in that case add a --no-verify-access flag to the publish command). Publish command can be re-run safely multiple times, so if something bad happens mid-release (e.g., your internet goes out), you should be able to safely fiinish the process. After publish finishes successfully the script will push version update commit and tags created in step 1. We do it automatically only post-release so that when evergreen picks up a commit in the main branch, all the tasks can run with the packages already published.

Add / Update / Remove Dependencies in Packages

To add, remove, or update a dependency in any workspace you can use the usual npm install with a --workspace argument added, e.g. to add react-aria dependency to compass-connect and compass-query-bar plugins you can run npm install --save react-aria --workspace @mongodb-js/compass-connect --workspace @mongodb-js/compass-query-bar.

Additionally if you want to update a version of an existing dependency, but don't want to figure out the scope manually, you can use npm run where helper script. To update webpack in every package that has it as a dev dependency you can run npm run where "devDependencies['webpack']" -- install --save-dev webpack@latest

Contributing

For issues, please create a ticket in our JIRA Project.

For contributing, please refer to CONTRIBUTING.md

Is there anything else you’d like to see in Compass? Let us know by submitting suggestions in out feedback forum.

License

SSPL

Packages

No packages published

Languages

  • JavaScript 79.5%
  • Less 17.7%
  • ANTLR 1.6%
  • CSS 0.9%
  • PEG.js 0.3%
  • Python 0.0%