html-get 2.11.4 → 2.11.5

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.
Files changed (2) hide show
  1. package/package.json +5 -3
  2. package/src/index.js +29 -20
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "html-get",
3
3
  "description": "Get the HTML from any website, using prerendering when is necessary.",
4
4
  "homepage": "https://nicedoc.com/microlinkhq/html-get",
5
- "version": "2.11.4",
5
+ "version": "2.11.5",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "html-get": "bin/index.js"
@@ -98,7 +98,8 @@
98
98
  "test/**/*.js",
99
99
  "!test/util.js"
100
100
  ],
101
- "timeout": "2m"
101
+ "timeout": "2m",
102
+ "workerThreads": false
102
103
  },
103
104
  "commitlint": {
104
105
  "extends": [
@@ -107,7 +108,8 @@
107
108
  },
108
109
  "nano-staged": {
109
110
  "*.js": [
110
- "prettier-standard"
111
+ "prettier-standard",
112
+ "standard --fix"
111
113
  ],
112
114
  "*.md": [
113
115
  "standard-markdown"
package/src/index.js CHANGED
@@ -152,24 +152,32 @@ const determinateMode = (url, { prerender }) => {
152
152
  return isFetchMode(url) ? 'fetch' : 'prerender'
153
153
  }
154
154
 
155
- const getContent = async (
156
- url,
157
- mode,
158
- { getBrowserless, gotOpts, headers, puppeteerOpts, rewriteUrls, toEncode }
159
- ) => {
160
- const isFetchMode = mode === 'fetch'
161
- const fetchOpts = isFetchMode
162
- ? { headers, toEncode, ...gotOpts }
163
- : { headers, toEncode, getBrowserless, gotOpts, ...puppeteerOpts }
164
- const content = await modes[mode](url, fetchOpts)
165
-
166
- const html = addHtml({
167
- ...content,
168
- ...(isFetchMode ? puppeteerOpts : undefined),
169
- rewriteUrls
170
- })
171
- return { ...content, html }
172
- }
155
+ const getContent = PCancelable.fn(
156
+ (
157
+ url,
158
+ mode,
159
+ { getBrowserless, gotOpts, headers, puppeteerOpts, rewriteUrls, toEncode },
160
+ onCancel
161
+ ) => {
162
+ const isFetchMode = mode === 'fetch'
163
+ const fetchOpts = isFetchMode
164
+ ? { headers, toEncode, ...gotOpts }
165
+ : { headers, toEncode, getBrowserless, gotOpts, ...puppeteerOpts }
166
+
167
+ const promise = modes[mode](url, fetchOpts)
168
+ onCancel(() => promise.cancel())
169
+
170
+ return promise.then(content => {
171
+ const html = addHtml({
172
+ ...content,
173
+ ...(isFetchMode ? puppeteerOpts : undefined),
174
+ rewriteUrls
175
+ })
176
+
177
+ return { ...content, html }
178
+ })
179
+ }
180
+ )
173
181
 
174
182
  module.exports = PCancelable.fn(
175
183
  async (
@@ -206,14 +214,15 @@ module.exports = PCancelable.fn(
206
214
  toEncode
207
215
  })
208
216
 
209
- onCancel(() => promise.onCancel())
217
+ onCancel(() => promise.cancel())
210
218
 
211
219
  const { mode, ...payload } = await promise
212
220
 
213
- return { ...payload, stats: { mode, timing: time.rounded() } }
221
+ return Object.assign(payload, { stats: { mode, timing: time.rounded() } })
214
222
  }
215
223
  )
216
224
 
217
225
  module.exports.REQ_TIMEOUT = REQ_TIMEOUT
218
226
  module.exports.ABORT_TYPES = ABORT_TYPES
219
227
  module.exports.isFetchMode = isFetchMode
228
+ module.exports.getContent = getContent