@antora/file-publisher
Advanced tools
Comparing version 3.1.7 to 3.1.8
'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 |
@@ -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": { |
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
17384
4
10
355
4
+ Addedyazl@~2.5
+ Addedbare-events@2.5.0(transitive)
+ Addedfast-fifo@1.3.2(transitive)
+ Addedqueue-tick@1.0.1(transitive)
+ Addedreplace-ext@2.0.0(transitive)
+ Addedstreamx@2.20.2(transitive)
+ Addedteex@1.0.1(transitive)
+ Addedtext-decoder@1.2.1(transitive)
+ Addedvinyl@3.0.0(transitive)
- Removed@vscode/gulp-vinyl-zip@~2.5
- Removedvinyl-fs@~3.0
- Removed@vscode/gulp-vinyl-zip@2.5.0(transitive)
- Removedappend-buffer@1.0.2(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbuffer-equal@1.0.1(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedclone-buffer@1.0.0(transitive)
- Removedcloneable-readable@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedduplexify@3.7.1(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedextend@3.0.2(transitive)
- Removedfd-slicer@1.1.0(transitive)
- Removedflush-write-stream@1.1.1(transitive)
- Removedfs-mkdirp-stream@1.0.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedglob@7.2.3(transitive)
- Removedglob-parent@3.1.0(transitive)
- Removedglob-stream@6.1.0(transitive)
- Removedgopd@1.0.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-absolute@1.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@3.1.0(transitive)
- Removedis-negated-glob@1.0.0(transitive)
- Removedis-relative@1.0.0(transitive)
- Removedis-unc-path@1.0.0(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedis-valid-glob@1.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjson-stable-stringify-without-jsonify@1.0.1(transitive)
- Removedlazystream@1.0.1(transitive)
- Removedlead@1.0.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removednow-and-later@2.0.1(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedonce@1.4.0(transitive)
- Removedordered-read-streams@1.0.1(transitive)
- Removedpath-dirname@1.0.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpend@1.2.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpump@2.0.1(transitive)
- Removedpumpify@1.5.1(transitive)
- Removedqueue@4.5.1(transitive)
- Removedreadable-stream@2.3.83.6.2(transitive)
- Removedremove-bom-buffer@3.0.0(transitive)
- Removedremove-bom-stream@1.2.0(transitive)
- Removedreplace-ext@1.0.1(transitive)
- Removedresolve-options@1.1.0(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedstream-shift@1.0.3(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedthrough@2.3.8(transitive)
- Removedthrough2@2.0.54.0.2(transitive)
- Removedthrough2-filter@3.1.0(transitive)
- Removedto-absolute-glob@2.0.2(transitive)
- Removedto-through@2.0.0(transitive)
- Removedunc-path-regex@0.1.2(transitive)
- Removedunique-stream@2.3.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedvalue-or-function@3.0.0(transitive)
- Removedvinyl@2.2.1(transitive)
- Removedvinyl-fs@3.0.3(transitive)
- Removedvinyl-sourcemap@1.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
- Removedyauzl@2.10.0(transitive)
Updatedvinyl@~3.0