Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit cc88031

Browse files
chore: Remove casts when accessing config props (#374)
1 parent 5b49317 commit cc88031

File tree

5 files changed

+10
-21
lines changed

5 files changed

+10
-21
lines changed

src/agent/debuglet.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {Controller} from './controller';
3737
import {Debuggee} from '../debuggee';
3838
import {StatusMessage} from '../client/stackdriver/status-message';
3939

40-
// The following import syntax is used because './config' has a default export
4140
import {defaultConfig} from './config';
4241
import * as scanner from './io/scanner';
4342
import * as SourceMapper from './io/sourcemapper';
@@ -283,10 +282,8 @@ export class Debuglet extends EventEmitter {
283282
const stat = promisify(fs.stat);
284283

285284
try {
286-
// TODO: Address the fact that `that.config.workingDirectory` could
287-
// be `null`.
288285
await stat(
289-
path.join(that.config.workingDirectory as string, 'package.json'));
286+
path.join(that.config.workingDirectory, 'package.json'));
290287
} catch (err) {
291288
that.logger.error('No package.json located in working directory.');
292289
that.emit('initError', new Error('No package.json found.'));
@@ -301,10 +298,8 @@ export class Debuglet extends EventEmitter {
301298

302299
let fileStats: scanner.ScanResults;
303300
try {
304-
// TODO: Address the case when `that.config.workingDirectory` is
305-
// `null`.
306301
fileStats = await scanner.scan(
307-
!id, that.config.workingDirectory as string, /.js$|.map$/);
302+
!id, that.config.workingDirectory, /.js$|.map$/);
308303
} catch (err) {
309304
that.logger.error('Error scanning the filesystem.', err);
310305
that.emit('initError', err);

src/agent/state/inspector-state.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,12 @@ class StateResolver {
294294

295295
stripCurrentWorkingDirectory_(path: string): string {
296296
// Strip 1 extra character to remove the slash.
297-
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
298-
return path.substr((this.config.workingDirectory as string).length + 1);
297+
return path.substr((this.config.workingDirectory!).length + 1);
299298
}
300299

301300
isPathInCurrentWorkingDirectory_(path: string): boolean {
302301
// return true;
303-
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
304-
return path.indexOf(this.config.workingDirectory as string) === 0;
302+
return path.indexOf(this.config.workingDirectory) === 0;
305303
}
306304

307305
isPathInNodeModulesDirectory_(path: string): boolean {

src/agent/state/legacy-state.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,12 @@ class StateResolver {
293293

294294
stripCurrentWorkingDirectory_(path: string): string {
295295
// Strip 1 extra character to remove the slash.
296-
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
297-
return path.substr((this.config.workingDirectory as string).length + 1);
296+
return path.substr((this.config.workingDirectory).length + 1);
298297
}
299298

300299
isPathInCurrentWorkingDirectory_(path: string): boolean {
301300
// return true;
302-
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
303-
return path.indexOf(this.config.workingDirectory as string) === 0;
301+
return path.indexOf(this.config.workingDirectory) === 0;
304302
}
305303

306304
isPathInNodeModulesDirectory_(path: string): boolean {

src/agent/util/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33
import {StatusMessage} from '../../client/stackdriver/status-message';
44
import * as stackdriver from '../../types/stackdriver';
55

6-
import {DebugAgentConfig} from '../config';
6+
import {ResolvedDebugAgentConfig} from '../config';
77
import {ScanStats} from '../io/scanner';
88

99

@@ -39,13 +39,12 @@ export interface Listener {
3939
}
4040
// Exposed for unit testing.
4141
export function findScripts(
42-
scriptPath: string, config: DebugAgentConfig,
42+
scriptPath: string, config: ResolvedDebugAgentConfig,
4343
fileStats: ScanStats): string[] {
4444
// Use repository relative mapping if present.
4545
if (config.appPathRelativeToRepository) {
4646
const candidate = scriptPath.replace(
47-
// TODO: Address the case where `config.workingDirectory` is `null`.
48-
config.appPathRelativeToRepository, config.workingDirectory as string);
47+
config.appPathRelativeToRepository, config.workingDirectory);
4948
// There should be no ambiguity resolution if project root is provided.
5049
return fileStats[candidate] ? [candidate] : [];
5150
}

test/test-v8debugapi.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ describe('v8debugapi', () => {
166166

167167
beforeEach((done) => {
168168
if (!api) {
169-
// TODO: Handle the case when config.workingDirectory is null
170-
scanner.scan(true, config.workingDirectory as string, /.js$|.map$/)
169+
scanner.scan(true, config.workingDirectory, /.js$|.map$/)
171170
.then((fileStats) => {
172171
const jsStats = fileStats.selectStats(/.js$/);
173172
const mapFiles = fileStats.selectFiles(/.map$/, process.cwd());

0 commit comments

Comments
 (0)