Skip to content

build(nx): add basic-lib generator for streamlined library creation #14992

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

Merged
merged 3 commits into from
Jun 5, 2025

Conversation

addisonbeck
Copy link
Contributor

@addisonbeck addisonbeck commented May 29, 2025

🎟️ Tracking

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

The tooling implemented in this PR is demonstrated on #15064

📔 Objective

  • Create a Nx plugin (@bitwarden/nx-plugin) to house our custom generators, executors, etc.
  • Create a Nx generator (@bitwarden/nx-plugin:basic-lib) for constructing basic libraries in libs. This generator will be useful for all common type libs that are just typescript projects with services, models, and tests.

See commit messages and some contributing docs on the subject at bitwarden/contributing-docs#603 for more info

💣 Side Effects

  • Nx created jest.preset.js in project root. This aligns with our plans to centralize jest config.
  • I went ahead and did some configuring of Nx and added @nx/js as a dependency, which will be needed for building libs.
  • I had to fix a bad relative import in a jest config along the way. This is in a seperate commit.

📸 Screenshots

Screen.Recording.2025-06-03.at.12.11.08.PM.mov

⏰ 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 May 29, 2025

Logo
Checkmarx One – Scan Summary & Details03a54102-dfef-46c7-a20a-9ac186c12ad4

New Issues (1)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Missing_HSTS_Header /apps/web/src/app/dirt/reports/pages/inactive-two-factor-report.component.ts: 131
detailsThe web-application does not define an HSTS header, leaving it vulnerable to attack.
ID: PJlSLvIAgFvf39MBov%2FkpgpnZHo%3D
Attack Vector

@addisonbeck addisonbeck force-pushed the nx-plugin branch 2 times, most recently from 585fc18 to 4be315c Compare May 29, 2025 20:53
Copy link

codecov bot commented May 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.76%. Comparing base (299976e) to head (3a654f1).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14992      +/-   ##
==========================================
- Coverage   36.77%   36.76%   -0.01%     
==========================================
  Files        3201     3201              
  Lines       92661    92661              
  Branches    13931    13931              
==========================================
- Hits        34076    34069       -7     
- Misses      57179    57186       +7     
  Partials     1406     1406              

☔ 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 nx-plugin branch 4 times, most recently from 5f13a97 to 2346fd7 Compare May 30, 2025 20:01
Base automatically changed from rename-tsconfig to main June 2, 2025 20:38
@addisonbeck addisonbeck force-pushed the nx-plugin branch 11 times, most recently from 1a1523a to f22d097 Compare June 3, 2025 16:22
@@ -7,7 +7,6 @@
"target": "ES2016",
"module": "ES2020",
"lib": ["es5", "es6", "es7", "dom", "ES2021", "ESNext.Disposable"],
"sourceMap": true,
Copy link
Contributor Author

@addisonbeck addisonbeck Jun 3, 2025

Choose a reason for hiding this comment

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

This is a duplicate line and is still present in the file below

@@ -210,6 +214,7 @@
"simplelog",
"style-loader",
"sysinfo",
"ts-node",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ts-node is used by nx/js

@@ -34,3 +34,4 @@
./apps/browser/src/safari/safari/Info.plist
./apps/browser/src/safari/desktop.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
./SECURITY.md
./libs/nx-plugin/src/generators/files/README.md__tmpl__
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might need a better way to do this in the future as we add more READMEs, more generators, other languages, etc. Maybe the no-capital-letters rule in general doesn't fit our project structure? I've let this be for now.

Copy link
Member

Choose a reason for hiding this comment

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

README.md are generally exempt this one isn't because of the alternate suffix. I would agree that it is fine for now but if we need we could probably change that to README.md* if we need to.

@@ -1,6 +1,6 @@
const { pathsToModuleNameMapper } = require("ts-jest");

const { compilerOptions } = require("../../../../tsconfig.base");
const { compilerOptions } = require("../../../tsconfig.base");
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 started throwing errors on me. Not sure how it's not failing on main.

@addisonbeck addisonbeck changed the title Nx plugin feat(devtools): introduce @bitwarden/nx-plugin with a lib generator Jun 3, 2025
@addisonbeck addisonbeck force-pushed the nx-plugin branch 2 times, most recently from db83dff to 56ca956 Compare June 3, 2025 17:44
@addisonbeck addisonbeck changed the title feat(devtools): introduce @bitwarden/nx-plugin with a lib generator feat(nx): add basic-lib generator for streamlined library creation Jun 3, 2025
@addisonbeck addisonbeck marked this pull request as ready for review June 3, 2025 22:50
@addisonbeck addisonbeck requested a review from a team as a code owner June 3, 2025 22:50
@addisonbeck addisonbeck requested a review from justindbaur June 3, 2025 22:50
@addisonbeck addisonbeck enabled auto-merge (squash) June 4, 2025 00:10
@addisonbeck addisonbeck marked this pull request as draft June 4, 2025 19:09
auto-merge was automatically disabled June 4, 2025 19:09

Pull request was converted to draft

@addisonbeck addisonbeck changed the base branch from main to tsconfig-eslint-extend-base June 4, 2025 19:14
Base automatically changed from tsconfig-eslint-extend-base to main June 5, 2025 15:08
This adds a new nx-plugin library with a generator for creating "common" type
Bitwarden libs. It is set up to accept a lib name, description, team, and
directory. It then
- Creates a folder in the directory (default to libs)
- Sets up complete library scaffolding:
  - README with team ownership
  - Build, lint and test task configuration
  - Test infrastructure
- Configures TypeScript path mapping
- Updates CODEOWNERS with team ownership
- Runs npm i

This will make library creation more consistent and reduce manual boilerplate setup.

The plugin design itself was generated by `npx nx g plugin`. This means we
used a plugin to generate a plugin that exports generators. To create our
generator generator, we first needed a generator.
Fix the relative path to tsconfig.base in the dirt/card library's Jest config.
The path was incorrectly using four parent directory traversals (../../../../)
when only three (../../../) were needed to reach the project root.
Copy link

sonarqubecloud bot commented Jun 5, 2025

@addisonbeck addisonbeck marked this pull request as ready for review June 5, 2025 16:44
@addisonbeck addisonbeck enabled auto-merge (squash) June 5, 2025 16:56
@addisonbeck addisonbeck changed the title feat(nx): add basic-lib generator for streamlined library creation build(nx): add basic-lib generator for streamlined library creation Jun 5, 2025
@@ -34,3 +34,4 @@
./apps/browser/src/safari/safari/Info.plist
./apps/browser/src/safari/desktop.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
./SECURITY.md
./libs/nx-plugin/src/generators/files/README.md__tmpl__
Copy link
Member

Choose a reason for hiding this comment

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

README.md are generally exempt this one isn't because of the alternate suffix. I would agree that it is fine for now but if we need we could probably change that to README.md* if we need to.

@addisonbeck addisonbeck merged commit e8224fd into main Jun 5, 2025
99 checks passed
@addisonbeck addisonbeck deleted the nx-plugin branch June 5, 2025 18:20
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.

2 participants