@antora/content-aggregator 3.2.0-alpha.8 → 3.2.0-alpha.9

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.
@@ -132,7 +132,7 @@ async function collectFiles (sourcesByUrl, loadOpts, concurrency, fetchedUrls =
132
132
  }
133
133
  return Promise.all(
134
134
  results.map(({ repo, authStatus, sources }) =>
135
- selectStartPathsForRepository(repo, authStatus, sources).then((startPaths) =>
135
+ selectStartPathsForRepository(repo, sources).then((startPaths) =>
136
136
  collectFilesFromStartPaths.bind(null, startPaths, repo, authStatus)
137
137
  )
138
138
  )
@@ -249,19 +249,32 @@ function extractCredentials (url) {
249
249
  return { displayUrl: url, url }
250
250
  }
251
251
 
252
- async function selectStartPathsForRepository (repo, authStatus, sources) {
252
+ async function selectStartPathsForRepository (repo, sources) {
253
253
  const startPaths = []
254
254
  const originUrls = {}
255
255
  for (const source of sources) {
256
256
  const { version, editUrl } = source
257
- // NOTE if repository is managed (has a url property), we can assume the remote name is origin
258
- // TODO if the repo has no remotes, then remoteName should be undefined
259
- const remoteName = repo.url ? 'origin' : source.remote || 'origin'
260
- const originUrl = repo.url || (originUrls[remoteName] ||= await resolveRemoteUrl(repo, remoteName))
257
+ let remoteName, originUrl
258
+ if (repo.url) {
259
+ remoteName = 'origin' // NOTE if repository is managed (has url property), we can assume remote name is origin
260
+ originUrl = repo.url
261
+ } else {
262
+ remoteName = source.remote || 'origin'
263
+ originUrl =
264
+ remoteName in originUrls
265
+ ? originUrls[remoteName]
266
+ : (originUrls[remoteName] = await resolveRemoteUrl(repo, remoteName))
267
+ if (!originUrl) {
268
+ remoteName = undefined
269
+ if ((originUrl = posixify ? 'file:///' + posixify(repo.dir) : 'file://' + repo.dir).indexOf(' ')) {
270
+ originUrl = originUrl.replace(SPACE_RX, '%20')
271
+ }
272
+ }
273
+ }
261
274
  const refs = await selectReferences(source, repo, remoteName)
262
275
  if (refs.length) {
263
276
  for (const ref of refs) {
264
- for (const startPath of await selectStartPaths(source, repo, remoteName, ref)) {
277
+ for (const startPath of await selectStartPaths(source, repo, ref)) {
265
278
  startPaths.push({ startPath, ref, originUrl, editUrl, version })
266
279
  }
267
280
  }
@@ -361,45 +374,40 @@ async function selectReferences (source, repo, remote) {
361
374
  }
362
375
  }
363
376
  // NOTE isomorphic-git includes HEAD in list of remote branches (see https://isomorphic-git.org/docs/listBranches)
364
- const remoteBranches = (await git.listBranches(Object.assign({ remote }, repo))).filter((it) => it !== 'HEAD')
377
+ const remoteBranches = remote
378
+ ? (await git.listBranches(Object.assign({ remote }, repo))).filter((it) => it !== 'HEAD')
379
+ : []
365
380
  if (remoteBranches.length) {
366
381
  for (const shortname of filterRefs(remoteBranches, branchPatterns, patternCache)) {
367
382
  const fullname = 'remotes/' + remote + '/' + shortname
368
383
  refs.set(shortname, { shortname, fullname, type: 'branch', remote, head: noWorktree })
369
384
  }
370
385
  }
371
- // NOTE only consider local branches if repo has a worktree or there are no remote tracking branches
372
- if (!isBare) {
386
+ if (!managed) {
373
387
  const localBranches = await git.listBranches(repo).then((branches) => {
374
- if (branches.length) return branches
375
- if (currentBranch == null) return getCurrentBranchName(repo).then((branch) => (branch ? [branch] : []))
376
- return currentBranch ? [currentBranch] : []
388
+ if (branches.length || isBare) return branches
389
+ if (currentBranch != null) return [currentBranch]
390
+ return getCurrentBranchName(repo).then((branch) => (branch ? [branch] : []))
377
391
  })
378
- if (localBranches.length) {
379
- const worktrees = await findWorktrees(repo, worktreePatterns)
380
- let onMatch
381
- if ((worktreePatterns.join('') || '.') !== '.') {
382
- const symbolicNames = new Map()
383
- worktrees.forEach(({ name, symbolicName = 'HEAD@' + name }, shortname) => {
384
- localBranches.push(symbolicName)
385
- symbolicNames.set(symbolicName, shortname)
386
- })
387
- onMatch = (candidate, { pattern }) => {
388
- const shortname = symbolicNames.get(candidate)
389
- return shortname ? (pattern.startsWith('HEAD@') ? shortname : undefined) : candidate
390
- }
391
- }
392
- for (const shortname of filterRefs(localBranches, branchPatterns, patternCache, onMatch)) {
393
- const head = (worktrees.get(shortname) || { head: noWorktree }).head
394
- refs.set(shortname, { shortname, fullname: 'heads/' + shortname, type: 'branch', head })
392
+ const worktrees = await findWorktrees(repo, worktreePatterns)
393
+ let onMatch
394
+ if ((worktreePatterns.join('') || '.') !== '.') {
395
+ const symbolicNames = new Map()
396
+ worktrees.forEach(({ name, symbolicName = 'HEAD@' + name }, shortname) => {
397
+ localBranches.push(symbolicName)
398
+ symbolicNames.set(symbolicName, shortname)
399
+ })
400
+ onMatch = (candidate, { pattern }) => {
401
+ const shortname = symbolicNames.get(candidate)
402
+ return shortname ? (pattern.startsWith('HEAD@') ? shortname : undefined) : candidate
395
403
  }
396
404
  }
397
- } else if (!managed || !remoteBranches.length) {
398
- const localBranches = await git.listBranches(repo)
399
405
  if (localBranches.length) {
400
- for (const shortname of filterRefs(localBranches, branchPatterns, patternCache)) {
401
- if (refs.has(shortname)) continue // NOTE prefer remote branches in bare repository
402
- refs.set(shortname, { shortname, fullname: 'heads/' + shortname, type: 'branch', head: noWorktree })
406
+ const preferRemote = isBare && remoteBranches.length > 0
407
+ for (const shortname of filterRefs(localBranches, branchPatterns, patternCache, onMatch)) {
408
+ if (preferRemote && refs.has(shortname)) continue
409
+ const head = (worktrees.get(shortname) || { head: false }).head
410
+ refs.set(shortname, { shortname, fullname: 'heads/' + shortname, type: 'branch', head })
403
411
  }
404
412
  }
405
413
  }
@@ -419,7 +427,7 @@ function getCurrentBranchName (repo, remote) {
419
427
  ).then((ref) => (ref.startsWith('refs/') ? ref.replace(SHORTEN_REF_RX, '') : undefined))
420
428
  }
421
429
 
422
- async function selectStartPaths (source, repo, remoteName, ref) {
430
+ async function selectStartPaths (source, repo, ref) {
423
431
  const url = repo.url
424
432
  const displayUrl = url || repo.dir
425
433
  const worktreePath = ref.head
@@ -734,18 +742,18 @@ function loadComponentDescriptor (files, ref, version) {
734
742
  if (!version) {
735
743
  if (version === undefined) throw new Error(`${COMPONENT_DESC_FILENAME} is missing a version`)
736
744
  if (version === false) throw new Error(`${COMPONENT_DESC_FILENAME} has an invalid version`)
737
- version = '' + (typeof version === 'number' ? version : '')
745
+ version = typeof version === 'number' ? '' + version : ''
738
746
  } else if (version === true) {
739
747
  version = ref.shortname.replace(PATH_SEPARATOR_RX, '-')
740
748
  } else if (version.constructor === Object) {
741
749
  const refname = ref.shortname
742
750
  let matched
743
751
  if (refname in version) {
744
- matched = version[refname]
752
+ matched = '' + (version[refname] ?? '')
745
753
  } else if (
746
754
  !Object.entries(version).some(([pattern, replacement]) => {
747
- const result = refname.replace(makeMatcherRx(pattern, VERSION_MATCHER_OPTS), '\0' + replacement)
748
- if (result === refname) return false
755
+ const result = refname.replace(makeMatcherRx(pattern, VERSION_MATCHER_OPTS), '\0' + (replacement ?? ''))
756
+ if (result === refname) return false // no match
749
757
  matched = result.substr(1)
750
758
  return true
751
759
  })
@@ -914,21 +922,18 @@ function generateCloneFolderName (url) {
914
922
  *
915
923
  * @param {Repository} repo - The repository on which to operate.
916
924
  * @param {String} remoteName - The name of the remote to resolve.
917
- * @returns {String} The URL of the specified remote, if defined, or the file URI to the local repository.
925
+ * @returns {String} The URL of the specified remote, if defined
918
926
  */
919
927
  function resolveRemoteUrl (repo, remoteName) {
920
928
  return git.getConfig(Object.assign({ path: 'remote.' + remoteName + '.url' }, repo)).then((url) => {
921
- if (url) {
922
- if (url.startsWith('https://') || url.startsWith('http://')) {
923
- return ~url.indexOf('@') ? url.replace(URL_AUTH_CLEANER_RX, '$1') : url
924
- }
925
- if (url.startsWith('git@')) return 'https://' + url.substr(4).replace(':', '/')
926
- if (url.startsWith('ssh://')) {
927
- return 'https://' + url.substr(url.indexOf('@') + 1 || 6).replace(URL_PORT_CLEANER_RX, '$1')
928
- }
929
+ if (!url) return
930
+ if (url.startsWith('https://') || url.startsWith('http://')) {
931
+ return ~url.indexOf('@') ? url.replace(URL_AUTH_CLEANER_RX, '$1') : url
932
+ }
933
+ if (url.startsWith('git@')) return 'https://' + url.substr(4).replace(':', '/')
934
+ if (url.startsWith('ssh://')) {
935
+ return 'https://' + url.substr(url.indexOf('@') + 1 || 6).replace(URL_PORT_CLEANER_RX, '$1')
929
936
  }
930
- url = posixify ? 'file:///' + posixify(repo.dir) : 'file://' + repo.dir
931
- return ~url.indexOf(' ') ? url.replace(SPACE_RX, '%20') : url
932
937
  })
933
938
  }
934
939
 
@@ -1065,31 +1070,29 @@ function resolveRepositoryFromWorktree (repo) {
1065
1070
  function findWorktrees (repo, patterns) {
1066
1071
  if (!patterns.length) return new Map()
1067
1072
  const mainWorktree =
1068
- patterns[0] === '.' && (patterns = patterns.slice(1))
1073
+ patterns[0] === '.' && (patterns = patterns.slice(1)) && !repo.noCheckout
1069
1074
  ? getCurrentBranchName(repo).then((branch) => branch && [branch, { head: repo.dir, name: '.' }])
1070
1075
  : Promise.resolve()
1071
- const worktreesDir = patterns.length ? ospath.join(repo.dir, '.git', 'worktrees') : undefined
1076
+ if (!patterns.length) return mainWorktree.then((entry) => new Map(entry && [entry]))
1077
+ const worktreesDir = ospath.join(repo.dir, repo.dir === repo.gitdir ? '' : '.git', 'worktrees')
1072
1078
  const patternCache = repo.cache[REF_PATTERN_CACHE_KEY]
1073
- return (
1074
- worktreesDir
1075
- ? fsp
1076
- .readdir(worktreesDir)
1077
- .then((worktreeNames) => filterRefs(worktreeNames, patterns, patternCache), invariably.emptyArray)
1078
- .then((worktreeNames) =>
1079
- Promise.all(
1080
- worktreeNames.map((worktreeName) => {
1081
- const gitdir = ospath.resolve(worktreesDir, worktreeName)
1082
- // NOTE branch name defaults to worktree name if HEAD is detached
1083
- return getCurrentBranchName(Object.assign({}, repo, { gitdir })).then((branch = worktreeName) =>
1084
- fsp
1085
- .readFile(ospath.join(gitdir, 'gitdir'), 'utf8')
1086
- .then((contents) => [branch, { head: ospath.dirname(contents.trimEnd()), name: worktreeName }])
1087
- )
1088
- })
1089
- )
1079
+ return fsp
1080
+ .readdir(worktreesDir)
1081
+ .then((worktreeNames) => filterRefs(worktreeNames, patterns, patternCache), invariably.emptyArray)
1082
+ .then((worktreeNames) =>
1083
+ Promise.all(
1084
+ worktreeNames.map((worktreeName) => {
1085
+ const gitdir = ospath.resolve(worktreesDir, worktreeName)
1086
+ // NOTE branch name defaults to worktree name if HEAD is detached
1087
+ return getCurrentBranchName(Object.assign({}, repo, { gitdir })).then((branch = worktreeName) =>
1088
+ fsp
1089
+ .readFile(ospath.join(gitdir, 'gitdir'), 'utf8')
1090
+ .then((contents) => [branch, { head: ospath.dirname(contents.trimEnd()), name: worktreeName }])
1090
1091
  )
1091
- : Promise.resolve()
1092
- ).then((entries = []) => mainWorktree.then((entry) => new Map(entry ? entries.push(entry) && entries : entries)))
1092
+ })
1093
+ )
1094
+ )
1095
+ .then((entries) => mainWorktree.then((main) => (main ? new Map(entries).set(main[0], main[1]) : new Map(entries))))
1093
1096
  }
1094
1097
 
1095
1098
  async function gracefulPromiseAllWithLimit (tasks, limit = Infinity) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antora/content-aggregator",
3
- "version": "3.2.0-alpha.8",
3
+ "version": "3.2.0-alpha.9",
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)",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@antora/expand-path-helper": "~3.0",
36
- "@antora/logger": "3.2.0-alpha.8",
36
+ "@antora/logger": "3.2.0-alpha.9",
37
37
  "@antora/user-require-helper": "~3.0",
38
38
  "braces": "~3.0",
39
39
  "cache-directory": "~2.0",