From 380f7abd8dde41b9869e7b97669cc9d616bc6b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=89=B2?= Date: Wed, 18 Sep 2024 15:03:05 +0800 Subject: [PATCH] fix(cli): fix could not find any [routes] variable (#1832) --- schematics/utils/alain.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/schematics/utils/alain.ts b/schematics/utils/alain.ts index 00a1ca6e2c..4756904040 100644 --- a/schematics/utils/alain.ts +++ b/schematics/utils/alain.ts @@ -16,9 +16,9 @@ import { } from '@angular-devkit/schematics'; import { Schema as ComponentSchema } from '@schematics/angular/component/schema'; import { - findNode, insertImport, - addProviderToModule as _addProviderToModule + addProviderToModule as _addProviderToModule, + getSourceNodes } from '@schematics/angular/utility/ast-utils'; import { InsertChange } from '@schematics/angular/utility/change'; import { buildRelativePath, findModuleFromOptions, ModuleOptions } from '@schematics/angular/utility/find-module'; @@ -32,8 +32,6 @@ import { addServiceToModuleOrStandalone, findRoutesPath, getSourceFile, ROUTINS_ import { isStandalone } from './standalone'; import { getProject, NgAlainProjectDefinition } from './workspace'; -const TEMPLATE_FILENAME_RE = /\.template$/; - export interface CommonSchema extends ComponentSchema { // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any; @@ -178,7 +176,9 @@ export function addValueToVariable( needWrap: boolean = true ): void { const source = getSourceFile(tree, filePath); - const node = findNode(source, ts.SyntaxKind.Identifier, variableName); + const node = getSourceNodes(source).find( + node => node.kind == ts.SyntaxKind.Identifier && node.getText() === variableName + ); if (!node) { throw new SchematicsException(`Could not find any [${variableName}] variable in path '${filePath}'.`); }