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

Commit

Permalink
chore: Remove casts when accessing config props (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicKramer committed Dec 11, 2017
1 parent 5b49317 commit cc88031
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
9 changes: 2 additions & 7 deletions src/agent/debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {Controller} from './controller';
import {Debuggee} from '../debuggee';
import {StatusMessage} from '../client/stackdriver/status-message';

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

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

let fileStats: scanner.ScanResults;
try {
// TODO: Address the case when `that.config.workingDirectory` is
// `null`.
fileStats = await scanner.scan(
!id, that.config.workingDirectory as string, /.js$|.map$/);
!id, that.config.workingDirectory, /.js$|.map$/);
} catch (err) {
that.logger.error('Error scanning the filesystem.', err);
that.emit('initError', err);
Expand Down
6 changes: 2 additions & 4 deletions src/agent/state/inspector-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,12 @@ class StateResolver {

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

isPathInCurrentWorkingDirectory_(path: string): boolean {
// return true;
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
return path.indexOf(this.config.workingDirectory as string) === 0;
return path.indexOf(this.config.workingDirectory) === 0;
}

isPathInNodeModulesDirectory_(path: string): boolean {
Expand Down
6 changes: 2 additions & 4 deletions src/agent/state/legacy-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,12 @@ class StateResolver {

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

isPathInCurrentWorkingDirectory_(path: string): boolean {
// return true;
// TODO: Handle the case where `this.config.workingDirectory` is `null`.
return path.indexOf(this.config.workingDirectory as string) === 0;
return path.indexOf(this.config.workingDirectory) === 0;
}

isPathInNodeModulesDirectory_(path: string): boolean {
Expand Down
7 changes: 3 additions & 4 deletions src/agent/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import {StatusMessage} from '../../client/stackdriver/status-message';
import * as stackdriver from '../../types/stackdriver';

import {DebugAgentConfig} from '../config';
import {ResolvedDebugAgentConfig} from '../config';
import {ScanStats} from '../io/scanner';


Expand Down Expand Up @@ -39,13 +39,12 @@ export interface Listener {
}
// Exposed for unit testing.
export function findScripts(
scriptPath: string, config: DebugAgentConfig,
scriptPath: string, config: ResolvedDebugAgentConfig,
fileStats: ScanStats): string[] {
// Use repository relative mapping if present.
if (config.appPathRelativeToRepository) {
const candidate = scriptPath.replace(
// TODO: Address the case where `config.workingDirectory` is `null`.
config.appPathRelativeToRepository, config.workingDirectory as string);
config.appPathRelativeToRepository, config.workingDirectory);
// There should be no ambiguity resolution if project root is provided.
return fileStats[candidate] ? [candidate] : [];
}
Expand Down
3 changes: 1 addition & 2 deletions test/test-v8debugapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ describe('v8debugapi', () => {

beforeEach((done) => {
if (!api) {
// TODO: Handle the case when config.workingDirectory is null
scanner.scan(true, config.workingDirectory as string, /.js$|.map$/)
scanner.scan(true, config.workingDirectory, /.js$|.map$/)
.then((fileStats) => {
const jsStats = fileStats.selectStats(/.js$/);
const mapFiles = fileStats.selectFiles(/.map$/, process.cwd());
Expand Down

0 comments on commit cc88031

Please sign in to comment.