UNPKG

5.69 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/schematics/src/ngrx-push-migration/index.ts"],"names":[],"mappings":";;;AAAA,+BAAiC;AACjC,yDAA+D;AAC/D,yDAU+B;AAE/B,IAAM,YAAY,GAAG,eAAe,CAAC;AACrC,IAAM,eAAe,GAAG,yBAAyB,CAAC;AAClD,IAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,IAAM,oBAAoB,GAAG,UAAC,IAAa;IACzC,OAAA,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe;AAAtD,CAAsD,CAAC;AAEzD,IAAM,eAAe,GAAG,UAAC,IAAa;IACpC,OAAA,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;QACrB,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC;AAD/D,CAC+D,CAAC;AAElE,SAAgB,iBAAiB;IAC/B,OAAO,UAAC,IAAU;QAChB,OAAA,IAAA,gCAAc,EAAC,IAAI,EAAE,UAAC,QAAQ;YAC5B,IAAI,KAA8B,CAAC;YACnC,IAAM,OAAO,GAAa,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE;gBAC7D,IAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAE3B,OAAO,CAAC,IAAI,CACV,IAAI,+BAAa,CACf,QAAQ,CAAC,QAAQ;gBACjB,oEAAoE;gBACpE,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAM,EAC7B,CAAC,EACD,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAC/B,CACF,CAAC;aACH;YAED,OAAO,IAAA,+BAAa,EAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAA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gBACjE,IAAM,OAAO,GAAa,IAAA,mCAAiB,EACzC,UAAU,EACV,UAAU,CAAC,QAAQ,EACnB,eAAe,EACf,gBAAgB,CACjB,CAAC;gBACF,IAAA,+BAAa,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;aACnD;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAtBD,sEAsBC;AAED;IACE,OAAO,IAAA,kBAAK,EAAC;QACX,iBAAiB,EAAE;QACnB,6BAA6B,EAAE;QAC/B,6BAA6B,EAAE;KAChC,CAAC,CAAC;AACL,CAAC;AAND,+BAMC","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 REACTIVE_MODULE = 'ReactiveComponentModule';\nconst COMPONENT_MODULE = '@ngrx/component';\n\nconst reactiveModuleToFind = (node: ts.Node) =>\n ts.isIdentifier(node) && node.text === REACTIVE_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 importReactiveComponentModule(): Rule {\n return (host: Tree) => {\n visitTSSourceFiles(host, (sourceFile) => {\n let hasCommonModuleOrBrowserModule = false;\n let hasReactiveComponentModule = false;\n\n visitNgModuleImports(sourceFile, (_, importNodes) => {\n hasCommonModuleOrBrowserModule = importNodes.some(ngModulesToFind);\n hasReactiveComponentModule = importNodes.some(reactiveModuleToFind);\n });\n\n if (hasCommonModuleOrBrowserModule && !hasReactiveComponentModule) {\n const changes: Change[] = addImportToModule(\n sourceFile,\n sourceFile.fileName,\n REACTIVE_MODULE,\n COMPONENT_MODULE\n );\n commitChanges(host, sourceFile.fileName, changes);\n }\n });\n };\n}\n\nexport function exportReactiveComponentModule(): Rule {\n return (host: Tree) => {\n visitTSSourceFiles(host, (sourceFile) => {\n let hasCommonModuleOrBrowserModule = false;\n let hasReactiveComponentModule = false;\n\n visitNgModuleExports(sourceFile, (_, exportNodes) => {\n hasCommonModuleOrBrowserModule = exportNodes.some(ngModulesToFind);\n hasReactiveComponentModule = exportNodes.some(reactiveModuleToFind);\n });\n\n if (hasCommonModuleOrBrowserModule && !hasReactiveComponentModule) {\n const changes: Change[] = addExportToModule(\n sourceFile,\n sourceFile.fileName,\n REACTIVE_MODULE,\n COMPONENT_MODULE\n );\n commitChanges(host, sourceFile.fileName, changes);\n }\n });\n };\n}\n\nexport default function (): Rule {\n return chain([\n migrateToNgrxPush(),\n importReactiveComponentModule(),\n exportReactiveComponentModule(),\n ]);\n}\n"]}
\No newline at end of file