Skip to content

Commit 43e51ac

Browse files
committed
Merge branch 'master' into fallbackable
2 parents 34106e3 + c18bf40 commit 43e51ac

File tree

30 files changed

+160
-131
lines changed

30 files changed

+160
-131
lines changed

app-config-cli/package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/cli",
33
"description": "CLI for @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -35,14 +35,14 @@
3535
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3636
},
3737
"dependencies": {
38-
"@app-config/config": "^2.1.7",
39-
"@app-config/core": "^2.1.7",
40-
"@app-config/encryption": "^2.1.7",
41-
"@app-config/generate": "^2.1.7",
42-
"@app-config/logging": "^2.1.7",
43-
"@app-config/node": "^2.1.7",
44-
"@app-config/schema": "^2.1.7",
45-
"@app-config/utils": "^2.1.7",
38+
"@app-config/config": "^2.1.8",
39+
"@app-config/core": "^2.1.8",
40+
"@app-config/encryption": "^2.1.8",
41+
"@app-config/generate": "^2.1.8",
42+
"@app-config/logging": "^2.1.8",
43+
"@app-config/node": "^2.1.8",
44+
"@app-config/schema": "^2.1.8",
45+
"@app-config/utils": "^2.1.8",
4646
"clipboardy": "2",
4747
"common-tags": "1",
4848
"execa": "5",

app-config-config/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/config",
33
"description": "The config in @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -30,17 +30,17 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33-
"@app-config/core": "^2.1.7",
34-
"@app-config/default-extensions": "^2.1.7",
35-
"@app-config/extensions": "^2.1.7",
36-
"@app-config/logging": "^2.1.7",
37-
"@app-config/meta": "^2.1.7",
38-
"@app-config/node": "^2.1.7",
39-
"@app-config/schema": "^2.1.7",
40-
"@app-config/utils": "^2.1.7"
33+
"@app-config/core": "^2.1.8",
34+
"@app-config/default-extensions": "^2.1.8",
35+
"@app-config/extensions": "^2.1.8",
36+
"@app-config/logging": "^2.1.8",
37+
"@app-config/meta": "^2.1.8",
38+
"@app-config/node": "^2.1.8",
39+
"@app-config/schema": "^2.1.8",
40+
"@app-config/utils": "^2.1.8"
4141
},
4242
"devDependencies": {
43-
"@app-config/test-utils": "^2.1.7"
43+
"@app-config/test-utils": "^2.1.8"
4444
},
4545
"prettier": "@lcdev/prettier",
4646
"jest": {

app-config-core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/core",
33
"description": "Core logic for App Config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -30,15 +30,15 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33-
"@app-config/logging": "^2.1.7",
34-
"@app-config/utils": "^2.1.7",
33+
"@app-config/logging": "^2.1.8",
34+
"@app-config/utils": "^2.1.8",
3535
"@iarna/toml": "3",
3636
"js-yaml": "^3.13.1",
3737
"json5": "2",
3838
"lodash.merge": "^4.6.2"
3939
},
4040
"devDependencies": {
41-
"@app-config/test-utils": "^2.1.7",
41+
"@app-config/test-utils": "^2.1.8",
4242
"@types/js-yaml": "3",
4343
"@types/lodash.merge": "4"
4444
},

app-config-cypress/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/cypress",
33
"description": "Cypress testing plugin for @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -31,11 +31,11 @@
3131
},
3232
"dependencies": {},
3333
"peerDependencies": {
34-
"@app-config/main": "^2.1.7",
34+
"@app-config/main": "^2.1.8",
3535
"cypress": "6"
3636
},
3737
"devDependencies": {
38-
"@app-config/main": "^2.1.7",
38+
"@app-config/main": "^2.1.8",
3939
"cypress": "6"
4040
},
4141
"prettier": "@lcdev/prettier",

app-config-default-extensions/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/default-extensions",
33
"description": "Default parsing extensions for @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -22,10 +22,10 @@
2222
"test": "jest"
2323
},
2424
"dependencies": {
25-
"@app-config/core": "^2.1.7",
26-
"@app-config/encryption": "^2.1.7",
27-
"@app-config/extensions": "^2.1.7",
28-
"@app-config/git": "^2.1.7",
25+
"@app-config/core": "^2.1.8",
26+
"@app-config/encryption": "^2.1.8",
27+
"@app-config/extensions": "^2.1.8",
28+
"@app-config/git": "^2.1.8",
2929
"@app-config/v1-compat": "^2.1.4"
3030
},
3131
"devDependencies": {},

