@antora/content-aggregator 3.0.0-rc.2 → 3.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  const camelCaseKeys = require('camelcase-keys')
4
4
  const { createHash } = require('crypto')
5
- const createHttpPlugin = require('./git-plugin-http')
5
+ const createGitHttpPlugin = require('./git-plugin-http')
6
6
  const decodeUint8Array = require('./decode-uint8-array')
7
7
  const EventEmitter = require('events')
8
8
  const expandPath = require('@antora/expand-path-helper')
@@ -417,9 +417,8 @@ async function collectFilesFromReference (source, repo, remoteName, authStatus,
417
417
  }
418
418
 
419
419
  function collectFilesFromStartPath (startPath, repo, authStatus, ref, worktreePath, originUrl, editUrl, version) {
420
- return (worktreePath
421
- ? readFilesFromWorktree(worktreePath, startPath)
422
- : readFilesFromGitTree(repo, ref.oid, startPath)
420
+ return (
421
+ worktreePath ? readFilesFromWorktree(worktreePath, startPath) : readFilesFromGitTree(repo, ref.oid, startPath)
423
422
  )
424
423
  .then((files) => {
425
424
  const componentVersionBucket = loadComponentDescriptor(files, ref, version)
@@ -775,27 +774,31 @@ function buildFetchOptions (repo, progress, displayUrl, credentialsFromUrl, gitP
775
774
  function createProgress (urls, term) {
776
775
  if (term.isTTY && term.columns > 59) {
777
776
  let maxUrlLength = 0
777
+ const width = term.columns
778
778
  for (const url of urls) {
779
779
  if (~url.indexOf(':') && GIT_URI_DETECTOR_RX.test(url)) {
780
780
  const urlLength = extractCredentials(url).displayUrl.length
781
781
  if (urlLength > maxUrlLength) maxUrlLength = urlLength
782
782
  }
783
783
  }
784
- const progress = new MultiProgress(term)
785
- // NOTE remove the width of the operation, then partition the difference between the url and bar
786
- progress.maxLabelWidth = Math.min(Math.ceil((term.columns - GIT_OPERATION_LABEL_LENGTH) / 2), maxUrlLength)
787
- return progress
784
+ return Object.assign(new MultiProgress(term), {
785
+ // NOTE remove the operation width, then partition the difference between the url and bar
786
+ maxLabelWidth: Math.min(Math.ceil((width - GIT_OPERATION_LABEL_LENGTH) / 2), maxUrlLength),
787
+ width,
788
+ })
788
789
  }
789
790
  }
790
791
 
791
792
  function createProgressListener (progress, progressLabel, operation) {
793
+ const width = progress.width
792
794
  const progressBar = progress.newBar(formatProgressBar(progressLabel, progress.maxLabelWidth, operation), {
793
795
  complete: '#',
794
796
  incomplete: '-',
795
797
  renderThrottle: 25,
796
798
  total: 100,
799
+ width,
797
800
  })
798
- const ticks = progressBar.stream.columns - progressBar.fmt.replace(':bar', '').length
801
+ const ticks = width - progressBar.fmt.replace(':bar', '').length
799
802
  // NOTE leave room for indeterminate progress at end of bar; this isn't strictly needed for a bare clone
800
803
  progressBar.scaleFactor = Math.max(0, (ticks - 1) / ticks)
801
804
  progressBar.tick(0)
@@ -936,7 +939,7 @@ function loadGitPlugins (gitConfig, networkConfig, startDir) {
936
939
  credentialManager = new GitCredentialManagerStore().configure({ config: gitConfig.credentials, startDir })
937
940
  }
938
941
  if (gitConfig.ensureGitSuffix) urlRouter = { ensureGitSuffix: (url) => (url.endsWith('.git') ? url : url + '.git') }
939
- const http = plugins.get('http') || createHttpPlugin(networkConfig, 'git/isomorphic-git@' + git.version())
942
+ const http = plugins.get('http') || createGitHttpPlugin(networkConfig)
940
943
  return { credentialManager, http, urlRouter }
941
944
  }
942
945
 
@@ -1013,28 +1016,29 @@ function findWorktrees (repo, patterns) {
1013
1016
  const linkedOnly = patterns[0] === '.' ? !(patterns = patterns.slice(1)) : true
1014
1017
  let worktreesDir
1015
1018
  const patternCache = repo.cache[REF_PATTERN_CACHE_KEY]
1016
- return (patterns.length
1017
- ? fsp
1018
- .readdir((worktreesDir = ospath.join(repo.dir, '.git', 'worktrees')))
1019
- .then((worktreeNames) => filterRefs(worktreeNames, patterns, patternCache), invariably.emptyArray)
1020
- .then((worktreeNames) =>
1021
- worktreeNames.length
1022
- ? Promise.all(
1023
- worktreeNames.map((worktreeName) => {
1024
- const gitdir = ospath.resolve(worktreesDir, worktreeName)
1025
- // NOTE uses name of worktree as branch name if HEAD is detached
1026
- return git
1027
- .currentBranch(Object.assign({}, repo, { gitdir }))
1028
- .then((branch = worktreeName) =>
1029
- fsp
1030
- .readFile(ospath.join(gitdir, 'gitdir'), 'utf8')
1031
- .then((contents) => ({ branch, dir: ospath.dirname(contents.trimRight()) }))
1032
- )
1033
- })
1034
- ).then((entries) => entries.reduce((accum, it) => accum.set(it.branch, it.dir), new Map()))
1035
- : new Map()
1036
- )
1037
- : Promise.resolve(new Map())
1019
+ return (
1020
+ patterns.length
1021
+ ? fsp
1022
+ .readdir((worktreesDir = ospath.join(repo.dir, '.git', 'worktrees')))
1023
+ .then((worktreeNames) => filterRefs(worktreeNames, patterns, patternCache), invariably.emptyArray)
1024
+ .then((worktreeNames) =>
1025
+ worktreeNames.length
1026
+ ? Promise.all(
1027
+ worktreeNames.map((worktreeName) => {
1028
+ const gitdir = ospath.resolve(worktreesDir, worktreeName)
1029
+ // NOTE uses name of worktree as branch name if HEAD is detached
1030
+ return git
1031
+ .currentBranch(Object.assign({}, repo, { gitdir }))
1032
+ .then((branch = worktreeName) =>
1033
+ fsp
1034
+ .readFile(ospath.join(gitdir, 'gitdir'), 'utf8')
1035
+ .then((contents) => ({ branch, dir: ospath.dirname(contents.trimRight()) }))
1036
+ )
1037
+ })
1038
+ ).then((entries) => entries.reduce((accum, it) => accum.set(it.branch, it.dir), new Map()))
1039
+ : new Map()
1040
+ )
1041
+ : Promise.resolve(new Map())
1038
1042
  ).then((worktrees) =>
1039
1043
  linkedOnly
1040
1044
  ? worktrees
@@ -2,9 +2,7 @@
2
2
 
3
3
  function flattenDeep (array, accum = []) {
4
4
  const len = array.length
5
- for (let i = 0, it; i < len; i++) {
6
- Array.isArray((it = array[i])) ? flattenDeep(it, accum) : accum.push(it)
7
- }
5
+ for (let i = 0, it; i < len; i++) Array.isArray((it = array[i])) ? flattenDeep(it, accum) : accum.push(it)
8
6
  return accum
9
7
  }
10
8
 
@@ -1,6 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  const get = require('simple-get')
4
+ const defaultUserAgent = 'git/isomorphic-git@' + require('./git').version()
4
5
 
5
6
  function distillResponse (res) {
6
7
  const { url, method, statusCode, statusMessage, headers } = res
@@ -25,13 +26,21 @@ async function mergeBuffers (data) {
25
26
  return Buffer.from(data.buffer)
26
27
  }
27
28
 
28
- module.exports = ({ httpProxy, httpsProxy, noProxy }, userAgent) => {
29
+ function mergeHeaders (headers, extraHeaders) {
30
+ const mergedHeaders = { 'user-agent': defaultUserAgent }
31
+ if (extraHeaders == null) return Object.assign(headers, mergedHeaders)
32
+ for (const name in extraHeaders) mergedHeaders[name.toLowerCase()] = extraHeaders[name]
33
+ for (const name in headers) mergedHeaders[name.toLowerCase()] = headers[name]
34
+ return mergedHeaders
35
+ }
36
+
37
+ module.exports = ({ headers: extraHeaders, httpProxy, httpsProxy, noProxy } = {}) => {
29
38
  if ((httpsProxy || httpProxy) && noProxy !== '*') {
30
39
  const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent')
31
40
  const shouldProxy = require('should-proxy')
32
41
  return {
33
42
  async request ({ url, method, headers, body }) {
34
- headers['user-agent'] = userAgent
43
+ headers = mergeHeaders(headers, extraHeaders)
35
44
  body = await mergeBuffers(body)
36
45
  const proxy = url.startsWith('https:')
37
46
  ? { Agent: HttpsProxyAgent, url: httpsProxy }
@@ -46,7 +55,7 @@ module.exports = ({ httpProxy, httpsProxy, noProxy }, userAgent) => {
46
55
  }
47
56
  return {
48
57
  async request ({ url, method, headers, body }) {
49
- headers['user-agent'] = userAgent
58
+ headers = mergeHeaders(headers, extraHeaders)
50
59
  body = await mergeBuffers(body)
51
60
  return new Promise((resolve, reject) =>
52
61
  get({ url, method, headers, body }, (err, res) => (err ? reject(err) : resolve(distillResponse(res))))
@@ -129,10 +129,7 @@ function makeSingleMatcherRx (pattern) {
129
129
  function patternToRx (pattern) {
130
130
  return (
131
131
  (pattern.charAt() === '.' ? '' : '(?!\\.)') +
132
- pattern
133
- .replace(NON_GLOB_SPECIAL_CHARS_RX, '\\$&')
134
- .replace('\\\\*', '\\x2a')
135
- .replace('*', '.*?')
132
+ pattern.replace(NON_GLOB_SPECIAL_CHARS_RX, '\\$&').replace('\\\\*', '\\x2a').replace('*', '.*?')
136
133
  )
137
134
  }
138
135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/content-aggregator",
3
- "version": "3.0.0-rc.2",
3
+ "version": "3.0.0-rc.3",
4
4
  "description": "Fetches and aggregates content from distributed sources for use in an Antora documentation pipeline.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "OpenDevise Inc. (https://opendevise.com)",
@@ -52,5 +52,5 @@
52
52
  "static site",
53
53
  "web publishing"
54
54
  ],
55
- "gitHead": "b64861391b7e55ea31fcecce4490b9cc02fec1c7"
55
+ "gitHead": "f3b3cbb4a08640bbcf55e685929409e20b186634"
56
56
  }