single-file-cli 2.0.4 → 2.0.6

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/Dockerfile CHANGED
@@ -9,5 +9,4 @@ ENTRYPOINT [ \
9
9
  "./single-file", \
10
10
  "--browser-executable-path", "/usr/bin/chromium-browser", \
11
11
  "--output-directory", "./../../out/", \
12
- "--browser-args", "[\"--no-sandbox\"]", \
13
12
  "--dump-content" ]
package/build-lib.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
 
3
- deno vendor "npm:single-file-core"
3
+ deno vendor "npm:single-file-core@1.3.28"
4
4
 
5
5
  echo "
6
6
  import { build } from 'npm:esbuild';
@@ -80,4 +80,5 @@ await Promise.all(SCRIPTS.map(script => Deno.remove(script)));
80
80
  await Deno.remove('lib/single-file-hooks-frames.js');
81
81
  " | deno run --allow-read --allow-write --allow-net --allow-run --allow-env --lock=node_modules/deno.lock.tmp -
82
82
 
83
- rm -rf node_modules
83
+ rm -rf node_modules
84
+ rm -rf vendor
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
@@ -21,11 +21,12 @@
21
21
  * Source.
22
22
  */
23
23
 
24
- import { BROWSER_PATHS, BROWSER_ARGS } from "./chromium-constants.js";
25
- import { build, makeTempDir, Command, errors, remove } from "../deno-polyfill.js";
24
+ import { BROWSER_PATHS, BROWSER_ARGS } from "./constants.js";
25
+ import { Deno } from "./deno-polyfill.js";
26
26
 
27
27
  const PIPED_STD_CONFIG = "piped";
28
28
 
29
+ const { build, makeTempDir, Command, errors, remove } = Deno;
29
30
  let child, profilePath;
30
31
  export { launchBrowser, closeBrowser };
31
32
 
