single-file-cli 2.0.76 → 2.0.77
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/build.sh +1 -1
- package/deno.json +1 -1
- package/lib/browser.js +0 -3
- package/lib/cdp-client.js +88 -22
- package/lib/single-file-bundle.js +1 -1
- package/lib/single-file-script.js +59 -28
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +1 -1
|
@@ -21,41 +21,68 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
/* global singlefile,
|
|
24
|
+
/* global singlefile, atob, Headers */
|
|
25
25
|
|
|
26
26
|
import { script, hookScript, zipScript } from "../lib/single-file-bundle.js";
|
|
27
27
|
import { Deno } from "./deno-polyfill.js";
|
|
28
28
|
|
|
29
|
+
const FETCH_FUNCTION_NAME = "__singleFileFetch";
|
|
30
|
+
const RESOLVE_FETCH_FUNCTION_NAME = "__singleFileResolveFetch";
|
|
31
|
+
const REJECT_FETCH_FUNCTION_NAME = "__singleFileRejectFetch";
|
|
32
|
+
|
|
29
33
|
const { readTextFile } = Deno;
|
|
30
|
-
export { getScriptSource, getHookScriptSource, getZipScriptSource };
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
export {
|
|
36
|
+
FETCH_FUNCTION_NAME,
|
|
37
|
+
RESOLVE_FETCH_FUNCTION_NAME,
|
|
38
|
+
REJECT_FETCH_FUNCTION_NAME,
|
|
39
|
+
getScriptSource,
|
|
40
|
+
getHookScriptSource,
|
|
41
|
+
getZipScriptSource
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function initSingleFile(constants) {
|
|
45
|
+
const nativeFetch = globalThis.fetch;
|
|
46
|
+
const pendingRequests = new Map();
|
|
47
|
+
let lastRequestId = 0;
|
|
48
|
+
const { RESOLVE_FETCH_FUNCTION_NAME, REJECT_FETCH_FUNCTION_NAME, FETCH_FUNCTION_NAME } = constants;
|
|
49
|
+
|
|
50
|
+
globalThis[RESOLVE_FETCH_FUNCTION_NAME] = (requestId, result) => {
|
|
51
|
+
const pendingRequest = pendingRequests.get(requestId);
|
|
52
|
+
if (pendingRequest) {
|
|
53
|
+
pendingRequests.delete(requestId);
|
|
54
|
+
const binaryString = atob(result.data);
|
|
55
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
56
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
57
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
58
|
+
}
|
|
59
|
+
pendingRequest.resolve({
|
|
60
|
+
status: result.status,
|
|
61
|
+
headers: new Headers(result.headers),
|
|
62
|
+
arrayBuffer: () => Promise.resolve(bytes.buffer)
|
|
57
63
|
});
|
|
58
64
|
}
|
|
65
|
+
};
|
|
66
|
+
globalThis[REJECT_FETCH_FUNCTION_NAME] = (requestId, error) => {
|
|
67
|
+
const pendingRequest = pendingRequests.get(requestId);
|
|
68
|
+
if (pendingRequest) {
|
|
69
|
+
pendingRequests.delete(requestId);
|
|
70
|
+
pendingRequest.reject(new Error(error.error));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
singlefile.init({
|
|
75
|
+
fetch: async (url, options) => {
|
|
76
|
+
try {
|
|
77
|
+
return await nativeFetch(url, options);
|
|
78
|
+
} catch {
|
|
79
|
+
const requestId = lastRequestId++;
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
pendingRequests.set(requestId, { resolve, reject });
|
|
82
|
+
globalThis[FETCH_FUNCTION_NAME](JSON.stringify({ requestId, url, options }));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
59
86
|
});
|
|
60
87
|
}
|
|
61
88
|
|
|
@@ -66,7 +93,11 @@ async function getScriptSource(options) {
|
|
|
66
93
|
if (options.browserStylesheets && options.browserStylesheets.length) {
|
|
67
94
|
source += "addEventListener(\"load\",()=>{const styleElement=document.createElement(\"style\");styleElement.textContent=" + JSON.stringify(await readScriptFiles(options.browserStylesheets)) + ";document.body.appendChild(styleElement);});";
|
|
68
95
|
}
|
|
69
|
-
source += "(" + initSingleFile.toString() + ")(
|
|
96
|
+
source += "(" + initSingleFile.toString() + ")(" + JSON.stringify({
|
|
97
|
+
FETCH_FUNCTION_NAME,
|
|
98
|
+
RESOLVE_FETCH_FUNCTION_NAME,
|
|
99
|
+
REJECT_FETCH_FUNCTION_NAME
|
|
100
|
+
}) + ");";
|
|
70
101
|
return source;
|
|
71
102
|
}
|
|
72
103
|
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.77";
|
package/package.json
CHANGED
package/single-file-cli-api.js
CHANGED
|
@@ -36,7 +36,7 @@ const DEFAULT_OPTIONS = {
|
|
|
36
36
|
compressHTML: true,
|
|
37
37
|
loadDeferredImages: true,
|
|
38
38
|
loadDeferredImagesMaxIdleTime: 1500,
|
|
39
|
-
filenameTemplate: "{page-title} ({date-locale} {time-locale}).
|
|
39
|
+
filenameTemplate: "%if-empty<{page-title}|No title> ({date-locale} {time-locale}).{filename-extension}",
|
|
40
40
|
filenameMaxLength: 192,
|
|
41
41
|
filenameMaxLengthUnit: "bytes",
|
|
42
42
|
filenameReplacedCharacters: ["~", "+", "?", "%", "*", ":", "|", "\"", "<", ">", "\\\\", "\x00-\x1f", "\x7F"],
|