-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): remove deprecated
defaultCollection
from worksp…
…ace configuration The deprecated 'defaultCollection' workspace option has been removed BREAKING CHANGE: The deprecated `defaultCollection` workspace option has been removed. Use `schematicCollections` instead. Before ```json "defaultCollection": "@angular/material" ``` After ```json "schematicCollections": ["@angular/material"] ```
- Loading branch information
1 parent
d58428d
commit 6802423
Showing
6 changed files
with
142 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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
35 changes: 35 additions & 0 deletions
35
packages/schematics/angular/migrations/update-16/replace-default-collection-option.ts
This file contains 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,35 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import { JsonValue, isJsonObject } from '@angular-devkit/core'; | ||
import { Rule } from '@angular-devkit/schematics'; | ||
import { updateWorkspace } from '../../utility/workspace'; | ||
|
||
/** Migration to replace 'defaultCollection' option in angular.json. */ | ||
export default function (): Rule { | ||
return updateWorkspace((workspace) => { | ||
// workspace level | ||
replaceDefaultCollection(workspace.extensions['cli']); | ||
|
||
// Project level | ||
for (const project of workspace.projects.values()) { | ||
replaceDefaultCollection(project.extensions['cli']); | ||
} | ||
}); | ||
} | ||
|
||
function replaceDefaultCollection(cliExtension: JsonValue | undefined): void { | ||
if (cliExtension && isJsonObject(cliExtension) && cliExtension['defaultCollection']) { | ||
// If `schematicsCollection` defined `defaultCollection` is ignored hence no need to warn. | ||
if (!cliExtension['schematicCollections']) { | ||
cliExtension['schematicCollections'] = [cliExtension['defaultCollection']]; | ||
} | ||
|
||
delete cliExtension['defaultCollection']; | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
packages/schematics/angular/migrations/update-16/replace-default-collection-option_spec.ts
This file contains 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,101 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import { EmptyTree } from '@angular-devkit/schematics'; | ||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
import { ProjectType, WorkspaceSchema } from '../../utility/workspace-models'; | ||
|
||
describe(`Migration to replace 'defaultCollection' option.`, () => { | ||
const schematicName = 'replace-default-collection-option'; | ||
const schematicRunner = new SchematicTestRunner( | ||
'migrations', | ||
require.resolve('../migration-collection.json'), | ||
); | ||
|
||
let tree: UnitTestTree; | ||
beforeEach(() => { | ||
tree = new UnitTestTree(new EmptyTree()); | ||
}); | ||
|
||
it(`should replace 'defaultCollection' with 'schematicCollections' at the root level`, async () => { | ||
const angularConfig = { | ||
version: 1, | ||
projects: {}, | ||
cli: { | ||
defaultCollection: 'foo', | ||
}, | ||
}; | ||
|
||
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { cli } = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
expect(cli.defaultCollection).toBeUndefined(); | ||
expect(cli.schematicCollections).toEqual(['foo']); | ||
}); | ||
|
||
it(`should not error when 'cli' is not defined`, async () => { | ||
const angularConfig: WorkspaceSchema = { | ||
version: 1, | ||
projects: {}, | ||
}; | ||
|
||
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { cli } = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
expect(cli).toBeUndefined(); | ||
}); | ||
|
||
it(`should replace 'defaultCollection' with 'schematicCollections' at the project level`, async () => { | ||
const angularConfig = { | ||
version: 1, | ||
cli: { | ||
defaultCollection: 'foo', | ||
}, | ||
projects: { | ||
test: { | ||
sourceRoot: '', | ||
root: '', | ||
prefix: '', | ||
projectType: ProjectType.Application, | ||
cli: { | ||
defaultCollection: 'bar', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { | ||
projects: { test }, | ||
} = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
expect(test.cli.defaultCollection).toBeUndefined(); | ||
expect(test.cli.schematicCollections).toEqual(['bar']); | ||
}); | ||
|
||
it(`should not replace 'defaultCollection' with 'schematicCollections', when it is already defined`, async () => { | ||
const angularConfig = { | ||
version: 1, | ||
projects: {}, | ||
cli: { | ||
defaultCollection: 'foo', | ||
schematicCollections: ['bar'], | ||
}, | ||
}; | ||
|
||
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2)); | ||
const newTree = await schematicRunner.runSchematic(schematicName, {}, tree); | ||
const { cli } = JSON.parse(newTree.readContent('/angular.json')); | ||
|
||
expect(cli.defaultCollection).toBeUndefined(); | ||
expect(cli.schematicCollections).toEqual(['bar']); | ||
}); | ||
}); |
This file contains 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