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

@antora/file-publisher

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antora/file-publisher - npm Package Compare versions

Comparing version 3.1.7 to 3.1.8

lib/cloneable-readable.js

35

lib/providers/archive.js
'use strict'
const expandPath = require('@antora/expand-path-helper')
const fs = require('fs')
const ospath = require('path')
const publishStream = require('./common/publish-stream')
const { dest: vzipDest } = require('@vscode/gulp-vinyl-zip')
const { Writable } = require('stream')
const forEach = (construct, write, final) => new Writable({ objectMode: true, construct, write, final })
const { ZipFile } = require('yazl')

@@ -14,5 +18,32 @@ const { DEFAULT_DEST_ARCHIVE } = require('../constants.js')

const report = { provider: 'archive', path: destFile, resolvedPath: absDestFile }
return publishStream(vzipDest(absDestFile), files).then(() => report)
return publishStream(zipDest(absDestFile), files).then(() => report)
}
function zipDest (zipPath, zipFile = new ZipFile(), writeStream) {
return forEach(
(done) => {
fs.mkdir(ospath.dirname(zipPath), { recursive: true }, (mkdirErr) =>
mkdirErr ? done(mkdirErr) : zipFile.outputStream.pipe((writeStream = fs.createWriteStream(zipPath))) && done()
)
},
(file, _, done) => {
const zipStat = file.stat ? { compress: true, mode: file.stat.mode, mtime: file.stat.mtime } : { compress: true }
try {
file.isStream()
? zipFile.addReadStream(file.contents, file.relative, zipStat)
: file.isNull() || zipFile.addBuffer(file.isSymbolic() ? file.symlink : file.contents, file.relative, zipStat)
done()
} catch (addErr) {
const bubbleError = () => done(addErr)
writeStream.on('error', bubbleError).on('close', bubbleError)
zipFile.outputStream.end()
}
},
(done) => {
writeStream.on('error', done).on('close', done)
zipFile.on('error', done).end()
}
)
}
module.exports = publishToArchive

10

lib/providers/common/publish-stream.js

@@ -12,11 +12,11 @@ 'use strict'

*
* @param {Function} destAdapter - A Vinyl destination adapter, preconfigured to
* write to a destination (e.g., `require('vinyl-fs').dest('path/to/dir')`).
* @param {Function} dest - A Vinyl destination adapter, preconfigured to
* write to a destination (e.g., `dest('path/to/dir')` from vinyl-fs).
* @param {Readable<File>} files - A Readable stream of virtual files to publish.
* @returns {Promise} A promise that resolves when the stream has ended.
* @returns {Promise} A promise that resolves when the stream ends (i.e., emits the finish event).
*/
function publishStream (destAdapter, files) {
return new Promise((resolve, reject) => files.pipe(destAdapter).on('error', reject).on('end', resolve))
function publishStream (dest, files) {
return new Promise((resolve, reject) => files.pipe(dest).on('error', reject).on('finish', resolve))
}
module.exports = publishStream

@@ -5,5 +5,9 @@ 'use strict'

const { promises: fsp } = require('fs')
const mkdirp = (path) => fsp.mkdir(path, { recursive: true })
const rmrf = (path) => fsp['rm' in fsp ? 'rm' : 'rmdir'](path, { recursive: true, force: true })
const ospath = require('path')
const { pathToFileURL } = require('url')
const publishStream = require('./common/publish-stream')
const { dest: vfsDest } = require('vinyl-fs')
const { PassThrough, Writable } = require('stream')
const forEach = (write, final) => new Writable({ objectMode: true, write, final })

@@ -15,10 +19,62 @@ const { DEFAULT_DEST_FS } = require('../constants.js')

const absDestDir = expandPath(destDir, { dot: playbook.dir })
const report = { provider: 'fs', path: destDir, resolvedPath: absDestDir, fileUri: pathToFileURL(absDestDir).href }
return config.clean
? fsp['rm' in fsp ? 'rm' : 'rmdir'](absDestDir, { recursive: true, force: true })
.then(() => publishStream(vfsDest(absDestDir), files))
.then(() => report)
: publishStream(vfsDest(absDestDir), files).then(() => report)
return (config.clean ? rmrf(absDestDir).then(() => mkdirp(absDestDir)) : mkdirp(absDestDir))
.then(() => publishStream(fsDest(absDestDir), files))
.then(() => ({ provider: 'fs', path: destDir, resolvedPath: absDestDir, fileUri: pathToFileURL(absDestDir).href }))
}
function fsDest (toDir, dirs = new Map(), fileRestream = new PassThrough({ objectMode: true })) {
return forEach(
(file, _, done) => {
if (file.isNull()) return done()
fileRestream.push(file)
const dir = ospath.dirname(file.path)
if (dir === '.' || dirs.has(dir)) return done()
dirs.set(dir, true)
let ancestorDir = ospath.dirname(dir)
do {
if (ancestorDir === '.' || dirs.get(ancestorDir) === false) break
dirs.set(ancestorDir, false)
} while ((ancestorDir = ospath.dirname(ancestorDir)))
done()
},
function (done, mkdirs = []) {
dirs.forEach((create, dir) => create && mkdirs.push(mkdirp(ospath.join(toDir, dir))))
Promise.all(mkdirs).then(() => {
fileRestream
.end()
.pipe(
forEach((file, _, done_) => {
const abspath = ospath.join(toDir, file.path)
const { gid, mode, uid } = file.stat || {}
fsp.open(abspath, 'w', mode).then(async (fh) => {
try {
await fh.writeFile(file.contents)
const stat = await fh.stat()
if (mode && mode !== stat.mode) await fh.chmod(mode)
const { gid: fGid, uid: fUid } = stat
const newOwner = { gid: fGid, uid: fUid }
if (typeof gid === 'number' && gid >= 0 && typeof fGid === 'number' && fGid >= 0 && gid !== fGid) {
newOwner.gid = gid
newOwner.changed = true
}
if (typeof uid === 'number' && uid >= 0 && typeof fUid === 'number' && fUid >= 0 && uid !== fUid) {
newOwner.uid = uid
newOwner.changed = true
}
if (newOwner.changed) await fh.chown(newOwner.uid, newOwner.gid).catch(() => undefined)
fh.close().then(done_, done_)
} catch (writeErr) {
const bubbleError = () => done_(writeErr)
fh.close().then(bubbleError, bubbleError)
}
}, done_)
})
)
.on('error', done)
.on('close', done)
}, done)
}
)
}
module.exports = publishToFs

