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

fix(mdc-migration): migrate components selectively bug #26427

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

llorenspujol
Copy link
Contributor

Fixes mdc-migration to migrate only the selected components.

Fixes #26426

Copy link
Contributor

@wagnermaciel wagnermaciel left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jan 31, 2023
@mmalerba mmalerba added merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed and removed action: merge The PR is ready for merge by the caretaker labels Jan 31, 2023
@mmalerba
Copy link
Contributor

@llorenspujol It looks like this change caused it to stop migrating legacy-core when using --components all. I've added a commit with the changes to the golden test so you can see what changed (easier to look at the github diff than the test output). In order to merge we'll need to fix. You can run yarn bazel run //integration/mdc-migration:test.approve to re-approve the golden test changes after making changes. Once fixed properly, it should just negate the changes in the commit I added.

@llorenspujol
Copy link
Contributor Author

llorenspujol commented Feb 2, 2023

@llorenspujol It looks like this change caused it to stop migrating legacy-core when using --components all. I've added a commit with the changes to the golden test so you can see what changed (easier to look at the github diff than the test output). In order to merge we'll need to fix. You can run yarn bazel run //integration/mdc-migration:test.approve to re-approve the golden test changes after making changes. Once fixed properly, it should just negate the changes in the commit I added.

Yes, I see, thanks for the commit. What is happening here is that MatLegacyOptionModule comes from 'legacy-core', not 'legacy-option', so it fails.
I just went straightforward, and to solve it, I always replace imports that come from 'legacy-core'. This solution is not 100% perfect, since if one user is not migrating any component related to MatOptionModule, it will either way migrate it. I think it is an edge case thought, since it may be very strange using the MatOptionModule alone, but it can happen.

The perfect solution may be one that resolves this test:

it('should not replace only mat legacy option module if not specified', async () => {
    await runMigrationTest(
      `
        import {NgModule} from '@angular/core';
        import {MatLegacyOptionModule, LEGACY_VERSION} from '@angular/material/legacy-core';
        @NgModule({imports: [MatLegacyOptionModule]})
        export class AppModule {}
      `,
      `
        import {NgModule} from '@angular/core';
        import {MatLegacyOptionModule} from '@angular/material/legacy-core';
        import {VERSION} from '@angular/material/core';
        @NgModule({imports: [MatLegacyOptionModule]})
        export class AppModule {}
      `,
    );
  });

In this test the LEGACY_VERSION is migrated, but not the MatLegacyOptionModule. IMO I think is really an edge case, and we can go with it as it is. That being said, if this test needs to be solved for X reasons, we can do it, I just want to first validate the task before putting any more effort on it!

@michaelfaith
Copy link

michaelfaith commented Feb 2, 2023

One thought, is you could have a separate const array that consists of the options.components that are exported from legacy-core (it may just be option in this case) and change the first condition to check if

(lastImportName  === 'legacy-core' && CORE_COMPONENTS.includes(componentMigrator.component))

@mmalerba
Copy link
Contributor

mmalerba commented Feb 2, 2023

I think it should be fine to only migrate core symbols when option or optgroup is chosen for migration. A check like the one @michaelfaith suggested should work for that

Fixes mdc-migration to migrate only the selected components.

Fixes angular#26426
@llorenspujol
Copy link
Contributor Author

Agreed, it makes more sense this way. I added the necessary changes to only migrate core symbols if option or optgroup is chosen for migration. The code is basically as @michaelfaith pointed out 👌

@michaelfaith
Copy link

I think all of the feedback items have been addressed on this. Or is there more to do?

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 28, 2023
@angular-robot angular-robot bot merged commit fba14dc into angular:main Feb 28, 2023
angular-robot bot pushed a commit that referenced this pull request Feb 28, 2023
…26427)

Fixes mdc-migration to migrate only the selected components.

(cherry picked from commit fba14dc)
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Mar 3, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`15.2.0` -> `15.2.1`](https://renovatebot.com/diffs/npm/@angular%2fcdk/15.2.0/15.2.1) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`15.2.0` -> `15.2.1`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/15.2.0/15.2.1) |

---

### Release Notes

<details>
<summary>angular/components</summary>

### [`v15.2.1`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1521-silicone-soliloquy-2023-03-01)

[Compare Source](angular/components@15.2.0...15.2.1)

#### Breaking Changes

#####

-   the description for body-1 and body-2 has changed

##### material

| Commit | Type | Description |
| -- | -- | -- |
| [9a57674fea](angular/components@9a57674) | fix | **chips:** allow attribute selectors for chips ([#&#8203;26683](angular/components#26683)) |
| [fdf1dc4b07](angular/components@fdf1dc4) | fix | **chips:** chips should assume their minimum density rather than error for small densities ([#&#8203;26688](angular/components#26688)) |
| [d61443b62d](angular/components@d61443b) | fix | **chips:** remove spans from top level of component ([#&#8203;26689](angular/components#26689)) |
| [5e67c1a345](angular/components@5e67c1a) | fix | **chips:** styling not updating when actions are removed ([#&#8203;26696](angular/components#26696)) |
| [a87735e4ba](angular/components@a87735e) | fix | **list:** add disabled attribute for mat-list-item buttons ([#&#8203;26672](angular/components#26672)) |
| [54d157f3d2](angular/components@54d157f) | fix | **schematics:** migrate to mdc components selectively bug ([#&#8203;26427](angular/components#26427)) |
| [4338e5ee57](angular/components@4338e5e) | fix | **snack-bar:** misaligned lines on safari for long messages ([#&#8203;26692](angular/components#26692)) |

#####

| Commit | Type | Description |
| -- | -- | -- |
| [b71fa77f7d](angular/components@b71fa77) | docs | reverse body-1 and body-2 typography description ([#&#8203;26330](angular/components#26330)) |

#### Special Thanks

Hamza jayri, Kristiyan Kostadinov, Matthieu Riegler, Miles Malerba, OneSidedPrism, VICTORIA JOHNSON and llorenspujol

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNTQuMSIsInVwZGF0ZWRJblZlciI6IjM0LjE1NC4xIn0=-->

Co-authored-by: cabr2-bot <[email protected]>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1800
Reviewed-by: Epsilon_02 <[email protected]>
Co-authored-by: Calciumdibromid Bot <[email protected]>
Co-committed-by: Calciumdibromid Bot <[email protected]>
@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 Mar 31, 2023
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 merge: fix commit message When the PR is merged, rewrites/fixups of the commit messages are needed target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(mdc-migration): Migrate components selectively is bugged
5 participants