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

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const node_module_engine_host_1 = require("./node-module-engine-host");
  4. /**
  5. * An EngineHost that uses a registry to super seed locations of collection.json files, but
  6. * revert back to using node modules resolution. This is done for testing.
  7. */
  8. class NodeModulesTestEngineHost extends node_module_engine_host_1.NodeModulesEngineHost {
  9. constructor() {
  10. super(...arguments);
  11. this._collections = new Map();
  12. this._tasks = [];
  13. }
  14. get tasks() { return this._tasks; }
  15. clearTasks() { this._tasks = []; }
  16. registerCollection(name, path) {
  17. this._collections.set(name, path);
  18. }
  19. transformContext(context) {
  20. const oldAddTask = context.addTask;
  21. context.addTask = (task, dependencies) => {
  22. this._tasks.push(task.toConfiguration());
  23. return oldAddTask.call(context, task, dependencies);
  24. };
  25. return context;
  26. }
  27. _resolveCollectionPath(name) {
  28. const maybePath = this._collections.get(name);
  29. if (maybePath) {
  30. return maybePath;
  31. }
  32. return super._resolveCollectionPath(name);
  33. }
  34. }
  35. exports.NodeModulesTestEngineHost = NodeModulesTestEngineHost;