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AO,GAAa,IAAA,mCAAiB,EACzC,UAAU,EACV,UAAU,CAAC,QAAQ,EACnB,WAAW,EACX,gBAAgB,CACjB,CAAC;gBACF,IAAA,+BAAa,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACpD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAtBD,4CAsBC;AAED;IACE,OAAO,IAAA,kBAAK,EAAC,CAAC,iBAAiB,EAAE,EAAE,gBAAgB,EAAE,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC;AAC9E,CAAC;AAFD,4BAEC","sourcesContent":["import * as ts from 'typescript';\nimport { Tree, Rule, chain } from '@angular-devkit/schematics';\nimport {\n commitChanges,\n visitTemplates,\n ReplaceChange,\n Change,\n visitTSSourceFiles,\n visitNgModuleImports,\n visitNgModuleExports,\n addImportToModule,\n addExportToModule,\n} from '../../schematics-core';\n\nconst ASYNC_REGEXP = /\\| {0,}async/g;\nconst PUSH_MODULE = 'PushModule';\nconst COMPONENT_MODULE = '@ngrx/component';\n\nconst pushModuleToFind = (node: ts.Node) =>\n ts.isIdentifier(node) && node.text === PUSH_MODULE;\n\nconst ngModulesToFind = (node: ts.Node) =>\n ts.isIdentifier(node) &&\n (node.text === 'CommonModule' || node.text === 'BrowserModule');\n\nexport function migrateToNgrxPush(): Rule {\n return (host: Tree) =>\n visitTemplates(host, (template) => {\n let match: RegExpMatchArray | null;\n const changes: Change[] = [];\n while ((match = ASYNC_REGEXP.exec(template.content)) !== null) {\n const m = match.toString();\n\n changes.push(\n new ReplaceChange(\n template.fileName,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n template.start + match.index!,\n m,\n m.replace('async', 'ngrxPush')\n )\n );\n }\n\n return commitChanges(host, template.fileName, changes);\n });\n}\n\nexport function importPushModule(): Rule {\n return (host: Tree) => {\n visitTSSourceFiles(host, (sourceFile) => {\n let hasCommonModuleOrBrowserModule = false;\n let hasPushModule = false;\n\n visitNgModuleImports(sourceFile, (_, importNodes) => {\n hasCommonModuleOrBrowserModule = importNodes.some(ngModulesToFind);\n hasPushModule = importNodes.some(pushModuleToFind);\n });\n\n if (hasCommonModuleOrBrowserModule && !hasPushModule) {\n const changes: Change[] = addImportToModule(\n sourceFile,\n sourceFile.fileName,\n PUSH_MODULE,\n COMPONENT_MODULE\n );\n commitChanges(host, sourceFile.fileName, changes);\n }\n });\n };\n}\n\nexport function exportPushModule(): Rule {\n return (host: Tree) => {\n visitTSSourceFiles(host, (sourceFile) => {\n let hasCommonModuleOrBrowserModule = false;\n let hasPushModule = false;\n\n visitNgModuleExports(sourceFile, (_, exportNodes) => {\n hasCommonModuleOrBrowserModule = exportNodes.some(ngModulesToFind);\n hasPushModule = exportNodes.some(pushModuleToFind);\n });\n\n if (hasCommonModuleOrBrowserModule && !hasPushModule) {\n const changes: Change[] = addExportToModule(\n sourceFile,\n sourceFile.fileName,\n PUSH_MODULE,\n COMPONENT_MODULE\n );\n commitChanges(host, sourceFile.fileName, changes);\n }\n });\n };\n}\n\nexport default function (): Rule {\n return chain([migrateToNgrxPush(), importPushModule(), exportPushModule()]);\n}\n"]} |