Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const command = define({
console.error("Error: Please specify a subcommand (init, set, get, pull, or delete)");
console.error("");
console.error("Usage:");
console.error(" e2sm init - Initialize .e2smrc.json configuration file");
console.error(" e2sm init - Initialize .e2smrc.jsonc configuration file");
console.error(" e2sm set - Upload .env file to AWS Secrets Manager");
console.error(" e2sm get - Display secret from AWS Secrets Manager");
console.error(" e2sm pull - Pull secret and generate .env file");
Expand Down
20 changes: 20 additions & 0 deletions src/lib/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ describe("jsonToEnv", () => {
const result = jsonToEnv({ FOO: "bar\nbaz" });
expect(result).toBe('FOO="bar\nbaz"');
});

test("converts number values to string", () => {
const result = jsonToEnv({ PORT: 3000, DEBUG: 1 });
expect(result).toBe('PORT="3000"\nDEBUG="1"');
});

test("converts boolean values to string", () => {
const result = jsonToEnv({ ENABLED: true, DISABLED: false });
expect(result).toBe('ENABLED="true"\nDISABLED="false"');
});

test("converts null and undefined to string", () => {
const result = jsonToEnv({ NULL_VAL: null, UNDEF_VAL: undefined });
expect(result).toBe('NULL_VAL="null"\nUNDEF_VAL="undefined"');
});

test("converts object values to string", () => {
const result = jsonToEnv({ OBJ: { nested: "value" } });
expect(result).toBe('OBJ="[object Object]"');
});
Comment thread
lemtoc marked this conversation as resolved.
Outdated
});

describe("generateEnvHeader", () => {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export function parseEnvContent(content: string): Record<string, string> {
/**
* Converts JSON object to .env format string.
*/
export function jsonToEnv(data: Record<string, string>): string {
export function jsonToEnv(data: Record<string, unknown>): string {
return Object.entries(data)
.map(([key, value]) => {
const escaped = value.replace(/"/g, '\\"');
const stringValue = typeof value === "string" ? value : String(value);
Comment thread
lemtoc marked this conversation as resolved.
Outdated
const escaped = stringValue.replace(/"/g, '\\"');
return `${key}="${escaped}"`;
})
.join("\n");
Expand Down
Loading