-
Notifications
You must be signed in to change notification settings - Fork 11.9k
fix(@angular/cli): discover migrations and schematics from installed packages when omitted by registry metadata #33718
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
Closed
alan-agius4
wants to merge
3
commits into
angular:main
from
alan-agius4:fix-update-github-packages-migrations-fallback
+186
−18
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
3ec4367
fix(@angular/cli): discover migrations from installed packages when o…
alan-agius4 c957ded
fix(@angular/cli): always install package during ng add to inspect ma…
alan-agius4 78a2b68
fixup! fix(@angular/cli): discover migrations from installed packages…
alan-agius4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /** | ||
| * @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.dev/license | ||
| */ | ||
|
|
||
| import assert from 'node:assert'; | ||
| import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import path from 'path'; | ||
| import { resolveFallbackMigrations } from './cli'; | ||
| import type { PackageVersionInfo, UpdatePlan } from './update-resolver'; | ||
|
|
||
| describe('resolveFallbackMigrations', () => { | ||
| let tempRoot: string; | ||
| let pkgDir: string; | ||
| beforeEach(async () => { | ||
| const baseTmpDir = process.env['TEST_TMPDIR']; | ||
| assert(baseTmpDir, 'TEST_TMPDIR is not set'); | ||
| tempRoot = await mkdtemp(path.join(baseTmpDir, 'angular-cli-update-cli-test-')); | ||
| pkgDir = path.join(tempRoot, 'node_modules/@company/library-name'); | ||
| await mkdir(pkgDir, { recursive: true }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await rm(tempRoot, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('discovers migrations from installed package.json when omitted from plan.migrationsToRun', async () => { | ||
| await writeFile( | ||
| path.join(pkgDir, 'package.json'), | ||
| JSON.stringify({ | ||
| name: '@company/library-name', | ||
| version: '21.2.0-next.1', | ||
| 'ng-update': { | ||
| migrations: './schematics/migration.json', | ||
| }, | ||
| }), | ||
| 'utf8', | ||
| ); | ||
|
|
||
| const plan: UpdatePlan = { | ||
| packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), | ||
| migrationsToRun: [], | ||
| packageInfoMap: new Map([ | ||
| [ | ||
| '@company/library-name', | ||
| { | ||
| name: '@company/library-name', | ||
| npmPackageJson: { | ||
| name: '@company/library-name', | ||
| versions: ['21.1.0', '21.2.0-next.1'], | ||
| 'dist-tags': {}, | ||
| }, | ||
| installed: { | ||
| version: '21.1.0' as unknown as PackageVersionInfo['version'], | ||
| packageJson: { name: '@company/library-name', version: '21.1.0' }, | ||
| updateMetadata: { packageGroup: {}, requirements: {} }, | ||
| }, | ||
| packageJsonRange: '^21.1.0', | ||
| }, | ||
| ], | ||
| ]), | ||
| registryClient: undefined as unknown as UpdatePlan['registryClient'], | ||
| }; | ||
|
|
||
| const migrations = await resolveFallbackMigrations(tempRoot, plan); | ||
|
|
||
| expect(migrations).toEqual([ | ||
| { | ||
| package: '@company/library-name', | ||
| collection: './schematics/migration.json', | ||
| from: '21.1.0', | ||
| to: '21.2.0-next.1', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('does not duplicate migration if package is already in plan.migrationsToRun', async () => { | ||
| await writeFile( | ||
| path.join(pkgDir, 'package.json'), | ||
| JSON.stringify({ | ||
| name: '@company/library-name', | ||
| version: '21.2.0-next.1', | ||
| 'ng-update': { | ||
| migrations: './schematics/migration.json', | ||
| }, | ||
| }), | ||
| 'utf8', | ||
| ); | ||
|
|
||
| const plan: UpdatePlan = { | ||
| packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), | ||
| migrationsToRun: [ | ||
| { | ||
| package: '@company/library-name', | ||
| collection: './schematics/migration.json', | ||
| from: '21.1.0', | ||
| to: '21.2.0-next.1', | ||
| }, | ||
| ], | ||
| packageInfoMap: new Map(), | ||
| registryClient: undefined as unknown as UpdatePlan['registryClient'], | ||
| }; | ||
|
|
||
| const migrations = await resolveFallbackMigrations(tempRoot, plan); | ||
|
|
||
| expect(migrations).toHaveSize(1); | ||
| }); | ||
|
|
||
| it('returns unchanged migrations when package has no ng-update field on disk', async () => { | ||
| await writeFile( | ||
| path.join(pkgDir, 'package.json'), | ||
| JSON.stringify({ | ||
| name: '@company/library-name', | ||
| version: '21.2.0-next.1', | ||
| }), | ||
| 'utf8', | ||
| ); | ||
|
|
||
| const plan: UpdatePlan = { | ||
| packagesToUpdate: new Map([['@company/library-name', '21.2.0-next.1']]), | ||
| migrationsToRun: [], | ||
| packageInfoMap: new Map(), | ||
| registryClient: undefined as unknown as UpdatePlan['registryClient'], | ||
| }; | ||
|
|
||
| const migrations = await resolveFallbackMigrations(tempRoot, plan); | ||
|
|
||
| expect(migrations).toHaveSize(0); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.