-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(migrations): Disabling nullishCoalescingNotNullable & optionalChainNotNullable on ng update #68080
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
kirjs
merged 1 commit into
angular:main
from
aparzi:migration-strict-safe-navigation-narrow
Apr 13, 2026
Merged
feat(migrations): Disabling nullishCoalescingNotNullable & optionalChainNotNullable on ng update #68080
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions
40
packages/core/schematics/migrations/strict-safe-navigation-narrow/BUILD.bazel
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,40 @@ | ||
| load("//tools:defaults.bzl", "jasmine_test", "ts_project") | ||
|
|
||
| package( | ||
| default_visibility = [ | ||
| "//packages/core/schematics:__pkg__", | ||
| "//packages/core/schematics/test:__pkg__", | ||
| ], | ||
| ) | ||
|
|
||
| ts_project( | ||
| name = "strict-safe-navigation-narrow", | ||
| srcs = glob( | ||
| ["**/*.ts"], | ||
| exclude = ["*.spec.ts"], | ||
| ), | ||
| deps = [ | ||
| "//:node_modules/@angular-devkit/core", | ||
| "//:node_modules/@angular-devkit/schematics", | ||
| "//:node_modules/@schematics/angular", | ||
| "//packages/core/schematics/utils", | ||
| ], | ||
| ) | ||
|
|
||
| ts_project( | ||
| name = "test_lib", | ||
| testonly = True, | ||
| srcs = glob(["*.spec.ts"]), | ||
| deps = [ | ||
| ":strict-safe-navigation-narrow", | ||
| "//:node_modules/@angular-devkit/core", | ||
| "//:node_modules/@angular-devkit/schematics", | ||
| "//:node_modules/@schematics/angular", | ||
| "//packages/core/schematics/utils", | ||
| ], | ||
| ) | ||
|
|
||
| jasmine_test( | ||
| name = "test", | ||
| data = [":test_lib"], | ||
| ) |
40 changes: 40 additions & 0 deletions
40
packages/core/schematics/migrations/strict-safe-navigation-narrow/index.ts
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,40 @@ | ||
| /** | ||
| * @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 {Rule, Tree} from '@angular-devkit/schematics'; | ||
| import {getProjectTsConfigPaths} from '../../utils/project_tsconfig_paths'; | ||
| import {JSONFile} from '@schematics/angular/utility/json-file'; | ||
|
|
||
| export function migrate(): Rule { | ||
| return async (tree: Tree) => { | ||
| const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree); | ||
| const allPaths = [...new Set([...buildPaths, ...testPaths])]; | ||
|
|
||
| for (const tsconfigPath of allPaths) { | ||
| const json = new JSONFile(tree, tsconfigPath); | ||
| const compilerOptions = json.get(['compilerOptions']); | ||
|
|
||
| if ( | ||
| !compilerOptions || | ||
| typeof compilerOptions !== 'object' || | ||
| Object.keys(compilerOptions).length === 0 | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| json.modify( | ||
| ['angularCompilerOptions', 'extendedDiagnostics', 'checks', 'nullishCoalescingNotNullable'], | ||
| 'suppress', | ||
| ); | ||
| json.modify( | ||
| ['angularCompilerOptions', 'extendedDiagnostics', 'checks', 'optionalChainNotNullable'], | ||
| 'suppress', | ||
| ); | ||
| } | ||
| }; | ||
| } | ||
141 changes: 141 additions & 0 deletions
141
packages/core/schematics/migrations/strict-safe-navigation-narrow/migration.spec.ts
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,141 @@ | ||
| /** | ||
| * @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 {HostTree} from '@angular-devkit/schematics'; | ||
| import {UnitTestTree} from '@angular-devkit/schematics/testing/index.js'; | ||
| import {migrate} from './index'; | ||
|
|
||
| function parseConfig(tree: UnitTestTree, path: string) { | ||
| return JSON.parse(tree.readContent(path).replace(/\/\/.*$/gm, '')); | ||
| } | ||
|
|
||
| describe('strict-safe-navigation-narrow migration', () => { | ||
| let tree: UnitTestTree; | ||
|
|
||
| beforeEach(() => { | ||
| tree = new UnitTestTree(new HostTree()); | ||
| tree.create( | ||
| '/angular.json', | ||
| JSON.stringify({ | ||
| version: 1, | ||
| projects: { | ||
| t: { | ||
| root: '', | ||
| architect: { | ||
| build: { | ||
| options: { | ||
| tsConfig: './tsconfig.json', | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('should not add options if compilerOptions is empty', async () => { | ||
| tree.create( | ||
| '/tsconfig.json', | ||
| JSON.stringify({ | ||
| compilerOptions: {}, | ||
| }), | ||
| ); | ||
|
|
||
| const runMigration = migrate(); | ||
| await runMigration(tree, {} as any); | ||
|
|
||
| const tsconfig = parseConfig(tree, '/tsconfig.json'); | ||
| expect(tsconfig.angularCompilerOptions).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should not add options if compilerOptions is missing', async () => { | ||
| tree.create('/tsconfig.json', JSON.stringify({})); | ||
|
|
||
| const runMigration = migrate(); | ||
| await runMigration(tree, {} as any); | ||
|
|
||
| const tsconfig = parseConfig(tree, '/tsconfig.json'); | ||
| expect(tsconfig.angularCompilerOptions).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should add suppress options if compilerOptions is not empty', async () => { | ||
| tree.create( | ||
| '/tsconfig.json', | ||
| JSON.stringify({ | ||
| compilerOptions: { | ||
| target: 'es2020', | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const runMigration = migrate(); | ||
| await runMigration(tree, {} as any); | ||
|
|
||
| const tsconfig = parseConfig(tree, '/tsconfig.json'); | ||
| expect( | ||
| tsconfig.angularCompilerOptions.extendedDiagnostics.checks.nullishCoalescingNotNullable, | ||
| ).toBe('suppress'); | ||
| expect( | ||
| tsconfig.angularCompilerOptions.extendedDiagnostics.checks.optionalChainNotNullable, | ||
| ).toBe('suppress'); | ||
| }); | ||
|
|
||
| it('should preserve existing checks', async () => { | ||
| tree.create( | ||
| '/tsconfig.json', | ||
| JSON.stringify({ | ||
| compilerOptions: { | ||
| target: 'es2020', | ||
| }, | ||
| angularCompilerOptions: { | ||
| extendedDiagnostics: { | ||
| checks: { | ||
| somethingElse: 'warning', | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| const runMigration = migrate(); | ||
| await runMigration(tree, {} as any); | ||
|
|
||
| const tsconfig = parseConfig(tree, '/tsconfig.json'); | ||
| expect(tsconfig.angularCompilerOptions.extendedDiagnostics.checks.somethingElse).toBe( | ||
| 'warning', | ||
| ); | ||
| expect( | ||
| tsconfig.angularCompilerOptions.extendedDiagnostics.checks.nullishCoalescingNotNullable, | ||
| ).toBe('suppress'); | ||
| expect( | ||
| tsconfig.angularCompilerOptions.extendedDiagnostics.checks.optionalChainNotNullable, | ||
| ).toBe('suppress'); | ||
| }); | ||
|
|
||
| it('should handle tsconfig with comments', async () => { | ||
| tree.create( | ||
| '/tsconfig.json', | ||
| `{ | ||
| // This is a comment | ||
| "compilerOptions": { | ||
| "target": "es2020" | ||
| } | ||
| }`, | ||
| ); | ||
|
|
||
| const runMigration = migrate(); | ||
| await runMigration(tree, {} as any); | ||
|
|
||
| const tsconfig = parseConfig(tree, '/tsconfig.json'); | ||
| expect(tsconfig.compilerOptions.target).toBe('es2020'); | ||
| expect( | ||
| tsconfig.angularCompilerOptions.extendedDiagnostics.checks.nullishCoalescingNotNullable, | ||
| ).toBe('suppress'); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.