Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antora/ui-loader

Package Overview
Dependencies
Maintainers
2
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/ui-loader - npm Package Compare versions

Comparing version 3.0.0-alpha.5 to 3.0.0-alpha.6

86

lib/load-ui.js
'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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc