mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
On Windows 10 and 11 machines, environment variables are not case sensitive. The system PATH is actually defined as `process.env.Path`, however Node.js kindly handles the case sensitivity and will automatically return the system path when specifying `process.env.PATH`.
When we clone the environment variables via `{ ...process.env }`, we lose the automatic resolving of `Path` to `PATH`. To fix this, we need to explicitly copy the `PATH`.
#### Tests
- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`
#### Code Review
- [ ] This PR has a concise title and thorough description useful to a reviewer
- [ ] Issue from task tracker has a link to this PR
121 lines
2.1 KiB
TypeScript
Vendored
121 lines
2.1 KiB
TypeScript
Vendored
import { cloneEnv } from '../src';
|
|
|
|
it('should clone env with Path', () => {
|
|
expect(
|
|
cloneEnv(
|
|
new Proxy(
|
|
{
|
|
foo: 'bar',
|
|
Path: 'baz',
|
|
},
|
|
{
|
|
get(target: typeof process.env, prop: string) {
|
|
if (prop === 'PATH') {
|
|
return target.PATH ?? target.Path;
|
|
}
|
|
return target[prop];
|
|
},
|
|
}
|
|
)
|
|
)
|
|
).toEqual({
|
|
foo: 'bar',
|
|
Path: 'baz',
|
|
PATH: 'baz',
|
|
});
|
|
});
|
|
|
|
it('should clone env with PATH', () => {
|
|
expect(
|
|
cloneEnv({
|
|
foo: 'bar',
|
|
PATH: 'baz',
|
|
})
|
|
).toEqual({
|
|
foo: 'bar',
|
|
PATH: 'baz',
|
|
});
|
|
});
|
|
|
|
it('should clone and merge multiple env objects', () => {
|
|
// note: this also tests the last object doesn't overwrite `PATH` with
|
|
// `undefined`
|
|
expect(
|
|
cloneEnv(
|
|
{
|
|
foo: 'bar',
|
|
},
|
|
{
|
|
PATH: 'baz',
|
|
},
|
|
{
|
|
baz: 'wiz',
|
|
}
|
|
)
|
|
).toEqual({
|
|
foo: 'bar',
|
|
PATH: 'baz',
|
|
baz: 'wiz',
|
|
});
|
|
});
|
|
|
|
it('should clone the actual process.env object', () => {
|
|
expect(cloneEnv(process.env).PATH).toEqual(process.env.PATH);
|
|
});
|
|
|
|
it('should overwrite PATH with last value', () => {
|
|
expect(
|
|
cloneEnv(
|
|
new Proxy(
|
|
{
|
|
Path: 'foo',
|
|
},
|
|
{
|
|
get(target: typeof process.env, prop: string) {
|
|
if (prop === 'PATH') {
|
|
return target.PATH ?? target.Path;
|
|
}
|
|
return target[prop];
|
|
},
|
|
}
|
|
),
|
|
{
|
|
PATH: 'bar',
|
|
},
|
|
{
|
|
PATH: undefined,
|
|
}
|
|
)
|
|
).toEqual({
|
|
Path: 'foo',
|
|
PATH: undefined,
|
|
});
|
|
});
|
|
|
|
it('should handle process.env at any argument position', () => {
|
|
expect(
|
|
cloneEnv(
|
|
{
|
|
foo: 'bar',
|
|
},
|
|
new Proxy(
|
|
{
|
|
Path: 'baz',
|
|
},
|
|
{
|
|
get(target: typeof process.env, prop: string) {
|
|
if (prop === 'PATH') {
|
|
return target.PATH ?? target.Path;
|
|
}
|
|
return target[prop];
|
|
},
|
|
}
|
|
)
|
|
)
|
|
).toEqual({
|
|
foo: 'bar',
|
|
Path: 'baz',
|
|
PATH: 'baz',
|
|
});
|
|
});
|