From 71e37fbf426a8d013d6b413d29b358bc93cddbd6 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Wed, 11 Sep 2019 16:46:52 +0200 Subject: [PATCH] refactor: change `varFile` parameter name to `varfile` --- docs/reference/config.md | 18 ++--- garden-service/src/config/project.ts | 46 +++++------ .../test-projects/varfiles-custom/garden.yml | 4 +- .../test/unit/src/config/project.ts | 76 +++++++++---------- garden-service/test/unit/src/garden.ts | 4 +- 5 files changed, 74 insertions(+), 74 deletions(-) diff --git a/docs/reference/config.md b/docs/reference/config.md index f9d183febf..09003bfccd 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -132,9 +132,9 @@ environmentDefaults: - stage ``` -### `environmentDefaults.varFile` +### `environmentDefaults.varfile` -[environmentDefaults](#environmentdefaults) > varFile +[environmentDefaults](#environmentdefaults) > varfile Specify a path (relative to the project root) to a file containing variables, that we apply on top of the _environment-specific_ `variables` field. The file should be in a standard "dotenv" format, specified @@ -288,7 +288,7 @@ sources: - repositoryUrl: "git+https://github.com/org/repo.git#v2.0" ``` -### `varFile` +### `varfile` Specify a path (relative to the project root) to a file containing variables, that we apply on top of the project-wide `variables` field. The file should be in a standard "dotenv" format, specified @@ -298,7 +298,7 @@ If you don't set the field and the `garden.env` file does not exist, we simply i If you do override the default value and the file doesn't exist, an error will be thrown. _Note that in many cases it is advisable to only use environment-specific var files, instead of combining -multiple ones. See the `environments[].varFile` field for this option._ +multiple ones. See the `environments[].varfile` field for this option._ | Type | Required | Default | | -------- | -------- | -------------- | @@ -366,9 +366,9 @@ environments: - stage ``` -### `environments[].varFile` +### `environments[].varfile` -[environments](#environments) > varFile +[environments](#environments) > varfile Specify a path (relative to the project root) to a file containing variables, that we apply on top of the _environment-specific_ `variables` field. The file should be in a standard "dotenv" format, specified @@ -415,7 +415,7 @@ environmentDefaults: providers: - name: environments: - varFile: garden..env + varfile: garden..env variables: {} modules: include: @@ -426,13 +426,13 @@ providers: sources: - name: repositoryUrl: -varFile: garden.env +varfile: garden.env variables: {} environments: - providers: - name: environments: - - varFile: garden..env + - varfile: garden..env variables: {} name: ``` diff --git a/garden-service/src/config/project.ts b/garden-service/src/config/project.ts index d812315cc1..ec5b561e83 100644 --- a/garden-service/src/config/project.ts +++ b/garden-service/src/config/project.ts @@ -34,8 +34,8 @@ import { defaultDotIgnoreFiles } from "../util/fs" import { pathExists, readFile } from "fs-extra" import { resolve } from "path" -export const defaultVarFilePath = "garden.env" -export const defaultEnvVarFilePath = (environmentName: string) => `garden.${environmentName}.env` +export const defaultVarfilePath = "garden.env" +export const defaultEnvVarfilePath = (environmentName: string) => `garden.${environmentName}.env` export interface CommonEnvironmentConfig { providers?: ProviderConfig[] // further validated by each plugin @@ -51,17 +51,17 @@ export const environmentConfigSchema = joi.object() DEPRECATED - Please use the top-level \`providers\` field instead, and if needed use the \`environments\` key on the provider configurations to limit them to specific environments. `), - varFile: joi.string() + varfile: joi.string() .posixPath() .default( - (context: any) => defaultEnvVarFilePath(context.name || ""), defaultEnvVarFilePath(""), + (context: any) => defaultEnvVarfilePath(context.name || ""), defaultEnvVarfilePath(""), ) .description(dedent` Specify a path (relative to the project root) to a file containing variables, that we apply on top of the _environment-specific_ \`variables\` field. The file should be in a standard "dotenv" format, specified [here](https://github.com/motdotla/dotenv#rules). - If you don't set the field and the \`${defaultEnvVarFilePath("")}\` file does not exist, + If you don't set the field and the \`${defaultEnvVarfilePath("")}\` file does not exist, we simply ignore it. If you do override the default value and the file doesn't exist, an error will be thrown. `), variables: joiVariables() @@ -73,7 +73,7 @@ export const environmentConfigSchema = joi.object() export interface EnvironmentConfig extends CommonEnvironmentConfig { name: string - varFile?: string + varfile?: string } export interface Environment extends EnvironmentConfig { @@ -129,7 +129,7 @@ export interface ProjectConfig { }, providers: ProviderConfig[] sources?: SourceConfig[] - varFile?: string + varfile?: string variables: PrimitiveMap } @@ -146,7 +146,7 @@ export const defaultEnvironments: EnvironmentConfig[] = [ environments: [], }, ], - varFile: defaultEnvVarFilePath("local"), + varfile: defaultEnvVarfilePath("local"), variables: {}, }, ] @@ -236,9 +236,9 @@ export const projectSchema = joi.object() "Please refer to individual plugins/providers for details on how to configure them.", ), sources: projectSourcesSchema, - varFile: joi.string() + varfile: joi.string() .posixPath() - .default(defaultVarFilePath) + .default(defaultVarfilePath) .description(dedent` Specify a path (relative to the project root) to a file containing variables, that we apply on top of the project-wide \`variables\` field. The file should be in a standard "dotenv" format, specified @@ -248,7 +248,7 @@ export const projectSchema = joi.object() If you do override the default value and the file doesn't exist, an error will be thrown. _Note that in many cases it is advisable to only use environment-specific var files, instead of combining - multiple ones. See the \`environments[].varFile\` field for this option._ + multiple ones. See the \`environments[].varfile\` field for this option._ `), variables: joiVariables() .description("Variables to configure for all environments."), @@ -276,7 +276,7 @@ export async function resolveProjectConfig(config: ProjectConfig): Promise[] }, name: config.name, sources: config.sources, - varFile: config.varFile, + varfile: config.varfile, variables: config.variables, environments: environments.map(e => omit(e, ["providers"])), }, @@ -354,8 +354,8 @@ export async function resolveProjectConfig(config: ProjectConfig): Promise environment.variables > project.varFile > project.variables + * We also attempt to load the configured varfiles, and include those in the merge. The precedence order is as follows: + * environment.varfile > environment.variables > project.varfile > project.variables * * For provider configuration, we filter down to the providers that are enabled for all environments (no `environments` * key specified) and those that explicitly list the specified environments. Then we merge any provider configs with @@ -400,16 +400,16 @@ export async function pickEnvironment(config: ProjectConfig, environmentName: st } } - const projectVarFileVars = await loadVarFile( - config.path, config.varFile, defaultVarFilePath, + const projectVarfileVars = await loadVarfile( + config.path, config.varfile, defaultVarfilePath, ) - const envVarFileVars = await loadVarFile( - config.path, environmentConfig.varFile, defaultEnvVarFilePath(environmentName), + const envVarfileVars = await loadVarfile( + config.path, environmentConfig.varfile, defaultEnvVarfilePath(environmentName), ) const variables: PrimitiveMap = merge( - merge(config.variables, projectVarFileVars), - merge(environmentConfig.variables, envVarFileVars), + merge(config.variables, projectVarfileVars), + merge(environmentConfig.variables, envVarfileVars), ) return { @@ -418,12 +418,12 @@ export async function pickEnvironment(config: ProjectConfig, environmentName: st } } -async function loadVarFile(projectRoot: string, path: string | undefined, defaultPath: string): Promise { +async function loadVarfile(projectRoot: string, path: string | undefined, defaultPath: string): Promise { const resolvedPath = resolve(projectRoot, path || defaultPath) const exists = await pathExists(resolvedPath) if (!exists && path && path !== defaultPath) { - throw new ConfigurationError(`Could not find varFile at path '${path}'`, { + throw new ConfigurationError(`Could not find varfile at path '${path}'`, { path, resolvedPath, }) @@ -436,7 +436,7 @@ async function loadVarFile(projectRoot: string, path: string | undefined, defaul try { return dotenv.parse(await readFile(resolvedPath)) } catch (error) { - throw new ConfigurationError(`Unable to load varFile at '${path}': ${error}`, { + throw new ConfigurationError(`Unable to load varfile at '${path}': ${error}`, { error, path, }) diff --git a/garden-service/test/unit/data/test-projects/varfiles-custom/garden.yml b/garden-service/test/unit/data/test-projects/varfiles-custom/garden.yml index 07f00d014c..5e916bdd1a 100644 --- a/garden-service/test/unit/data/test-projects/varfiles-custom/garden.yml +++ b/garden-service/test/unit/data/test-projects/varfiles-custom/garden.yml @@ -2,5 +2,5 @@ kind: Project name: varfiles-custom environments: - name: default - varFile: foo.default.env -varFile: foo.env + varfile: foo.default.env +varfile: foo.env diff --git a/garden-service/test/unit/src/config/project.ts b/garden-service/test/unit/src/config/project.ts index a782126ef7..e625cf8c56 100644 --- a/garden-service/test/unit/src/config/project.ts +++ b/garden-service/test/unit/src/config/project.ts @@ -6,8 +6,8 @@ import { resolveProjectConfig, defaultEnvironments, pickEnvironment, - defaultVarFilePath, - defaultEnvVarFilePath, + defaultVarfilePath, + defaultEnvVarfilePath, } from "../../../../src/config/project" import { DEFAULT_API_VERSION } from "../../../../src/constants" import { expectError } from "../../../helpers" @@ -44,12 +44,12 @@ describe("resolveProjectConfig", () => { { name: "default", providers: [], - varFile: defaultEnvVarFilePath("default"), + varfile: defaultEnvVarfilePath("default"), variables: {}, }, ], sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) }) @@ -76,7 +76,7 @@ describe("resolveProjectConfig", () => { }, environments: defaultEnvironments, sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) }) @@ -129,7 +129,7 @@ describe("resolveProjectConfig", () => { { name: "default", providers: [], - varFile: defaultEnvVarFilePath("default"), + varfile: defaultEnvVarfilePath("default"), variables: { envVar: "foo", }, @@ -141,7 +141,7 @@ describe("resolveProjectConfig", () => { repositoryUrl, }, ], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, variables: { defaultEnvVar: "foo", platform: platform(), @@ -205,7 +205,7 @@ describe("resolveProjectConfig", () => { { name: "default", providers: [], - varFile: defaultEnvVarFilePath("default"), + varfile: defaultEnvVarfilePath("default"), variables: { envVar: "foo", }, @@ -227,7 +227,7 @@ describe("resolveProjectConfig", () => { }, ], sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) delete process.env.TEST_ENV_VAR_A @@ -259,7 +259,7 @@ describe("resolveProjectConfig", () => { }, environments: defaultEnvironments, sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) }) @@ -287,7 +287,7 @@ describe("resolveProjectConfig", () => { }, environments: defaultEnvironments, sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) }) @@ -338,7 +338,7 @@ describe("resolveProjectConfig", () => { { name: "default", providers: [], - varFile: defaultEnvVarFilePath("default"), + varfile: defaultEnvVarfilePath("default"), variables: { envVar: "foo", }, @@ -357,7 +357,7 @@ describe("resolveProjectConfig", () => { }, ], sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, }) }) @@ -406,7 +406,7 @@ describe("resolveProjectConfig", () => { { name: "default", providers: [], - varFile: defaultEnvVarFilePath("default"), + varfile: defaultEnvVarfilePath("default"), variables: { envVar: "bar", }, @@ -422,7 +422,7 @@ describe("resolveProjectConfig", () => { }, ], sources: [], - varFile: defaultVarFilePath, + varfile: defaultVarfilePath, variables: { defaultVar: "foo", }, @@ -578,9 +578,9 @@ describe("pickEnvironment", () => { }) }) - it("should load variables from default project varFile if it exists", async () => { - const varFilePath = resolve(tmpPath, defaultVarFilePath) - await writeFile(varFilePath, dedent` + it("should load variables from default project varfile if it exists", async () => { + const varfilePath = resolve(tmpPath, defaultVarfilePath) + await writeFile(varfilePath, dedent` a=a b=b `) @@ -614,9 +614,9 @@ describe("pickEnvironment", () => { }) }) - it("should load variables from default environment varFile if it exists", async () => { - const varFilePath = resolve(tmpPath, defaultEnvVarFilePath("default")) - await writeFile(varFilePath, dedent` + it("should load variables from default environment varfile if it exists", async () => { + const varfilePath = resolve(tmpPath, defaultEnvVarfilePath("default")) + await writeFile(varfilePath, dedent` b=B c=c `) @@ -650,9 +650,9 @@ describe("pickEnvironment", () => { }) }) - it("should load variables from custom project varFile if specified", async () => { - const varFilePath = resolve(tmpPath, "foo.env") - await writeFile(varFilePath, dedent` + it("should load variables from custom project varfile if specified", async () => { + const varfilePath = resolve(tmpPath, "foo.env") + await writeFile(varfilePath, dedent` a=a b=b `) @@ -674,7 +674,7 @@ describe("pickEnvironment", () => { }, ], providers: [], - varFile: "foo.env", + varfile: "foo.env", variables: {}, } @@ -687,9 +687,9 @@ describe("pickEnvironment", () => { }) }) - it("should load variables from custom environment varFile if specified", async () => { - const varFilePath = resolve(tmpPath, "foo.env") - await writeFile(varFilePath, dedent` + it("should load variables from custom environment varfile if specified", async () => { + const varfilePath = resolve(tmpPath, "foo.env") + await writeFile(varfilePath, dedent` b=B c=c `) @@ -704,7 +704,7 @@ describe("pickEnvironment", () => { environments: [ { name: "default", - varFile: "foo.env", + varfile: "foo.env", variables: {}, }, ], @@ -724,15 +724,15 @@ describe("pickEnvironment", () => { }) }) - it("should correctly merge all variable sources in precedence order (variables fields and varFiles)", async () => { + it("should correctly merge all variable sources in precedence order (variables fields and varfiles)", async () => { // Precedence 1/4 (highest) - await writeFile(resolve(tmpPath, defaultEnvVarFilePath("default")), dedent` + await writeFile(resolve(tmpPath, defaultEnvVarfilePath("default")), dedent` d=D e=e `) // Precedence 3/4 - await writeFile(resolve(tmpPath, defaultVarFilePath), dedent` + await writeFile(resolve(tmpPath, defaultVarfilePath), dedent` b=B c=c `) @@ -773,7 +773,7 @@ describe("pickEnvironment", () => { }) }) - it("should throw if project varFile is set to non-default and it doesn't exist", async () => { + it("should throw if project varfile is set to non-default and it doesn't exist", async () => { const config: ProjectConfig = { apiVersion: DEFAULT_API_VERSION, kind: "Project", @@ -788,17 +788,17 @@ describe("pickEnvironment", () => { }, ], providers: [], - varFile: "foo.env", + varfile: "foo.env", variables: {}, } await expectError( () => pickEnvironment(config, "default"), - (err) => expect(err.message).to.equal("Could not find varFile at path 'foo.env'"), + (err) => expect(err.message).to.equal("Could not find varfile at path 'foo.env'"), ) }) - it("should throw if environment varFile is set to non-default and it doesn't exist", async () => { + it("should throw if environment varfile is set to non-default and it doesn't exist", async () => { const config: ProjectConfig = { apiVersion: DEFAULT_API_VERSION, kind: "Project", @@ -809,7 +809,7 @@ describe("pickEnvironment", () => { environments: [ { name: "default", - varFile: "foo.env", + varfile: "foo.env", variables: {}, }, ], @@ -819,7 +819,7 @@ describe("pickEnvironment", () => { await expectError( () => pickEnvironment(config, "default"), - (err) => expect(err.message).to.equal("Could not find varFile at path 'foo.env'"), + (err) => expect(err.message).to.equal("Could not find varfile at path 'foo.env'"), ) }) }) diff --git a/garden-service/test/unit/src/garden.ts b/garden-service/test/unit/src/garden.ts index a96a813459..e6586c5518 100644 --- a/garden-service/test/unit/src/garden.ts +++ b/garden-service/test/unit/src/garden.ts @@ -254,7 +254,7 @@ describe("Garden", () => { expect(garden.gardenDirPath).to.eql(gardenDirPath) }) - it("should load default varFiles if they exist", async () => { + it("should load default varfiles if they exist", async () => { const projectRoot = join(dataDir, "test-projects", "varfiles") const garden = await Garden.factory(projectRoot, {}) expect(garden.variables).to.eql({ @@ -264,7 +264,7 @@ describe("Garden", () => { }) }) - it("should load custom varFiles if specified", async () => { + it("should load custom varfiles if specified", async () => { const projectRoot = join(dataDir, "test-projects", "varfiles-custom") const garden = await Garden.factory(projectRoot, {}) expect(garden.variables).to.eql({