Skip to content

Commit

Permalink
feat(@angular/cli): remove deprecated defaultProject from workspace…
Browse files Browse the repository at this point in the history
… configuration

The deprecated 'defaultProject' workspace option has been removed

BREAKING CHANGE: The deprecated `defaultProject` workspace option has been removed. The project to use will be determined from the current working directory.
  • Loading branch information
alan-agius4 authored and angular-robot[bot] committed Feb 17, 2023
1 parent ada4d69 commit d58428d
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 68 deletions.
5 changes: 0 additions & 5 deletions packages/angular/cli/lib/config/workspace-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
"type": "string",
"description": "Path where new projects will be created."
},
"defaultProject": {
"type": "string",
"description": "Default project name used in commands.",
"x-deprecated": "The project to use will be determined from the current working directory."
},
"projects": {
"type": "object",
"patternProperties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ export abstract class SchematicsCommandModule
return 0;
}

private defaultProjectDeprecationWarningShown = false;
private getProjectName(): string | undefined {
const { workspace, logger } = this.context;
if (!workspace) {
Expand All @@ -368,20 +367,6 @@ export abstract class SchematicsCommandModule
return projectName;
}

const defaultProjectName = workspace.extensions['defaultProject'];
if (typeof defaultProjectName === 'string' && defaultProjectName) {
if (!this.defaultProjectDeprecationWarningShown) {
logger.warn(tags.oneLine`
DEPRECATED: The 'defaultProject' workspace option has been deprecated.
The project to use will be determined from the current working directory.
`);

this.defaultProjectDeprecationWarningShown = true;
}

return defaultProjectName;
}

return undefined;
}

Expand Down
16 changes: 0 additions & 16 deletions packages/angular/cli/src/utilities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ function findProjectByPath(workspace: AngularWorkspace, location: string): strin
return projects[0][1];
}

let defaultProjectDeprecationWarningShown = false;
export function getProjectByCwd(workspace: AngularWorkspace): string | null {
if (workspace.projects.size === 1) {
// If there is only one project, return that one.
Expand All @@ -314,21 +313,6 @@ export function getProjectByCwd(workspace: AngularWorkspace): string | null {
return project;
}

const defaultProject = workspace.extensions['defaultProject'];
if (defaultProject && typeof defaultProject === 'string') {
// If there is a default project name, return it.
if (!defaultProjectDeprecationWarningShown) {
console.warn(
`DEPRECATED: The 'defaultProject' workspace option has been deprecated. ` +
`The project to use will be determined from the current working directory.`,
);

defaultProjectDeprecationWarningShown = true;
}

return defaultProject;
}

return null;
}

Expand Down
7 changes: 1 addition & 6 deletions packages/angular_devkit/core/src/workspace/json/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ import { WorkspaceHost } from '../host';
import { JsonWorkspaceMetadata, JsonWorkspaceSymbol } from './metadata';
import { createVirtualAstObject } from './utilities';

const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze([
'cli',
'defaultProject',
'newProjectRoot',
'schematics',
]);
const ANGULAR_WORKSPACE_EXTENSIONS = Object.freeze(['cli', 'newProjectRoot', 'schematics']);
const ANGULAR_PROJECT_EXTENSIONS = Object.freeze(['cli', 'schematics', 'projectType', 'i18n']);

interface ParserContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('readJsonWorkpace Parsing', () => {

expect(Array.from(workspace.projects.keys())).toEqual(['my-app', 'my-app-e2e']);
expect(workspace.extensions['newProjectRoot']).toBe('projects');
expect(workspace.extensions['defaultProject']).toBe('my-app');
expect(workspace.projects.get('my-app')!.extensions['schematics']).toEqual({
'@schematics/angular:component': { styleext: 'scss' },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,5 @@
}
}
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,5 @@
"new": {
"root": "src"
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,5 @@
"1": {
"root": "src"
}
},
"defaultProject": "my-app"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,5 @@
}
}
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,5 @@
}
}
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,5 @@
}
}
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,5 @@
}
}
}
},
"defaultProject": "my-app"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"schematics": {

"remove-default-project-option": {
"version": "16.0.0",
"factory": "./update-16/remove-default-project-option",
"description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory."
}
}
}
Original file line number Diff line number Diff line change
@@ -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'];
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @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';

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 = {
version: 1,
projects: {},
defaultProject: 'foo',
};

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

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

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

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

expect(defaultProject).toBeUndefined();
});
});
1 change: 0 additions & 1 deletion packages/schematics/angular/utility/workspace-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ interface WorkspaceCLISchema {
}
export interface WorkspaceSchema {
version: 1;
defaultProject?: string;
cli?: WorkspaceCLISchema;
projects: {
[key: string]: WorkspaceProject<ProjectType.Application | ProjectType.Library>;
Expand Down
4 changes: 1 addition & 3 deletions tests/legacy-cli/e2e/assets/13.0-project/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,4 @@
}
}
}
},
"defaultProject": "thirteen-project"
}
}}

0 comments on commit d58428d

Please sign in to comment.