What is the process for extracting the paths of component files from an Angular ngModule file?

I've been on the lookout for automation options to streamline the process of refactoring an Angular application, as doing it manually can be quite tedious.

We're working on reducing our app's shared module by extracting components/directives into their own modules through treeshaking. This requires going through each feature module in the app and verifying if a directive or component selector is present in the template. If found, the module containing the template must import the new module of the treeshaken directive/component from the shared module. Are there any tools available to assist with this refactoring task? It seems like a common requirement.


If there isn't a universal solution, I would still like to programmatically generate a list of absolute paths of components in the declarations array of any given .module.ts file.

The challenges I am currently encountering include:

  • File names of components may differ from their Class names
  • Some components are deeply nested within multiple barrel references
  • TsConfig paths are customizing imports in the project

Answer №1

This question is quite intriguing, however, there currently isn't a readily available tool that can address your specific issue.

Here are some suggestions I have:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Improprove performance in Angular by efficiently updating the view through the service

Utilizing the uiSettings service, I am able to control different parts of templates based on user data. Currently, I am directly accessing this service from the template like so: <li *ngIf="uiService.demoButton()"> <button [router ...

Troubleshooting ngModel Binding Issue with Sub-Children in CKEditor 5 and Angular 7

Firstly, I am sharing my code below: ListPagesComponent: export class ListPagesComponent { public model = { id: -1, actif: 0, link: '', htmlContent: { fr: '', ...

Utilizing the URL path name for data retrieval in Next.js 14 - A step-by-step guide

I'm currently developing a blog using AWS Amplify Gen 2 and GraphQL for a Next.js 14 project with TypeScript. As part of my application, I need to fetch specific data based on the URL path name. Here's how I've approached it: My approach in ...

Angular Image/Video Preview: Enhance Your Visual Content Display

Is there a way to preview both images and videos when uploading files in Angular? I have successfully implemented image preview but need help with video preview. Check out the stackblitz link below for reference: CLICK HERE CODE onSelectFile(ev ...

Is there a way to emphasize certain words with angular?

In order to convert all words starting with "@" into an <a> (html link) element, I am looking for a solution using Angular 8 and considering the use of a custom pipe. For example, if the phrase is "Hello, @test" -> "Hello, <a href="...&qu ...

Tracking property changes in Angular can help developers easily identify modifications to specific

import { Component ,OnInit} from '@angular/core'; import { QuizService } from './quiz.service'; import { timer } from 'rxjs'; import { take, map } from 'rxjs/operators'; @Component({ selector: 'app-r ...

Exploring the process of iterating over asynchronous data in Angular

There is an angular component in my project that fetches data from the server, processes it, and then assigns it to a variable: class Component { data = []; ngOnInit() { this.store.select(data).pipe( map(data => { this.data = this.transf ...

Can Angular facilitate the establishment of an Express.js server directly in the browser?

Can an Express.js server be initialized within the browser using Angular? I am interested in executing Node scripts on the Express server via an Angular component. ...

Error encountered: Unable to locate module 'psl'

I'm encountering an issue when trying to execute a pre-existing project. The error message I keep receiving can be viewed in the following error logs image Whenever I attempt to run "npm i", this error arises and I would greatly appreciate it if some ...

Error: The attribute 'detect' is not a valid property of object 'GraphModel'

I am currently experimenting with using TensorFlow JS to develop a real-time object detection application in Angular 13. My goal is to utilize a video element that captures footage from the webcam, and I am attempting to invoke the model.detect(video) meth ...

Discovering the element on which the value has decreased - a helpful guide

I am attempting to create a drag and drop feature for simple calculations. Users can drag the UP value and drop it on either BH or OT. The issue I'm facing is that I cannot identify the ID where the user dropped, and the onDrop() function is not work ...

Advanced Angular2 Services Expansion

I'm looking to enhance an existing angular service (for example, Http). Requirements: The extension of the service should be done through angular's dependency injection It should be possible to extend the service multiple times using a pattern ...

How can I configure a mocked dependency in Jest to return a specific value in a function?

I am currently working on simulating a mongoose model to facilitate unit testing for an express controller. To keep things simple, I've removed all unnecessary code and provided below the specific scenario I'm dealing with. Here's the snippe ...

Utilizing Array Notation in Typescript to Retrieve Elements from Class

In my programming project, I am working with two classes: Candles and Candle. The Candles class includes a property called list, which is an array containing instances of the Candle class. class Candles { public list: Array<Candle>; } class Candl ...

Ways to import a library in JavaScript/TypeScript on a web browser?

I'm currently working on a project that involves a TypeScript file and an HTML page. Right now, I am loading the necessary libraries for the TypeScript file in the HTML Page using script tags like <script src="https://unpkg.com/<a href="/cd ...

Trouble accessing images from database in Angular 2 with Firebase

Recently, I've integrated an image upload feature for my database using the following function: private saveFileData(upload: Upload): void { this.firebaseAuth.authState.subscribe(auth => { this.db.list(`uploads/${auth && auth.email && au ...

Issue with intrinsic attributes detected in Typescript for the component

Hey, I'm encountering an issue that says, "The type '{ data: dataProp[]; }' cannot be assigned to type 'IntrinsicAttributes & dataProp'. A property 'data' does not exist on type 'IntrinsicAttributes & dataPro ...

How can we define a function using a generic type in this scenario using Typescript?

Here's a challenge that I'm facing. I have this specific type definition: type FuncType<T> = (value: T) => T I want to create a function using this type that follows this structure: const myFunc: FuncType<T> = (value) => valu ...

Processing a list in Angular using Observables

In my Angular12 application, I am fetching data from a Firebase Realtime DB using AngularFire. To streamline my code and ensure consistency, I have implemented a DAO service to preprocess the retrieved data (e.g., converting string dates to Date objects). ...

When a module is generated, it appends an additional slash to the path in the app.module.ts file

I've noticed a strange behavior with the generator in Angular CLI tools that adds an extra slash character for modules. For example, when running ng generate component visual a line like this is added to the app.module.ts file import { VisualCo ...