index.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. var desc = Object.getOwnPropertyDescriptor(m, k);
  12. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  13. desc = { enumerable: true, get: function() { return m[k]; } };
  14. }
  15. Object.defineProperty(o, k2, desc);
  16. }) : (function(o, m, k, k2) {
  17. if (k2 === undefined) k2 = k;
  18. o[k2] = m[k];
  19. }));
  20. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  21. Object.defineProperty(o, "default", { enumerable: true, value: v });
  22. }) : function(o, v) {
  23. o["default"] = v;
  24. });
  25. var __importStar = (this && this.__importStar) || (function () {
  26. var ownKeys = function(o) {
  27. ownKeys = Object.getOwnPropertyNames || function (o) {
  28. var ar = [];
  29. for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
  30. return ar;
  31. };
  32. return ownKeys(o);
  33. };
  34. return function (mod) {
  35. if (mod && mod.__esModule) return mod;
  36. var result = {};
  37. if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
  38. __setModuleDefault(result, mod);
  39. return result;
  40. };
  41. })();
  42. Object.defineProperty(exports, "__esModule", { value: true });
  43. exports.TempScopedNodeJsSyncHost = void 0;
  44. const fs = __importStar(require("node:fs"));
  45. const os = __importStar(require("node:os"));
  46. const path = __importStar(require("node:path"));
  47. const src_1 = require("../../src");
  48. const host_1 = require("../host");
  49. /**
  50. * A Sync Scoped Host that creates a temporary directory and scope to it.
  51. */
  52. class TempScopedNodeJsSyncHost extends src_1.virtualFs.ScopedHost {
  53. _sync;
  54. _root;
  55. constructor() {
  56. const root = (0, src_1.normalize)(path.join(os.tmpdir(), `devkit-host-${+Date.now()}-${process.pid}`));
  57. fs.mkdirSync((0, src_1.getSystemPath)(root));
  58. super(new host_1.NodeJsSyncHost(), root);
  59. this._root = root;
  60. }
  61. get files() {
  62. const sync = this.sync;
  63. function _visit(p) {
  64. return sync
  65. .list(p)
  66. .map((fragment) => (0, src_1.join)(p, fragment))
  67. .reduce((files, path) => {
  68. if (sync.isDirectory(path)) {
  69. return files.concat(_visit(path));
  70. }
  71. else {
  72. return files.concat(path);
  73. }
  74. }, []);
  75. }
  76. return _visit((0, src_1.normalize)('/'));
  77. }
  78. get root() {
  79. return this._root;
  80. }
  81. get sync() {
  82. if (!this._sync) {
  83. this._sync = new src_1.virtualFs.SyncDelegateHost(this);
  84. }
  85. return this._sync;
  86. }
  87. }
  88. exports.TempScopedNodeJsSyncHost = TempScopedNodeJsSyncHost;