single-file-cli 2.0.83 → 2.1.1
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/.github/workflows/ci.yml +30 -0
- package/build.sh +1 -1
- package/compile.sh +18 -13
- package/deno.json +2 -3
- package/deno.lock +545 -56
- package/lib/browser.js +58 -15
- package/lib/cdp-client-util.js +6 -6
- package/lib/cdp-client.js +151 -94
- package/lib/deno-polyfill.js +25 -30
- package/lib/single-file-bundle.js +1 -1
- package/lib/single-file-script.js +3 -1
- package/lib/version.js +1 -1
- package/options.js +2 -1
- package/package.json +13 -8
- package/single-file-cli-api.js +48 -26
- package/single-file-launcher.js +11 -2
- package/test/e2e/crawl.test.js +144 -0
- package/test/e2e/frame-gate.test.js +62 -0
- package/test/e2e/output-json.test.js +45 -0
- package/test/unit/command.test.js +41 -0
- package/test/unit/file-url.test.js +37 -0
package/lib/deno-polyfill.js
CHANGED
|
@@ -29,11 +29,6 @@ import * as path from "path";
|
|
|
29
29
|
|
|
30
30
|
const DENO_RUNTIME_DETECTED = typeof Deno !== "undefined";
|
|
31
31
|
|
|
32
|
-
const NPM_MODULES = {
|
|
33
|
-
"ws": "ws",
|
|
34
|
-
"simple-cdp": "simple-cdp",
|
|
35
|
-
};
|
|
36
|
-
|
|
37
32
|
const NODE_MODULES = {
|
|
38
33
|
"fs": "node:fs/promises",
|
|
39
34
|
"os": "node:os",
|
|
@@ -68,7 +63,9 @@ const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
|
|
|
68
63
|
}
|
|
69
64
|
async spawn() {
|
|
70
65
|
const childProcess = await import(NODE_MODULES["child_process"]);
|
|
71
|
-
const
|
|
66
|
+
const stdio = [this.options.stdin, this.options.stdout, this.options.stderr]
|
|
67
|
+
.map(config => config == "null" ? "ignore" : config == "piped" ? "pipe" : "inherit");
|
|
68
|
+
const child = childProcess.spawn(this.path, this.options.args, { stdio });
|
|
72
69
|
|
|
73
70
|
await new Promise((resolve, reject) => {
|
|
74
71
|
child.on("spawn", () => resolve());
|
|
@@ -81,14 +78,8 @@ const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
|
|
|
81
78
|
});
|
|
82
79
|
});
|
|
83
80
|
return {
|
|
84
|
-
status: new Promise(
|
|
85
|
-
child.on("exit", code => {
|
|
86
|
-
if (code === 0 || code === 143 || code === 130 || code === null) {
|
|
87
|
-
resolve();
|
|
88
|
-
} else {
|
|
89
|
-
reject(new Error(`Process exited with code ${code}`));
|
|
90
|
-
}
|
|
91
|
-
});
|
|
81
|
+
status: new Promise(resolve => {
|
|
82
|
+
child.on("exit", (code, signal) => resolve({ success: code === 0, code, signal }));
|
|
92
83
|
}),
|
|
93
84
|
kill() {
|
|
94
85
|
child.kill();
|
|
@@ -122,22 +113,21 @@ const DenoAPI = {
|
|
|
122
113
|
const pathAPI = {
|
|
123
114
|
dirname,
|
|
124
115
|
toFileUrl,
|
|
116
|
+
fromFileUrl,
|
|
125
117
|
SEPARATOR: DENO_RUNTIME_DETECTED ? path.SEPARATOR : path.sep
|
|
126
118
|
};
|
|
127
119
|
|
|
128
120
|
const isDeno = DENO_RUNTIME_DETECTED;
|
|
129
121
|
|
|
130
|
-
|
|
122
|
+
// the connection to the browser relies on the WebSocket of the runtime, which
|
|
123
|
+
// Node.js provides since 22.4.0 and can still be turned off with
|
|
124
|
+
// --no-experimental-websocket
|
|
125
|
+
if (typeof globalThis.WebSocket !== "function") {
|
|
126
|
+
throw new Error("WebSocket is not available, Node.js 22.4.0 or later is required");
|
|
127
|
+
}
|
|
131
128
|
|
|
132
129
|
export { DenoAPI as Deno, pathAPI as path, isDeno };
|
|
133
130
|
|
|
134
|
-
async function initGlobalThisProperties() {
|
|
135
|
-
if (!DENO_RUNTIME_DETECTED) {
|
|
136
|
-
const { WebSocket } = await import(getNPMModule("ws"));
|
|
137
|
-
globalThis.WebSocket = WebSocket;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
131
|
async function readFile(path) {
|
|
142
132
|
if (DENO_RUNTIME_DETECTED) {
|
|
143
133
|
return Deno.readFile(path);
|
|
@@ -219,21 +209,21 @@ async function remove(path, options = {}) {
|
|
|
219
209
|
}
|
|
220
210
|
|
|
221
211
|
function exit(code) {
|
|
212
|
+
if (code == "SIGINT") {
|
|
213
|
+
code = 130;
|
|
214
|
+
} else if (code == "SIGTERM") {
|
|
215
|
+
code = 143;
|
|
216
|
+
}
|
|
222
217
|
if (DENO_RUNTIME_DETECTED) {
|
|
223
218
|
Deno.exit(code);
|
|
224
219
|
} else {
|
|
225
|
-
if (code == "SIGINT") {
|
|
226
|
-
code = 130;
|
|
227
|
-
} else if (code == "SIGTERM") {
|
|
228
|
-
code = 143;
|
|
229
|
-
}
|
|
230
220
|
process.exit(code);
|
|
231
221
|
}
|
|
232
222
|
}
|
|
233
223
|
|
|
234
224
|
function addSignalListener(signal, listener) {
|
|
235
225
|
if (DENO_RUNTIME_DETECTED) {
|
|
236
|
-
Deno.addSignalListener(signal, listener);
|
|
226
|
+
Deno.addSignalListener(signal, () => listener(signal));
|
|
237
227
|
} else {
|
|
238
228
|
process.once(signal, listener);
|
|
239
229
|
}
|
|
@@ -261,6 +251,11 @@ async function toFileUrl(filePath) {
|
|
|
261
251
|
}
|
|
262
252
|
}
|
|
263
253
|
|
|
264
|
-
function
|
|
265
|
-
|
|
254
|
+
async function fromFileUrl(fileUrl) {
|
|
255
|
+
if (DENO_RUNTIME_DETECTED) {
|
|
256
|
+
return path.fromFileUrl(fileUrl);
|
|
257
|
+
} else {
|
|
258
|
+
const url = await import(NODE_MODULES["url"]);
|
|
259
|
+
return url.fileURLToPath(fileUrl);
|
|
260
|
+
}
|
|
266
261
|
}
|