nitayneeman / schematics-utilities

🛠️ Useful exported utilities for working with Schematics
https://nitayneeman.github.io/schematics-utilities
MIT License
86 stars 9 forks source link

addModuleImportToRootModule does not work with module initialization #7

Open lexon0011 opened 5 years ago

lexon0011 commented 5 years ago

I use the the function addModuleImportToRootModule in the following way:

addModuleImportToRootModule(
   host,
   `MyModule.forRoot(
     {
       option1: '<value of option1>',
       option2: '<value of option2>',
     })`,
   '@mycompany/my-module',
   project
);

As result, I get an invalid import statement in my app.module.ts. The module will be added correctly to the NgModule, but create an invalid import statement:

import { MyModule.forRoot(
   {
       option1: '<value of option1>',
       option2: '<value of option2>',
   }) } from '@mycompany/my-module';

Is there a way to to solve this problem?

Thanks!

nitayneeman commented 5 years ago

HI,

The original code has been changed, as you can see here: https://github.com/angular/components/blob/e02fa3a2ab2fc5616c633437dd74691bd8a0cf85/src/cdk/schematics/utils/ast.ts#L31

It's possible this change solves your issue, so if you could verify that, it would be awesome! Anyway - I'm planning to update the code, but it may take a while.

Until then, feel free to suggest a solution 🙂

nitayneeman commented 4 years ago

It has been done - the code was refactored to use the original source!

Would you like to check if now, with v2.0.0, the issue still happens?

dipaktelangre commented 4 years ago

I am also getting the same issue and has been not able to proceed further.

dipaktelangre commented 4 years ago

I have imported same function from @schematics/angular instead of schematics-utilities and now its working.

import {
  addProviderToModule,
  addImportToModule,
} from "@schematics/angular/utility/ast-utils";