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

Function migrate

packages/core/schematics/ng-generate/inject-migration/index.ts:24–64  ·  view source on GitHub ↗
(options: Options)

Source from the content-addressed store, hash-verified

22}
23
24export function migrate(options: Options): Rule {
25 return async (tree: Tree, context: SchematicContext) => {
26 const basePath = process.cwd();
27 let pathToMigrate: string | undefined;
28 if (options.path) {
29 if (options.path.startsWith('..')) {
30 throw new SchematicsException(
31 'Cannot run inject migration outside of the current project.',
32 );
33 }
34 pathToMigrate = normalizePath(join(basePath, options.path));
35 }
36
37 const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree);
38 const allPaths = [...buildPaths, ...testPaths];
39
40 if (!allPaths.length) {
41 context.logger.warn('Could not find any tsconfig file. Cannot run the inject migration.');
42 return;
43 }
44
45 let sourceFilesCount = 0;
46
47 for (const tsconfigPath of allPaths) {
48 const program = createMigrationProgram(tree, tsconfigPath, basePath);
49 const sourceFiles = program
50 .getSourceFiles()
51 .filter(
52 (sourceFile) =>
53 (pathToMigrate ? sourceFile.fileName.startsWith(pathToMigrate) : true) &&
54 canMigrateFile(basePath, sourceFile, program),
55 );
56
57 sourceFilesCount += runInjectMigration(tree, sourceFiles, basePath, options);
58 }
59
60 if (sourceFilesCount === 0) {
61 context.logger.warn('Inject migration did not find any files to migrate');
62 }
63 };
64}
65
66function runInjectMigration(
67 tree: Tree,

Callers

nothing calls this directly

Calls 8

normalizePathFunction · 0.90
getProjectTsConfigPathsFunction · 0.90
createMigrationProgramFunction · 0.90
canMigrateFileFunction · 0.90
joinFunction · 0.85
runInjectMigrationFunction · 0.85
warnMethod · 0.65
filterMethod · 0.45

Tested by

no test coverage detected