Skip to content
angular challenges logo Angular Challenges

๐Ÿ”ด Extend Lib Generator

Challenge #25

Created by Thomas Laforge

Information

Welcome to the marvelous world of Nx generators.

Generators are awesome tools that can help you and your team generate code more quickly, especially for pieces of code that you use frequently. While using Nx, you create libraries regularly, but sometimes the default generator doesnโ€™t perfectly meet your needs.

Statement

The goal of this challenge is to create a generator that extends the default library generator of Nx. You will need to override the default jest.config.ts and a eslintrc.json with a custom one.

You can either use all the default parameters of the Nx library generator or choose to modify some and keep others as defaults. The choice is yours.

Constraints

You should only override the jest configuration is the unitTestRunner option is set at jest, and you should only update the eslint configuration if the linter is set to eslint.


jest.config.ts

/* eslint-disable */
export default {
displayName: '< libName >', // ๐Ÿ‘ˆ lib name
preset: '../../../jest.preset.js', // ๐Ÿ‘ˆ be careful with the path
setupFilesAfterEnv: ['<rootDir>/src/subscription-setup.ts'],
transform: {
'^.+\\.(ts|mjs|js|html)$': [
'jest-preset-angular',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
},
],
},
transformIgnorePatterns: ['node_modules/(?!(.*\\.mjs$|lodash-es))'],
};

eslintrc.json

Add the rule "@typescript-eslint/member-ordering": "off" inside the rules properties of ts files.

Contributors

Thanks to all the contributors who have helped make this documentation better!

  • tomalaforge
  • LMFinney