Skip to content

Conversation

addisonbeck
Copy link
Contributor

@addisonbeck addisonbeck commented Sep 29, 2025

🎟️ Tracking

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

All other clients are dependent on this PR for the new nx webpack plugin

📔 Objective

Enable Nx builds in the cli. For example:

# basic commands
npx nx serve cli
npx nx build cli
npx nx test cli
npx nx lint cli

# target the bit-dev build 
npx nx serve cli --configuration=bit-dev

# targeting a production build (no "dev" suffix)
npx nx build cli --configuration=bit

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 a bunch of optional parameters that come from Nx in Nx builds.

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 a bit simpler since we can start just depending on values from params.

Otherwise, this is a fairly straightforward port of the build commands from cli'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.

I've included some docs on using Nx in a root level docs folder. I got architecture's blessing to create this folder here.

📸 Screenshots

Here are some screenshots of various local nx builds. These aren't comprehensive, and the project.json should be reviewed to see what is available. I think I've verified that they all work locally. In CI you can reference the "Experimental Nx CI" job to see what is passing and what isn't. Please note this job will pass even if there are errors, so it should be reviewed even if it's green. For convenience I've included a screenshot of the last CI run showing

Screenshot 2025-10-01 at 2 19 09 PM Screenshot 2025-10-01 at 2 19 22 PM Screenshot 2025-10-01 at 2 20 06 PM

⏰ 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

@addisonbeck addisonbeck changed the title feat(cli): integrate Nx with CLI application feat(cli): enable building the cli with nx Sep 29, 2025
Copy link
Contributor

github-actions bot commented Sep 29, 2025

Logo
Checkmarx One – Scan Summary & Details65819417-deb0-4a87-9a83-1010714a6e88

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

@addisonbeck addisonbeck force-pushed the add-nx-to-the-cli branch 3 times, most recently from 232c72a to e7ea2f7 Compare September 30, 2025 21:10
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.75%. Comparing base (aa3be49) to head (17675f1).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16648      +/-   ##
==========================================
- Coverage   38.75%   38.75%   -0.01%     
==========================================
  Files        3406     3407       +1     
  Lines       96688    96713      +25     
  Branches    14533    14541       +8     
==========================================
+ Hits        37473    37482       +9     
- Misses      57577    57592      +15     
- Partials     1638     1639       +1     

☔ 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-the-cli branch 9 times, most recently from 0103f77 to 8a4fcf3 Compare October 1, 2025 19:42
@addisonbeck addisonbeck marked this pull request as ready for review October 1, 2025 19:56
@addisonbeck addisonbeck requested review from a team and coroiu October 1, 2025 19:56
@addisonbeck addisonbeck enabled auto-merge (squash) October 1, 2025 20:44
@addisonbeck addisonbeck changed the title feat(cli): enable building the cli with nx build(cli): integrate nx Oct 1, 2025
@addisonbeck addisonbeck marked this pull request as draft October 6, 2025 15:30
auto-merge was automatically disabled October 6, 2025 15:30

Pull request was converted to draft

@addisonbeck addisonbeck force-pushed the add-nx-to-the-cli branch 4 times, most recently from 6a2b37b to 38be8b1 Compare October 6, 2025 21:30
@addisonbeck addisonbeck marked this pull request as ready for review October 6, 2025 21:39
Comment on lines +36 to +46
return buildConfig({
configName: "OSS",
entry: "./src/bw.ts",
tsConfig: "./tsconfig.json",
outputPath: path.resolve(__dirname, "build"),
mode: mode,
env: ENV,
modulesPath: [path.resolve("../../node_modules")],
localesPath: "./src/locales",
externalsModulesDir: "../../node_modules",
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of these are the default values in webpack.base, but they won't be for long so I was verbose with these args.

@addisonbeck addisonbeck requested a review from dereknance October 6, 2025 21:50
dereknance
dereknance previously approved these changes Oct 6, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: instead of putting the default values interspersed in the code

patterns: [{ from: params.localesPath || "./src/locales", to: "locales" }],

could we move it all to one place?

const DEFAULT_PARAMS = {
  outputPath: "...",
  mode: "...",
  env: "...",
  modulesPath: [],
  localesPath: "...",
  externalsModulesDir: "...",
  watch: "...",
};

module.exports.buildConfig = function buildConfig(params) {
  params = { ...DEFAULT_PARAMS, params };

Copy link
Contributor Author

@addisonbeck addisonbeck Oct 7, 2025

Choose a reason for hiding this comment

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

Good idea. Really cleans this up a lot. Implemented as suggested on a72cd0e.

"mode": "development",
"outputPath": "dist/apps/cli/oss-dev"
},
"bit": {
Copy link
Contributor

Choose a reason for hiding this comment

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

question/suggestion: should we take this as an opportunity to stop using bit?

Suggested change
"bit": {
"commercial": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented as suggested on 537d6d7

I'm going to get a task in Jira for the next Nx focused epic to rename the folders themselves whenever we remove the old npm scripts. No ticket for that right this second but I'm talking to Todd about it.

Screenshot of a "commercial" build passing:

Screenshot 2025-10-07 at 8 42 22 AM

Copy link

sonarqubecloud bot commented Oct 7, 2025

@addisonbeck addisonbeck merged commit ddc8400 into main Oct 7, 2025
126 of 128 checks passed
@addisonbeck addisonbeck deleted the add-nx-to-the-cli branch October 7, 2025 13:48
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.

3 participants