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

[Feature] Document the monorepo architecture, build process and dependencies #6418

Open
ottok opened this issue Dec 29, 2024 · 4 comments
Open

Comments

@ottok
Copy link
Contributor

ottok commented Dec 29, 2024

I have been trying to reproduce the build of OneKey. My goal is to build the Chrome extension and the Electron app in a clean Debian/Ubuntu container. However, I find it challenging to understand the build process. Could you please create a BUILD.md that explains things such as:

  • the monorepo architecture, what is OneKey's code, what are external dependencies
  • how are those dependencies downloaded and from where
  • if the build is done offline, how can those dependencies be listed and downloaded in advance
  • how can the build be instructed to only build a subset of the artifacts (mainly only the Chromium extension and Electron app for Linux)

There are many oddities that are hard to understand. Why for example do you need rimrafto delete files, why isn't a regular rm -rf enough? Why is there a zip.js wrapper, why not call zip directly? What is the purpose of cross-env?

I have documented some things I've uncovered so far in x...ottok:onekey-app-monorepo:build-audit, but understanding the repository structure by purely reading the build files seems overly complex, so I was hoping maybe you can produce some documentation on the topic. Thanks!

@originalix
Copy link
Contributor

Hi! Thanks for raising this issue about building OneKey in Ubuntu. Let me explain the build system and address your specific questions:

The monorepo uses Yarn workspaces to manage multiple apps (desktop, extension, mobile, web) and shared packages. For building in Ubuntu, you'll need:

# Install prerequisites
sudo apt-get install -y git curl build-essential python3 libusb-1.0-0-dev libudev-dev

# Setup Node.js 20+ and Yarn
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
corepack enable && corepack prepare [email protected] --activate

# Build steps
git clone https://github.com/OneKeyHQ/app-monorepo.git
cd app-monorepo
yarn install
yarn workspace @onekeyhq/ext build:v3      # Chrome extension
yarn workspace @onekeyhq/desktop build      # Desktop app

About your specific questions:

  • rimraf: Used instead of rm -rf for consistent behavior across Windows/Linux/Mac and better handling of file permissions
  • cross-env: Ensures environment variables work consistently across different shells and platforms
  • zip.js: Handles browser-specific packaging requirements and version management for extensions

Common issues:

  • Node.js version conflicts: Use n version manager
  • Permission errors: Check node_modules ownership
  • Missing dependencies: Install build-essential package

The build process works offline after initial setup since all dependencies are managed through yarn.lock.

Let me know if you run into any specific issues!

@originalix
Copy link
Contributor

Actually, we haven't tested whether it compiles successfully in Docker. If you run into issues there, you'll need to address them based on the specific errors you get.

@ottok
Copy link
Contributor Author

ottok commented Dec 29, 2024 via email

@originalix
Copy link
Contributor

originalix commented Dec 30, 2024

Hi, thanks a lot for your submission! Here's the design background of our monorepo. Feel free to discuss any questions you might have at any time.

We use a monorepo + workspaces because it lets us share critical crypto/blockchain code across platforms while keeping platform-specific stuff separate. This means:

  • Core crypto logic stays consistent everywhere
  • Teams can work independently on their platform
  • Dependencies are managed centrally
  • Changes can be tested across all platforms

The build system complexity comes from needing to support multiple platforms while ensuring consistent behavior for all developers. Each workspace can build independently, making it faster to test changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants