single-file-cli 2.0.77 → 2.0.79
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/deno.json +1 -1
- package/deno.lock +4 -4
- package/lib/cdp-client-util.js +95 -0
- package/lib/cdp-client.js +587 -566
- package/lib/deno-polyfill.js +3 -1
- package/lib/single-file-script.js +47 -3
- package/lib/version.js +1 -1
- package/options.js +156 -107
- package/package.json +2 -2
package/deno.json
CHANGED
package/deno.lock
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"jsr:@simple-cdp/simple-cdp@^1.8.6": "1.8.6",
|
|
6
6
|
"jsr:@std/internal@^1.0.10": "1.0.12",
|
|
7
7
|
"jsr:@std/path@^1.1.2": "1.1.2",
|
|
8
|
-
"npm:@eslint/js@^9.39.
|
|
8
|
+
"npm:@eslint/js@^9.39.1": "9.39.1",
|
|
9
9
|
"npm:simple-cdp@^1.8.6": "1.8.6",
|
|
10
10
|
"npm:ws@^8.18.3": "8.18.3"
|
|
11
11
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"npm": {
|
|
30
|
-
"@eslint/js@9.39.
|
|
31
|
-
"integrity": "sha512-
|
|
30
|
+
"@eslint/js@9.39.1": {
|
|
31
|
+
"integrity": "sha512-S26Stp4zCy88tH94QbBv3XCuzRQiZ9yXofEILmglYTh/Ug/a9/umqvgFtYBAo3Lp0nsI/5/qH1CCrbdK3AP1Tw=="
|
|
32
32
|
},
|
|
33
33
|
"simple-cdp@1.8.6": {
|
|
34
34
|
"integrity": "sha512-c33zKvBOOIBfdfDCr++N8Dv6kY03wD+cGuu3MEiBJHC4LtHE5aSwjw5E+dOSeuXolS+8MoDzYuWrJdT+IFp8bw=="
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
],
|
|
76
76
|
"packageJson": {
|
|
77
77
|
"dependencies": [
|
|
78
|
-
"npm:@eslint/js@^9.39.
|
|
78
|
+
"npm:@eslint/js@^9.39.1",
|
|
79
79
|
"npm:simple-cdp@^1.8.6",
|
|
80
80
|
"npm:ws@^8.18.3"
|
|
81
81
|
]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2025 Gildas Lormeau
|
|
3
|
+
* contact : gildas.lormeau <at> gmail.com
|
|
4
|
+
*
|
|
5
|
+
* This file is part of SingleFile.
|
|
6
|
+
*
|
|
7
|
+
* The code in this file is free software: you can redistribute it and/or
|
|
8
|
+
* modify it under the terms of the GNU Affero General Public License
|
|
9
|
+
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
10
|
+
* of the License, or (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* The code in this file is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
15
|
+
* General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
18
|
+
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
19
|
+
* AGPL normally required by section 4, provided you include this license
|
|
20
|
+
* notice and a URL through which recipients can access the Corresponding
|
|
21
|
+
* Source.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/* global setTimeout, clearTimeout, fetch, URL, Headers, btoa */
|
|
25
|
+
|
|
26
|
+
import { Deno, isDeno } from "./deno-polyfill.js";
|
|
27
|
+
|
|
28
|
+
const ABORT_EVENT = "abort";
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
fetchWithFileSupport as fetch,
|
|
32
|
+
waitForTimeout,
|
|
33
|
+
arrayBufferToBase64,
|
|
34
|
+
getAlternativeUrl
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async function fetchWithFileSupport(url, fetchOptions = {}) {
|
|
38
|
+
const isFileUrl = url.startsWith("file://");
|
|
39
|
+
if (!isFileUrl) {
|
|
40
|
+
return await fetch(url, fetchOptions);
|
|
41
|
+
}
|
|
42
|
+
if (isDeno) {
|
|
43
|
+
return await fetch(url, fetchOptions);
|
|
44
|
+
}
|
|
45
|
+
const filePath = decodeURIComponent(url.replace(/^file:\/\//, ""));
|
|
46
|
+
const { readFile } = Deno;
|
|
47
|
+
try {
|
|
48
|
+
const fileData = await readFile(filePath);
|
|
49
|
+
return createFileResponse(fileData, 200);
|
|
50
|
+
} catch {
|
|
51
|
+
return createFileResponse(new ArrayBuffer(0), 404);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function createFileResponse(data, status) {
|
|
55
|
+
const isError = status === 404;
|
|
56
|
+
return {
|
|
57
|
+
status,
|
|
58
|
+
headers: new Headers({
|
|
59
|
+
"content-type": isError ? "text/plain" : "application/octet-stream",
|
|
60
|
+
"content-length": data.length ? data.length.toString() : "0"
|
|
61
|
+
}),
|
|
62
|
+
arrayBuffer: async () => data.buffer || data
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function waitForTimeout(abortSignal, maxDelay, errorMessage, errorCode) {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
abortSignal.addEventListener(ABORT_EVENT, onAbort);
|
|
70
|
+
const timeoutId = setTimeout(() => {
|
|
71
|
+
abortSignal.removeEventListener(ABORT_EVENT, onAbort);
|
|
72
|
+
const error = new Error(errorMessage);
|
|
73
|
+
error.code = errorCode;
|
|
74
|
+
reject(error);
|
|
75
|
+
}, maxDelay);
|
|
76
|
+
|
|
77
|
+
function onAbort() {
|
|
78
|
+
abortSignal.removeEventListener(ABORT_EVENT, onAbort);
|
|
79
|
+
clearTimeout(timeoutId);
|
|
80
|
+
resolve();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function arrayBufferToBase64(arrayBuffer) {
|
|
86
|
+
return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getAlternativeUrl(url) {
|
|
90
|
+
const alternativeUrl = new URL(url);
|
|
91
|
+
if (!alternativeUrl.pathname.endsWith("/")) {
|
|
92
|
+
alternativeUrl.pathname = alternativeUrl.pathname + "/";
|
|
93
|
+
}
|
|
94
|
+
return alternativeUrl.href;
|
|
95
|
+
}
|