Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ngcc): execute schematic-like migrations in ngcc #33279

Closed

Commits on Oct 23, 2019

  1. fix(ngcc): prevent reflected decorators from being clobbered

    ngcc has an internal cache of computed decorator information for
    reflected classes, which could previously be mutated by consumers of the
    reflection host. With the ability to inject synthesized decorators, such
    decorators would inadvertently be added into the array of decorators
    that was owned by the internal cache of the reflection host, incorrectly
    resulting in synthesized decorators to be considered real decorators on
    a class. This commit fixes the issue by cloning the cached array before
    returning it.
    JoostK committed Oct 23, 2019
    Configuration menu
    Copy the full SHA
    73437e7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    fd8b1a8 View commit details
    Browse the repository at this point in the history
  3. feat(ngcc): migrate services that are missing @Injectable()

    A class that is provided as Angular service is required to have an
    `@Injectable()` decorator so that the compiler generates its injectable
    definition for the runtime. Applications are automatically migrated
    using the "missing-injectable" schematic, however libraries built for
    older version of Angular may not yet satisfy this requirement.
    
    This commit ports the "missing-injectable" schematic to a migration that
    is ran when ngcc is processing a library. This ensures that any service
    that is provided from an NgModule or Directive/Component will have an
    `@Injectable()` decorator.
    JoostK committed Oct 23, 2019
    Configuration menu
    Copy the full SHA
    9642f89 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    be384d1 View commit details
    Browse the repository at this point in the history
  5. refactor(ivy): mark synthetic decorators explicitly

    In ngcc's migration system, synthetic decorators can be injected into a
    compilation to ensure that certain classes are compiled with Angular
    logic, where the original library code did not include the necessary
    decorators. Prior to this change, synthesized decorators would have a
    fake AST structure as associated node and a made-up identifier. In
    theory, this may introduce issues downstream:
    
    1) a decorator's node is used for diagnostics, so it must have position
    information. Having fake AST nodes without a position is therefore a
    problem. Note that this is currently not a problem in practice, as
    injected synthesized decorators would not produce any diagnostics.
    
    2) the decorator's identifier should refer to an imported symbol.
    Therefore, it is required that the symbol is actually imported.
    Moreover, bundle formats such as UMD and CommonJS use namespaces for
    imports, so a bare `ts.Identifier` would not be suitable to use as
    identifier. This was also not a problem in practice, as the identifier
    is only used in the `setClassMetadata` generated code, which is omitted
    for synthetically injected decorators.
    
    To remedy these potential issues, this commit makes a decorator's
    identifier optional and switches its node over from a fake AST structure
    to the class' name.
    JoostK committed Oct 23, 2019
    Configuration menu
    Copy the full SHA
    72882c4 View commit details
    Browse the repository at this point in the history
  6. refactor(ngcc): rework undecorated parent migration

    Previously, the (currently disabled) undecorated parent migration in
    ngcc would produce errors when a base class could not be determined
    statically or when a class extends from a class in another package. This
    is not ideal, as it would cause the library to fail compilation without
    a workaround, whereas those problems are not guaranteed to cause issues.
    
    Additionally, inheritance chains were not handled. This commit reworks
    the migration to address these limitations.
    JoostK committed Oct 23, 2019
    Configuration menu
    Copy the full SHA
    7960f91 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    72b67d6 View commit details
    Browse the repository at this point in the history
  8. feat(ngcc): enable migrations to apply schematics to libraries

    When upgrading an Angular application to a new version using the Angular
    CLI, built-in schematics are being run to update user code from
    deprecated patterns to the new way of working. For libraries that have
    been built for older versions of Angular however, such schematics have
    not been executed which means that deprecated code patterns may still be
    present, potentially resulting in incorrect behavior.
    
    Some of the logic of schematics has been ported over to ngcc migrations,
    which are automatically run on libraries. These migrations achieve the
    same goal of the regular schematics, but operating on published library
    sources instead of used code.
    JoostK committed Oct 23, 2019
    Configuration menu
    Copy the full SHA
    ebf596c View commit details
    Browse the repository at this point in the history