fix(angular): handle ngrx imports for apps that do not migrate to config file (#16812)
This commit is contained in:
parent
7d42d887e3
commit
6728bbbc98
@ -6,6 +6,7 @@ import type { SourceFile } from 'typescript';
|
|||||||
import {
|
import {
|
||||||
addImportToModule,
|
addImportToModule,
|
||||||
addProviderToAppConfig,
|
addProviderToAppConfig,
|
||||||
|
addProviderToBootstrapApplication,
|
||||||
addProviderToModule,
|
addProviderToModule,
|
||||||
} from '../../../utils/nx-devkit/ast-utils';
|
} from '../../../utils/nx-devkit/ast-utils';
|
||||||
import type { NormalizedNgRxGeneratorOptions } from './normalize-options';
|
import type { NormalizedNgRxGeneratorOptions } from './normalize-options';
|
||||||
@ -23,8 +24,11 @@ function addRootStoreImport(
|
|||||||
storeForRoot: string
|
storeForRoot: string
|
||||||
) {
|
) {
|
||||||
if (isParentStandalone) {
|
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);
|
addProviderToAppConfig(tree, parentPath, provideRootStore);
|
||||||
|
} else if (parentContents.includes('bootstrapApplication')) {
|
||||||
|
addProviderToBootstrapApplication(tree, parentPath, provideRootStore);
|
||||||
} else {
|
} else {
|
||||||
addProviderToRoute(tree, parentPath, route, provideRootStore);
|
addProviderToRoute(tree, parentPath, route, provideRootStore);
|
||||||
}
|
}
|
||||||
@ -44,8 +48,11 @@ function addRootEffectsImport(
|
|||||||
effectsForEmptyRoot: string
|
effectsForEmptyRoot: string
|
||||||
) {
|
) {
|
||||||
if (isParentStandalone) {
|
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);
|
addProviderToAppConfig(tree, parentPath, provideRootEffects);
|
||||||
|
} else if (parentContents.includes('bootstrapApplication')) {
|
||||||
|
addProviderToBootstrapApplication(tree, parentPath, provideRootEffects);
|
||||||
} else {
|
} else {
|
||||||
addProviderToRoute(tree, parentPath, route, provideRootEffects);
|
addProviderToRoute(tree, parentPath, route, provideRootEffects);
|
||||||
}
|
}
|
||||||
@ -91,8 +98,15 @@ function addStoreForFeatureImport(
|
|||||||
storeForFeature: string
|
storeForFeature: string
|
||||||
) {
|
) {
|
||||||
if (isParentStandalone) {
|
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);
|
addProviderToAppConfig(tree, parentPath, provideStoreForFeature);
|
||||||
|
} else if (parentContents.includes('bootstrapApplication')) {
|
||||||
|
addProviderToBootstrapApplication(
|
||||||
|
tree,
|
||||||
|
parentPath,
|
||||||
|
provideStoreForFeature
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
addProviderToRoute(tree, parentPath, route, provideStoreForFeature);
|
addProviderToRoute(tree, parentPath, route, provideStoreForFeature);
|
||||||
}
|
}
|
||||||
@ -117,8 +131,15 @@ function addEffectsForFeatureImport(
|
|||||||
effectsForFeature: string
|
effectsForFeature: string
|
||||||
) {
|
) {
|
||||||
if (isParentStandalone) {
|
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);
|
addProviderToAppConfig(tree, parentPath, provideEffectsForFeature);
|
||||||
|
} else if (parentContents.includes('bootstrapApplication')) {
|
||||||
|
addProviderToBootstrapApplication(
|
||||||
|
tree,
|
||||||
|
parentPath,
|
||||||
|
provideEffectsForFeature
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
addProviderToRoute(tree, parentPath, route, provideEffectsForFeature);
|
addProviderToRoute(tree, parentPath, route, provideEffectsForFeature);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user