Skip to content

Commit e1318c6

Browse files
committed
feat(#135): adds deprecation warning on $substitute directive
1 parent becfc13 commit e1318c6

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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 {

0 commit comments

Comments
 (0)