fix(bazel): Support new e2e project layout (#29318)
https://github.com/angular/angular-cli/pull/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
This commit is contained in:

committed by
Matias Niemelä

parent
3facdebd07
commit
8ef690c342
@ -6,6 +6,7 @@ ts_library(
|
||||
name = "utility",
|
||||
srcs = [
|
||||
"json-utils.ts",
|
||||
"workspace-utils.ts",
|
||||
],
|
||||
module_name = "@angular/bazel/src/schematics/utility",
|
||||
deps = [
|
||||
@ -21,6 +22,7 @@ ts_library(
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"json-utils_spec.ts",
|
||||
"workspace-utils_spec.ts",
|
||||
],
|
||||
deps = [
|
||||
":utility",
|
||||
|
40
packages/bazel/src/schematics/utility/workspace-utils.ts
Normal file
40
packages/bazel/src/schematics/utility/workspace-utils.ts
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user