Skip to content

Commit becfc13

Browse files
committed
feat(#130): starts on creating deprecation warnings on parsing extensions
NOTE that '$git' directive is currently incompatible with being included twice
1 parent 1912747 commit becfc13

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

app-config-default-extensions/index.js

+5-3
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

+11-1
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-git/package.json

+1
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

+8
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

+1
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

+25-11
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)