Skip to content

Commit

Permalink
fix: treat self-managed repos as vendors
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed May 12, 2021
1 parent f45b55c commit 482720b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
10 changes: 3 additions & 7 deletions src/core/findLocalPackages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'
import { dotIndoId, loadConfig, RootConfig } from './config'
import { RootConfig } from './config'
import { findPackages } from './findPackages'
import { fs } from './fs'
import { isSelfManaged } from './helpers'

/**
* Find local packages for an `.indo.json` root.
Expand All @@ -15,11 +15,7 @@ export function findLocalPackages(cfg: RootConfig) {
// Find packages in nested repostories.
Object.keys(cfg.repos).forEach(repoDir => {
const absRepoDir = join(cfg.root, repoDir)

// Nested roots are skipped since they load themselves.
if (loadConfig(join(absRepoDir, dotIndoId))) return
// Linked repos are skipped since they are readonly.
if (fs.isLink(absRepoDir)) return
if (isSelfManaged(absRepoDir)) return

// Ensure globs targeting a specific repo can be used.
const ignore = cfg.ignore.map(glob =>
Expand Down
17 changes: 16 additions & 1 deletion src/core/findVendorPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { dirname, join, relative } from 'path'
import { crawl, createMatcher } from 'recrawl-sync'
import { fs } from './fs'
import { RootConfig } from './config'
import { findPackages } from './findPackages'
import { loadPackage, toPackagePath } from './Package'
import { isNodeModules } from './helpers'
import { isNodeModules, isSelfManaged } from './helpers'

export function findVendorPackages(cfg: RootConfig) {
const packagePaths: string[] = []
Expand Down Expand Up @@ -52,5 +53,19 @@ export function findVendorPackages(cfg: RootConfig) {
}
})

// Treat self-managed repos as vendors.
Object.keys(cfg.repos).forEach(repoDir => {
const absRepoDir = join(cfg.root, repoDir)
if (isSelfManaged(absRepoDir)) {
// Ensure globs targeting a specific repo can be used.
const ignore = cfg.ignore.map(glob =>
glob.startsWith(repoDir + '/') ? glob.slice(repoDir.length) : glob
)
findPackages(absRepoDir, ignore).forEach(pkgPath => {
packagePaths.push(pkgPath)
})
}
})

return packagePaths
}
15 changes: 14 additions & 1 deletion src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import crypto from 'crypto'
import prompt, { Choice } from 'prompts'
import semver from 'semver'
import * as os from 'os'
import { relative, resolve } from 'path'
import { join, relative, resolve } from 'path'
import realpath from 'realpath-native'
import { formatElapsed } from 'misty'
import { gray } from 'kleur'
import log from 'shared-log'
import { dotIndoId, loadConfig } from './config'
import { fs } from './fs'

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

/**
* Returns `true` if the given directory should __not__ be managed
* by `indo` from a higher directory.
*/
export function isSelfManaged(absRepoDir: string) {
// Linked repos are readonly.
if (fs.isLink(absRepoDir)) return true
// Nested roots are managed explicitly.
return !!loadConfig(join(absRepoDir, dotIndoId))
}

/** Returns true if `parent` is equal to (or a parent of) the `path` argument */
export const isDescendant = (path: string, parent: string) =>
path === parent || path.startsWith(parent + '/')
Expand Down

0 comments on commit 482720b

Please sign in to comment.