Skip to content

Commit

Permalink
fix(core): error in some cases when referencing modules within file
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Aug 6, 2019
1 parent 117efe3 commit 377fd2e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
12 changes: 11 additions & 1 deletion garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ export class Garden {
return
}

this.log.silly(`Resolving providers`)

const rawConfigs = this.getRawProviderConfigs()
const plugins = await Bluebird.map(rawConfigs, async (config) => this.loadPlugin(config.name))

Expand Down Expand Up @@ -488,6 +490,8 @@ export class Garden {
const actions = await this.getActionHelper()
const configs = await this.getRawModuleConfigs(keys)

keys ? this.log.silly(`Resolving module configs ${keys.join(", ")}`) : this.log.silly(`Resolving module configs`)

if (!opts.configContext) {
opts.configContext = new ModuleConfigContext(
this,
Expand Down Expand Up @@ -606,6 +610,8 @@ export class Garden {
* and the versions of its dependencies (in sorted order).
*/
async resolveVersion(moduleName: string, moduleDependencies: (Module | BuildDependencyConfig)[], force = false) {
this.log.silly(`Resolving version for module ${moduleName}`)

const depModuleNames = moduleDependencies.map(m => m.name)
depModuleNames.sort()
const cacheKey = ["moduleVersions", moduleName, ...depModuleNames]
Expand All @@ -620,7 +626,7 @@ export class Garden {

const config = await this.resolveModuleConfig(moduleName)
const dependencyKeys = moduleDependencies.map(dep => getModuleKey(dep.name, dep.plugin))
const dependencies = await this.resolveModuleConfigs(dependencyKeys)
const dependencies = await this.getRawModuleConfigs(dependencyKeys)
const cacheContexts = dependencies.concat([config]).map(c => getModuleCacheContext(c))

const version = await this.vcs.resolveVersion(config, dependencies)
Expand Down Expand Up @@ -670,6 +676,8 @@ export class Garden {

await Bluebird.map(rawConfigs, async (config) => this.addModule(config))

this.log.silly(`Scanned and found ${rawConfigs.length} modules`)

this.modulesScanned = true
})
}
Expand All @@ -687,6 +695,7 @@ export class Garden {
*/
private async addModule(config: ModuleConfig) {
const key = getModuleKey(config.name, config.plugin)
this.log.silly(`Adding module ${key}`)

if (this.moduleConfigs[key]) {
const paths = [this.moduleConfigs[key].path, config.path]
Expand All @@ -712,6 +721,7 @@ export class Garden {
path = resolve(this.projectRoot, path)
this.log.silly(`Load module configs from ${path}`)
const resources = await loadConfig(this.projectRoot, path)
this.log.silly(`Loaded module configs from ${path}`)
return <ModuleResource[]>resources.filter(r => r.kind === "Module")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM busybox
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kind: Project
name: issue-1067
---
kind: Module
name: container-module
type: container
allowPublish: false
build:
dependencies:
- name: exec-module
---
kind: Module
type: exec
allowPublish: false
include: []
name: exec-module
build:
command:
- echo
- "${modules.container-module.path}"
8 changes: 8 additions & 0 deletions garden-service/test/unit/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,14 @@ describe("Garden", () => {
// We template in the value for the module's allowPublish field to test this
expect(module.allowPublish).to.equal(false)
})

it("should handle module references within single file", async () => {
const projectRoot = getDataDir("test-projects", "1067-module-ref-within-file")
const garden = await makeTestGarden(projectRoot)

// This should just complete successfully
await garden.resolveModuleConfigs()
})
})

describe("resolveVersion", () => {
Expand Down

0 comments on commit 377fd2e

Please sign in to comment.