node-modules-test-engine-host.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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.dev/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. exports.NodeModulesTestEngineHost = void 0;
  11. const 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. */
  16. class NodeModulesTestEngineHost extends node_module_engine_host_1.NodeModulesEngineHost {
  17. #collections = new Map();
  18. #tasks = [];
  19. get tasks() {
  20. return this.#tasks;
  21. }
  22. clearTasks() {
  23. this.#tasks = [];
  24. }
  25. registerCollection(name, path) {
  26. this.#collections.set(name, path);
  27. }
  28. transformContext(context) {
  29. const oldAddTask = context.addTask.bind(context);
  30. context.addTask = (task, dependencies) => {
  31. this.#tasks.push(task.toConfiguration());
  32. return oldAddTask(task, dependencies);
  33. };
  34. return context;
  35. }
  36. _resolveCollectionPath(name, requester) {
  37. return this.#collections.get(name) ?? super._resolveCollectionPath(name, requester);
  38. }
  39. }
  40. exports.NodeModulesTestEngineHost = NodeModulesTestEngineHost;