Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added:

- Install: Added automated install and upgrade support for Linux using official setup scripts
- Setting: Added `env` setting to pass environment variables when starting Dev Proxy
- Task provider: Added `env` property to task definition for passing environment variables
- Quick Fixes: Enable local language model fix now adds or updates `languageModel.enabled: true` for supported plugins only
- Workspace: Added automatic prompt to recommend extension in `.vscode/extensions.json` when Dev Proxy config files are detected
- Command: Added `Add to Workspace Recommendations` to manually add extension to workspace recommendations
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ You can also manually add the extension to recommendations at any time using the
| `dev-proxy-toolkit.closeTerminal` | `boolean` | `true` | Close terminal when stopping |
| `dev-proxy-toolkit.apiPort` | `number` | `8897` | Port for Dev Proxy API communication |
| `dev-proxy-toolkit.devProxyPath` | `string` | `""` | Custom path to Dev Proxy executable (uses auto-detection if empty) |
| `dev-proxy-toolkit.env` | `object` | `{}` | Environment variables to set when starting Dev Proxy |

## Tasks

Expand Down Expand Up @@ -255,6 +256,22 @@ Run Dev Proxy as a VS Code task for integration with build workflows.
}
```

You can pass environment variables to Dev Proxy using the `env` property:

```json
{
"label": "Start Dev Proxy",
"type": "devproxy",
"command": "start",
"env": {
"NODE_ENV": "development",
"DEBUG": "true"
},
"isBackground": true,
"problemMatcher": "$devproxy-watch"
}
```

## MCP Server

This extension includes an MCP server for AI-assisted development. See [Dev Proxy MCP Server](https://github.com/dev-proxy-tools/mcp) for available tools.
Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@
"type": "string"
},
"description": "Additional command-line arguments"
},
"env": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"description": "Environment variables to set when starting Dev Proxy"
}
}
}
Expand Down Expand Up @@ -219,6 +226,14 @@
"type": "string",
"default": "",
"description": "Custom path to the Dev Proxy executable. If empty, auto-detection is used."
},
"dev-proxy-toolkit.env": {
"type": "object",
"additionalProperties": {
"type": "string"
},
"default": {},
"description": "Environment variables to set when starting Dev Proxy."
}
}
},
Expand Down
15 changes: 14 additions & 1 deletion src/services/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ export class TerminalService {
private readonly createNewTerminal: boolean;
private readonly showTerminal: boolean;
private readonly closeTerminalOnStop: boolean;
private readonly env: { [key: string]: string } | undefined;

constructor(config?: TerminalServiceConfig) {
this.createNewTerminal = config?.createNewTerminal ?? true;
this.showTerminal = config?.showTerminal ?? true;
this.closeTerminalOnStop = config?.closeTerminalOnStop ?? true;
this.env = config?.env;
}

/**
* Create a TerminalService using VS Code configuration.
*/
static fromConfiguration(): TerminalService {
const config = vscode.workspace.getConfiguration('dev-proxy-toolkit');
const env = config.get<{ [key: string]: string }>('env');
return new TerminalService({
createNewTerminal: config.get<boolean>('newTerminal', true),
showTerminal: config.get<boolean>('showTerminal', true),
closeTerminalOnStop: config.get<boolean>('closeTerminal', true),
env: env && Object.keys(env).length > 0 ? env : undefined,
});
}

Expand All @@ -41,7 +45,15 @@ export class TerminalService {
return vscode.window.activeTerminal;
}

const terminal = vscode.window.createTerminal('Dev Proxy');
const terminalOptions: vscode.TerminalOptions = {
name: 'Dev Proxy',
};

if (this.env) {
terminalOptions.env = this.env;
}

const terminal = vscode.window.createTerminal(terminalOptions);

if (this.showTerminal) {
terminal.show();
Expand Down Expand Up @@ -79,4 +91,5 @@ export interface TerminalServiceConfig {
createNewTerminal?: boolean;
showTerminal?: boolean;
closeTerminalOnStop?: boolean;
env?: { [key: string]: string };
}
9 changes: 7 additions & 2 deletions src/task-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface DevProxyTaskDefinition extends vscode.TaskDefinition {
command: 'start' | 'stop';
configFile?: string;
args?: string[];
env?: { [key: string]: string };
label?: string;
}

Expand Down Expand Up @@ -68,9 +69,13 @@ export class DevProxyTaskProvider implements vscode.TaskProvider {

if (definition.command === 'start') {
const args = this.buildArgumentsFromDefinition(definition);
execution = new vscode.ShellExecution(this.devProxyExe, args, {
const shellOptions: vscode.ShellExecutionOptions = {
cwd: '${workspaceFolder}'
});
};
if (definition.env && Object.keys(definition.env).length > 0) {
shellOptions.env = definition.env;
}
execution = new vscode.ShellExecution(this.devProxyExe, args, shellOptions);
} else if (definition.command === 'stop') {
// Use curl to stop Dev Proxy via API
const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit');
Expand Down
25 changes: 25 additions & 0 deletions src/test/task-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ suite('DevProxyTaskProvider', () => {

assert.ok(resolved, 'Should resolve task with args');
});

test('should handle env in definition', () => {
const provider = new DevProxyTaskProvider(mockContext);

const env = { 'NODE_ENV': 'test', 'DEBUG': 'true' };
const taskDefinition = {
type: 'devproxy',
command: 'start' as const,
env,
label: 'Start with Env',
};

const mockTask = new vscode.Task(
taskDefinition,
vscode.TaskScope.Workspace,
'Start with Env',
'devproxy'
);

const resolved = provider.resolveTask(mockTask);

assert.ok(resolved, 'Should resolve task with env');
const execution = resolved!.execution as vscode.ShellExecution;
assert.deepStrictEqual(execution.options?.env, env, 'Should pass env to shell execution options');
});
});

suite('task properties', () => {
Expand Down
35 changes: 35 additions & 0 deletions src/test/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,41 @@ suite('TerminalService', () => {
assert.ok((mockTerminal.hide as sinon.SinonStub).calledOnce);
assert.ok((mockTerminal.show as sinon.SinonStub).notCalled);
});

test('should pass env to terminal when env is provided', () => {
const mockTerminal = {
show: sandbox.stub(),
hide: sandbox.stub(),
name: 'Dev Proxy',
} as unknown as vscode.Terminal;

const createStub = sandbox.stub(vscode.window, 'createTerminal').returns(mockTerminal);

const env = { 'NODE_ENV': 'test', 'DEBUG': 'true' };
const service = new TerminalService({ createNewTerminal: true, showTerminal: true, env });
service.getOrCreateTerminal();

assert.ok(createStub.calledOnce);
const options = createStub.firstCall.args[0] as vscode.TerminalOptions;
assert.deepStrictEqual(options.env, env, 'Should pass env to terminal options');
});

test('should not include env in terminal options when env is undefined', () => {
const mockTerminal = {
show: sandbox.stub(),
hide: sandbox.stub(),
name: 'Dev Proxy',
} as unknown as vscode.Terminal;

const createStub = sandbox.stub(vscode.window, 'createTerminal').returns(mockTerminal);

const service = new TerminalService({ createNewTerminal: true, showTerminal: true });
service.getOrCreateTerminal();

assert.ok(createStub.calledOnce);
const options = createStub.firstCall.args[0] as vscode.TerminalOptions;
assert.strictEqual(options.env, undefined, 'Should not include env in terminal options');
});
});

suite('disposeDevProxyTerminals', () => {
Expand Down