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