Skip to content

Commit

Permalink
feat(@schematics/angular): add migratiom to remove defaultProject i…
Browse files Browse the repository at this point in the history
…n workspace config

This option is deprecated in Angular CLI and will be removed in a future major version.
  • Loading branch information
alan-agius4 authored and dgp1130 committed Mar 21, 2022
1 parent 4cbfb87 commit e49220f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
Expand Up @@ -14,6 +14,11 @@
"version": "14.0.0",
"factory": "./update-14/remove-show-circular-dependencies-option",
"description": "Remove 'showCircularDependencies' option from browser and server builders."
},
"remove-default-project-option": {
"version": "14.0.0",
"factory": "./update-14/remove-default-project-option",
"description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory."
}
}
}
@@ -0,0 +1,17 @@
/**
* @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 { Rule } from '@angular-devkit/schematics';
import { updateWorkspace } from '../../utility/workspace';

/** Migration to remove 'defaultProject' option from angular.json. */
export default function (): Rule {
return updateWorkspace((workspace) => {
delete workspace.extensions['defaultProject'];
});
}
@@ -0,0 +1,51 @@
/**
* @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 { WorkspaceSchema } from '../../utility/workspace-models';

describe(`Migration to remove 'defaultProject' option.`, () => {
const schematicName = 'remove-default-project-option';
const schematicRunner = new SchematicTestRunner(
'migrations',
require.resolve('../migration-collection.json'),
);

let tree: UnitTestTree;
beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
});

it(`should remove 'defaultProject'`, async () => {
const angularConfig: WorkspaceSchema = {
version: 1,
projects: {},
defaultProject: 'foo',
};

tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));

expect(defaultProject).toBeUndefined();
});

it(`should not error when 'defaultProject' is not defined`, async () => {
const angularConfig: WorkspaceSchema = {
version: 1,
projects: {},
};

tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { defaultProject } = JSON.parse(newTree.readContent('/angular.json'));

expect(defaultProject).toBeUndefined();
});
});

0 comments on commit e49220f

Please sign in to comment.