Skip to content

Switch theming API migration to ng update and other fixes #22628

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

Merged
merged 5 commits into from
May 7, 2021

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented May 5, 2021

Split up into several commits that include the following changes:

  1. Switches the themingApi migration from ng generate to ng update as discussed. This required some adjustments to the code that is called by the CLI, as well as some changes to the unit test setup.
  2. Fixes an issue where external stylesheets weren't being picked up as expected. This one is by @devversion.
  3. Updates the migration logic not to migrate unprefixed deprecated variables if there is no Material import. This can technically leave some transient dependencies unmigrated, but since their names are very generic, we can't guarantee that the user is referring to our variable. This commit also expands the list of variables that will be migrated.
  4. Based on external feedback, it adds a message at the end of the migration.
  5. Fixes an issue where the @use statement for the new API would be inserted too far down in the file, if the file only has one @import statement which is placed further down too. This results in a compilation error, because @use statements have to be at the top.

@crisbeto crisbeto added P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful merge safe merge: preserve commits When the PR is merged, a rebase and merge should be performed target: rc This PR is targeted for the next release-candidate labels May 5, 2021
@crisbeto crisbeto requested review from jelbourn and devversion May 5, 2021 15:29
@google-cla

This comment has been minimized.

@google-cla google-cla bot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label May 5, 2021
@josephperrott josephperrott added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels May 5, 2021
@crisbeto crisbeto force-pushed the theming-api-ng-update branch from 7a17485 to ec7ebff Compare May 5, 2021 15:37
@google-cla

This comment has been minimized.

@google-cla google-cla bot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels May 5, 2021
@devversion
Copy link
Member

@googlebot I consent.

@google-cla google-cla bot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels May 5, 2021
@crisbeto crisbeto added this to the 12.0.0 milestone May 5, 2021
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 One minor comment.

const count = ThemingApiMigration.migratedFileCount;

if (count > 0) {
context.logger.info(`Migrated ${count === 1 ? `${count} files` : `1 file`} to the ` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ternary needs to be inversed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, out of curiosity, is there a doc/guide we could link too? that might be nice to see when the migration ran.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we have a doc about the migration in particular. It'll be mentioned in the changelog.

@crisbeto crisbeto force-pushed the theming-api-ng-update branch from ec7ebff to 70343d7 Compare May 5, 2021 16:32
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label May 5, 2021
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

crisbeto and others added 5 commits May 6, 2021 20:08
Switches the `themingApi` migration from `ng generate` to `ng update`. Includes refactoring it into a `DevkitMigration` and changing the test setup to match.
Stylesheets which aren't referneced as part of any component
are also candidates for migration. We search for such stylesheets
by recursing through the virtual devkit tree. This logic is currently
not working for cases where project targets have a `root` set within
the Angular CLI workspace configuration. It breaks because we do not
build up a workspace-relative path, but instead only collect the file
names.

Signed-off-by: Kristiyan Kostadinov <[email protected]>
…e is an import

Changes the migration logic so that variables without a `mat-` or `cdk-` prefix are only migrated if there is an explicit Material import. This aims to prevent accidental renames for variables that we don't own.

Also adds a few variables that were previously skipped.
…tion

Based on external feedback, adds a message with the number of migrated files at the end of the theming API migration.
…se statement at the top of the file in some cases

Our logic for determining where to insert an `@use` statement is to look for the first `@import` and insert before it. The problem is that if the theming import is the only one in the file and it's further down, we'll insert it incorrectly, because `@use` has to always be above other statements.
@crisbeto crisbeto force-pushed the theming-api-ng-update branch from 70343d7 to d5f2935 Compare May 6, 2021 18:08
@mmalerba mmalerba merged commit cd12aa7 into angular:master May 7, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement merge: preserve commits When the PR is merged, a rebase and merge should be performed P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants