@akashic/headless-driver 2.6.2 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/utils.d.ts CHANGED
@@ -2,7 +2,19 @@
2
2
  * ファイルを読み込む。
3
3
  *
4
4
  * @param url url または path
5
- * @param opt オプション
6
5
  */
7
6
  export declare function loadFile(url: string): Promise<string>;
7
+ /**
8
+ * loadFile() の内部実装のうち、特にテストのため外部から参照するものをまとめた namespace 。
9
+ * 通常の利用では参照する必要はない。
10
+ */
11
+ export declare namespace LoadFileInternal {
12
+ /**
13
+ * 最大並列ロード数。
14
+ * 環境によって、node-fetch を一定数以上並列に実行すると応答がなくなったりエラーになる場合がある。
15
+ * 具体的な値は調整の余地がある。少なくとも Windows 環境で、128 以上で問題が起きることがわかっている。
16
+ */
17
+ const MAX_PARALLEL_LOAD = 32;
18
+ function loadImpl(url: string): Promise<string>;
19
+ }
8
20
  export declare function isHttpProtocol(url: string): boolean;
package/lib/utils.js CHANGED
@@ -9,28 +9,70 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isHttpProtocol = exports.loadFile = void 0;
12
+ exports.isHttpProtocol = exports.LoadFileInternal = exports.loadFile = void 0;
13
13
  const fs = require("fs");
14
14
  const node_fetch_1 = require("node-fetch");
15
+ const waitings = [];
16
+ let loadingCount = 0;
15
17
  /**
16
18
  * ファイルを読み込む。
17
19
  *
18
20
  * @param url url または path
19
- * @param opt オプション
20
21
  */
21
22
  function loadFile(url) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- if (isHttpProtocol(url)) {
24
- const res = yield (0, node_fetch_1.default)(url, { method: "GET" });
25
- return res.text();
24
+ const promise = new Promise((resolve, reject) => {
25
+ waitings.push({ url, resolve, reject });
26
+ });
27
+ processWaitingLoad();
28
+ return promise;
29
+ });
30
+ }
31
+ exports.loadFile = loadFile;
32
+ function processWaitingLoad() {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ if (loadingCount >= LoadFileInternal.MAX_PARALLEL_LOAD || waitings.length === 0)
35
+ return;
36
+ const { url, resolve, reject } = waitings.shift();
37
+ try {
38
+ ++loadingCount;
39
+ resolve(yield LoadFileInternal.loadImpl(url));
26
40
  }
27
- else {
28
- const str = fs.readFileSync(url, { encoding: "utf8" });
29
- return str;
41
+ catch (e) {
42
+ reject(e);
43
+ }
44
+ finally {
45
+ --loadingCount;
46
+ processWaitingLoad();
30
47
  }
31
48
  });
32
49
  }
33
- exports.loadFile = loadFile;
50
+ /**
51
+ * loadFile() の内部実装のうち、特にテストのため外部から参照するものをまとめた namespace 。
52
+ * 通常の利用では参照する必要はない。
53
+ */
54
+ var LoadFileInternal;
55
+ (function (LoadFileInternal) {
56
+ /**
57
+ * 最大並列ロード数。
58
+ * 環境によって、node-fetch を一定数以上並列に実行すると応答がなくなったりエラーになる場合がある。
59
+ * 具体的な値は調整の余地がある。少なくとも Windows 環境で、128 以上で問題が起きることがわかっている。
60
+ */
61
+ LoadFileInternal.MAX_PARALLEL_LOAD = 32;
62
+ function loadImpl(url) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ if (isHttpProtocol(url)) {
65
+ const res = yield (0, node_fetch_1.default)(url, { method: "GET" });
66
+ return res.text();
67
+ }
68
+ else {
69
+ const str = fs.readFileSync(url, { encoding: "utf8" });
70
+ return str;
71
+ }
72
+ });
73
+ }
74
+ LoadFileInternal.loadImpl = loadImpl;
75
+ })(LoadFileInternal = exports.LoadFileInternal || (exports.LoadFileInternal = {}));
34
76
  function isHttpProtocol(url) {
35
77
  return /^(http|https)\:\/\//.test(url);
36
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akashic/headless-driver",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "A library to execute contents using Akashic Engine headlessly",
5
5
  "main": "lib/index.js",
6
6
  "author": "DWANGO Co., Ltd.",
@@ -55,7 +55,7 @@
55
55
  "jest": "^29.1.2",
56
56
  "npm-run-all": "^4.1.5",
57
57
  "pixelmatch": "^5.3.0",
58
- "pngjs": "^6.0.0",
58
+ "pngjs": "^7.0.0",
59
59
  "prettier": "^2.7.1",
60
60
  "remark-cli": "^11.0.0",
61
61
  "rimraf": "^4.0.0",