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:
parent
3facdebd07
commit
8ef690c342
|
@ -5,7 +5,7 @@ ts_library(
|
||||||
name = "e2e_lib",
|
name = "e2e_lib",
|
||||||
testonly = 1,
|
testonly = 1,
|
||||||
srcs = glob(["src/**/*.ts"]),
|
srcs = glob(["src/**/*.ts"]),
|
||||||
tsconfig = ":tsconfig.e2e.json",
|
tsconfig = ":tsconfig.e2e.json" if len(glob(["tsconfig.e2e.json"])) else ":tsconfig.json",
|
||||||
deps = [
|
deps = [
|
||||||
"@npm//@types/jasmine",
|
"@npm//@types/jasmine",
|
||||||
"@npm//@types/jasminewd2",
|
"@npm//@types/jasminewd2",
|
||||||
|
|
|
@ -8,14 +8,18 @@
|
||||||
* @fileoverview Schematics for ng-new project that builds with Bazel.
|
* @fileoverview Schematics for ng-new project that builds with Bazel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {JsonAstObject, parseJsonAst, strings} from '@angular-devkit/core';
|
import {JsonAstObject, parseJsonAst} from '@angular-devkit/core';
|
||||||
import {Rule, SchematicContext, SchematicsException, Tree, apply, applyTemplates, chain, mergeWith, move, schematic, url} from '@angular-devkit/schematics';
|
import {Rule, SchematicContext, SchematicsException, Tree, apply, applyTemplates, chain, mergeWith, url} from '@angular-devkit/schematics';
|
||||||
import {getWorkspacePath} from '@schematics/angular/utility/config';
|
import {getWorkspacePath} from '@schematics/angular/utility/config';
|
||||||
import {findPropertyInAstObject, insertPropertyInAstObjectInOrder} from '@schematics/angular/utility/json-utils';
|
import {findPropertyInAstObject, insertPropertyInAstObjectInOrder} from '@schematics/angular/utility/json-utils';
|
||||||
import {validateProjectName} from '@schematics/angular/utility/validation';
|
import {validateProjectName} from '@schematics/angular/utility/validation';
|
||||||
|
|
||||||
import {isJsonAstObject, removeKeyValueInAstObject, replacePropertyInAstObject} from '../utility/json-utils';
|
import {isJsonAstObject, removeKeyValueInAstObject, replacePropertyInAstObject} from '../utility/json-utils';
|
||||||
|
import {findE2eArchitect} from '../utility/workspace-utils';
|
||||||
|
|
||||||
import {Schema} from './schema';
|
import {Schema} from './schema';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Packages that build under Bazel require additional dev dependencies. This
|
* Packages that build under Bazel require additional dev dependencies. This
|
||||||
* function adds those dependencies to "devDependencies" section in
|
* function adds those dependencies to "devDependencies" section in
|
||||||
|
@ -98,6 +102,9 @@ function updateGitignore() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the architect in angular.json to use Bazel builder.
|
||||||
|
*/
|
||||||
function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
|
function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
|
||||||
return (host: Tree, context: SchematicContext) => {
|
return (host: Tree, context: SchematicContext) => {
|
||||||
const {name} = options;
|
const {name} = options;
|
||||||
|
@ -153,13 +160,10 @@ function updateAngularJsonToUseBazelBuilder(options: Schema): Rule {
|
||||||
},
|
},
|
||||||
indent);
|
indent);
|
||||||
|
|
||||||
const e2e = `${options.name}-e2e`;
|
const e2eArchitect = findE2eArchitect(workspaceJsonAst, name);
|
||||||
const e2eNode = findPropertyInAstObject(projects as JsonAstObject, e2e);
|
if (e2eArchitect) {
|
||||||
if (e2eNode) {
|
|
||||||
const architect =
|
|
||||||
findPropertyInAstObject(e2eNode as JsonAstObject, 'architect') as JsonAstObject;
|
|
||||||
replacePropertyInAstObject(
|
replacePropertyInAstObject(
|
||||||
recorder, architect, 'e2e', {
|
recorder, e2eArchitect, 'e2e', {
|
||||||
builder: '@angular/bazel:build',
|
builder: '@angular/bazel:build',
|
||||||
options: {
|
options: {
|
||||||
bazelCommand: 'test',
|
bazelCommand: 'test',
|
||||||
|
|
|
@ -6,6 +6,7 @@ ts_library(
|
||||||
name = "utility",
|
name = "utility",
|
||||||
srcs = [
|
srcs = [
|
||||||
"json-utils.ts",
|
"json-utils.ts",
|
||||||
|
"workspace-utils.ts",
|
||||||
],
|
],
|
||||||
module_name = "@angular/bazel/src/schematics/utility",
|
module_name = "@angular/bazel/src/schematics/utility",
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -21,6 +22,7 @@ ts_library(
|
||||||
testonly = True,
|
testonly = True,
|
||||||
srcs = [
|
srcs = [
|
||||||
"json-utils_spec.ts",
|
"json-utils_spec.ts",
|
||||||
|
"workspace-utils_spec.ts",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":utility",
|
":utility",
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue