Skip to content

Commit

Permalink
Fixes bugs when saving system params to manifest (#5532)
Browse files Browse the repository at this point in the history
* Fixes bugs when saving system params to manifest

* Linting

* ReplaceAll is not defined in node14 :(

* Fixing tests

* Removes .only
  • Loading branch information
joehan authored Feb 21, 2023
1 parent 4755cb7 commit 74f82cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/extensions/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function writeEnvFiles(
): Promise<void> {
for (const spec of specs) {
const content = Object.entries(spec.params)
.filter((r) => r[1].baseValue !== "") // Don't write empty values
.filter((r) => r[1].baseValue !== "" && r[1].baseValue !== undefined) // Don't write empty values
.sort((a, b) => {
return a[0].localeCompare(b[0]);
})
Expand Down
4 changes: 3 additions & 1 deletion src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export async function promptOnce<A extends inquirer.Answers>(
* @return The value as returned by `inquirer` for that quesiton.
*/
export async function promptOnce<A>(question: Question, options: Options = {}): Promise<A> {
question.name = question.name || "question";
// Need to replace any .'s in the question name - otherwise, Inquirer puts the answer
// in a nested object like so: `"a.b.c" => {a: {b: {c: "my-answer"}}}`
question.name = question.name?.replace(/\./g, "/") || "question";
await prompt(options, [question]);
return options[question.name];
}
8 changes: 8 additions & 0 deletions src/test/prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("prompt", () => {
let inquirerStub: sinon.SinonStub;
const PROMPT_RESPONSES = {
lint: true,
"lint/dint/mint": true,
project: "the-best-project-ever",
};

Expand Down Expand Up @@ -73,5 +74,12 @@ describe("prompt", () => {
expect(r).to.equal(true);
expect(inquirerStub).calledOnce;
});

it("should handle names with .'s", async () => {
const r = await prompt.promptOnce({ name: "lint.dint.mint" });

expect(r).to.equal(true);
expect(inquirerStub).calledOnce;
});
});
});

0 comments on commit 74f82cf

Please sign in to comment.