Use dynamic imports for code splitting

feature/search
Kelvin Schoofs 6 years ago
parent 599dddbd24
commit 212f8e619f

@ -6,8 +6,6 @@ import * as vscode from 'vscode';
import { getConfigs } from './config';
import { FileSystemConfig } from './fileSystemConfig';
import * as Logging from './logging';
import * as proxy from './proxy';
import { getSession as getPuttySession } from './putty';
import { toPromise } from './toPromise';
// tslint:disable-next-line:variable-name
@ -47,7 +45,7 @@ export async function calculateActualConfig(config: FileSystemConfig): Promise<F
} else {
config.putty = replaceVariables(config.putty);
}
const session = await getPuttySession(config.putty, config.host, config.username, nameOnly);
const session = await (await import('./putty')).getSession(config.putty, config.host, config.username, nameOnly);
if (!session) throw new Error(`Couldn't find the requested PuTTY session`);
if (session.protocol !== 'ssh') throw new Error(`The requested PuTTY session isn't a SSH session`);
config.username = config.username || session.username;
@ -161,9 +159,9 @@ export async function createSocket(config: FileSystemConfig): Promise<NodeJS.Rea
break;
case 'socks4':
case 'socks5':
return await proxy.socks(config);
return await (await import ('./proxy')).socks(config);
case 'http':
return await proxy.http(config);
return await (await import ('./proxy')).http(config);
default:
throw new Error(`Unknown proxy method`);
}

@ -2,12 +2,9 @@
import { Client, ClientChannel } from 'ssh2';
import * as vscode from 'vscode';
import { getConfig, getConfigs, loadConfigs, UPDATE_LISTENERS } from './config';
import { createSSH, getSFTP } from './connect';
import { FileSystemConfig } from './fileSystemConfig';
import * as Logging from './logging';
import * as settings from './settings';
import SSHFileSystem from './sshFileSystem';
import { MemoryDuplex } from './streams';
import { catchingPromise, toPromise } from './toPromise';
async function assertFs(man: Manager, uri: vscode.Uri) {
@ -39,6 +36,7 @@ function createTreeItem(manager: Manager, name: string): vscode.TreeItem {
async function tryGetHome(ssh: Client): Promise<string | null> {
const exec = await toPromise<ClientChannel>(cb => ssh.exec('echo Home: ~', cb));
const { MemoryDuplex } = await import('./streams');
const stdout = new MemoryDuplex();
exec.stdout.pipe(stdout);
await toPromise(cb => exec.on('close', cb));
@ -107,6 +105,7 @@ export class Manager implements vscode.FileSystemProvider, vscode.TreeDataProvid
if (!config) {
throw new Error(`A SSH filesystem with the name '${name}' doesn't exist`);
}
const { createSSH, getSFTP } = await import('./connect');
const client = await createSSH(config);
if (!client) return reject(null);
let root = config!.root || '/';
@ -277,8 +276,9 @@ export class Manager implements vscode.FileSystemProvider, vscode.TreeDataProvid
// Would open the Settings UI, list all locations the (potentially) merged config originates from,
// and allow the user to pick (and edit) one of them. Maybe have a back-to-the-list button?
}
public openSettings() {
settings.open(this.context.extensionPath);
public async openSettings() {
const { open } = await import('./settings');
return open(this.context.extensionPath);
}
}

Loading…
Cancel
Save