"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); exports.isDevkitMigration = exports.createMigrationSchematicRule = exports.cdkMigrations = void 0; const tasks_1 = require("@angular-devkit/schematics/tasks"); const update_tool_1 = require("../update-tool"); const project_tsconfig_paths_1 = require("../utils/project-tsconfig-paths"); const devkit_file_system_1 = require("./devkit-file-system"); const devkit_migration_1 = require("./devkit-migration"); const find_stylesheets_1 = require("./find-stylesheets"); const attribute_selectors_1 = require("./migrations/attribute-selectors"); const class_inheritance_1 = require("./migrations/class-inheritance"); const class_names_1 = require("./migrations/class-names"); const constructor_signature_1 = require("./migrations/constructor-signature"); const css_selectors_1 = require("./migrations/css-selectors"); const element_selectors_1 = require("./migrations/element-selectors"); const input_names_1 = require("./migrations/input-names"); const method_call_arguments_1 = require("./migrations/method-call-arguments"); const misc_template_1 = require("./migrations/misc-template"); const output_names_1 = require("./migrations/output-names"); const property_names_1 = require("./migrations/property-names"); const symbol_removal_1 = require("./migrations/symbol-removal"); /** List of migrations which run for the CDK update. */ exports.cdkMigrations = [ attribute_selectors_1.AttributeSelectorsMigration, class_inheritance_1.ClassInheritanceMigration, class_names_1.ClassNamesMigration, constructor_signature_1.ConstructorSignatureMigration, css_selectors_1.CssSelectorsMigration, element_selectors_1.ElementSelectorsMigration, input_names_1.InputNamesMigration, method_call_arguments_1.MethodCallArgumentsMigration, misc_template_1.MiscTemplateMigration, output_names_1.OutputNamesMigration, property_names_1.PropertyNamesMigration, symbol_removal_1.SymbolRemovalMigration, ]; /** * Creates a Angular schematic rule that runs the upgrade for the * specified target version. */ function createMigrationSchematicRule(targetVersion, extraMigrations, upgradeData, onMigrationCompleteFn) { return async (tree, context) => { const logger = context.logger; const workspace = await (0, project_tsconfig_paths_1.getWorkspaceConfigGracefully)(tree); if (workspace === null) { logger.error('Could not find workspace configuration file.'); return; } // Keep track of all project source files which have been checked/migrated. This is // necessary because multiple TypeScript projects can contain the same source file and // we don't want to check these again, as this would result in duplicated failure messages. const analyzedFiles = new Set(); const fileSystem = new devkit_file_system_1.DevkitFileSystem(tree); const projectNames = workspace.projects.keys(); const migrations = [...exports.cdkMigrations, ...extraMigrations]; let hasFailures = false; for (const projectName of projectNames) { const project = workspace.projects.get(projectName); const buildTsconfigPath = (0, project_tsconfig_paths_1.getTargetTsconfigPath)(project, 'build'); const testTsconfigPath = (0, project_tsconfig_paths_1.getTargetTsconfigPath)(project, 'test'); if (!buildTsconfigPath && !testTsconfigPath) { logger.warn(`Skipping migration for project ${projectName}. Unable to determine 'tsconfig.json' file in workspace config.`); continue; } // In some applications, developers will have global stylesheets which are not // specified in any Angular component. Therefore we glob up all CSS and SCSS files // in the project and migrate them if needed. // TODO: rework this to collect global stylesheets from the workspace config. // TODO: https://github.com/angular/components/issues/24032. const additionalStylesheetPaths = (0, find_stylesheets_1.findStylesheetFiles)(tree, project.root); if (buildTsconfigPath !== null) { runMigrations(project, projectName, buildTsconfigPath, additionalStylesheetPaths, false); } if (testTsconfigPath !== null) { runMigrations(project, projectName, testTsconfigPath, additionalStylesheetPaths, true); } } let runPackageManager = false; // Run the global post migration static members for all // registered devkit migrations. migrations.forEach(m => { const actionResult = isDevkitMigration(m) && m.globalPostMigration !== undefined ? m.globalPostMigration(tree, targetVersion, context) : null; if (actionResult) { runPackageManager = runPackageManager || actionResult.runPackageManager; } }); // If a migration requested the package manager to run, we run it as an // asynchronous post migration task. We cannot run it synchronously, // as file changes from the current migration task are not applied to // the file system yet. if (runPackageManager) { context.addTask(new tasks_1.NodePackageInstallTask({ quiet: false })); } if (onMigrationCompleteFn) { onMigrationCompleteFn(context, targetVersion, hasFailures); } /** Runs the migrations for the specified workspace project. */ function runMigrations(project, projectName, tsconfigPath, additionalStylesheetPaths, isTestTarget) { const program = update_tool_1.UpdateProject.createProgramFromTsconfig(tsconfigPath, fileSystem); const updateContext = { isTestTarget, projectName, project, tree, }; const updateProject = new update_tool_1.UpdateProject(updateContext, program, fileSystem, analyzedFiles, context.logger); const result = updateProject.migrate(migrations, targetVersion, upgradeData, additionalStylesheetPaths); // Commit all recorded edits in the update recorder. We apply the edits after all // migrations ran because otherwise offsets in the TypeScript program would be // shifted and individual migrations could no longer update the same source file. fileSystem.commitEdits(); hasFailures = hasFailures || result.hasFailures; } }; } exports.createMigrationSchematicRule = createMigrationSchematicRule; /** Whether the given migration type refers to a devkit migration */ function isDevkitMigration(value) { return devkit_migration_1.DevkitMigration.isPrototypeOf(value); } exports.isDevkitMigration = isDevkitMigration; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGV2a2l0LW1pZ3JhdGlvbi1ydWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9zY2hlbWF0aWNzL25nLXVwZGF0ZS9kZXZraXQtbWlncmF0aW9uLXJ1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7R0FNRzs7O0FBR0gsNERBQXdFO0FBR3hFLGdEQUE2QztBQUk3Qyw0RUFBb0c7QUFFcEcsNkRBQXNEO0FBQ3RELHlEQUF1RjtBQUN2Rix5REFBdUQ7QUFDdkQsMEVBQTZFO0FBQzdFLHNFQUF5RTtBQUN6RSwwREFBNkQ7QUFDN0QsOEVBQWlGO0FBQ2pGLDhEQUFpRTtBQUNqRSxzRUFBeUU7QUFDekUsMERBQTZEO0FBQzdELDhFQUFnRjtBQUNoRiw4REFBaUU7QUFDakUsNERBQStEO0FBQy9ELGdFQUFtRTtBQUVuRSxnRUFBbUU7QUFFbkUsdURBQXVEO0FBQzFDLFFBQUEsYUFBYSxHQUFpQztJQUN6RCxpREFBMkI7SUFDM0IsNkNBQXlCO0lBQ3pCLGlDQUFtQjtJQUNuQixxREFBNkI7SUFDN0IscUNBQXFCO0lBQ3JCLDZDQUF5QjtJQ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