From 8cd7be4a040316144144ac0af3f9c69d0db7efe5 Mon Sep 17 00:00:00 2001 From: Jason Barry Date: Fri, 7 Oct 2022 10:19:10 -0700 Subject: [PATCH 1/2] chore: kebab-case post-processing flag --- docs/commands/env.md | 6 +++--- src/commands/env/env-get.cjs | 2 +- src/commands/env/env-list.cjs | 2 +- src/commands/env/env-set.cjs | 2 +- src/utils/env/index.cjs | 3 ++- tests/integration/650.command.envelope.test.cjs | 2 +- tests/unit/utils/env/index.test.cjs | 2 ++ 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/commands/env.md b/docs/commands/env.md index b0b3b65bbdf..90f577d1d47 100644 --- a/docs/commands/env.md +++ b/docs/commands/env.md @@ -85,7 +85,7 @@ netlify env:get **Flags** - `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") -- `scope` (*builds | functions | post_processing | runtime | any*) - Specify a scope +- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope - `debug` (*boolean*) - Print debugging information - `httpProxy` (*string*) - Proxy server address to route requests through. - `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server @@ -135,7 +135,7 @@ netlify env:list **Flags** - `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") -- `scope` (*builds | functions | post_processing | runtime | any*) - Specify a scope +- `scope` (*builds | functions | post-processing | runtime | any*) - Specify a scope - `debug` (*boolean*) - Print debugging information - `httpProxy` (*string*) - Proxy server address to route requests through. - `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server @@ -168,7 +168,7 @@ netlify env:set **Flags** - `context` (*string*) - Specify a deploy context or branch (contexts: "production", "deploy-preview", "branch-deploy", "dev") (default: all contexts) -- `scope` (*builds | functions | post_processing | runtime*) - Specify a scope (default: all scopes) +- `scope` (*builds | functions | post-processing | runtime*) - Specify a scope (default: all scopes) - `debug` (*boolean*) - Print debugging information - `httpProxy` (*string*) - Proxy server address to route requests through. - `httpProxyCertificateFilename` (*string*) - Certificate file to use when connecting using a proxy server diff --git a/src/commands/env/env-get.cjs b/src/commands/env/env-get.cjs index 87a8b1a1df9..3699ae14ee0 100644 --- a/src/commands/env/env-get.cjs +++ b/src/commands/env/env-get.cjs @@ -77,7 +77,7 @@ const createEnvGetCommand = (program) => ) .addOption( new Option('-s, --scope ', 'Specify a scope') - .choices(['builds', 'functions', 'post_processing', 'runtime', 'any']) + .choices(['builds', 'functions', 'post-processing', 'runtime', 'any']) .default('any'), ) .addExamples([ diff --git a/src/commands/env/env-list.cjs b/src/commands/env/env-list.cjs index 2f4f96be614..1097cbc074e 100644 --- a/src/commands/env/env-list.cjs +++ b/src/commands/env/env-list.cjs @@ -140,7 +140,7 @@ const createEnvListCommand = (program) => ) .addOption( new Option('-s, --scope ', 'Specify a scope') - .choices(['builds', 'functions', 'post_processing', 'runtime', 'any']) + .choices(['builds', 'functions', 'post-processing', 'runtime', 'any']) .default('any'), ) .addExamples([ diff --git a/src/commands/env/env-set.cjs b/src/commands/env/env-set.cjs index e6d67fefb12..cc10f82bbf0 100644 --- a/src/commands/env/env-set.cjs +++ b/src/commands/env/env-set.cjs @@ -165,7 +165,7 @@ const createEnvSetCommand = (program) => new Option('-s, --scope ', 'Specify a scope (default: all scopes)').choices([ 'builds', 'functions', - 'post_processing', + 'post-processing', 'runtime', ]), ) diff --git a/src/utils/env/index.cjs b/src/utils/env/index.cjs index d8399e3a179..c78d1fc5bc5 100644 --- a/src/utils/env/index.cjs +++ b/src/utils/env/index.cjs @@ -150,7 +150,7 @@ const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'an const configFileEnv = filterEnvBySource(env, 'configFile') // filter out configFile env vars if a non-configFile scope is passed - const includeConfigEnvVars = ['any', 'builds', 'post_processing'].includes(scope) + const includeConfigEnvVars = /any|builds|post[-_]processing/.test(scope) // Sources of environment variables, in ascending order of precedence. return { @@ -172,6 +172,7 @@ const getHumanReadableScopes = (scopes) => { builds: 'Builds', functions: 'Functions', post_processing: 'Post processing', + 'post-processing': 'Post processing', runtime: 'Runtime', } if (!scopes) { diff --git a/tests/integration/650.command.envelope.test.cjs b/tests/integration/650.command.envelope.test.cjs index b7c352d631f..80c23aa2b00 100644 --- a/tests/integration/650.command.envelope.test.cjs +++ b/tests/integration/650.command.envelope.test.cjs @@ -366,7 +366,7 @@ test('env:set --scope should set the scope of an existing env var without needin await withMockApi(routes, async ({ apiUrl, requests }) => { const cliResponse = await callCli( - ['env:set', 'EXISTING_VAR', '--scope', 'runtime', 'post_processing', '--json'], + ['env:set', 'EXISTING_VAR', '--scope', 'runtime', 'post-processing', '--json'], getCLIOptions({ builder, apiUrl }), true, ) diff --git a/tests/unit/utils/env/index.test.cjs b/tests/unit/utils/env/index.test.cjs index 5659e10c660..c9ef39b51af 100644 --- a/tests/unit/utils/env/index.test.cjs +++ b/tests/unit/utils/env/index.test.cjs @@ -118,8 +118,10 @@ test('should convert scope keys into a human-readable list', (t) => { t.is(getHumanReadableScopes([]), '') t.is(getHumanReadableScopes(), 'Builds, Post processing') t.is(getHumanReadableScopes(['post_processing']), 'Post processing') + t.is(getHumanReadableScopes(['post-processing']), 'Post processing') t.is(getHumanReadableScopes(['builds', 'functions']), 'Builds, Functions') t.is(getHumanReadableScopes(['builds', 'functions', 'runtime', 'post_processing']), 'All') + t.is(getHumanReadableScopes(['builds', 'functions', 'runtime', 'post-processing']), 'All') }) test('should normalize a branch name or context', (t) => { From fcd96151b4bafbfdc84ec3b27af12ce72c357bc8 Mon Sep 17 00:00:00 2001 From: Jason Barry Date: Tue, 25 Oct 2022 16:01:34 -0700 Subject: [PATCH 2/2] test: fix test --- src/utils/env/index.cjs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/utils/env/index.cjs b/src/utils/env/index.cjs index c78d1fc5bc5..63c3929ee0c 100644 --- a/src/utils/env/index.cjs +++ b/src/utils/env/index.cjs @@ -168,12 +168,13 @@ const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', scope = 'an * @returns {string} A human-readable, comma-separated list of scopes */ const getHumanReadableScopes = (scopes) => { - const HUMAN_SCOPES = { - builds: 'Builds', - functions: 'Functions', - post_processing: 'Post processing', - 'post-processing': 'Post processing', - runtime: 'Runtime', + const HUMAN_SCOPES = ['Builds', 'Functions', 'Runtime', 'Post processing'] + const SCOPES_MAP = { + builds: HUMAN_SCOPES[0], + functions: HUMAN_SCOPES[1], + runtime: HUMAN_SCOPES[2], + post_processing: HUMAN_SCOPES[3], + 'post-processing': HUMAN_SCOPES[3], } if (!scopes) { // if `scopes` is not available, the env var comes from netlify.toml @@ -184,7 +185,7 @@ const getHumanReadableScopes = (scopes) => { // shorthand instead of listing every available scope return 'All' } - return scopes.map((scope) => HUMAN_SCOPES[scope]).join(', ') + return scopes.map((scope) => SCOPES_MAP[scope]).join(', ') } /**