@antora/ui-loader
Advanced tools
Comparing version 3.0.0-alpha.5 to 3.0.0-alpha.6
'use strict' | ||
const camelCaseKeys = require('camelcase-keys') | ||
const collectBuffer = require('bl') | ||
const concat = require('simple-concat') | ||
const { createHash } = require('crypto') | ||
@@ -9,3 +9,3 @@ const expandPath = require('@antora/expand-path-helper') | ||
const { promises: fsp } = require('fs') | ||
const get = require('got') | ||
const { concat: get } = require('simple-get') | ||
const getCacheDir = require('cache-directory') | ||
@@ -46,2 +46,6 @@ const minimatchAll = require('minimatch-all') | ||
* retrieved if configured as a snapshot. | ||
* @param {Object} playbook.network - The network configuration object for Antora. | ||
* @param {String} [playbook.network.httpProxy=undefined] - The URL of the proxy to use for HTTP URLs. | ||
* @param {String} [playbook.network.httpsProxy=undefined] - The URL of the proxy to use for HTTPS URLs. | ||
* @param {String} [playbook.network.noProxy=undefined] - The list of domains and IPs that should not be proxied. | ||
* @param {Object} playbook.ui - The UI configuration object for Antora. | ||
@@ -73,7 +77,7 @@ * @param {String} playbook.ui.bundle - The UI bundle configuration. | ||
return fetch && bundle.snapshot | ||
? downloadBundle(bundleUrl, cachePath) | ||
? downloadBundle(bundleUrl, cachePath, createAgent(bundleUrl, playbook.network || {})) | ||
: fsp | ||
.stat(cachePath) | ||
.then((stat) => new File({ path: cachePath, stat })) | ||
.catch(() => downloadBundle(bundleUrl, cachePath)) | ||
.catch(() => downloadBundle(bundleUrl, cachePath, createAgent(bundleUrl, playbook.network || {}))) | ||
}) | ||
@@ -159,27 +163,42 @@ } else { | ||
function downloadBundle (url, to) { | ||
return get(url, { resolveBodyOnly: true, responseType: 'buffer' }) | ||
.then( | ||
(body) => | ||
new Promise((resolve, reject) => | ||
new ReadableFile(new MemoryFile({ path: ospath.basename(to), contents: body })) | ||
.pipe(vzip.src()) | ||
.on('error', (err) => | ||
reject( | ||
Object.assign(err, { message: `not a valid zip file; ${err.message}`, summary: 'Invalid UI bundle' }) | ||
) | ||
) | ||
.on('finish', () => | ||
fsp | ||
.mkdir(ospath.dirname(to), { recursive: true }) | ||
.then(() => fsp.writeFile(to, body)) | ||
.then(() => resolve(new File({ path: to, stat: { isDirectory: () => false } }))) | ||
) | ||
function createAgent (url, { httpProxy, httpsProxy, noProxy }) { | ||
if (httpsProxy || httpProxy) { | ||
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent') | ||
const proxy = url.startsWith('https:') | ||
? { ProxyAgent: HttpsProxyAgent, url: httpsProxy } | ||
: { ProxyAgent: HttpProxyAgent, url: httpProxy } | ||
if (proxy.url && require('should-proxy')(url, { no_proxy: noProxy })) { | ||
// see https://github.com/delvedor/hpagent/issues/18 | ||
const { protocol, hostname, port, username, password } = new URL(proxy.url) | ||
const proxyUrl = { protocol, hostname, port, username: username || null, password: password || null } | ||
return new proxy.ProxyAgent({ proxy: proxyUrl }) | ||
} | ||
} | ||
} | ||
function downloadBundle (url, to, agent) { | ||
return new Promise((resolve, reject) => { | ||
get({ url, agent }, (err, response, contents) => { | ||
if (err) reject(err) | ||
if (response.statusCode !== 200) { | ||
const message = `Response code ${response.statusCode} (${response.statusMessage})` | ||
return reject(Object.assign(new Error(message), { name: 'HTTPError' })) | ||
} | ||
new ReadableFile(new MemoryFile({ path: ospath.basename(to), contents })) | ||
.pipe(vzip.src()) | ||
.on('error', (err) => | ||
reject(Object.assign(err, { message: `not a valid zip file; ${err.message}`, summary: 'Invalid UI bundle' })) | ||
) | ||
) | ||
.catch((err) => { | ||
const wrapped = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`) | ||
wrapped.stack += '\nCaused by: ' + (err.stack || 'unknown') | ||
throw wrapped | ||
.on('finish', function () { | ||
fsp | ||
.mkdir(ospath.dirname(to), { recursive: true }) | ||
.then(() => fsp.writeFile(to, contents)) | ||
.then(() => resolve(new File({ path: to, stat: { isDirectory: () => false } }))) | ||
}) | ||
}) | ||
}).catch((err) => { | ||
const wrapped = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`) | ||
wrapped.stack += '\nCaused by: ' + (err.stack || 'unknown') | ||
throw wrapped | ||
}) | ||
} | ||
@@ -221,10 +240,7 @@ | ||
if (file.isStream()) { | ||
file.contents.pipe( | ||
collectBuffer((err, data) => { | ||
if (err) return next(err) | ||
file.contents = data | ||
file.stat.size = data.length | ||
next(null, file) | ||
}) | ||
) | ||
concat(file.contents, (err, contents) => { | ||
if (err) return next(err) | ||
file.stat.size = (file.contents = contents).length | ||
next(null, file) | ||
}) | ||
} else { | ||
@@ -231,0 +247,0 @@ file.stat.size = file.contents.length |
{ | ||
"name": "@antora/ui-loader", | ||
"version": "3.0.0-alpha.5", | ||
"version": "3.0.0-alpha.6", | ||
"description": "Downloads a UI bundle, if necessary, and loads the files into a UI catalog for use in an Antora documentation pipeline.", | ||
@@ -21,9 +21,11 @@ "license": "MPL-2.0", | ||
"@antora/expand-path-helper": "~1.0", | ||
"bl": "~5.0", | ||
"cache-directory": "~2.0", | ||
"camelcase-keys": "~6.2", | ||
"got": "~11.8", | ||
"gulp-vinyl-zip": "~2.2", | ||
"hpagent": "~0.1.0", | ||
"js-yaml": "~4.1", | ||
"minimatch-all": "~1.1", | ||
"should-proxy": "~1.0", | ||
"simple-concat": "~1.0", | ||
"simple-get": "~4.0", | ||
"vinyl": "~2.2", | ||
@@ -47,3 +49,3 @@ "vinyl-fs": "~3.0" | ||
], | ||
"gitHead": "433242dd89b2859355cf6a5ea045337f527a3415" | ||
"gitHead": "38ec002e88eede3ce5c401a6e226d1a0356945c5" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35373
440
12
+ Addedhpagent@~0.1.0
+ Addedshould-proxy@~1.0
+ Addedsimple-concat@~1.0
+ Addedsimple-get@~4.0
+ Addedhpagent@0.1.2(transitive)
+ Addedshould-proxy@1.0.4(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@4.0.1(transitive)
- Removedbl@~5.0
- Removedgot@~11.8
- Removed@sindresorhus/is@4.6.0(transitive)
- Removed@szmarczak/http-timer@4.0.6(transitive)
- Removed@types/cacheable-request@6.0.3(transitive)
- Removed@types/http-cache-semantics@4.0.4(transitive)
- Removed@types/keyv@3.1.4(transitive)
- Removed@types/node@22.10.0(transitive)
- Removed@types/responselike@1.0.3(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbl@5.0.0(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedcacheable-lookup@5.0.4(transitive)
- Removedcacheable-request@7.0.4(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddefer-to-connect@2.0.1(transitive)
- Removedget-stream@5.2.0(transitive)
- Removedgot@11.8.6(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp2-wrapper@1.0.3(transitive)
- Removedieee754@1.2.1(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlowercase-keys@2.0.0(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removednormalize-url@6.1.0(transitive)
- Removedp-cancelable@2.1.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedquick-lru@5.1.1(transitive)
- Removedresolve-alpn@1.2.1(transitive)
- Removedresponselike@2.0.1(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedundici-types@6.20.0(transitive)