1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 02:03:39 +00:00

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

* feat(nx): add basic-lib generator for streamlined library creation

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(dirt/card): correct tsconfig path in jest configuration

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.

* chore(codeowners): clarify some nx ownership stuff
This commit is contained in:
Addison Beck
2025-06-05 14:20:23 -04:00
committed by GitHub
parent 509af7b7bd
commit e8224fdbe3
34 changed files with 1273 additions and 578 deletions

View File

@@ -0,0 +1,4 @@
# <%= name %>
Owned by: <%= team %>
<%= description %>

View File

@@ -0,0 +1,3 @@
import baseConfig from "<%= offsetFromRoot %>eslint.config.mjs";
export default [...baseConfig];

View File

@@ -0,0 +1,10 @@
module.exports = {
displayName: '<%= name %>',
preset: '<%= offsetFromRoot %>jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '<%= offsetFromRoot %>coverage/libs/<%= name %>',
};

View File

@@ -0,0 +1,11 @@
{
"name": "@bitwarden/<%= name %>",
"version": "0.0.1",
"description": "<%= description %>",
"private": true,
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "GPL-3.0",
"author": "<%= team %>"
}

View File

@@ -0,0 +1,33 @@
{
"name": "<%= name %>",
"$schema": "<%= offsetFromRoot %>node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/<%= name %>/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/<%= name %>",
"main": "libs/<%= name %>/src/index.ts",
"tsConfig": "libs/<%= name %>/tsconfig.lib.json",
"assets": ["libs/<%= name%>/*.md"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/<%= name %>/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/<%= name %>/jest.config.js"
}
}
},
}

View File

@@ -0,0 +1,8 @@
import * as lib from './index';
describe('<%= name %>', () => {
// This test will fail until something is exported from index.ts
it('should work', () => {
expect(lib).toBeDefined();
});
});

View File

@@ -0,0 +1,13 @@
{
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.js", "src/**/*.spec.ts"]
}

View File

@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "<%= offsetFromRoot %>/dist/out-tsc",
"module": "commonjs",
"moduleResolution": "node10",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}