single-file-cli 2.0.45 → 2.0.46

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.45",
3
+ "version": "2.0.46",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
@@ -36,7 +36,8 @@ const NODE_MODULES = {
36
36
  "fs": "node:fs/promises",
37
37
  "os": "node:os",
38
38
  "child_process": "node:child_process",
39
- "url": "node:url"
39
+ "url": "node:url",
40
+ "process": "node:process"
40
41
  };
41
42
 
42
43
  const args = DENO_RUNTIME_DETECTED ? Deno.args : process.argv.slice(2);
@@ -111,11 +112,14 @@ const DenoAPI = {
111
112
  addSignalListener,
112
113
  build,
113
114
  errors,
114
- Command
115
+ Command,
116
+ cwd
115
117
  };
116
118
 
117
119
  const pathAPI = {
118
- dirname
120
+ dirname,
121
+ toFileUrl,
122
+ SEPARATOR: DENO_RUNTIME_DETECTED ? path.SEPARATOR : path.sep
119
123
  };
120
124
 
121
125
  await initGlobalThisProperties();
@@ -204,6 +208,11 @@ function exit(code) {
204
208
  if (DENO_RUNTIME_DETECTED) {
205
209
  Deno.exit(code);
206
210
  } else {
211
+ if (code == "SIGINT") {
212
+ code = 130;
213
+ } else if (code == "SIGTERM") {
214
+ code = 143;
215
+ }
207
216
  process.exit(code);
208
217
  }
209
218
  }
@@ -216,10 +225,28 @@ function addSignalListener(signal, listener) {
216
225
  }
217
226
  }
218
227
 
228
+ async function cwd() {
229
+ if (DENO_RUNTIME_DETECTED) {
230
+ return Deno.cwd();
231
+ } else {
232
+ const process = await import(NODE_MODULES["process"]);
233
+ return process.cwd();
234
+ }
235
+ }
236
+
219
237
  async function dirname(filePath) {
220
238
  return path.dirname(filePath);
221
239
  }
222
240
 
241
+ async function toFileUrl(filePath) {
242
+ if (DENO_RUNTIME_DETECTED) {
243
+ return path.toFileUrl(filePath);
244
+ } else {
245
+ const url = await import(NODE_MODULES["url"]);
246
+ return url.pathToFileURL(filePath).href;
247
+ }
248
+ }
249
+
223
250
  function getNPMModule(module) {
224
251
  return NPM_MODULES[module];
225
252
  }
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "2.0.45";
1
+ export const version = "2.0.46";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-cli",
3
- "version": "2.0.45",
3
+ "version": "2.0.46",
4
4
  "description": "SingleFile CLI",
5
5
  "author": "Gildas Lormeau",
6
6
  "engines": {
@@ -101,7 +101,7 @@ async function initialize(options) {
101
101
  async function capture(urls, options) {
102
102
  let newTasks;
103
103
  const taskUrls = tasks.map(task => task.url);
104
- newTasks = urls.map(url => createTask(url, options));
104
+ newTasks = await Promise.all(urls.map(url => createTask(url, options)));
105
105
  newTasks = newTasks.filter(task => task && !taskUrls.includes(task.url));
106
106
  if (newTasks.length) {
107
107
  tasks = tasks.concat(newTasks);
@@ -161,13 +161,13 @@ async function runNextTask() {
161
161
  if (pageData) {
162
162
  task.filename = pageData.filename;
163
163
  if (options.crawlLinks && testMaxDepth(task)) {
164
- let newTasks = pageData.links
165
- .map(urlLink => createTask(urlLink, options, task, tasks[0]))
166
- .filter(task => task &&
167
- testMaxDepth(task) &&
168
- !tasks.find(otherTask => otherTask.url == task.url) &&
169
- (!options.crawlInnerLinksOnly || task.isInnerLink) &&
170
- (!options.crawlNoParent || (task.isChild || !task.isInnerLink)));
164
+ const urls = pageData.links;
165
+ let newTasks = await Promise.all(urls.map(url => createTask(url, options, task, tasks[0])));
166
+ newTasks = newTasks.filter(task => task &&
167
+ testMaxDepth(task) &&
168
+ !tasks.find(otherTask => otherTask.url == task.url) &&
169
+ (!options.crawlInnerLinksOnly || task.isInnerLink) &&
170
+ (!options.crawlNoParent || (task.isChild || !task.isInnerLink)));
171
171
  tasks.splice(tasks.length, 0, ...newTasks);
172
172
  }
173
173
  }
@@ -182,15 +182,16 @@ function testMaxDepth(task) {
182
182
  (options.crawlExternalLinksMaxDepth == 0 || task.externalLinkDepth < options.crawlExternalLinksMaxDepth);
183
183
  }
184
184
 
185
- function createTask(url, options, parentTask, rootTask) {
185
+ async function createTask(url, options, parentTask, rootTask) {
186
186
  url = parentTask ? rewriteURL(url, options.crawlRemoveURLFragment, options.crawlRewriteRules) : url;
187
187
  if (!VALID_URL_TEST.test(url)) {
188
188
  try {
189
189
  url = url.replace(/\\/g, "/");
190
190
  url = url.replace(/#/g, "%23");
191
- url = new URL(url, import.meta.url).href;
191
+ const baseURL = await path.toFileUrl((await Deno.cwd()) + path.SEPARATOR);
192
+ url = new URL(url, baseURL).href;
192
193
  } catch (error) {
193
- throw new Error("Invalid URL or file path: " + url);
194
+ throw new Error("Invalid URL or file path: " + url, { cause: error });
194
195
  }
195
196
  }
196
197
  const isInnerLink = rootTask && url.startsWith(getHostURL(rootTask.url));