@@ -72,4 +72,9 @@ 'use strict'

const cloneStreams = publishers.length > 1
return Promise.all(publishers.map((publish) => publish(new ReadableOutputFileArray(files, cloneStreams), playbook)))
return Promise.all(
publishers.length > 1
? publishers
.map((publish) => publish.bind(null, new ReadableOutputFileArray(files, true), playbook))
.map((publish) => publish())
: [publishers[0](new ReadableOutputFileArray(files), playbook)]
)
}

@@ -76,0 +81,0 @@

'use strict'
const CloneableReadable = require('./cloneable-readable')
const { Readable } = require('stream')

@@ -29,14 +30,14 @@ const Vinyl = require('vinyl')

// Q: do we also need to clone stat?
function toOutputFile (file, cloneStreams) {
const contents = file.contents
const outputFile = new File({ contents, path: file.out.path, stat: file.stat })
if (cloneStreams && outputFile.isStream()) {
const outputFileContents = outputFile.contents
if (outputFileContents !== contents) {
// NOTE: workaround for @antora/lunr-extension <= 1.0.0-alpha.8
if (!('get' in (Object.getOwnPropertyDescriptor(file, 'contents') || {}))) file.contents = outputFileContents
if (cloneStreams && isStream(contents)) {
// NOTE: guard in case contents is created on access (needed for @antora/lunr-extension <= 1.0.0-alpha.8)
if ((Object.getOwnPropertyDescriptor(file, 'contents') || { writable: true }).writable) {
const oContents =
contents instanceof CloneableReadable || typeof contents.clone === 'function'
? contents
: (file.contents = new CloneableReadable(contents))
outputFile.contents = oContents._allocated ? oContents.clone() : (oContents._allocated = true) && oContents
}
// NOTE: even the last occurrence must be cloned when using vinyl-fs even though cloneable-readable claims otherwise
outputFile.contents = outputFileContents.clone()
}

@@ -46,2 +47,6 @@ return outputFile

function isStream (obj) {
return obj && typeof obj.pipe === 'function'
}
module.exports = ReadableOutputFileArray
{
"name": "@antora/file-publisher",
"version": "3.1.7",
"version": "3.1.8",
"description": "Publishes the publishable files in the virtual file catalog(s) to the destination(s) specified in the playbook.",

@@ -22,2 +22,3 @@ "license": "MPL-2.0",

"imports": {
"#cloneable-readable": "./lib/cloneable-readable.js",
"#constants": "./lib/constants.js"

@@ -28,5 +29,4 @@ },

"@antora/user-require-helper": "~2.0",
"@vscode/gulp-vinyl-zip": "~2.5",
"vinyl": "~2.2",
"vinyl-fs": "~3.0"
"vinyl": "~3.0",
"yazl": "~2.5"
},

@@ -33,0 +33,0 @@ "engines": {

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