Skip to content

Commit

Permalink
fix(angular): handle ngrx imports for apps that do not migrate to con…
Browse files Browse the repository at this point in the history
…fig file (#16812)
  • Loading branch information
Coly010 authored May 9, 2023
1 parent 7d42d88 commit 6728bbb
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/angular/src/generators/ngrx/lib/add-imports-to-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { SourceFile } from 'typescript';
import {
addImportToModule,
addProviderToAppConfig,
addProviderToBootstrapApplication,
addProviderToModule,
} from '../../../utils/nx-devkit/ast-utils';
import type { NormalizedNgRxGeneratorOptions } from './normalize-options';
Expand All @@ -23,8 +24,11 @@ function addRootStoreImport(
storeForRoot: string
) {
if (isParentStandalone) {
if (tree.read(parentPath, 'utf-8').includes('ApplicationConfig')) {
const parentContents = tree.read(parentPath, 'utf-8');
if (parentContents.includes('ApplicationConfig')) {
addProviderToAppConfig(tree, parentPath, provideRootStore);
} else if (parentContents.includes('bootstrapApplication')) {
addProviderToBootstrapApplication(tree, parentPath, provideRootStore);
} else {
addProviderToRoute(tree, parentPath, route, provideRootStore);
}
Expand All @@ -44,8 +48,11 @@ function addRootEffectsImport(
effectsForEmptyRoot: string
) {
if (isParentStandalone) {
if (tree.read(parentPath, 'utf-8').includes('ApplicationConfig')) {
const parentContents = tree.read(parentPath, 'utf-8');
if (parentContents.includes('ApplicationConfig')) {
addProviderToAppConfig(tree, parentPath, provideRootEffects);
} else if (parentContents.includes('bootstrapApplication')) {
addProviderToBootstrapApplication(tree, parentPath, provideRootEffects);
} else {
addProviderToRoute(tree, parentPath, route, provideRootEffects);
}
Expand Down Expand Up @@ -91,8 +98,15 @@ function addStoreForFeatureImport(
storeForFeature: string
) {
if (isParentStandalone) {
if (tree.read(parentPath, 'utf-8').includes('ApplicationConfig')) {
const parentContents = tree.read(parentPath, 'utf-8');
if (parentContents.includes('ApplicationConfig')) {
addProviderToAppConfig(tree, parentPath, provideStoreForFeature);
} else if (parentContents.includes('bootstrapApplication')) {
addProviderToBootstrapApplication(
tree,
parentPath,
provideStoreForFeature
);
} else {
addProviderToRoute(tree, parentPath, route, provideStoreForFeature);
}
Expand All @@ -117,8 +131,15 @@ function addEffectsForFeatureImport(
effectsForFeature: string
) {
if (isParentStandalone) {
if (tree.read(parentPath, 'utf-8').includes('ApplicationConfig')) {
const parentContents = tree.read(parentPath, 'utf-8');
if (parentContents.includes('ApplicationConfig')) {
addProviderToAppConfig(tree, parentPath, provideEffectsForFeature);
} else if (parentContents.includes('bootstrapApplication')) {
addProviderToBootstrapApplication(
tree,
parentPath,
provideEffectsForFeature
);
} else {
addProviderToRoute(tree, parentPath, route, provideEffectsForFeature);
}
Expand Down

0 comments on commit 6728bbb

Please sign in to comment.