MCPcopy Create free account
hub / github.com/angular/angular / migrate

Function migrate

packages/core/schematics/ng-generate/output-migration/index.ts:18–72  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

16}
17
18export function migrate(options: Options): Rule {
19 return async (tree, context) => {
20 await runMigrationInDevkit({
21 tree,
22 getMigration: (fs) =>
23 new OutputMigration({
24 shouldMigrate: (_, file) => {
25 return (
26 file.rootRelativePath.startsWith(fs.normalize(options.path)) &&
27 !/(^|\/)node_modules\//.test(file.rootRelativePath)
28 );
29 },
30 }),
31 beforeProgramCreation: (tsconfigPath, stage) => {
32 if (stage === MigrationStage.Analysis) {
33 context.logger.info(`Preparing analysis for: ${tsconfigPath}...`);
34 } else {
35 context.logger.info(`Running migration for: ${tsconfigPath}...`);
36 }
37 },
38 afterProgramCreation: (info, fs) => {
39 const analysisPath = fs.resolve(options.analysisDir);
40
41 // Support restricting the analysis to subfolders for larger projects.
42 if (analysisPath !== '/') {
43 info.sourceFiles = info.sourceFiles.filter((sf) => sf.fileName.startsWith(analysisPath));
44 info.fullProgramSourceFiles = info.fullProgramSourceFiles.filter((sf) =>
45 sf.fileName.startsWith(analysisPath),
46 );
47 }
48 },
49 beforeUnitAnalysis: (tsconfigPath) => {
50 context.logger.info(`Scanning for outputs: ${tsconfigPath}...`);
51 },
52 afterAllAnalyzed: () => {
53 context.logger.info(``);
54 context.logger.info(`Processing analysis data between targets...`);
55 context.logger.info(``);
56 },
57 afterAnalysisFailure: () => {
58 context.logger.error('Migration failed unexpectedly with no analysis data');
59 },
60 whenDone: ({detectedOutputs, problematicOutputs, successRate}) => {
61 const migratedOutputs = detectedOutputs - problematicOutputs;
62 const successRatePercent = (successRate * 100).toFixed(2);
63
64 context.logger.info('');
65 context.logger.info(`Successfully migrated to outputs as functions 🎉`);
66 context.logger.info(
67 ` -> Migrated ${migratedOutputs} out of ${detectedOutputs} detected outputs (${successRatePercent} %).`,
68 );
69 },
70 });
71 };
72}

Callers

nothing calls this directly

Calls 7

runMigrationInDevkitFunction · 0.90
normalizeMethod · 0.65
infoMethod · 0.65
resolveMethod · 0.65
errorMethod · 0.65
testMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected