UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.NodeModulesTestEngineHost = void 0;
11const node_module_engine_host_1 = require("./node-module-engine-host");
12/**
13 * An EngineHost that uses a registry to super seed locations of collection.json files, but
14 * revert back to using node modules resolution. This is done for testing.
15 */
16class NodeModulesTestEngineHost extends node_module_engine_host_1.NodeModulesEngineHost {
17 constructor() {
18 super(...arguments);
19 this._collections = new Map();
20 this._tasks = [];
21 }
22 get tasks() {
23 return this._tasks;
24 }
25 clearTasks() {
26 this._tasks = [];
27 }
28 registerCollection(name, path) {
29 this._collections.set(name, path);
30 }
31 transformContext(context) {
32 const oldAddTask = context.addTask;
33 context.addTask = (task, dependencies) => {
34 this._tasks.push(task.toConfiguration());
35 return oldAddTask.call(context, task, dependencies);
36 };
37 return context;
38 }
39 _resolveCollectionPath(name, requester) {
40 const maybePath = this._collections.get(name);
41 if (maybePath) {
42 return maybePath;
43 }
44 return super._resolveCollectionPath(name, requester);
45 }
46}
47exports.NodeModulesTestEngineHost = NodeModulesTestEngineHost;