From becfc1361ee6f7c716d0cde3593acc3d66398e6a Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Fri, 16 Apr 2021 12:58:59 -0600 Subject: [PATCH 1/2] feat(#130): starts on creating deprecation warnings on parsing extensions NOTE that '$git' directive is currently incompatible with being included twice --- app-config-default-extensions/index.js | 8 +++--- app-config-encryption/src/index.ts | 12 ++++++++- app-config-git/package.json | 1 + app-config-git/src/index.ts | 8 ++++++ app-config-git/tsconfig.json | 1 + app-config-v1-compat/src/index.ts | 36 ++++++++++++++++++-------- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/app-config-default-extensions/index.js b/app-config-default-extensions/index.js index 31fc11d6..ac6b6cea 100644 --- a/app-config-default-extensions/index.js +++ b/app-config-default-extensions/index.js @@ -40,16 +40,18 @@ module.exports = { eqDirective(), parseDirective(), hiddenDirective(), - v1Compat(), envDirective(aliases, environmentOverride, environmentSourceNames), envVarDirective(aliases, environmentOverride, environmentSourceNames), extendsDirective(), extendsSelfDirective(), overrideDirective(), - encryptedDirective(symmetricKey), timestampDirective(), substituteDirective(aliases, environmentOverride, environmentSourceNames), - gitRefDirectives(), + + // these will be removed in v3 + v1Compat(true), + gitRefDirectives(undefined, true), + encryptedDirective(symmetricKey, true), ]; }, defaultEnvExtensions() { diff --git a/app-config-encryption/src/index.ts b/app-config-encryption/src/index.ts index faa3220a..7ad0fc17 100644 --- a/app-config-encryption/src/index.ts +++ b/app-config-encryption/src/index.ts @@ -1,5 +1,6 @@ import type { ParsingExtension } from '@app-config/core'; import { named } from '@app-config/extension-utils'; +import { logger } from '@app-config/logging'; import { DecryptedSymmetricKey, decryptValue } from './encryption'; export * from './encryption'; @@ -7,10 +8,19 @@ export * from './secret-agent'; export * from './secret-agent-tls'; /** Decrypts inline encrypted values */ -export default function encryptedDirective(symmetricKey?: DecryptedSymmetricKey): ParsingExtension { +export default function encryptedDirective( + symmetricKey?: DecryptedSymmetricKey, + shouldShowDeprecationNotice?: true, +): ParsingExtension { return named('encryption', (value) => { if (typeof value === 'string' && value.startsWith('enc:')) { return async (parse) => { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/encryption parsing extension. Please install @app-config/encryption and add it to your meta file "parsingExtensions".', + ); + } + const decrypted = await decryptValue(value, symmetricKey); return parse(decrypted, { fromSecrets: true, parsedFromEncryptedValue: true }); diff --git a/app-config-git/package.json b/app-config-git/package.json index 3487d399..aab08821 100644 --- a/app-config-git/package.json +++ b/app-config-git/package.json @@ -32,6 +32,7 @@ "dependencies": { "@app-config/core": "^2.4.6", "@app-config/extension-utils": "^2.4.6", + "@app-config/logging": "^2.4.6", "simple-git": "2" }, "devDependencies": { diff --git a/app-config-git/src/index.ts b/app-config-git/src/index.ts index 2cee7b46..c6be0649 100644 --- a/app-config-git/src/index.ts +++ b/app-config-git/src/index.ts @@ -1,12 +1,14 @@ import simpleGit from 'simple-git'; import { ParsingExtension, AppConfigError, Fallbackable } from '@app-config/core'; import { named, forKey, validateOptions } from '@app-config/extension-utils'; +import { logger } from '@app-config/logging'; class GitError extends Fallbackable {} /** Access to the git branch and commit ref */ export default function gitRefDirectives( getStatus: typeof gitStatus = gitStatus, + shouldShowDeprecationNotice?: true, ): ParsingExtension { return named( '$git', @@ -15,6 +17,12 @@ export default function gitRefDirectives( validateOptions( (SchemaBuilder) => SchemaBuilder.stringSchema(), (value) => async (parse) => { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/git parsing extension. Please install @app-config/git and add it to your meta file "parsingExtensions".', + ); + } + switch (value) { case 'commit': return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true })); diff --git a/app-config-git/tsconfig.json b/app-config-git/tsconfig.json index 7af4427b..aeebcf6e 100644 --- a/app-config-git/tsconfig.json +++ b/app-config-git/tsconfig.json @@ -9,6 +9,7 @@ "references": [ { "path": "../app-config-test-utils" }, { "path": "../app-config-core" }, + { "path": "../app-config-logging" }, { "path": "../app-config-extension-utils" } ] } diff --git a/app-config-v1-compat/src/index.ts b/app-config-v1-compat/src/index.ts index 47805c40..695748f0 100644 --- a/app-config-v1-compat/src/index.ts +++ b/app-config-v1-compat/src/index.ts @@ -7,7 +7,7 @@ import { FileSource } from '@app-config/node'; import { logger } from '@app-config/logging'; /** V1 app-config compatibility */ -export default function v1Compat(): ParsingExtension { +export default function v1Compat(shouldShowDeprecationNotice?: true): ParsingExtension { return named('v1-compat', (value, [_, key], context) => { // only apply in top-level app-config property if (context[context.length - 1]?.[0] !== Root) { @@ -16,16 +16,6 @@ export default function v1Compat(): ParsingExtension { if (key === 'app-config' && isObject(value)) { return async (parse, _, ctx) => { - if (ctx instanceof FileSource) { - logger.warn( - `Using V1 compatibility layer for special 'app-config' property in ${ctx.filePath}! This functionality is deprecated and may be removed in the future.`, - ); - } else { - logger.warn( - `Using V1 compatibility layer for special 'app-config' property! This functionality is deprecated and may be removed in the future.`, - ); - } - const resolveAmbiguousFilename = async (filepath: string) => { let resolvedPath = filepath; @@ -56,6 +46,12 @@ export default function v1Compat(): ParsingExtension { // TODO: multiple properties defined if ('extends' in value) { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".', + ); + } + return parse( { $extends: await resolveAmbiguousFilename(value.extends as string) }, { shouldMerge: true }, @@ -63,6 +59,12 @@ export default function v1Compat(): ParsingExtension { } if ('extendsOptional' in value) { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".', + ); + } + return parse( { $extends: { @@ -75,6 +77,12 @@ export default function v1Compat(): ParsingExtension { } if ('override' in value) { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".', + ); + } + return parse( { $override: await resolveAmbiguousFilename(value.override as string) }, { shouldOverride: true }, @@ -82,6 +90,12 @@ export default function v1Compat(): ParsingExtension { } if ('overrideOptional' in value) { + if (shouldShowDeprecationNotice) { + logger.warn( + 'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".', + ); + } + return parse( { $override: { From e1318c69680c27123c2f37139f39f3210bec806c Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Sat, 1 May 2021 19:03:22 -0600 Subject: [PATCH 2/2] feat(#135): adds deprecation warning on $substitute directive --- .../src/substitute-directive.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/app-config-extensions/src/substitute-directive.ts b/app-config-extensions/src/substitute-directive.ts index fc2ce62d..f20d641c 100644 --- a/app-config-extensions/src/substitute-directive.ts +++ b/app-config-extensions/src/substitute-directive.ts @@ -28,6 +28,12 @@ export function substituteDirective( validateObject(value, [...ctx, key]); if (Array.isArray(value)) throw new AppConfigError('$substitute was given an array'); + if (value.$name) { + logger.warn( + `Detected deprecated use of $name in a $substitute directive. Use 'name' instead.`, + ); + } + const name = (await parse(selectDefined(value.name, value.$name))).toJSON(); validateString(name, [...ctx, key, [InObject, 'name']]); @@ -35,6 +41,12 @@ export function substituteDirective( const parseValue = async (strValue: string | null) => { const parseBool = (await parse(selectDefined(value.parseBool, value.$parseBool))).toJSON(); + if (value.$parseBool) { + logger.warn( + `Detected deprecated use of $parseBool in a $substitute directive. Use 'parseBool' instead.`, + ); + } + if (parseBool) { const parsed = strValue !== null && (strValue.toLowerCase() === 'true' || strValue === '1'); @@ -48,6 +60,12 @@ export function substituteDirective( const parseInt = (await parse(selectDefined(value.parseInt, value.$parseInt))).toJSON(); + if (value.$parseInt) { + logger.warn( + `Detected deprecated use of $parseInt in a $substitute directive. Use 'parseInt' instead.`, + ); + } + if (parseInt) { const parsed = Number.parseInt(strValue, 10); @@ -58,6 +76,12 @@ export function substituteDirective( return parse(parsed, { shouldFlatten: true }); } + if (value.$parseFloat) { + logger.warn( + `Detected deprecated use of $parseFloat in a $substitute directive. Use 'parseFloat' instead.`, + ); + } + const parseFloat = ( await parse(selectDefined(value.parseFloat, value.$parseFloat)) ).toJSON(); @@ -89,6 +113,18 @@ export function substituteDirective( const fallback = (await parse(selectDefined(value.fallback, value.$fallback))).toJSON(); const allowNull = (await parse(selectDefined(value.allowNull, value.$allowNull))).toJSON(); + if (value.$fallback) { + logger.warn( + `Detected deprecated use of $fallback in a $substitute directive. Use 'fallback' instead.`, + ); + } + + if (value.$allowNull) { + logger.warn( + `Detected deprecated use of $allowNull in a $substitute directive. Use 'allowNull' instead.`, + ); + } + if (allowNull) { validateStringOrNull(fallback, [...ctx, key, [InObject, 'fallback']]); } else {