single-file-cli 2.0.9 → 2.0.11
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/lib/browser.js +6 -7
- package/lib/deno-polyfill.js +4 -2
- package/lib/version.js +1 -1
- package/options.js +1 -1
- package/package.json +4 -2
- package/single-file +2 -105
- package/single-file-launcher.js +108 -0
- package/single-file-node.js +5 -0
package/deno.json
CHANGED
package/lib/browser.js
CHANGED
|
@@ -31,7 +31,7 @@ let child, profilePath;
|
|
|
31
31
|
export { launchBrowser, closeBrowser };
|
|
32
32
|
|
|
33
33
|
async function launchBrowser(options = {}, indexPath = 0) {
|
|
34
|
-
|
|
34
|
+
const executablePath = options.executablePath || BROWSER_PATHS[build.os][indexPath];
|
|
35
35
|
const args = Array.from(BROWSER_ARGS);
|
|
36
36
|
profilePath = await makeTempDir();
|
|
37
37
|
if (options.headless) {
|
|
@@ -39,9 +39,6 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
39
39
|
} else {
|
|
40
40
|
args.push("--start-maximized");
|
|
41
41
|
}
|
|
42
|
-
if (options.executablePath) {
|
|
43
|
-
path = options.executablePath;
|
|
44
|
-
}
|
|
45
42
|
if (options.debug) {
|
|
46
43
|
args.push("--auto-open-devtools-for-tabs");
|
|
47
44
|
}
|
|
@@ -57,11 +54,11 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
57
54
|
if (options.httpProxyServer) {
|
|
58
55
|
args.push("--proxy-server=" + options.httpProxyServer);
|
|
59
56
|
}
|
|
60
|
-
args.push(
|
|
57
|
+
args.push("--user-data-dir=" + profilePath);
|
|
61
58
|
if (options.args) {
|
|
62
59
|
args.push(...options.args);
|
|
63
60
|
}
|
|
64
|
-
const command = new Command(
|
|
61
|
+
const command = new Command(executablePath, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
|
|
65
62
|
try {
|
|
66
63
|
child = await command.spawn();
|
|
67
64
|
} catch (error) {
|
|
@@ -69,8 +66,10 @@ async function launchBrowser(options = {}, indexPath = 0) {
|
|
|
69
66
|
if (indexPath + 1 < BROWSER_PATHS[build.os].length) {
|
|
70
67
|
await launchBrowser(options, indexPath + 1);
|
|
71
68
|
} else {
|
|
72
|
-
throw
|
|
69
|
+
throw "Chromium executable not found. Set the path using the --executable-path option.";
|
|
73
70
|
}
|
|
71
|
+
} else {
|
|
72
|
+
throw error;
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
child.ref();
|
package/lib/deno-polyfill.js
CHANGED
|
@@ -39,8 +39,6 @@ const NODE_MODULES = {
|
|
|
39
39
|
"url": "node:url"
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export { DenoAPI as Deno, pathAPI as path, initGlobalThisProperties };
|
|
43
|
-
|
|
44
42
|
const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
|
|
45
43
|
|
|
46
44
|
const stdout = {
|
|
@@ -119,6 +117,10 @@ const pathAPI = {
|
|
|
119
117
|
dirname
|
|
120
118
|
};
|
|
121
119
|
|
|
120
|
+
await initGlobalThisProperties();
|
|
121
|
+
|
|
122
|
+
export { DenoAPI as Deno, pathAPI as path };
|
|
123
|
+
|
|
122
124
|
async function initGlobalThisProperties() {
|
|
123
125
|
if (!DENO_RUNTIME_DETECTED) {
|
|
124
126
|
const { WebSocket } = await import(getNPMModule("ws"));
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "2.0.
|
|
1
|
+
export const version = "2.0.11";
|
package/options.js
CHANGED
|
@@ -154,7 +154,7 @@ async function getOptions() {
|
|
|
154
154
|
Object.keys(OPTIONS_INFO).forEach(optionName => {
|
|
155
155
|
const optionInfo = getOptionInfo(optionName);
|
|
156
156
|
const optionKey = getOptionKey(optionName, optionInfo);
|
|
157
|
-
if (optionInfo.defaultValue !== undefined) {
|
|
157
|
+
if (options[optionKey] === undefined && optionInfo.defaultValue !== undefined) {
|
|
158
158
|
options[optionKey] = OPTIONS_INFO[optionName].defaultValue;
|
|
159
159
|
}
|
|
160
160
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "single-file-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "SingleFile CLI",
|
|
5
5
|
"author": "Gildas Lormeau",
|
|
6
6
|
"engines": {
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"node": ">=20"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"bin":
|
|
12
|
+
"bin": {
|
|
13
|
+
"single-file": "./single-file-node.js"
|
|
14
|
+
},
|
|
13
15
|
"dependencies": {
|
|
14
16
|
"simple-cdp": "^1.8.2",
|
|
15
17
|
"ws": "^8.16.0"
|
package/single-file
CHANGED
|
@@ -1,108 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-net --allow-env --allow-run
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Copyright 2010-2024 Gildas Lormeau
|
|
5
|
-
* contact : gildas.lormeau <at> gmail.com
|
|
6
|
-
*
|
|
7
|
-
* This file is part of SingleFile.
|
|
8
|
-
*
|
|
9
|
-
* The code in this file is free software: you can redistribute it and/or
|
|
10
|
-
* modify it under the terms of the GNU Affero General Public License
|
|
11
|
-
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
12
|
-
* of the License, or (at your option) any later version.
|
|
13
|
-
*
|
|
14
|
-
* The code in this file is distributed in the hope that it will be useful,
|
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
17
|
-
* General Public License for more details.
|
|
18
|
-
*
|
|
19
|
-
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
20
|
-
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
21
|
-
* AGPL normally required by section 4, provided you include this license
|
|
22
|
-
* notice and a URL through which recipients can access the Corresponding
|
|
23
|
-
* Source.
|
|
24
|
-
*/
|
|
3
|
+
import { run } from "./single-file-launcher.js";
|
|
25
4
|
|
|
26
|
-
|
|
27
|
-
import { initGlobalThisProperties, Deno, path } from "./lib/deno-polyfill.js";
|
|
28
|
-
import options from "./options.js";
|
|
29
|
-
|
|
30
|
-
const { readTextFile } = Deno;
|
|
31
|
-
const { toFileUrl } = path;
|
|
32
|
-
await initGlobalThisProperties();
|
|
33
|
-
await run(options);
|
|
34
|
-
|
|
35
|
-
async function run(options = {}) {
|
|
36
|
-
let urls;
|
|
37
|
-
if (options.url && !VALID_URL_TEST.test(options.url)) {
|
|
38
|
-
options.url = (await toFileUrl(new URL(options.url, import.meta.url).pathname)).href;
|
|
39
|
-
}
|
|
40
|
-
if (options.urlsFile) {
|
|
41
|
-
urls = (await readTextFile(options.urlsFile)).split("\n");
|
|
42
|
-
} else {
|
|
43
|
-
urls = [options.url];
|
|
44
|
-
}
|
|
45
|
-
if (options.browserCookies) {
|
|
46
|
-
const cookies = [];
|
|
47
|
-
for (const cookie of options.browserCookies) {
|
|
48
|
-
const [name, value, domain, path, expires, httpOnly, secure, sameSite, url] = cookie.split(",");
|
|
49
|
-
cookies.push({
|
|
50
|
-
name,
|
|
51
|
-
value,
|
|
52
|
-
url,
|
|
53
|
-
domain,
|
|
54
|
-
path,
|
|
55
|
-
secure,
|
|
56
|
-
httpOnly,
|
|
57
|
-
sameSite,
|
|
58
|
-
expires
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
options.browserCookies = cookies;
|
|
62
|
-
}
|
|
63
|
-
if (options.browserCookiesFile) {
|
|
64
|
-
const cookiesContent = await readTextFile(options.browserCookiesFile);
|
|
65
|
-
try {
|
|
66
|
-
options.browserCookies = JSON.parse(cookiesContent);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
options.browserCookies = parseCookies(cookiesContent);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (options.httpHeaders) {
|
|
72
|
-
const headers = {};
|
|
73
|
-
for (const header of options.httpHeaders) {
|
|
74
|
-
const [name, value] = header.split("=");
|
|
75
|
-
headers[name] = value.trim();
|
|
76
|
-
}
|
|
77
|
-
options.httpHeaders = headers;
|
|
78
|
-
}
|
|
79
|
-
options.retrieveLinks = true;
|
|
80
|
-
const singlefile = await initialize(options);
|
|
81
|
-
await singlefile.capture(urls);
|
|
82
|
-
await singlefile.finish();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function parseCookies(textValue) {
|
|
86
|
-
const httpOnlyRegExp = /^#HttpOnly_(.*)/;
|
|
87
|
-
return textValue.split(/\r\n|\n/)
|
|
88
|
-
.filter(line => line.trim() && (!/^#/.test(line) || httpOnlyRegExp.test(line)))
|
|
89
|
-
.map(line => {
|
|
90
|
-
const httpOnly = httpOnlyRegExp.test(line);
|
|
91
|
-
if (httpOnly) {
|
|
92
|
-
line = line.replace(httpOnlyRegExp, "$1");
|
|
93
|
-
}
|
|
94
|
-
const values = line.split(/\t/);
|
|
95
|
-
if (values.length == 7) {
|
|
96
|
-
return {
|
|
97
|
-
domain: values[0],
|
|
98
|
-
path: values[2],
|
|
99
|
-
secure: values[3] == "TRUE",
|
|
100
|
-
expires: (values[4] && Number(values[4])) || undefined,
|
|
101
|
-
name: values[5],
|
|
102
|
-
value: values[6],
|
|
103
|
-
httpOnly
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
.filter(cookieData => cookieData);
|
|
108
|
-
}
|
|
5
|
+
await run();
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2010-2024 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 URL */
|
|
25
|
+
|
|
26
|
+
import { VALID_URL_TEST, initialize } from "./single-file-cli-api.js";
|
|
27
|
+
import { Deno, path } from "./lib/deno-polyfill.js";
|
|
28
|
+
import options from "./options.js";
|
|
29
|
+
|
|
30
|
+
const { readTextFile } = Deno;
|
|
31
|
+
const { toFileUrl } = path;
|
|
32
|
+
|
|
33
|
+
export { run };
|
|
34
|
+
|
|
35
|
+
async function run() {
|
|
36
|
+
let urls;
|
|
37
|
+
if (options.url && !VALID_URL_TEST.test(options.url)) {
|
|
38
|
+
options.url = (await toFileUrl(new URL(options.url, import.meta.url).pathname)).href;
|
|
39
|
+
}
|
|
40
|
+
if (options.urlsFile) {
|
|
41
|
+
urls = (await readTextFile(options.urlsFile)).split("\n");
|
|
42
|
+
} else {
|
|
43
|
+
urls = [options.url];
|
|
44
|
+
}
|
|
45
|
+
if (options.browserCookies) {
|
|
46
|
+
const cookies = [];
|
|
47
|
+
for (const cookie of options.browserCookies) {
|
|
48
|
+
const [name, value, domain, path, expires, httpOnly, secure, sameSite, url] = cookie.split(",");
|
|
49
|
+
cookies.push({
|
|
50
|
+
name,
|
|
51
|
+
value,
|
|
52
|
+
url,
|
|
53
|
+
domain,
|
|
54
|
+
path,
|
|
55
|
+
secure,
|
|
56
|
+
httpOnly,
|
|
57
|
+
sameSite,
|
|
58
|
+
expires
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
options.browserCookies = cookies;
|
|
62
|
+
}
|
|
63
|
+
if (options.browserCookiesFile) {
|
|
64
|
+
const cookiesContent = await readTextFile(options.browserCookiesFile);
|
|
65
|
+
try {
|
|
66
|
+
options.browserCookies = JSON.parse(cookiesContent);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
options.browserCookies = parseCookies(cookiesContent);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (options.httpHeaders) {
|
|
72
|
+
const headers = {};
|
|
73
|
+
for (const header of options.httpHeaders) {
|
|
74
|
+
const [name, value] = header.split("=");
|
|
75
|
+
headers[name] = value.trim();
|
|
76
|
+
}
|
|
77
|
+
options.httpHeaders = headers;
|
|
78
|
+
}
|
|
79
|
+
options.retrieveLinks = true;
|
|
80
|
+
const singlefile = await initialize(options);
|
|
81
|
+
await singlefile.capture(urls);
|
|
82
|
+
await singlefile.finish();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseCookies(textValue) {
|
|
86
|
+
const httpOnlyRegExp = /^#HttpOnly_(.*)/;
|
|
87
|
+
return textValue.split(/\r\n|\n/)
|
|
88
|
+
.filter(line => line.trim() && (!/^#/.test(line) || httpOnlyRegExp.test(line)))
|
|
89
|
+
.map(line => {
|
|
90
|
+
const httpOnly = httpOnlyRegExp.test(line);
|
|
91
|
+
if (httpOnly) {
|
|
92
|
+
line = line.replace(httpOnlyRegExp, "$1");
|
|
93
|
+
}
|
|
94
|
+
const values = line.split(/\t/);
|
|
95
|
+
if (values.length == 7) {
|
|
96
|
+
return {
|
|
97
|
+
domain: values[0],
|
|
98
|
+
path: values[2],
|
|
99
|
+
secure: values[3] == "TRUE",
|
|
100
|
+
expires: (values[4] && Number(values[4])) || undefined,
|
|
101
|
+
name: values[5],
|
|
102
|
+
value: values[6],
|
|
103
|
+
httpOnly
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
.filter(cookieData => cookieData);
|
|
108
|
+
}
|