app-config-encryption/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/encryption",
33
"description": "Secret value encryption for @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -30,12 +30,12 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33-
"@app-config/core": "^2.1.7",
34-
"@app-config/logging": "^2.1.7",
35-
"@app-config/meta": "^2.1.7",
36-
"@app-config/node": "^2.1.7",
37-
"@app-config/settings": "^2.1.7",
38-
"@app-config/utils": "^2.1.7",
33+
"@app-config/core": "^2.1.8",
34+
"@app-config/logging": "^2.1.8",
35+
"@app-config/meta": "^2.1.8",
36+
"@app-config/node": "^2.1.8",
37+
"@app-config/settings": "^2.1.8",
38+
"@app-config/utils": "^2.1.8",
3939
"@lcdev/ws-rpc": "0.4",
4040
"@types/openpgp": "4",
4141
"common-tags": "1",
@@ -46,7 +46,7 @@
4646
"ws": "7"
4747
},
4848
"devDependencies": {
49-
"@app-config/test-utils": "^2.1.7",
49+
"@app-config/test-utils": "^2.1.8",
5050
"get-port": "5"
5151
},
5252
"prettier": "@lcdev/prettier",

app-config-extension-utils/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/extension-utils",
33
"description": "Utilities for writing @app-config parsing extensions",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -30,7 +30,7 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33-
"@app-config/core": "^2.1.7",
33+
"@app-config/core": "^2.1.8",
3434
"@serafin/schema-builder": "0.14"
3535
},
3636
"devDependencies": {},

app-config-extensions/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@app-config/extensions",
33
"description": "Common parsing extensions for @app-config",
4-
"version": "2.1.7",
4+
"version": "2.1.8",
55
"license": "MPL-2.0",
66
"author": {
77
"name": "Launchcode",
@@ -30,15 +30,15 @@
3030
"prepublishOnly": "yarn clean && yarn build && yarn build:es"
3131
},
3232
"dependencies": {
33-
"@app-config/core": "^2.1.7",
34-
"@app-config/extension-utils": "^2.1.7",
35-
"@app-config/logging": "^2.1.7",
36-
"@app-config/node": "^2.1.7",
37-
"@app-config/utils": "^2.1.7",
33+
"@app-config/core": "^2.1.8",
34+
"@app-config/extension-utils": "^2.1.8",
35+
"@app-config/logging": "^2.1.8",
36+
"@app-config/node": "^2.1.8",
37+
"@app-config/utils": "^2.1.8",
3838
"lodash.isequal": "4"
3939
},
4040
"devDependencies": {
41-
"@app-config/test-utils": "^2.1.7",
41+
"@app-config/test-utils": "^2.1.8",
4242
"@types/lodash.isequal": "4"
4343
},
4444
"prettier": "@lcdev/prettier",

app-config-extensions/src/index.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,24 @@ describe('$substitute directive', () => {
940940
expect(parsed.toJSON()).toEqual({ foo: 'bar' });
941941
});
942942

943+
it('allows null value when $allowNull', async () => {
944+
const source = new LiteralSource({
945+
foo: { $substitute: { $name: 'FOO', $fallback: null, $allowNull: true } },
946+
});
947+
948+
const parsed = await source.read([environmentVariableSubstitution()]);
949+
950+
expect(parsed.toJSON()).toEqual({ foo: null });
951+
});
952+
953+
it('does not allow number even when $allowNull', async () => {
954+
const source = new LiteralSource({
955+
foo: { $substitute: { $name: 'FOO', $fallback: 42, $allowNull: true } },
956+
});
957+
958+
await expect(source.read([environmentVariableSubstitution()])).rejects.toThrow();
959+
});
960+
943961
it('doesnt visit fallback if name is defined', async () => {
944962
const failDirective = forKey('$fail', () => () => {
945963
throw new Error();

app-config-extensions/src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ export function environmentVariableSubstitution(
252252
stringSchema(),
253253
);
254254

255+
const validateStringOrNull: ValidationFunction<string> = validationFunction(
256+
({ fromJsonSchema }) => fromJsonSchema({ type: ['null', 'string'] } as const),
257+
);
258+
255259
return forKey(['$substitute', '$subs'], (value, key, ctx) => async (parse) => {
256260
if (typeof value === 'string') {
257261
return parse(performAllSubstitutions(value, envType), { shouldFlatten: true });
@@ -260,7 +264,7 @@ export function environmentVariableSubstitution(
260264
validateObject(value, [...ctx, key]);
261265
if (Array.isArray(value)) throw new AppConfigError('$substitute was given an array');
262266

263-
const { $name: variableName, $fallback: fallback } = value;
267+
const { $name: variableName, $fallback: fallback, $allowNull: allowNull } = value;
264268
validateString(variableName, [...ctx, key, [InObject, '$name']]);
265269

266270
const resolvedValue = process.env[variableName];
@@ -271,7 +275,12 @@ export function environmentVariableSubstitution(
271275

272276
if (fallback !== undefined) {
273277
const fallbackValue = (await parse(fallback)).toJSON();
274-
validateString(fallbackValue, [...ctx, key, [InObject, '$fallback']]);
278+
279+
if (allowNull) {
280+
validateStringOrNull(fallbackValue, [...ctx, key, [InObject, '$fallback']]);
281+
} else {
282+
validateString(fallbackValue, [...ctx, key, [InObject, '$fallback']]);
283+
}
275284

276285
return parse(fallbackValue, { shouldFlatten: true });
277286
}

0 commit comments

Comments
 (0)