Skip to content

Commit 482720b

Browse files
committed
fix: treat self-managed repos as vendors
1 parent f45b55c commit 482720b

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/core/findLocalPackages.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from 'path'
2-
import { dotIndoId, loadConfig, RootConfig } from './config'
2+
import { RootConfig } from './config'
33
import { findPackages } from './findPackages'
4-
import { fs } from './fs'
4+
import { isSelfManaged } from './helpers'
55

66
/**
77
* Find local packages for an `.indo.json` root.
@@ -15,11 +15,7 @@ export function findLocalPackages(cfg: RootConfig) {
1515
// Find packages in nested repostories.
1616
Object.keys(cfg.repos).forEach(repoDir => {
1717
const absRepoDir = join(cfg.root, repoDir)
18-
19-
// Nested roots are skipped since they load themselves.
20-
if (loadConfig(join(absRepoDir, dotIndoId))) return
21-
// Linked repos are skipped since they are readonly.
22-
if (fs.isLink(absRepoDir)) return
18+
if (isSelfManaged(absRepoDir)) return
2319

2420
// Ensure globs targeting a specific repo can be used.
2521
const ignore = cfg.ignore.map(glob =>

src/core/findVendorPackages.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { dirname, join, relative } from 'path'
22
import { crawl, createMatcher } from 'recrawl-sync'
33
import { fs } from './fs'
44
import { RootConfig } from './config'
5+
import { findPackages } from './findPackages'
56
import { loadPackage, toPackagePath } from './Package'
6-
import { isNodeModules } from './helpers'
7+
import { isNodeModules, isSelfManaged } from './helpers'
78

89
export function findVendorPackages(cfg: RootConfig) {
910
const packagePaths: string[] = []
@@ -52,5 +53,19 @@ export function findVendorPackages(cfg: RootConfig) {
5253
}
5354
})
5455

56+
// Treat self-managed repos as vendors.
57+
Object.keys(cfg.repos).forEach(repoDir => {
58+
const absRepoDir = join(cfg.root, repoDir)
59+
if (isSelfManaged(absRepoDir)) {
60+
// Ensure globs targeting a specific repo can be used.
61+
const ignore = cfg.ignore.map(glob =>
62+
glob.startsWith(repoDir + '/') ? glob.slice(repoDir.length) : glob
63+
)
64+
findPackages(absRepoDir, ignore).forEach(pkgPath => {
65+
packagePaths.push(pkgPath)
66+
})
67+
}
68+
})
69+
5570
return packagePaths
5671
}

src/core/helpers.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import crypto from 'crypto'
33
import prompt, { Choice } from 'prompts'
44
import semver from 'semver'
55
import * as os from 'os'
6-
import { relative, resolve } from 'path'
6+
import { join, relative, resolve } from 'path'
77
import realpath from 'realpath-native'
88
import { formatElapsed } from 'misty'
99
import { gray } from 'kleur'
1010
import log from 'shared-log'
11+
import { dotIndoId, loadConfig } from './config'
12+
import { fs } from './fs'
1113

1214
export { default as log } from 'shared-log'
1315
export { gray, green, red, yellow, cyan } from 'kleur'
@@ -31,6 +33,17 @@ export const time = <T>(label: string, action: () => T) => {
3133
return result
3234
}
3335

36+
/**
37+
* Returns `true` if the given directory should __not__ be managed
38+
* by `indo` from a higher directory.
39+
*/
40+
export function isSelfManaged(absRepoDir: string) {
41+
// Linked repos are readonly.
42+
if (fs.isLink(absRepoDir)) return true
43+
// Nested roots are managed explicitly.
44+
return !!loadConfig(join(absRepoDir, dotIndoId))
45+
}
46+
3447
/** Returns true if `parent` is equal to (or a parent of) the `path` argument */
3548
export const isDescendant = (path: string, parent: string) =>
3649
path === parent || path.startsWith(parent + '/')

0 commit comments

Comments
 (0)