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.3 to 3.1.0

121

lib/load-ui.js
'use strict'
const { compile: bracesToGroup } = require('braces')
const camelCaseKeys = require('camelcase-keys')
const { createHash } = require('crypto')

@@ -115,8 +114,8 @@ const expandPath = require('@antora/expand-path-helper')

).catch((err) => {
const wrapped = new Error(
const errWrapper = new Error(
`Failed to read UI ${bundleFile.isDirectory() ? 'directory' : 'bundle'}: ` +
(bundleUrl === bundleFile.path ? bundleUrl : `${bundleFile.path} (resolved from url: ${bundleUrl})`)
)
wrapped.stack += '\nCaused by: ' + (err.stack || 'unknown')
throw wrapped
errWrapper.stack += `\nCaused by: ${err.stack || 'unknown'}`
throw errWrapper
})

@@ -198,5 +197,5 @@ ),

}).catch((err) => {
const wrapped = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`)
wrapped.stack += '\nCaused by: ' + (err.stack || 'unknown')
throw wrapped
const errWrapper = new Error(`${err.summary || 'Failed to download UI bundle'}: ${url}`)
errWrapper.stack += `\nCaused by: ${err.stack || 'unknown'}`
throw errWrapper
})

@@ -262,36 +261,40 @@ }

function srcSupplementalFiles (filesSpec, startDir) {
if (!filesSpec) {
return new Map()
} else if (Array.isArray(filesSpec)) {
return Promise.all(
filesSpec.reduce((accum, { path: path_, contents: contents_ }) => {
if (!path_) {
return accum
} else if (contents_) {
if (~contents_.indexOf('\n') || !EXT_RX.test(contents_)) {
accum.push(new MemoryFile({ path: path_, contents: Buffer.from(contents_) }))
if (!filesSpec) return new Map()
let cwd
return (
Array.isArray(filesSpec)
? Promise.all(
filesSpec.reduce((accum, { path: path_, contents: contents_ }) => {
if (!path_) {
return accum
} else if (contents_) {
if (~contents_.indexOf('\n') || !EXT_RX.test(contents_)) {
accum.push(new MemoryFile({ path: path_, contents: Buffer.from(contents_) }))
} else {
contents_ = expandPath(contents_, { dot: startDir })
accum.push(
fsp
.stat(contents_)
.then((stat) =>
fsp.readFile(contents_).then((contents) => new File({ path: path_, contents, stat }))
)
)
}
} else {
contents_ = expandPath(contents_, { dot: startDir })
accum.push(
fsp
.stat(contents_)
.then((stat) => fsp.readFile(contents_).then((contents) => new File({ path: path_, contents, stat })))
)
accum.push(new MemoryFile({ path: path_ }))
}
} else {
accum.push(new MemoryFile({ path: path_ }))
}
return accum
}, [])
).then((files) => files.reduce((accum, file) => accum.set(file.path, file) && accum, new Map()))
} else {
const cwd = expandPath(filesSpec, { dot: startDir })
return fsp.access(cwd).then(
() => srcFs(cwd),
(err) => {
// Q: should we skip unreadable files?
throw Object.assign(err, { message: `problem encountered while reading ui.supplemental_files: ${err.message}` })
}
)
}
return accum
}, [])
).then((files) => files.reduce((accum, file) => accum.set(file.path, file) && accum, new Map()))
: fsp.access((cwd = expandPath(filesSpec, { dot: startDir }))).then(() => srcFs(cwd))
).catch((err) => {
const dir = cwd ? filesSpec + (filesSpec === cwd ? '' : ` (resolved to ${cwd})`) : undefined
if (err.code === 'ENOENT' && err.path === cwd) {
throw new Error(`Specified ui.supplemental_files directory does not exist: ${dir}`)
} else {
const errWrapper = new Error(`Failed to read ui.supplemental_files ${cwd ? `directory: ${dir}` : 'entry'}`)
errWrapper.stack += `\nCaused by: ${err.stack || 'unknown'}`
throw errWrapper
}
})
}

@@ -308,3 +311,3 @@

files.delete(UI_DESC_FILENAME)
const config = camelCaseKeys(yaml.load(configFile.contents.toString()), { deep: true })
const config = camelCaseKeys(yaml.load(configFile.contents.toString()))
const staticFiles = config.staticFiles

@@ -319,2 +322,12 @@ if (staticFiles && staticFiles.length) config.isStaticFile = picomatch(staticFiles, STATIC_FILE_MATCHER_OPTS)

function camelCaseKeys (o) {
if (Array.isArray(o)) return o.map(camelCaseKeys)
if (o == null || o.constructor !== Object) return o
const accum = {}
for (const [k, v] of Object.entries(o)) {
accum[k.toLowerCase().replace(/[_-]([a-z0-9])/g, (_, l, idx) => (idx ? l.toUpperCase() : l))] = camelCaseKeys(v)
}
return accum
}
function classifyFile (file, config) {

@@ -371,11 +384,10 @@ if (config.isStaticFile && config.isStaticFile(file.path)) {

(statErr) => {
if (statErr.symlink) {
statErr.message =
statErr.code === 'ELOOP'
? `Symbolic link cycle detected at ${relpath}`
: `Broken symbolic link detected at ${relpath}`
} else {
statErr.message = statErr.message.replace(`'${abspath}'`, relpath)
}
done(statErr)
done(
Object.assign(statErr, {
message: statErr.symlink
? (statErr.code === 'ELOOP' ? 'ELOOP: symbolic link cycle, ' : 'ENOENT: broken symbolic link, ') +
`${relpath} -> ${statErr.symlink}`
: statErr.message.replace(`'${abspath}'`, relpath),
})
)
}

@@ -392,5 +404,10 @@ )

if (!lstat.isSymbolicLink()) return lstat
return fsp.stat(path_).catch((statErr) => {
throw Object.assign(statErr, { symlink: true })
})
return fsp.stat(path_).catch((statErr) =>
fsp
.readlink(path_)
.catch(() => undefined)
.then((symlink) => {
throw Object.assign(statErr, { symlink })
})
)
})

@@ -397,0 +414,0 @@ }

@@ -29,2 +29,7 @@ 'use strict'

removeFile (file) {
const filesForType = this[$files].get(file.type)
return filesForType ? filesForType.delete(file.path) : false
}
findByType (type) {

@@ -31,0 +36,0 @@ const filesForType = this[$files].get(type)

{
"name": "@antora/ui-loader",
"version": "3.0.3",
"version": "3.1.0",
"description": "Downloads a UI bundle, if necessary, and loads the files into a UI catalog for use in an Antora documentation pipeline.",

@@ -19,2 +19,10 @@ "license": "MPL-2.0",

"main": "lib/index.js",
"exports": {
".": "./lib/index.js",
"./ui-catalog": "./lib/ui-catalog.js",
"./package.json": "./package.json"
},
"imports": {
"#constants": "./lib/constants.js"
},
"dependencies": {

@@ -24,6 +32,5 @@ "@antora/expand-path-helper": "~2.0",

"cache-directory": "~2.0",
"camelcase-keys": "~7.0",
"glob-stream": "~7.0",
"gulp-vinyl-zip": "~2.5",
"hpagent": "~0.1.0",
"hpagent": "~1.0",
"js-yaml": "~4.1",

@@ -36,3 +43,3 @@ "picomatch": "~2.3",

"engines": {
"node": ">=12.21.0"
"node": ">=16.0.0"
},

@@ -39,0 +46,0 @@ "files": [

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