.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / fast-glob / out / providers / reader-async.js
1 "use strict";\r
2 var __extends = (this && this.__extends) || (function () {\r
3     var extendStatics = function (d, b) {\r
4         extendStatics = Object.setPrototypeOf ||\r
5             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r
6             function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r
7         return extendStatics(d, b);\r
8     };\r
9     return function (d, b) {\r
10         extendStatics(d, b);\r
11         function __() { this.constructor = d; }\r
12         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r
13     };\r
14 })();\r
15 Object.defineProperty(exports, "__esModule", { value: true });\r
16 var readdir = require("@mrmlnc/readdir-enhanced");\r
17 var reader_1 = require("./reader");\r
18 var fs_stream_1 = require("../adapters/fs-stream");\r
19 var ReaderAsync = /** @class */ (function (_super) {\r
20     __extends(ReaderAsync, _super);\r
21     function ReaderAsync() {\r
22         return _super !== null && _super.apply(this, arguments) || this;\r
23     }\r
24     Object.defineProperty(ReaderAsync.prototype, "fsAdapter", {\r
25         /**\r
26          * Returns FileSystem adapter.\r
27          */\r
28         get: function () {\r
29             return new fs_stream_1.default(this.options);\r
30         },\r
31         enumerable: true,\r
32         configurable: true\r
33     });\r
34     /**\r
35      * Use async API to read entries for Task.\r
36      */\r
37     ReaderAsync.prototype.read = function (task) {\r
38         var _this = this;\r
39         var root = this.getRootDirectory(task);\r
40         var options = this.getReaderOptions(task);\r
41         var entries = [];\r
42         return new Promise(function (resolve, reject) {\r
43             var stream = _this.api(root, task, options);\r
44             stream.on('error', function (err) {\r
45                 _this.isEnoentCodeError(err) ? resolve([]) : reject(err);\r
46                 stream.pause();\r
47             });\r
48             stream.on('data', function (entry) { return entries.push(_this.transform(entry)); });\r
49             stream.on('end', function () { return resolve(entries); });\r
50         });\r
51     };\r
52     /**\r
53      * Returns founded paths.\r
54      */\r
55     ReaderAsync.prototype.api = function (root, task, options) {\r
56         if (task.dynamic) {\r
57             return this.dynamicApi(root, options);\r
58         }\r
59         return this.staticApi(task, options);\r
60     };\r
61     /**\r
62      * Api for dynamic tasks.\r
63      */\r
64     ReaderAsync.prototype.dynamicApi = function (root, options) {\r
65         return readdir.readdirStreamStat(root, options);\r
66     };\r
67     /**\r
68      * Api for static tasks.\r
69      */\r
70     ReaderAsync.prototype.staticApi = function (task, options) {\r
71         return this.fsAdapter.read(task.patterns, options.filter);\r
72     };\r
73     return ReaderAsync;\r
74 }(reader_1.default));\r
75 exports.default = ReaderAsync;\r