-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow .env style output from resolve and add associated docs (#159)
* allow .env style output from resolve and add associated docs * add --no-prompt flag, and naive subshell via isTTY detection, implements #160
- Loading branch information
1 parent
ccd00ce
commit 8549dbe
Showing
8 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"dmno": patch | ||
--- | ||
|
||
adds env as an output format option for dmno resolve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect, test, describe } from 'vitest'; | ||
import { stringifyObjectAsEnvFile } from './env-file-helpers'; | ||
|
||
describe('stringifyObjectAsEnvFile', () => { | ||
test('basic', () => { | ||
const result = stringifyObjectAsEnvFile({ foo: 'bar', baz: 'qux' }); | ||
expect(result).toEqual('foo="bar"\nbaz="qux"'); | ||
}); | ||
test('escapes backslashes', () => { | ||
const result = stringifyObjectAsEnvFile({ foo: 'bar\\baz' }); | ||
expect(result).toEqual('foo="bar\\\\baz"'); | ||
}); | ||
test('escapes newlines', () => { | ||
const result = stringifyObjectAsEnvFile({ foo: 'bar\nbaz' }); | ||
expect(result).toEqual('foo="bar\\nbaz"'); | ||
}); | ||
test('escapes double quotes', () => { | ||
const result = stringifyObjectAsEnvFile({ foo: 'bar"baz' }); | ||
expect(result).toEqual('foo="bar\\"baz"'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function stringifyObjectAsEnvFile(obj: Record<string, string>) { | ||
return Object.entries(obj).map(([key, value]) => { | ||
// Handle newlines and quotes by wrapping in double quotes and escaping | ||
const formattedValue = String(value) | ||
.replace(/\\/g, '\\\\') // escape backslashes first | ||
.replace(/\n/g, '\\n') // escape newlines | ||
.replace(/"/g, '\\"'); // escape double quotes | ||
|
||
return `${key}="${formattedValue}"`; | ||
}).join('\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { execSync, spawn } from 'child_process'; | ||
import { expect, test, describe } from 'vitest'; | ||
import { isSubshell } from './shell-helpers'; | ||
|
||
describe('isSubshell', () => { | ||
test('basic', () => { | ||
expect(isSubshell()).toBe(false); | ||
}); | ||
test('subshell', () => { | ||
const child = spawn('bash', ['-c', 'echo $PPID $(echo $PPID)']); | ||
child.stdout.on('data', () => { | ||
expect(isSubshell()).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isSubshell = () => !process.stdin.isTTY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters