Skip to content

Commit

Permalink
refactor: rename Module to GardenModule for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Aug 12, 2020
1 parent 9bb9d42 commit d4b99e4
Show file tree
Hide file tree
Showing 69 changed files with 248 additions and 231 deletions.
26 changes: 12 additions & 14 deletions core/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { defaultProvider } from "./config/provider"
import { ParameterError, PluginError, InternalError, RuntimeError } from "./exceptions"
import { Garden, ModuleActionMap } from "./garden"
import { LogEntry } from "./logger/log-entry"
import { Module } from "./types/module"
import { GardenModule } from "./types/module"
import {
PluginActionContextParams,
PluginActionParamsBase,
Expand Down Expand Up @@ -308,7 +308,7 @@ export class ActionRouter implements TypeGuard {
return result
}

async getBuildStatus<T extends Module>(
async getBuildStatus<T extends GardenModule>(
params: ModuleActionRouterParams<GetBuildStatusParams<T>>
): Promise<BuildStatus> {
return this.callModuleHandler({
Expand All @@ -318,25 +318,25 @@ export class ActionRouter implements TypeGuard {
})
}

async build<T extends Module>(params: ModuleActionRouterParams<BuildModuleParams<T>>): Promise<BuildResult> {
async build<T extends GardenModule>(params: ModuleActionRouterParams<BuildModuleParams<T>>): Promise<BuildResult> {
return this.callModuleHandler({
params,
actionType: "build",
defaultHandler: async () => ({}),
})
}

async publishModule<T extends Module>(
async publishModule<T extends GardenModule>(
params: ModuleActionRouterParams<PublishModuleParams<T>>
): Promise<PublishResult> {
return this.callModuleHandler({ params, actionType: "publish", defaultHandler: dummyPublishHandler })
}

async runModule<T extends Module>(params: ModuleActionRouterParams<RunModuleParams<T>>): Promise<RunResult> {
async runModule<T extends GardenModule>(params: ModuleActionRouterParams<RunModuleParams<T>>): Promise<RunResult> {
return this.callModuleHandler({ params, actionType: "runModule" })
}

async testModule<T extends Module>(
async testModule<T extends GardenModule>(
params: ModuleActionRouterParams<Omit<TestModuleParams<T>, "artifactsPath">>
): Promise<TestResult> {
const tmpDir = await tmp.dir({ unsafeCleanup: true })
Expand Down Expand Up @@ -364,7 +364,7 @@ export class ActionRouter implements TypeGuard {
}
}

async getTestResult<T extends Module>(
async getTestResult<T extends GardenModule>(
params: ModuleActionRouterParams<GetTestResultParams<T>>
): Promise<TestResult | null> {
const result = await this.callModuleHandler({
Expand Down Expand Up @@ -989,9 +989,7 @@ export class ActionRouter implements TypeGuard {
* Recursively wraps the base handler (if any) on an action handler, such that the base handler receives the _next_
* base handler as the `base` parameter when called from within the handler.
*/
private wrapBase<T extends ActionHandler<any, any> | ModuleActionHandler<any, any>>(
handler?: T
): T | undefined {
private wrapBase<T extends ActionHandler<any, any> | ModuleActionHandler<any, any>>(handler?: T): T | undefined {
if (!handler) {
return undefined
}
Expand Down Expand Up @@ -1206,19 +1204,19 @@ export class ActionRouter implements TypeGuard {

type CommonParams = keyof PluginActionContextParams

type WrappedServiceActionHandlers<T extends Module = Module> = {
type WrappedServiceActionHandlers<T extends GardenModule = GardenModule> = {
[P in keyof ServiceActionParams<T>]: WrappedModuleActionHandler<ServiceActionParams<T>[P], ServiceActionOutputs[P]>
}

type WrappedTaskActionHandlers<T extends Module = Module> = {
type WrappedTaskActionHandlers<T extends GardenModule = GardenModule> = {
[P in keyof TaskActionParams<T>]: WrappedModuleActionHandler<TaskActionParams<T>[P], TaskActionOutputs[P]>
}

type WrappedModuleActionHandlers<T extends Module = Module> = {
type WrappedModuleActionHandlers<T extends GardenModule = GardenModule> = {
[P in keyof ModuleActionParams<T>]: WrappedModuleActionHandler<ModuleActionParams<T>[P], ModuleActionOutputs[P]>
}

type WrappedModuleAndRuntimeActionHandlers<T extends Module = Module> = WrappedModuleActionHandlers<T> &
type WrappedModuleAndRuntimeActionHandlers<T extends GardenModule = GardenModule> = WrappedModuleActionHandlers<T> &
WrappedServiceActionHandlers<T> &
WrappedTaskActionHandlers<T>

Expand Down
10 changes: 5 additions & 5 deletions core/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import semver from "semver"
import { isAbsolute, join, parse, resolve, sep, relative } from "path"
import { emptyDir, ensureDir } from "fs-extra"
import { ConfigurationError, RuntimeError } from "./exceptions"
import { FileCopySpec, Module, getModuleKey } from "./types/module"
import { FileCopySpec, GardenModule, getModuleKey } from "./types/module"
import { normalizeLocalRsyncPath, normalizeRelativePath } from "./util/fs"
import { LogEntry } from "./logger/log-entry"
import { ModuleConfig } from "./config/module"
Expand Down Expand Up @@ -91,7 +91,7 @@ export class BuildDir {
return new BuildDir(projectRoot, buildDirPath, buildMetadataDirPath)
}

async syncFromSrc(module: Module, log: LogEntry) {
async syncFromSrc(module: GardenModule, log: LogEntry) {
// We don't sync local exec modules to the build dir
if (isLocalExecModule(module)) {
log.silly("Skipping syncing from source for local exec module")
Expand All @@ -111,7 +111,7 @@ export class BuildDir {
})
}

async syncDependencyProducts(module: Module, graph: ConfigGraph, log: LogEntry) {
async syncDependencyProducts(module: GardenModule, graph: ConfigGraph, log: LogEntry) {
const buildPath = await this.buildPath(module)
const buildDependencies = module.build.dependencies

Expand Down Expand Up @@ -154,7 +154,7 @@ export class BuildDir {
await emptyDir(this.buildDirPath)
}

async buildPath(moduleOrConfig: Module | ModuleConfig): Promise<string> {
async buildPath(moduleOrConfig: GardenModule | ModuleConfig): Promise<string> {
// We don't stage the build for local exec modules, so the module path is effectively the build path.
if (isLocalExecModule(moduleOrConfig)) {
return moduleOrConfig.path
Expand Down Expand Up @@ -192,7 +192,7 @@ export class BuildDir {
log,
files,
}: {
module: Module
module: GardenModule
sourcePath: string
destinationPath: string
withDelete: boolean
Expand Down
10 changes: 5 additions & 5 deletions core/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getModuleWatchTasks } from "../tasks/helpers"
import { Command, CommandResult, CommandParams, handleProcessResults, PrepareParams } from "./base"
import { STATIC_DIR } from "../constants"
import { processModules } from "../process"
import { Module } from "../types/module"
import { GardenModule } from "../types/module"
import { getTestTasks } from "../tasks/test"
import { ConfigGraph } from "../config-graph"
import { getHotReloadServiceNames, validateHotReloadServiceNames } from "./helpers"
Expand Down Expand Up @@ -144,7 +144,7 @@ export class DevCommand extends Command<DevCommandArgs, DevCommandOpts> {
modules,
watch: true,
initialTasks,
changeHandler: async (updatedGraph: ConfigGraph, module: Module) => {
changeHandler: async (updatedGraph: ConfigGraph, module: GardenModule) => {
return getDevCommandWatchTasks({
garden,
log,
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function getDevCommandInitialTasks({
garden: Garden
log: LogEntry
graph: ConfigGraph
modules: Module[]
modules: GardenModule[]
hotReloadServiceNames: string[]
skipTests: boolean
}) {
Expand Down Expand Up @@ -235,7 +235,7 @@ export async function getDevCommandWatchTasks({
garden: Garden
log: LogEntry
updatedGraph: ConfigGraph
module: Module
module: GardenModule
hotReloadServiceNames: string[]
testNames: string[] | undefined
skipTests: boolean
Expand All @@ -249,7 +249,7 @@ export async function getDevCommandWatchTasks({
})

if (!skipTests) {
const testModules: Module[] = await updatedGraph.withDependantModules([module])
const testModules: GardenModule[] = await updatedGraph.withDependantModules([module])
tasks.push(
...flatten(
await Bluebird.map(testModules, (m) =>
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { Command, CommandResult, CommandParams } from "./base"
import Bluebird from "bluebird"
import { printHeader, getTerminalWidth } from "../logger/util"
import { LoggerType } from "../logger/logger"
import { Module } from "../types/module"
import { StringOption } from "../cli/params"
import { GardenModule } from "../types/module"

const pluginArgs = {
plugin: new StringOption({
Expand Down Expand Up @@ -105,7 +105,7 @@ export class PluginsCommand extends Command<Args> {
const provider = await garden.resolveProvider(log, args.plugin)
const ctx = garden.getPluginContext(provider)

let modules: Module[] = []
let modules: GardenModule[] = []

// Commands can optionally ask for all the modules in the project/environment
if (command.resolveModules) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
processCommandResultSchema,
resultMetadataKeys,
} from "./base"
import { Module } from "../types/module"
import { GardenModule } from "../types/module"
import { PublishTask } from "../tasks/publish"
import { GraphResults } from "../task-graph"
import { Garden } from "../garden"
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function publishModules({
garden: Garden
graph: ConfigGraph
log: LogEntry
modules: Module<any>[]
modules: GardenModule<any>[]
forceBuild: boolean
allowDirty: boolean
}): Promise<GraphResults> {
Expand Down
4 changes: 2 additions & 2 deletions core/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
processCommandResultSchema,
} from "./base"
import { processModules } from "../process"
import { Module } from "../types/module"
import { GardenModule } from "../types/module"
import { getTestTasks } from "../tasks/test"
import { printHeader } from "../logger/util"
import { GardenServer, startServer } from "../server/server"
Expand Down Expand Up @@ -117,7 +117,7 @@ export class TestCommand extends Command<Args, Opts> {

const graph = await garden.getConfigGraph(log)

const modules: Module[] = args.modules
const modules: GardenModule[] = args.modules
? graph.withDependantModules(graph.getModules({ names: args.modules }))
: // All modules are included in this case, so there's no need to compute dependants.
graph.getModules()
Expand Down
20 changes: 10 additions & 10 deletions core/src/config-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import toposort from "toposort"
import { flatten, pick, uniq, sortBy, pickBy } from "lodash"
import { BuildDependencyConfig } from "./config/module"
import { Module, getModuleKey, moduleNeedsBuild } from "./types/module"
import { GardenModule, getModuleKey, moduleNeedsBuild } from "./types/module"
import { Service, serviceFromConfig } from "./types/service"
import { Task, taskFromConfig } from "./types/task"
import { TestConfig } from "./config/test"
Expand All @@ -28,7 +28,7 @@ export type DependencyGraphNodeType = "build" | "deploy" | "run" | "test"

// The primary output type (for dependencies and dependants).
export type DependencyRelations = {
build: Module[]
build: GardenModule[]
deploy: Service[]
run: Task[]
test: TestConfig[]
Expand Down Expand Up @@ -77,7 +77,7 @@ export type DependencyGraph = { [key: string]: DependencyGraphNode }
*/
export class ConfigGraph {
private dependencyGraph: DependencyGraph
private modules: { [key: string]: Module }
private modules: { [key: string]: GardenModule }

private serviceConfigs: {
[key: string]: EntityConfigEntry<"service", ServiceConfig>
Expand All @@ -89,7 +89,7 @@ export class ConfigGraph {
[key: string]: EntityConfigEntry<"test", TestConfig>
}

constructor(modules: Module[], moduleTypes: ModuleTypeMap) {
constructor(modules: GardenModule[], moduleTypes: ModuleTypeMap) {
this.dependencyGraph = {}
this.modules = {}
this.serviceConfigs = {}
Expand Down Expand Up @@ -271,7 +271,7 @@ export class ConfigGraph {
}

// Convenience method used in the constructor above.
keyForModule(module: Module | BuildDependencyConfig) {
keyForModule(module: GardenModule | BuildDependencyConfig) {
return getModuleKey(module.name, module.plugin)
}

Expand Down Expand Up @@ -301,7 +301,7 @@ export class ConfigGraph {
/**
* Returns the Service with the specified name. Throws error if it doesn't exist.
*/
getModule(name: string, includeDisabled?: boolean): Module {
getModule(name: string, includeDisabled?: boolean): GardenModule {
return this.getModules({ names: [name], includeDisabled })[0]
}

Expand Down Expand Up @@ -358,7 +358,7 @@ export class ConfigGraph {
/**
* Returns the set union of modules with the set union of their dependants (across all dependency types, recursively).
*/
withDependantModules(modules: Module[]): Module[] {
withDependantModules(modules: GardenModule[]): GardenModule[] {
const dependants = modules.flatMap((m) => this.getDependantsForModule(m, true))
// We call getModules to ensure that the returned modules have up-to-date versions.
const dependantModules = this.modulesForRelations(this.mergeRelations(...dependants))
Expand All @@ -370,7 +370,7 @@ export class ConfigGraph {
* Includes the services and tasks contained in the given module, but does _not_ contain the build node for the
* module itself.
*/
getDependantsForModule(module: Module, recursive: boolean): DependencyRelations {
getDependantsForModule(module: GardenModule, recursive: boolean): DependencyRelations {
return this.getDependants({ nodeType: "build", name: module.name, recursive })
}

Expand Down Expand Up @@ -476,7 +476,7 @@ export class ConfigGraph {
/**
* Returns the (unique by name) list of modules represented in relations.
*/
private modulesForRelations(relations: DependencyRelations): Module[] {
private modulesForRelations(relations: DependencyRelations): GardenModule[] {
const moduleNames = uniq(
flatten([
relations.build,
Expand All @@ -493,7 +493,7 @@ export class ConfigGraph {
* Given the provided lists of build and runtime (service/task) dependencies, return a list of all
* modules required to satisfy those dependencies.
*/
resolveDependencyModules(buildDependencies: BuildDependencyConfig[], runtimeDependencies: string[]): Module[] {
resolveDependencyModules(buildDependencies: BuildDependencyConfig[], runtimeDependencies: string[]): GardenModule[] {
const moduleNames = buildDependencies.map((d) => getModuleKey(d.name, d.plugin))
const serviceNames = runtimeDependencies.filter(
(d) => this.serviceConfigs[d] && !this.isDisabled(this.serviceConfigs[d])
Expand Down
4 changes: 2 additions & 2 deletions core/src/config/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ export interface PosixPathSchema extends Joi.StringSchema {
subPathOnly(): this
}

interface CustomJoi extends Joi.Root {
export interface Schema extends Joi.Root {
object: () => CustomObjectSchema
environment: () => Joi.StringSchema
gitUrl: () => GitUrlSchema
posixPath: () => PosixPathSchema
}

export let joi: CustomJoi = Joi.extend({
export let joi: Schema = Joi.extend({
base: Joi.string(),
type: "posixPath",
flags: {
Expand Down
4 changes: 2 additions & 2 deletions core/src/config/config-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { KeyedSet } from "../util/keyed-set"
import { RuntimeContext } from "../runtime-context"
import { deline, dedent, naturalList } from "../util/string"
import { getProviderUrl, getModuleTypeUrl } from "../docs/common"
import { Module } from "../types/module"
import { GardenModule } from "../types/module"
import { ModuleConfig } from "./module"
import { ModuleVersion } from "../vcs/vcs"
import { isPrimitive } from "util"
Expand Down Expand Up @@ -811,7 +811,7 @@ export class OutputConfigContext extends ModuleConfigContext {
}: {
garden: Garden
resolvedProviders: ProviderMap
modules: Module[]
modules: GardenModule[]
runtimeContext: RuntimeContext
}) {
const versions = fromPairs(modules.map((m) => [m.name, m.version]))
Expand Down
6 changes: 3 additions & 3 deletions core/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const AsyncLock = require("async-lock")

import { TreeCache } from "./cache"
import { builtinPlugins } from "./plugins/plugins"
import { Module, getModuleCacheContext, getModuleKey, ModuleConfigMap, moduleFromConfig } from "./types/module"
import { GardenModule, getModuleCacheContext, getModuleKey, ModuleConfigMap, moduleFromConfig } from "./types/module"
import { pluginModuleSchema, ModuleTypeMap } from "./types/plugin/plugin"
import {
SourceConfig,
Expand Down Expand Up @@ -691,7 +691,7 @@ export class Garden {
return Object.values(keys ? pickKeys(this.moduleConfigs, keys, "module config") : this.moduleConfigs)
}

async getOutputConfigContext(log: LogEntry, modules: Module[], runtimeContext: RuntimeContext) {
async getOutputConfigContext(log: LogEntry, modules: GardenModule[], runtimeContext: RuntimeContext) {
const providers = await this.resolveProviders(log)
return new OutputConfigContext({
garden: this,
Expand Down Expand Up @@ -906,7 +906,7 @@ export class Garden {
*/
async resolveVersion(
moduleConfig: ModuleConfig,
moduleDependencies: (Module | BuildDependencyConfig)[],
moduleDependencies: (GardenModule | BuildDependencyConfig)[],
force = false
) {
const moduleName = moduleConfig.name
Expand Down
Loading

0 comments on commit d4b99e4

Please sign in to comment.