Skip to content

Commit c7e8900

Browse files
committed
Refactor process execution options to handle encoding and improve logging compatibility
1 parent 2caecbe commit c7e8900

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/client/common/process/rawProcessApis.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ function getDefaultOptions<T extends ShellOptions | SpawnOptions>(options: T, de
2121
const defaultOptions = { ...options };
2222
const execOptions = defaultOptions as SpawnOptions;
2323
if (execOptions) {
24-
execOptions.encoding =
25-
typeof execOptions.encoding === 'string' && execOptions.encoding.length > 0
26-
? execOptions.encoding
27-
: DEFAULT_ENCODING;
28-
const { encoding } = execOptions;
29-
delete execOptions.encoding;
30-
execOptions.encoding = encoding;
24+
// Handle encoding which can be string, null, or undefined from ExecOptions
25+
const encoding = execOptions.encoding;
26+
execOptions.encoding = typeof encoding === 'string' && encoding.length > 0 ? encoding : DEFAULT_ENCODING;
3127
}
3228
if (!defaultOptions.env || Object.keys(defaultOptions.env).length === 0) {
3329
const env = defaultEnv || process.env;
@@ -58,7 +54,12 @@ export function shellExec(
5854
const shellOptions = getDefaultOptions(options, defaultEnv);
5955
if (!options.doNotLog) {
6056
const processLogger = new ProcessLogger(new WorkspaceService());
61-
processLogger.logProcess(command, undefined, shellOptions);
57+
// Create compatible options for logging by ensuring encoding is not null
58+
const logOptions: SpawnOptions = {
59+
...shellOptions,
60+
encoding: shellOptions.encoding || undefined,
61+
};
62+
processLogger.logProcess(command, undefined, logOptions);
6263
}
6364
return new Promise((resolve, reject) => {
6465
// eslint-disable-next-line @typescript-eslint/no-explicit-any

src/client/ioc/container.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { EventEmitter } from 'events';
55
import { Container, decorate, injectable, interfaces } from 'inversify';
66
import { traceWarn } from '../logging';
7-
import { Abstract, IServiceContainer, Newable } from './types';
7+
import { IServiceContainer } from './types';
88

99
// This needs to be done once, hence placed in a common location.
1010
// Used by UnitTestSockerServer and also the extension unit tests.
@@ -25,7 +25,7 @@ export class ServiceContainer implements IServiceContainer {
2525
}
2626

2727
public getAll<T>(
28-
serviceIdentifier: string | symbol | Newable<T> | Abstract<T>,
28+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
2929
name?: string | number | symbol | undefined,
3030
): T[] {
3131
return name

src/client/ioc/serviceManager.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
// Licensed under the MIT License.
33
import { Container, injectable, interfaces } from 'inversify';
44

5-
import { Abstract, ClassType, IServiceManager, Newable } from './types';
6-
7-
type identifier<T> = string | symbol | Newable<T> | Abstract<T>;
5+
import { ClassType, IServiceManager } from './types';
86

97
@injectable()
108
export class ServiceManager implements IServiceManager {
119
constructor(private container: Container) {}
1210

1311
public add<T>(
14-
serviceIdentifier: identifier<T>,
12+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
1513

1614
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1715
constructor: new (...args: any[]) => T,
@@ -38,12 +36,12 @@ export class ServiceManager implements IServiceManager {
3836
this.container.bind<interfaces.Factory<T>>(factoryIdentifier).toFactory<T>(factoryMethod);
3937
}
4038

41-
public addBinding<T1, T2>(from: identifier<T1>, to: identifier<T2>): void {
39+
public addBinding<T1, T2>(from: interfaces.ServiceIdentifier<T1>, to: interfaces.ServiceIdentifier<T2>): void {
4240
this.container.bind(to).toService(from);
4341
}
4442

4543
public addSingleton<T>(
46-
serviceIdentifier: identifier<T>,
44+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
4745

4846
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4947
constructor: new (...args: any[]) => T,
@@ -64,7 +62,7 @@ export class ServiceManager implements IServiceManager {
6462
}
6563

6664
public addSingletonInstance<T>(
67-
serviceIdentifier: identifier<T>,
65+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
6866
instance: T,
6967
name?: string | number | symbol | undefined,
7068
): void {
@@ -75,11 +73,14 @@ export class ServiceManager implements IServiceManager {
7573
}
7674
}
7775

78-
public get<T>(serviceIdentifier: identifier<T>, name?: string | number | symbol | undefined): T {
76+
public get<T>(serviceIdentifier: interfaces.ServiceIdentifier<T>, name?: string | number | symbol | undefined): T {
7977
return name ? this.container.getNamed<T>(serviceIdentifier, name) : this.container.get<T>(serviceIdentifier);
8078
}
8179

82-
public tryGet<T>(serviceIdentifier: identifier<T>, name?: string | number | symbol | undefined): T | undefined {
80+
public tryGet<T>(
81+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
82+
name?: string | number | symbol | undefined,
83+
): T | undefined {
8384
try {
8485
return name
8586
? this.container.getNamed<T>(serviceIdentifier, name)
@@ -91,7 +92,10 @@ export class ServiceManager implements IServiceManager {
9192
return undefined;
9293
}
9394

94-
public getAll<T>(serviceIdentifier: identifier<T>, name?: string | number | symbol | undefined): T[] {
95+
public getAll<T>(
96+
serviceIdentifier: interfaces.ServiceIdentifier<T>,
97+
name?: string | number | symbol | undefined,
98+
): T[] {
9599
return name
96100
? this.container.getAllNamed<T>(serviceIdentifier, name)
97101
: this.container.getAll<T>(serviceIdentifier);

0 commit comments

Comments
 (0)