-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtesting-architect-host.js
136 lines (136 loc) · 5.79 KB
/
testing-architect-host.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"use strict";
/**
* @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.dev/license
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestingArchitectHost = void 0;
const src_1 = require("../src");
class TestingArchitectHost {
workspaceRoot;
currentDirectory;
_backendHost;
_builderImportMap = new Map();
_builderMap = new Map();
_targetMap = new Map();
/**
* Can provide a backend host, in case of integration tests.
* @param workspaceRoot The workspace root to use.
* @param currentDirectory The current directory to use.
* @param _backendHost A host to defer calls that aren't resolved here.
*/
constructor(workspaceRoot = '', currentDirectory = workspaceRoot, _backendHost = null) {
this.workspaceRoot = workspaceRoot;
this.currentDirectory = currentDirectory;
this._backendHost = _backendHost;
}
addBuilder(builderName, builder, description = 'Testing only builder.', optionSchema = { type: 'object' }) {
this._builderImportMap.set(builderName, builder);
this._builderMap.set(builderName, { builderName, description, optionSchema });
}
async addBuilderFromPackage(packageName) {
const packageJson = await Promise.resolve(`${packageName + '/package.json'}`).then(s => __importStar(require(s)));
if (!('builders' in packageJson)) {
throw new Error('Invalid package.json, builders key not found.');
}
if (!packageJson.name) {
throw new Error('Invalid package name');
}
const builderJsonPath = packageName + '/' + packageJson['builders'];
const builderJson = await Promise.resolve(`${builderJsonPath}`).then(s => __importStar(require(s)));
const builders = builderJson['builders'];
if (!builders) {
throw new Error('Invalid builders.json, builders key not found.');
}
for (const builderName of Object.keys(builders)) {
const b = builders[builderName];
// TODO: remove this check as v1 is not supported anymore.
if (!b.implementation) {
continue;
}
const handler = (await Promise.resolve(`${builderJsonPath + '/../' + b.implementation}`).then(s => __importStar(require(s)))).default;
const optionsSchema = await Promise.resolve(`${builderJsonPath + '/../' + b.schema}`).then(s => __importStar(require(s)));
this.addBuilder(`${packageJson.name}:${builderName}`, handler, b.description, optionsSchema);
}
}
addTarget(target, builderName, options = {}) {
this._targetMap.set((0, src_1.targetStringFromTarget)(target), { builderName, options });
}
async getBuilderNameForTarget(target) {
const name = (0, src_1.targetStringFromTarget)(target);
const maybeTarget = this._targetMap.get(name);
if (!maybeTarget) {
return this._backendHost && this._backendHost.getBuilderNameForTarget(target);
}
return maybeTarget.builderName;
}
/**
* Resolve a builder. This needs to return a string which will be used in a dynamic `import()`
* clause. This should throw if no builder can be found. The dynamic import will throw if
* it is unsupported.
* @param builderName The name of the builder to be used.
* @returns All the info needed for the builder itself.
*/
async resolveBuilder(builderName) {
return (this._builderMap.get(builderName) ||
(this._backendHost && this._backendHost.resolveBuilder(builderName)));
}
async getCurrentDirectory() {
return this.currentDirectory;
}
async getWorkspaceRoot() {
return this.workspaceRoot;
}
async getOptionsForTarget(target) {
const name = (0, src_1.targetStringFromTarget)(target);
const maybeTarget = this._targetMap.get(name);
if (!maybeTarget) {
return this._backendHost && this._backendHost.getOptionsForTarget(target);
}
return maybeTarget.options;
}
async getProjectMetadata(target) {
return this._backendHost && this._backendHost.getProjectMetadata(target);
}
async loadBuilder(info) {
return (this._builderImportMap.get(info.builderName) ||
(this._backendHost && this._backendHost.loadBuilder(info)));
}
}
exports.TestingArchitectHost = TestingArchitectHost;