Skip to content

Conversation

addisonbeck
Copy link
Contributor

@addisonbeck addisonbeck commented Oct 13, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-24802

📔 Objective

Enable Nx builds in the desktop app. For example:

# basic commands
npx nx serve desktop
npx nx build-native desktop
npx nx build desktop (bundles the next three)
npx nx build-renderer desktop 
npx nx build-main desktop 
npx nx build-preload desktop 
npx nx test desktop
npx nx lint desktop

Most complexity here is that we need to support the pre-nx build pipelines for a while, so we have to juggle both configurations. The recent refactor of our webpack config to a webpack config factory was pretty helpful here. I added some optional parameters that come from Nx in Nx builds. Most lines are just changes from relative paths to absolute paths to account for the fact that npm and nx have different working directories.

Once we update CI to use Nx builds exclusively, and the Nx builds have had time to get battle tested, we'll remove the old npm builds and this configuration will get much simpler.

Otherwise, this is a fairly straightforward port of the build commands from desktops's package.json into a functioning project.json. It uses the standard executors and follows Nx conventions for this kind of build without much else that is special.

📸 Screenshots

running npx nx serve desktop
a running serve

running npx nx build desktop
a build

running npx nx build-native desktop
building the native module

running npx nx test desktop and npx nx lint desktop
linting_and_testing

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Oct 13, 2025

Logo
Checkmarx One – Scan Summary & Details209e8d4a-c052-433c-bbb4-ac640ea8fd04

Great job! No new security vulnerabilities introduced in this pull request

Copy link

codecov bot commented Oct 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.93%. Comparing base (122c16e) to head (28f1fe9).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16860      +/-   ##
==========================================
- Coverage   38.94%   38.93%   -0.01%     
==========================================
  Files        3437     3437              
  Lines       97511    97511              
  Branches    14667    14667              
==========================================
- Hits        37977    37970       -7     
- Misses      57874    57881       +7     
  Partials     1660     1660              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@addisonbeck addisonbeck force-pushed the add-nx-to-desktop branch 3 times, most recently from 9fcb044 to 0d5f1b7 Compare October 13, 2025 20:59
Comment on lines 1 to 42
/* eslint-disable @typescript-eslint/no-require-imports */
const path = require("path");

const concurrently = require("concurrently");

const rimraf = require("rimraf");

const args = process.argv.splice(2);

const outputPath = path.resolve(__dirname, "../../../dist/apps/desktop");
rimraf.sync(outputPath);
require("fs").mkdirSync(outputPath, { recursive: true });

concurrently(
[
{
name: "Main",
command: `cross-env NODE_ENV=development OUTPUT_PATH=${outputPath} webpack --config webpack.config.js --config-name main --watch`,
prefixColor: "yellow",
},
{
name: "Prel",
command: `cross-env NODE_ENV=development OUTPUT_PATH=${outputPath} webpack --config webpack.config.js --config-name preload --watch`,
prefixColor: "magenta",
},
{
name: "Rend",
command: `cross-env NODE_ENV=development OUTPUT_PATH=${outputPath} webpack --config webpack.config.js --config-name renderer --watch`,
prefixColor: "cyan",
},
{
name: "Elec",
command: `npx wait-on ${outputPath}/main.js ${outputPath}/index.html && npx electron --no-sandbox --inspect=5858 ${args.join(
" ",
)} ${outputPath} --watch`,
prefixColor: "green",
},
],
{
prefix: "name",
outputStream: process.stdout,
killOthers: ["success", "failure"],
},
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This whole thing emulates start.js that is used for serving right now. The only real difference is that it cuts npm out of the equation - commands from package.json are in here instead.

Copy link

@addisonbeck addisonbeck marked this pull request as ready for review October 13, 2025 22:04
@addisonbeck addisonbeck requested a review from a team as a code owner October 13, 2025 22:04
@addisonbeck addisonbeck enabled auto-merge (squash) October 13, 2025 22:05
@addisonbeck addisonbeck disabled auto-merge October 13, 2025 22:05
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