Skip to content

Commit

Permalink
Obtain FsUtils from globalcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
digeff committed Sep 17, 2020
1 parent 4797c3e commit cd97c2c
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/common/sourceMaps/sourceMapResolutionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PathMapping } from '../../configuration';
import { ILogger, LogTag } from '../logging';
import { filterObject } from '../objUtils';
import { fixDriveLetterAndSlashes, properJoin, properResolve } from '../pathUtils';
import { LocalFsUtils } from '../fsUtils';
import { IFsUtils } from '../fsUtils';

export function getFullSourceEntry(sourceRoot: string | undefined, sourcePath: string): string {
if (!sourceRoot) {
Expand Down Expand Up @@ -137,7 +137,7 @@ export const defaultPathMappingResolver: PathMappingResolver = async (
* a package.json if there's no more precise match in the mapping.
*/
export const moduleAwarePathMappingResolver = (
fsUtils: LocalFsUtils,
fsUtils: IFsUtils,
compiledPath: string,
): PathMappingResolver => async (sourceRoot, pathMapping, logger) => {
// 1. Handle cases where we know the path is already absolute on disk.
Expand Down
4 changes: 2 additions & 2 deletions src/common/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MapUsingProjection } from './datastructure/mapUsingProjection';
import { memoize } from './objUtils';
import { fixDriveLetterAndSlashes, forceForwardSlashes } from './pathUtils';
import { escapeRegexSpecialChars, isRegexSpecialChar } from './stringUtils';
import { LocalFsUtils } from './fsUtils';
import { IFsUtils } from './fsUtils';

let isCaseSensitive = process.platform !== 'win32';

Expand Down Expand Up @@ -81,7 +81,7 @@ export const nearestDirectoryWhere = async (
/**
* Returns the closest parent directory that contains a file with the given name.
*/
export const nearestDirectoryContaining = (fsUtils: LocalFsUtils, rootDir: string, file: string) =>
export const nearestDirectoryContaining = (fsUtils: IFsUtils, rootDir: string, file: string) =>
nearestDirectoryWhere(rootDir, p => fsUtils.exists(path.join(p, file)));

// todo: not super correct, and most node libraries don't handle this accurately
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as vscode from 'vscode';
import { allDebugTypes, Commands, registerCommand } from './common/contributionUtils';
import { extensionId } from './configuration';
import { createGlobalContainer } from './ioc';
import { FSUtils } from './ioc-extras';
import { DelegateLauncherFactory } from './targets/delegate/delegateLauncherFactory';
import { registerAutoAttach } from './ui/autoAttach';
import { CascadeTerminationTracker } from './ui/cascadeTerminateTracker';
Expand Down Expand Up @@ -93,6 +94,7 @@ export function activate(context: vscode.ExtensionContext) {
context,
services.get(DelegateLauncherFactory),
services.get(TerminalLinkHandler),
services.get(FSUtils),
);
registerNpmScriptLens(context);
registerProfilingCommand(context, services);
Expand Down
3 changes: 2 additions & 1 deletion src/ioc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { ICdpApi } from './cdp/connection';
import { ObservableMap } from './common/datastructure/observableMap';
import { DefaultBrowserProvider, IDefaultBrowserProvider } from './common/defaultBrowserProvider';
import { OutFiles, VueComponentPaths } from './common/fileGlobList';
import { LocalAndRemoteFsUtils } from './common/fsUtils';
import { LocalAndRemoteFsUtils, LocalFsUtils } from './common/fsUtils';
import { ILogger } from './common/logging';
import { Logger } from './common/logging/logger';
import { CodeSearchStrategy } from './common/sourceMaps/codeSearchStrategy';
Expand Down Expand Up @@ -286,6 +286,7 @@ export const createGlobalContainer = (options: {
container.bind(ProcessEnv).toConstantValue(process.env);
container.bind(Execa).toConstantValue(execa);
container.bind(FS).toConstantValue(fsPromises);
container.bind(FSUtils).toConstantValue(new LocalFsUtils(fsPromises));
container
.bind<ExtensionLocation>(ExtensionLocation)
.toConstantValue(options.isRemote ? 'remote' : 'local');
Expand Down
4 changes: 2 additions & 2 deletions src/targets/node/nodeLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { basename, extname, resolve } from 'path';
import { IBreakpointsPredictor } from '../../adapter/breakpointPredictor';
import Cdp from '../../cdp/api';
import { DebugType } from '../../common/contributionUtils';
import { readfile, LocalFsUtils } from '../../common/fsUtils';
import { readfile, LocalFsUtils, IFsUtils } from '../../common/fsUtils';
import { ILogger, LogTag } from '../../common/logging';
import { fixDriveLetterAndSlashes } from '../../common/pathUtils';
import { delay } from '../../common/promiseUtil';
Expand Down Expand Up @@ -35,7 +35,7 @@ import { FSUtils } from '../../ioc-extras';
* is explicitly provided, it grabs that, otherwise it looks for the first
* existent path within the launch arguments.
*/
const tryGetProgramFromArgs = async (fsUtils: LocalFsUtils, config: INodeLaunchConfiguration) => {
const tryGetProgramFromArgs = async (fsUtils: IFsUtils, config: INodeLaunchConfiguration) => {
if (typeof config.stopOnEntry === 'string') {
return resolve(config.cwd, config.stopOnEntry);
}
Expand Down
4 changes: 2 additions & 2 deletions src/targets/node/nodeLauncherBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { NodeSourcePathResolver } from './nodeSourcePathResolver';
import { INodeTargetLifecycleHooks, NodeTarget } from './nodeTarget';
import { IProgram } from './program';
import { FSUtils } from '../../ioc-extras';
import { LocalFsUtils } from '../../common/fsUtils';
import { IFsUtils } from '../../common/fsUtils';

/**
* Telemetry received from the nested process.
Expand Down Expand Up @@ -131,7 +131,7 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
constructor(
@inject(INodeBinaryProvider) private readonly pathProvider: NodeBinaryProvider,
@inject(ILogger) protected readonly logger: ILogger,
@inject(FSUtils) protected readonly fsUtils: LocalFsUtils,
@inject(FSUtils) protected readonly fsUtils: IFsUtils,
) {}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/targets/node/nodeSourcePathResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { IUrlResolution } from '../../common/sourcePathResolver';
import * as urlUtils from '../../common/urlUtils';
import { ISourcePathResolverOptions, SourcePathResolverBase } from '../sourcePathResolver';
import { LocalFsUtils } from '../../common/fsUtils';
import { IFsUtils } from '../../common/fsUtils';
import { ILogger } from '../../common/logging';

interface IOptions extends ISourcePathResolverOptions {
Expand All @@ -23,7 +23,7 @@ interface IOptions extends ISourcePathResolverOptions {

export class NodeSourcePathResolver extends SourcePathResolverBase<IOptions> {
public constructor(
private readonly fsUtils: LocalFsUtils,
private readonly fsUtils: IFsUtils,
protected readonly options: IOptions,
protected readonly logger: ILogger,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/targets/node/nodeTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { IThreadDelegate } from '../../adapter/threads';
import Cdp from '../../cdp/api';
import Connection from '../../cdp/connection';
import { EventEmitter } from '../../common/events';
import { LocalFsUtils } from '../../common/fsUtils';
import { IFsUtils } from '../../common/fsUtils';
import { ILogger, LogTag } from '../../common/logging';
import { ISourcePathResolver } from '../../common/sourcePathResolver';
import { absolutePathToFileUrl } from '../../common/urlUtils';
Expand Down Expand Up @@ -47,7 +47,7 @@ export class NodeTarget implements ITarget, IThreadDelegate {
public readonly onNameChanged = this._onNameChangedEmitter.event;

constructor(
private readonly fsUtils: LocalFsUtils,
private readonly fsUtils: IFsUtils,
public readonly launchConfig: AnyNodeConfiguration,
private pathResolver: NodeSourcePathResolver,
private readonly targetOriginValue: ITargetOrigin,
Expand Down
6 changes: 3 additions & 3 deletions src/targets/node/nvmResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import * as path from 'path';
import * as fs from 'fs';
import { nvmHomeNotFound, nvmNotFound, nvmVersionNotFound, nvsNotFound } from '../../dap/errors';
import { ProtocolError } from '../../dap/protocolError';
import { injectable } from 'inversify';
import { inject, injectable } from 'inversify';
import { some } from '../../common/promiseUtil';
import { LocalFsUtils } from '../../common/fsUtils';
import { promises as fsPromises } from 'fs';
import { FSUtils } from '../../ioc-extras';

/**
* Resolves the location of Node installation querying an nvm installation.
Expand Down Expand Up @@ -40,8 +41,7 @@ const enum Vars {
@injectable()
export class NvmResolver implements INvmResolver {
constructor(
// We don't need Node to support remote file system at the moment, so we hardcode fsUtils
private readonly fsUtils = new LocalFsUtils(fsPromises),
@inject(FSUtils) private readonly fsUtils = new LocalFsUtils(fsPromises),
private readonly env = process.env,
private readonly arch = process.arch,
private readonly platform = process.platform,
Expand Down
4 changes: 2 additions & 2 deletions src/targets/node/terminalNodeLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
NodeBinary,
} from './nodeBinaryProvider';
import { ILogger } from '../../common/logging';
import { LocalFsUtils } from '../../common/fsUtils';
import { IFsUtils } from '../../common/fsUtils';
import { IProgram } from './program';
import { IStopMetadata, ITarget } from '../targets';
import { NodeLauncherBase, IProcessTelemetry, IRunData } from './nodeLauncherBase';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class TerminalNodeLauncher extends NodeLauncherBase<ITerminalLaunchConfig
@inject(INodeBinaryProvider) pathProvider: NodeBinaryProvider,
@inject(ILogger) logger: ILogger,
@inject(FS) private readonly fs: FsPromises,
@inject(FSUtils) fsUtils: LocalFsUtils,
@inject(FSUtils) fsUtils: IFsUtils,
) {
super(pathProvider, logger, fsUtils);
}
Expand Down
6 changes: 2 additions & 4 deletions src/ui/configuration/nodeDebugConfigurationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*--------------------------------------------------------*/

import * as fs from 'fs';
import { promises as fsPromises } from 'fs';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import * as vscode from 'vscode';
Expand All @@ -24,7 +23,7 @@ import {
ResolvingNodeAttachConfiguration,
ResolvingNodeLaunchConfiguration,
} from '../../configuration';
import { ExtensionContext } from '../../ioc-extras';
import { ExtensionContext, FSUtils } from '../../ioc-extras';
import { INvmResolver } from '../../targets/node/nvmResolver';
import { fixInspectFlags } from '../configurationUtils';
import { resolveProcessId } from '../processPicker';
Expand All @@ -47,8 +46,7 @@ export class NodeConfigurationResolver extends BaseConfigurationResolver<AnyNode
constructor(
@inject(ExtensionContext) context: vscode.ExtensionContext,
@inject(INvmResolver) private readonly nvmResolver: INvmResolver,
// We don't need Node to support remote file system at the moment, so we hardcode fsUtils
private readonly fsUtils: LocalFsUtils = new LocalFsUtils(fsPromises),
@inject(FSUtils) private readonly fsUtils: LocalFsUtils,
) {
super(context);
}
Expand Down
6 changes: 2 additions & 4 deletions src/ui/debugTerminalUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*--------------------------------------------------------*/

import * as vscode from 'vscode';
import { promises as fsPromises } from 'fs';
import { NeverCancelled } from '../common/cancellation';
import {
Commands,
Expand All @@ -28,7 +27,7 @@ import { DapTelemetryReporter } from '../telemetry/dapTelemetryReporter';
import { TerminalLinkHandler } from './terminalLinkHandler';
import { promises as fs } from 'fs';
import { ProxyLogger } from '../common/logging/proxyLogger';
import { LocalFsUtils } from '../common/fsUtils';
import { IFsUtils } from '../common/fsUtils';

export const launchVirtualTerminalParent = (
delegate: DelegateLauncherFactory,
Expand Down Expand Up @@ -138,8 +137,7 @@ export function registerDebugTerminalUI(
context: vscode.ExtensionContext,
delegateFactory: DelegateLauncherFactory,
linkHandler: TerminalLinkHandler,
// We don't need Node to support remote file system at the moment, so we hardcode fsUtils (it's only used for node here)
fsUtils = new LocalFsUtils(fsPromises),
fsUtils: IFsUtils,
) {
/**
* See docblocks on {@link DelegateLauncher} for more information on
Expand Down

0 comments on commit cd97c2c

Please sign in to comment.