diff --git a/my-library/README.md b/my-library/README.md new file mode 100644 index 0000000..a4853b1 --- /dev/null +++ b/my-library/README.md @@ -0,0 +1,7 @@ +# my-library + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test my-library` to execute the unit tests. diff --git a/my-library/eslint.config.js b/my-library/eslint.config.js new file mode 100644 index 0000000..67de88d --- /dev/null +++ b/my-library/eslint.config.js @@ -0,0 +1,34 @@ +const nx = require('@nx/eslint-plugin'); +const baseConfig = require('../eslint.config.js'); + +module.exports = [ + ...baseConfig, + ...nx.configs['flat/angular'], + ...nx.configs['flat/angular-template'], + { + files: ['**/*.ts'], + rules: { + '@angular-eslint/directive-selector': [ + 'error', + { + type: 'attribute', + prefix: 'lib', + style: 'camelCase', + }, + ], + '@angular-eslint/component-selector': [ + 'error', + { + type: 'element', + prefix: 'lib', + style: 'kebab-case', + }, + ], + }, + }, + { + files: ['**/*.html'], + // Override or add rules here + rules: {}, + }, +]; diff --git a/my-library/jest.config.ts b/my-library/jest.config.ts new file mode 100644 index 0000000..ae29d9f --- /dev/null +++ b/my-library/jest.config.ts @@ -0,0 +1,21 @@ +export default { + displayName: 'my-library', + preset: '../jest.preset.js', + setupFilesAfterEnv: ['/src/test-setup.ts'], + coverageDirectory: '../coverage/my-library', + transform: { + '^.+\\.(ts|mjs|js|html)$': [ + 'jest-preset-angular', + { + tsconfig: '/tsconfig.spec.json', + stringifyContentPathRegex: '\\.(html|svg)$', + }, + ], + }, + transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'], + snapshotSerializers: [ + 'jest-preset-angular/build/serializers/no-ng-attributes', + 'jest-preset-angular/build/serializers/ng-snapshot', + 'jest-preset-angular/build/serializers/html-comment', + ], +}; diff --git a/my-library/project.json b/my-library/project.json new file mode 100644 index 0000000..3a43a6d --- /dev/null +++ b/my-library/project.json @@ -0,0 +1,20 @@ +{ + "name": "my-library", + "$schema": "../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "my-library/src", + "prefix": "lib", + "projectType": "library", + "tags": [], + "targets": { + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "my-library/jest.config.ts" + } + }, + "lint": { + "executor": "@nx/eslint:lint" + } + } +} diff --git a/my-library/src/index.ts b/my-library/src/index.ts new file mode 100644 index 0000000..6b36f1a --- /dev/null +++ b/my-library/src/index.ts @@ -0,0 +1 @@ +export * from './lib/my-library/my-library.component'; diff --git a/my-library/src/lib/my-library/my-library.component.css b/my-library/src/lib/my-library/my-library.component.css new file mode 100644 index 0000000..e69de29 diff --git a/my-library/src/lib/my-library/my-library.component.html b/my-library/src/lib/my-library/my-library.component.html new file mode 100644 index 0000000..63437d7 --- /dev/null +++ b/my-library/src/lib/my-library/my-library.component.html @@ -0,0 +1 @@ +

my-library works!

diff --git a/my-library/src/lib/my-library/my-library.component.spec.ts b/my-library/src/lib/my-library/my-library.component.spec.ts new file mode 100644 index 0000000..eb6e257 --- /dev/null +++ b/my-library/src/lib/my-library/my-library.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { MyLibraryComponent } from './my-library.component'; + +describe('MyLibraryComponent', () => { + let component: MyLibraryComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [MyLibraryComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(MyLibraryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/my-library/src/lib/my-library/my-library.component.ts b/my-library/src/lib/my-library/my-library.component.ts new file mode 100644 index 0000000..92536aa --- /dev/null +++ b/my-library/src/lib/my-library/my-library.component.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; +import { CommonModule } from '@angular/common'; + +@Component({ + selector: 'lib-my-library', + standalone: true, + imports: [CommonModule], + templateUrl: './my-library.component.html', + styleUrl: './my-library.component.css', +}) +export class MyLibraryComponent {} diff --git a/my-library/src/test-setup.ts b/my-library/src/test-setup.ts new file mode 100644 index 0000000..ab1eeeb --- /dev/null +++ b/my-library/src/test-setup.ts @@ -0,0 +1,8 @@ +// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment +globalThis.ngJest = { + testEnvironmentOptions: { + errorOnUnknownElements: true, + errorOnUnknownProperties: true, + }, +}; +import 'jest-preset-angular/setup-jest'; diff --git a/my-library/tsconfig.json b/my-library/tsconfig.json new file mode 100644 index 0000000..74c8f45 --- /dev/null +++ b/my-library/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "target": "es2022", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true + }, + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ], + "extends": "../tsconfig.base.json", + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/my-library/tsconfig.lib.json b/my-library/tsconfig.lib.json new file mode 100644 index 0000000..64216c9 --- /dev/null +++ b/my-library/tsconfig.lib.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../dist/out-tsc", + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "types": [] + }, + "exclude": [ + "src/**/*.spec.ts", + "src/test-setup.ts", + "jest.config.ts", + "src/**/*.test.ts" + ], + "include": ["src/**/*.ts"] +} diff --git a/my-library/tsconfig.spec.json b/my-library/tsconfig.spec.json new file mode 100644 index 0000000..2894252 --- /dev/null +++ b/my-library/tsconfig.spec.json @@ -0,0 +1,16 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../dist/out-tsc", + "module": "commonjs", + "target": "es2016", + "types": ["jest", "node"] + }, + "files": ["src/test-setup.ts"], + "include": [ + "jest.config.ts", + "src/**/*.test.ts", + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +} diff --git a/nx.json b/nx.json index 37b3c32..3a2f654 100644 --- a/nx.json +++ b/nx.json @@ -72,6 +72,13 @@ "linter": "eslint", "style": "css", "unitTestRunner": "jest" + }, + "@nx/angular:library": { + "linter": "eslint", + "unitTestRunner": "jest" + }, + "@nx/angular:component": { + "style": "css" } } } diff --git a/tsconfig.base.json b/tsconfig.base.json index 428f209..686d7c1 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -15,6 +15,7 @@ "skipDefaultLibCheck": true, "baseUrl": ".", "paths": { + "@my-workspace/my-library": ["my-library/src/index.ts"], "@my-workspace/my-plugin": ["tools/my-plugin/src/index.ts"] } },