Skip to content

Commit

Permalink
Export CONFIG_PREFIX_SEPARATOR from loadSharedConfigFiles (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Oct 6, 2023
1 parent 58b25ce commit 719777c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-hornets-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/shared-ini-file-loader": patch
---

Export CONFIG_PREFIX_SEPARATOR from loadSharedConfigFiles
2 changes: 2 additions & 0 deletions packages/shared-ini-file-loader/src/loadSharedConfigFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export interface SharedConfigInit {

const swallowError = () => ({});

export const CONFIG_PREFIX_SEPARATOR = ".";

export const loadSharedConfigFiles = async (init: SharedConfigInit = {}): Promise<SharedConfigFiles> => {
const { filepath = getCredentialsFilepath(), configFilepath = getConfigFilepath() } = init;

Expand Down
7 changes: 4 additions & 3 deletions packages/shared-ini-file-loader/src/parseIni.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";
import { parseIni } from "./parseIni";

describe(parseIni.name, () => {
Expand Down Expand Up @@ -99,7 +100,7 @@ describe(parseIni.name, () => {
expect(parseIni(mockInput)).toStrictEqual({
[mockProfileName]: {
key: "value",
"subSection.subKey": "subValue",
[["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue",
},
});

Expand All @@ -112,11 +113,11 @@ describe(parseIni.name, () => {
expect(parseIni(`${mockInput}${mockInput2}`)).toStrictEqual({
[mockProfileName]: {
key: "value",
"subSection.subKey": "subValue",
[["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue",
},
[mockProfileName2]: {
key: "value2",
"subSection.subKey": "subValue2",
[["subSection", "subKey"].join(CONFIG_PREFIX_SEPARATOR)]: "subValue2",
},
});
});
Expand Down
4 changes: 3 additions & 1 deletion packages/shared-ini-file-loader/src/parseIni.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ParsedIniData } from "@smithy/types";

import { CONFIG_PREFIX_SEPARATOR } from "./loadSharedConfigFiles";

const profileNameBlockList = ["__proto__", "profile __proto__"];

export const parseIni = (iniData: string): ParsedIniData => {
Expand Down Expand Up @@ -28,7 +30,7 @@ export const parseIni = (iniData: string): ParsedIniData => {
currentSubSection = name;
} else {
map[currentSection] = map[currentSection] || {};
const key = currentSubSection ? `${currentSubSection}.${name}` : name;
const key = currentSubSection ? [currentSubSection, name].join(CONFIG_PREFIX_SEPARATOR) : name;
map[currentSection][key] = value;
}
}
Expand Down

0 comments on commit 719777c

Please sign in to comment.