@@ -56,10 +57,10 @@ async function launchBrowser(options = {}, indexPath = 0) {
56
57
  if (options.httpProxyServer) {
57
58
  args.push("--proxy-server=" + options.httpProxyServer);
58
59
  }
60
+ args.push(`--user-data-dir=${profilePath}`);
59
61
  if (options.args) {
60
62
  args.push(...options.args);
61
63
  }
62
- args.push(`--user-data-dir=${profilePath}`);
63
64
  const command = new Command(path, { args, stdout: PIPED_STD_CONFIG, stderr: PIPED_STD_CONFIG });
64
65
  try {
65
66
  child = await command.spawn();
@@ -23,7 +23,7 @@
23
23
 
24
24
  /* global setTimeout, clearTimeout */
25
25
 
26
- import { launchBrowser, closeBrowser } from "./chromium-browser.js";
26
+ import { launchBrowser, closeBrowser } from "./browser.js";
27
27
  import { getScriptSource, getHookScriptSource } from "./single-file-script.js";
28
28
  import { CDP } from "simple-cdp";
29
29
 
@@ -119,16 +119,14 @@ async function getPageData(options) {
119
119
  worldName: SINGLE_FILE_WORLD_NAME
120
120
  });
121
121
  await Runtime.enable();
122
- let topFrameId;
122
+ const topFrameId = targetInfo.id;
123
123
  const executionContextIdPromise = new Promise(resolve => {
124
124
  const CONTEXT_CREATED_EVENT = "executionContextCreated";
125
125
  Runtime.addEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
126
126
 
127
127
  async function executionContextCreated({ params }) {
128
128
  const { context } = params;
129
- if (context.auxData && context.auxData.isDefault && topFrameId === undefined) {
130
- topFrameId = context.auxData.frameId;
131
- } else if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
129
+ if (context.name === SINGLE_FILE_WORLD_NAME && context.auxData && context.auxData.frameId === topFrameId) {
132
130
  Runtime.removeEventListener(CONTEXT_CREATED_EVENT, executionContextCreated);
133
131
  await Runtime.disable();
134
132
  resolve(context.id);
@@ -145,20 +143,19 @@ async function getPageData(options) {
145
143
 
146
144
  async function onLifecycleEvent({ params }) {
147
145
  const { name, frameId } = params;
148
- if (topFrameId === undefined && frameId !== undefined) {
149
- topFrameId = frameId;
150
- }
151
- if (name === "DOMContentLoaded" && topFrameId !== undefined && frameId === topFrameId) {
152
- contentLoaded = true;
153
- }
154
- if (contentLoaded && name === (options.browserWaitUntil || NETWORK_IDLE_STATE) && frameId === topFrameId) {
155
- if (options.browserWaitDelay) {
156
- setTimeout(() => resolve, options.browserWaitDelay);
157
- } else {
158
- Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
159
- await Page.setLifecycleEventsEnabled({ enabled: false });
160
- await Page.disable();
161
- resolve();
146
+ if (frameId === topFrameId) {
147
+ if (name === "DOMContentLoaded") {
148
+ contentLoaded = true;
149
+ }
150
+ if (contentLoaded && name === (options.browserWaitUntil || NETWORK_IDLE_STATE)) {
151
+ if (options.browserWaitDelay) {
152
+ setTimeout(() => resolve, options.browserWaitDelay);
153
+ } else {
154
+ Page.removeEventListener(LIFE_CYCLE_EVENT, onLifecycleEvent);
155
+ await Page.setLifecycleEventsEnabled({ enabled: false });
156
+ await Page.disable();
157
+ resolve();
158
+ }
162
159
  }
163
160
  }
164
161
  }
@@ -209,7 +206,7 @@ async function getPageData(options) {
209
206
 
210
207
  function getBrowserOptions(options) {
211
208
  const browserOptions = {};
212
- browserOptions.args = options.browserArgs ? JSON.parse(options.browserArgs) : [];
209
+ browserOptions.args = options.browserArgs;
213
210
  browserOptions.headless = options.browserHeadless && !options.browserDebug;
214
211
  browserOptions.executablePath = options.browserExecutablePath;
215
212
  browserOptions.browserDebug = options.browserDebug;
@@ -39,23 +39,7 @@ const NODE_MODULES = {
39
39
  "url": "node:url"
40
40
  };
41
41
 
42
- export {
43
- initGlobalThisProperties,
44
- args,
45
- readTextFile,
46
- writeTextFile,
47
- mkdir,
48
- makeTempDir,
49
- stat,
50
- remove,
51
- stdout,
52
- exit,
53
- build,
54
- errors,
55
- Command,
56
- toFileUrl,
57
- dirname
58
- };
42
+ export { DenoAPI as Deno, pathAPI as path, initGlobalThisProperties };
59
43
 
60
44
  const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
61
45
 
@@ -76,6 +60,65 @@ const errors = {
76
60
  }
77
61
  };
78
62
 
63
+ const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
64
+ constructor(path, options = {}) {
65
+ this.path = path;
66
+ this.options = options;
67
+ }
68
+ async spawn() {
69
+ const childProcess = await import(NODE_MODULES["child_process"]);
70
+ const child = childProcess.spawn(this.path, this.options.args);
71
+
72
+ await new Promise((resolve, reject) => {
73
+ child.on("spawn", () => resolve());
74
+ child.on("error", error => {
75
+ if (error.code == "ENOENT") {
76
+ reject(new errors.NotFound(error.message));
77
+ } else {
78
+ reject(error);
79
+ }
80
+ });
81
+ });
82
+ return {
83
+ status: new Promise((resolve, reject) => {
84
+ child.on("exit", code => {
85
+ if (code === 0 || code === 143) {
86
+ resolve();
87
+ } else {
88
+ reject(new Error(`Process exited with code ${code}`));
89
+ }
90
+ });
91
+ }),
92
+ kill() {
93
+ child.kill();
94
+ },
95
+ ref() {
96
+ // Do nothing
97
+ }
98
+ };
99
+ }
100
+ };
101
+
102
+ const DenoAPI = {
103
+ args,
104
+ readTextFile,
105
+ writeTextFile,
106
+ mkdir,
107
+ makeTempDir,
108
+ stat,
109
+ remove,
110
+ stdout,
111
+ exit,
112
+ build,
113
+ errors,
114
+ Command
115
+ };
116
+
117
+ const pathAPI = {
118
+ toFileUrl,
119
+ dirname
120
+ };
121
+
79
122
  async function initGlobalThisProperties() {
80
123
  if (!DENO_RUNTIME_DETECTED) {
81
124
  const { WebSocket } = await import(getNPMModule("ws"));
@@ -152,45 +195,6 @@ function exit(code) {
152
195
  }
153
196
  }
154
197
 
155
- const Command = DENO_RUNTIME_DETECTED ? Deno.Command : class Command {
156
- constructor(path, options = {}) {
157
- this.path = path;
158
- this.options = options;
159
- }
160
- async spawn() {
161
- const childProcess = await import(NODE_MODULES["child_process"]);
162
- const child = childProcess.spawn(this.path, this.options.args);
163
-
164
- await new Promise((resolve, reject) => {
165
- child.on("spawn", () => resolve());
166
- child.on("error", error => {
167
- if (error.code == "ENOENT") {
168
- reject(new errors.NotFound(error.message));
169
- } else {
170
- reject(error);
171
- }
172
- });
173
- });
174
- return {
175
- status: new Promise((resolve, reject) => {
176
- child.on("exit", code => {
177
- if (code === 0 || code === 143) {
178
- resolve();
179
- } else {
180
- reject(new Error(`Process exited with code ${code}`));
181
- }
182
- });
183
- }),
184
- kill() {
185
- child.kill();
186
- },
187
- ref() {
188
- // Do nothing
189
- }
190
- };
191
- }
192
- };
193
-
194
198
  async function toFileUrl(filePath) {
195
199
  if (DENO_RUNTIME_DETECTED) {
196
200
  return path.toFileUrl(filePath);
@@ -201,11 +205,7 @@ async function toFileUrl(filePath) {
201
205
  }
202
206
 
203
207
  async function dirname(filePath) {
204
- if (DENO_RUNTIME_DETECTED) {
205
- return path.dirname(filePath);
206
- } else {
207
- return path.dirname(filePath);
208
- }
208
+ return path.dirname(filePath);
209
209
  }
210
210
 
211
211
  function getNPMModule(module) {