single-file-cli 2.0.75 → 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/README.MD +1 -1
- package/build.sh +1 -1
- package/deno.json +3 -3
- package/deno.lock +56 -21
- 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/options.js +3 -0
- package/package.json +4 -4
- 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/options.js
CHANGED
|
@@ -39,7 +39,9 @@ const OPTIONS_INFO = {
|
|
|
39
39
|
"block-audios": { description: "Block audios", type: "boolean", defaultValue: true },
|
|
40
40
|
"block-fonts": { description: "Block fonts", type: "boolean" },
|
|
41
41
|
"block-images": { description: "Block images", type: "boolean" },
|
|
42
|
+
"block-alternative-images": { description: "Block alternative images", type: "boolean", defaultValue: true },
|
|
42
43
|
"block-scripts": { description: "Block scripts", type: "boolean", defaultValue: true },
|
|
44
|
+
"block-stylesheets": { description: "Block stylesheets", type: "boolean", defaultValue: false },
|
|
43
45
|
"block-videos": { description: "Block videos", type: "boolean", defaultValue: true },
|
|
44
46
|
"block-mixed-content": { description: "Block mixed contents", type: "boolean" },
|
|
45
47
|
"blocked-URL-pattern": { description: "Regular expression matching URLs to block (e.g. 'annoying-banners\\.com')", type: "string[]" },
|
|
@@ -129,6 +131,7 @@ const OPTIONS_INFO = {
|
|
|
129
131
|
"remove-alternative-fonts": { description: "Remove alternative fonts to the ones displayed", type: "boolean", defaultValue: true },
|
|
130
132
|
"remove-alternative-medias": { description: "Remove alternative CSS stylesheets", type: "boolean", defaultValue: true },
|
|
131
133
|
"remove-alternative-images": { description: "Remove images for alternative sizes of screen", type: "boolean", defaultValue: true },
|
|
134
|
+
"remove-no-script-tags": { description: "Remove <noscript> tags", type: "boolean", defaultValue: true },
|
|
132
135
|
"save-original-URLs": { description: "Save the original URLS in the embedded contents", type: "boolean" },
|
|
133
136
|
"save-raw-page": { description: "Save the original page without interpreting it into the browser", type: "boolean" },
|
|
134
137
|
"urls-file": { description: "Path to a text file containing a list of URLs (separated by a newline) to save. You can also pass the options after each URL (e.g. 'https://www.example.com --filename-template={page-title}.html')", type: "string" },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "single-file-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.77",
|
|
4
4
|
"description": "SingleFile CLI",
|
|
5
5
|
"author": "Gildas Lormeau",
|
|
6
6
|
"engines": {
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"single-file": "single-file-node.js"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"simple-cdp": "^1.8.
|
|
17
|
-
"ws": "^8.18.
|
|
16
|
+
"simple-cdp": "^1.8.6",
|
|
17
|
+
"ws": "^8.18.3"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@eslint/js": "^9.
|
|
20
|
+
"@eslint/js": "^9.39.0"
|
|
21
21
|
}
|
|
22
22
|
}
|
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"],
|