Skip to content

Commit 2681e77

Browse files
Copilotphilmillman
andauthored
Filter undefined values from env format output (#235)
* Initial plan * Fix undefined values in env format output Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com> * Remove undefined items from `dmno resolve --format env` output * upgrade turbo cache action --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: philmillman <3722211+philmillman@users.noreply.github.com> Co-authored-by: philmillman <phil@dmno.dev>
1 parent 0913f97 commit 2681e77

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

.changeset/tasty-paws-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"dmno": patch
3+
---
4+
5+
Remove undefined items from `dmno resolve --format env` output

.github/workflows/release-preview.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Install node deps
3030
run: pnpm i
3131
- name: Enable turborepo build cache
32-
uses: rharkor/caching-for-turbo@v1.5
32+
uses: rharkor/caching-for-turbo@v2.3.2
3333
- name: Build publishable DMNO modules
3434
run: pnpm build:libs
3535

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Install node deps
2626
run: pnpm i
2727
- name: Enable turborepo build cache
28-
uses: rharkor/caching-for-turbo@v1.5
28+
uses: rharkor/caching-for-turbo@v2.3.2
2929
- name: Create Release Pull Request or Publish to npm
3030
id: changesets
3131
uses: changesets/action@v1

packages/core/src/cli/lib/env-file-helpers.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ describe('stringifyObjectAsEnvFile', () => {
1818
const result = stringifyObjectAsEnvFile({ foo: 'bar"baz' });
1919
expect(result).toEqual('foo="bar\\"baz"');
2020
});
21+
test('excludes undefined values', () => {
22+
const result = stringifyObjectAsEnvFile({ foo: 'bar', baz: undefined, qux: 'test' });
23+
expect(result).toEqual('foo="bar"\nqux="test"');
24+
});
2125
});
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export function stringifyObjectAsEnvFile(obj: Record<string, any>) {
2-
return Object.entries(obj).map(([key, value]) => {
3-
// Handle newlines and quotes by wrapping in double quotes and escaping
4-
const formattedValue = String(value)
5-
.replace(/\\/g, '\\\\') // escape backslashes first
6-
.replace(/\n/g, '\\n') // escape newlines
7-
.replace(/"/g, '\\"'); // escape double quotes
2+
return Object.entries(obj)
3+
.filter(([_key, value]) => value !== undefined) // Exclude undefined values
4+
.map(([key, value]) => {
5+
// Handle newlines and quotes by wrapping in double quotes and escaping
6+
const formattedValue = String(value)
7+
.replace(/\\/g, '\\\\') // escape backslashes first
8+
.replace(/\n/g, '\\n') // escape newlines
9+
.replace(/"/g, '\\"'); // escape double quotes
810

9-
return `${key}="${formattedValue}"`;
10-
}).join('\n');
11+
return `${key}="${formattedValue}"`;
12+
}).join('\n');
1113
}

0 commit comments

Comments
 (0)