Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(bazel): Support new e2e project layout (#29318)
angular/angular-cli#13780 changes the project layout for the e2e application. It is no longer a separate project and the e2e directory is now located alongside the existing project. This commit updates Bazel scheamtics to support both old and new project layout. PR Close #29318
- Loading branch information
Showing
5 changed files
with
97 additions
and
9 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
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,40 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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 {JsonAstNode, JsonAstObject} from '@angular-devkit/core'; | ||
import {findPropertyInAstObject} from '@schematics/angular/utility/json-utils'; | ||
import {isJsonAstObject} from './json-utils'; | ||
|
||
/** | ||
* Find the e2e architect node in the JSON ast. | ||
* The e2e application is relocated alongside the existing application. | ||
* This function supports looking up the e2e architect in both the new and old | ||
* layout. | ||
* See https://github.com/angular/angular-cli/pull/13780 | ||
*/ | ||
export function findE2eArchitect(ast: JsonAstObject, name: string): JsonAstObject|null { | ||
const projects = findPropertyInAstObject(ast, 'projects'); | ||
if (!isJsonAstObject(projects)) { | ||
return null; | ||
} | ||
let architect: JsonAstNode|null; | ||
const e2e = findPropertyInAstObject(projects, `${name}-e2e`); | ||
if (isJsonAstObject(e2e)) { | ||
architect = findPropertyInAstObject(e2e, 'architect'); | ||
} else { | ||
const project = findPropertyInAstObject(projects, name); | ||
if (!isJsonAstObject(project)) { | ||
return null; | ||
} | ||
architect = findPropertyInAstObject(project, 'architect'); | ||
} | ||
if (!isJsonAstObject(architect)) { | ||
return null; | ||
} | ||
return architect; | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/bazel/src/schematics/utility/workspace-utils_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,42 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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 {JsonAstObject, parseJsonAst} from '@angular-devkit/core'; | ||
import {isJsonAstObject} from './json-utils'; | ||
import {findE2eArchitect} from './workspace-utils'; | ||
|
||
describe('Workspace utils', () => { | ||
describe('findE2eArchitect', () => { | ||
it('should find e2e architect in old project layout', () => { | ||
const workspace = { | ||
projects: { | ||
demo: {}, | ||
'demo-e2e': { | ||
architect: {}, | ||
}, | ||
}, | ||
}; | ||
const ast = parseJsonAst(JSON.stringify(workspace)); | ||
const architect = findE2eArchitect(ast as JsonAstObject, 'demo'); | ||
expect(isJsonAstObject(architect)).toBe(true); | ||
}); | ||
|
||
it('should find e2e architect in new project layout', () => { | ||
const workspace = { | ||
projects: { | ||
demo: { | ||
architect: {}, | ||
}, | ||
}, | ||
}; | ||
const ast = parseJsonAst(JSON.stringify(workspace)); | ||
const architect = findE2eArchitect(ast as JsonAstObject, 'demo'); | ||
expect(isJsonAstObject(architect)).toBe(true); | ||
}); | ||
}); | ||
}); |