migration.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.default = default_1;
  11. const workspace_1 = require("../../utility/workspace");
  12. const TYPE_SCHEMATICS = ['component', 'directive', 'service'];
  13. const SEPARATOR_SCHEMATICS = ['guard', 'interceptor', 'module', 'pipe', 'resolver'];
  14. function default_1() {
  15. return (0, workspace_1.updateWorkspace)((workspace) => {
  16. let schematicsDefaults = workspace.extensions['schematics'];
  17. // Ensure "schematics" field is an object
  18. if (!schematicsDefaults ||
  19. typeof schematicsDefaults !== 'object' ||
  20. Array.isArray(schematicsDefaults)) {
  21. schematicsDefaults = workspace.extensions['schematics'] = {};
  22. }
  23. // Add "type" value for each schematic to continue generating a type suffix.
  24. // New default is an empty type value.
  25. for (const schematicName of TYPE_SCHEMATICS) {
  26. const schematic = (schematicsDefaults[`@schematics/angular:${schematicName}`] ??= {});
  27. if (typeof schematic === 'object' && !Array.isArray(schematic) && !('type' in schematic)) {
  28. schematic['type'] = schematicName;
  29. }
  30. }
  31. // Add "typeSeparator" value for each schematic to continue generating "." before type.
  32. // New default is an "-" type value.
  33. for (const schematicName of SEPARATOR_SCHEMATICS) {
  34. const schematic = (schematicsDefaults[`@schematics/angular:${schematicName}`] ??= {});
  35. if (typeof schematic === 'object' &&
  36. !Array.isArray(schematic) &&
  37. !('typeSeparator' in schematic)) {
  38. schematic['typeSeparator'] = '.';
  39. }
  40. }
  41. });
  42. }