Skip to content

Commit 31b8815

Browse files
committed
test(env): add comprehensive tests for env utilities
1 parent a8c459c commit 31b8815

4 files changed

Lines changed: 520 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.5](https://github.com/SocketDev/socket-lib/releases/tag/v1.3.5) - 2025-10-26
9+
10+
### Added
11+
12+
- Added `createEnvProxy()` utility function to `env` module for Windows-compatible environment variable access
13+
- Provides case-insensitive environment variable access (e.g., PATH, Path, path all work)
14+
- Smart priority system: overrides > exact match > case-insensitive fallback
15+
- Full Proxy implementation with proper handlers for get, set, has, deleteProperty, ownKeys
16+
- Opt-in helper for users who need Windows env var compatibility
17+
- Well-documented with usage examples and performance notes
18+
19+
### Fixed
20+
21+
- Fixed `spawn` module to preserve Windows `process.env` Proxy behavior
22+
- When no custom environment variables are provided, use `process.env` directly instead of spreading it
23+
- Preserves Windows case-insensitive environment variable access (PATH vs Path)
24+
- Fixes empty CLI output issue on Windows CI runners
25+
- Only spreads `process.env` when merging custom environment variables
26+
827
## [1.3.4](https://github.com/SocketDev/socket-lib/releases/tag/v1.3.4) - 2025-10-26
928

1029
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@socketsecurity/lib",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"license": "MIT",
55
"description": "Core utilities and infrastructure for Socket.dev security tools",
66
"keywords": [

src/env.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export function createEnvProxy(
6767
base: NodeJS.ProcessEnv,
6868
overrides?: Record<string, string | undefined>,
6969
): NodeJS.ProcessEnv {
70-
7170
return new Proxy(
7271
{},
7372
{
@@ -149,7 +148,10 @@ export function createEnvProxy(
149148
// Case-insensitive check.
150149
const upperProp = prop.toUpperCase()
151150
if (caseInsensitiveKeys.has(upperProp)) {
152-
if (overrides && findCaseInsensitiveEnvKey(overrides, upperProp) !== undefined) {
151+
if (
152+
overrides &&
153+
findCaseInsensitiveEnvKey(overrides, upperProp) !== undefined
154+
) {
153155
return true
154156
}
155157
if (findCaseInsensitiveEnvKey(base, upperProp) !== undefined) {
@@ -251,7 +253,9 @@ export function findCaseInsensitiveEnvKey(
251253
const targetLength = upperEnvVarName.length
252254
for (const key of Object.keys(env)) {
253255
// Fast path: bail early if lengths don't match.
254-
if (key.length !== targetLength) continue
256+
if (key.length !== targetLength) {
257+
continue
258+
}
255259
// Only call toUpperCase if length matches.
256260
if (key.toUpperCase() === upperEnvVarName) {
257261
return key

0 commit comments

Comments
 (0)