Skip to content

Commit 816d6d4

Browse files
authored
Merge pull request #150 from launchcodedev/v3-deprecation-warnings
Adds deprecation warning for usage of future non-default parsing extensions
2 parents c0e7671 + e1318c6 commit 816d6d4

File tree

7 files changed

+87
-15
lines changed

7 files changed

+87
-15
lines changed

app-config-default-extensions/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ module.exports = {
4040
eqDirective(),
4141
parseDirective(),
4242
hiddenDirective(),
43-
v1Compat(),
4443
envDirective(aliases, environmentOverride, environmentSourceNames),
4544
envVarDirective(aliases, environmentOverride, environmentSourceNames),
4645
extendsDirective(),
4746
extendsSelfDirective(),
4847
overrideDirective(),
49-
encryptedDirective(symmetricKey),
5048
timestampDirective(),
5149
substituteDirective(aliases, environmentOverride, environmentSourceNames),
52-
gitRefDirectives(),
50+
51+
// these will be removed in v3
52+
v1Compat(true),
53+
gitRefDirectives(undefined, true),
54+
encryptedDirective(symmetricKey, true),
5355
];
5456
},
5557
defaultEnvExtensions() {

app-config-encryption/src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
import type { ParsingExtension } from '@app-config/core';
22
import { named } from '@app-config/extension-utils';
3+
import { logger } from '@app-config/logging';
34
import { DecryptedSymmetricKey, decryptValue } from './encryption';
45

56
export * from './encryption';
67
export * from './secret-agent';
78
export * from './secret-agent-tls';
89

910
/** Decrypts inline encrypted values */
10-
export default function encryptedDirective(symmetricKey?: DecryptedSymmetricKey): ParsingExtension {
11+
export default function encryptedDirective(
12+
symmetricKey?: DecryptedSymmetricKey,
13+
shouldShowDeprecationNotice?: true,
14+
): ParsingExtension {
1115
return named('encryption', (value) => {
1216
if (typeof value === 'string' && value.startsWith('enc:')) {
1317
return async (parse) => {
18+
if (shouldShowDeprecationNotice) {
19+
logger.warn(
20+
'Detected deprecated use of @app-config/encryption parsing extension. Please install @app-config/encryption and add it to your meta file "parsingExtensions".',
21+
);
22+
}
23+
1424
const decrypted = await decryptValue(value, symmetricKey);
1525

1626
return parse(decrypted, { fromSecrets: true, parsedFromEncryptedValue: true });

app-config-extensions/src/substitute-directive.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@ export function substituteDirective(
2828
validateObject(value, [...ctx, key]);
2929
if (Array.isArray(value)) throw new AppConfigError('$substitute was given an array');
3030

31+
if (value.$name) {
32+
logger.warn(
33+
`Detected deprecated use of $name in a $substitute directive. Use 'name' instead.`,
34+
);
35+
}
36+
3137
const name = (await parse(selectDefined(value.name, value.$name))).toJSON();
3238

3339
validateString(name, [...ctx, key, [InObject, 'name']]);
3440

3541
const parseValue = async (strValue: string | null) => {
3642
const parseBool = (await parse(selectDefined(value.parseBool, value.$parseBool))).toJSON();
3743

44+
if (value.$parseBool) {
45+
logger.warn(
46+
`Detected deprecated use of $parseBool in a $substitute directive. Use 'parseBool' instead.`,
47+
);
48+
}
49+
3850
if (parseBool) {
3951
const parsed =
4052
strValue !== null && (strValue.toLowerCase() === 'true' || strValue === '1');
@@ -48,6 +60,12 @@ export function substituteDirective(
4860

4961
const parseInt = (await parse(selectDefined(value.parseInt, value.$parseInt))).toJSON();
5062

63+
if (value.$parseInt) {
64+
logger.warn(
65+
`Detected deprecated use of $parseInt in a $substitute directive. Use 'parseInt' instead.`,
66+
);
67+
}
68+
5169
if (parseInt) {
5270
const parsed = Number.parseInt(strValue, 10);
5371

@@ -58,6 +76,12 @@ export function substituteDirective(
5876
return parse(parsed, { shouldFlatten: true });
5977
}
6078

79+
if (value.$parseFloat) {
80+
logger.warn(
81+
`Detected deprecated use of $parseFloat in a $substitute directive. Use 'parseFloat' instead.`,
82+
);
83+
}
84+
6185
const parseFloat = (
6286
await parse(selectDefined(value.parseFloat, value.$parseFloat))
6387
).toJSON();
@@ -89,6 +113,18 @@ export function substituteDirective(
89113
const fallback = (await parse(selectDefined(value.fallback, value.$fallback))).toJSON();
90114
const allowNull = (await parse(selectDefined(value.allowNull, value.$allowNull))).toJSON();
91115

116+
if (value.$fallback) {
117+
logger.warn(
118+
`Detected deprecated use of $fallback in a $substitute directive. Use 'fallback' instead.`,
119+
);
120+
}
121+
122+
if (value.$allowNull) {
123+
logger.warn(
124+
`Detected deprecated use of $allowNull in a $substitute directive. Use 'allowNull' instead.`,
125+
);
126+
}
127+
92128
if (allowNull) {
93129
validateStringOrNull(fallback, [...ctx, key, [InObject, 'fallback']]);
94130
} else {

app-config-git/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dependencies": {
3333
"@app-config/core": "^2.4.6",
3434
"@app-config/extension-utils": "^2.4.6",
35+
"@app-config/logging": "^2.4.6",
3536
"simple-git": "2"
3637
},
3738
"devDependencies": {

app-config-git/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import simpleGit from 'simple-git';
22
import { ParsingExtension, AppConfigError, Fallbackable } from '@app-config/core';
33
import { named, forKey, validateOptions } from '@app-config/extension-utils';
4+
import { logger } from '@app-config/logging';
45

56
class GitError extends Fallbackable {}
67

78
/** Access to the git branch and commit ref */
89
export default function gitRefDirectives(
910
getStatus: typeof gitStatus = gitStatus,
11+
shouldShowDeprecationNotice?: true,
1012
): ParsingExtension {
1113
return named(
1214
'$git',
@@ -15,6 +17,12 @@ export default function gitRefDirectives(
1517
validateOptions(
1618
(SchemaBuilder) => SchemaBuilder.stringSchema(),
1719
(value) => async (parse) => {
20+
if (shouldShowDeprecationNotice) {
21+
logger.warn(
22+
'Detected deprecated use of @app-config/git parsing extension. Please install @app-config/git and add it to your meta file "parsingExtensions".',
23+
);
24+
}
25+
1826
switch (value) {
1927
case 'commit':
2028
return getStatus().then(({ commitRef }) => parse(commitRef, { shouldFlatten: true }));

app-config-git/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"references": [
1010
{ "path": "../app-config-test-utils" },
1111
{ "path": "../app-config-core" },
12+
{ "path": "../app-config-logging" },
1213
{ "path": "../app-config-extension-utils" }
1314
]
1415
}

app-config-v1-compat/src/index.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FileSource } from '@app-config/node';
77
import { logger } from '@app-config/logging';
88

99
/** V1 app-config compatibility */
10-
export default function v1Compat(): ParsingExtension {
10+
export default function v1Compat(shouldShowDeprecationNotice?: true): ParsingExtension {
1111
return named('v1-compat', (value, [_, key], context) => {
1212
// only apply in top-level app-config property
1313
if (context[context.length - 1]?.[0] !== Root) {
@@ -16,16 +16,6 @@ export default function v1Compat(): ParsingExtension {
1616

1717
if (key === 'app-config' && isObject(value)) {
1818
return async (parse, _, ctx) => {
19-
if (ctx instanceof FileSource) {
20-
logger.warn(
21-
`Using V1 compatibility layer for special 'app-config' property in ${ctx.filePath}! This functionality is deprecated and may be removed in the future.`,
22-
);
23-
} else {
24-
logger.warn(
25-
`Using V1 compatibility layer for special 'app-config' property! This functionality is deprecated and may be removed in the future.`,
26-
);
27-
}
28-
2919
const resolveAmbiguousFilename = async (filepath: string) => {
3020
let resolvedPath = filepath;
3121

@@ -56,13 +46,25 @@ export default function v1Compat(): ParsingExtension {
5646
// TODO: multiple properties defined
5747

5848
if ('extends' in value) {
49+
if (shouldShowDeprecationNotice) {
50+
logger.warn(
51+
'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".',
52+
);
53+
}
54+
5955
return parse(
6056
{ $extends: await resolveAmbiguousFilename(value.extends as string) },
6157
{ shouldMerge: true },
6258
);
6359
}
6460

6561
if ('extendsOptional' in value) {
62+
if (shouldShowDeprecationNotice) {
63+
logger.warn(
64+
'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".',
65+
);
66+
}
67+
6668
return parse(
6769
{
6870
$extends: {
@@ -75,13 +77,25 @@ export default function v1Compat(): ParsingExtension {
7577
}
7678

7779
if ('override' in value) {
80+
if (shouldShowDeprecationNotice) {
81+
logger.warn(
82+
'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".',
83+
);
84+
}
85+
7886
return parse(
7987
{ $override: await resolveAmbiguousFilename(value.override as string) },
8088
{ shouldOverride: true },
8189
);
8290
}
8391

8492
if ('overrideOptional' in value) {
93+
if (shouldShowDeprecationNotice) {
94+
logger.warn(
95+
'Detected deprecated use of @app-config/v1-compat parsing extension. Please install @app-config/v1-compat and add it to your meta file "parsingExtensions".',
96+
);
97+
}
98+
8599
return parse(
86100
{
87101
$override: {

0 commit comments

Comments
 (0)