Skip to content

Commit

Permalink
Create common module
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Feb 20, 2022
1 parent 83cf22a commit 85f7a69
Show file tree
Hide file tree
Showing 41 changed files with 134 additions and 278 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"**/node_modules/": true,
"dist/": true,
"util/": true,
"common/out": true,
"webview/build/": true,
".yarn/": true,
".yarnrc.yml": true,
Expand Down
32 changes: 30 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,44 @@
{
"label": "Extension - Watch all",
"group": "build",
"dependsOrder": "sequence",
"dependsOn": [
"Extension - Watch",
"Extension WebView - Watch"
"Extension Common - Watch",
"Extension - Watch non-Common"
],
"problemMatcher": [],
"isBackground": true,
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "Extension - Watch non-Common",
"group": "build",
"dependsOrder": "parallel",
"dependsOn": [
"Extension - Watch",
"Extension WebView - Watch"
],
"problemMatcher": [],
"isBackground": true,
},
{
"type": "shell",
"label": "Extension Common - Watch",
"command": "yarn watch",
"options": {
"cwd": "./common"
},
"group": "build",
"problemMatcher": {
"base": "$tsc-watch",
"source": "tsc-watch",
"owner": "tsc-watch",
"applyTo": "allDocuments"
},
"isBackground": true
},
{
"type": "npm",
"label": "Extension - Watch",
Expand Down
18 changes: 14 additions & 4 deletions .yarn/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2272,7 +2272,7 @@ __metadata:
languageName: node
linkType: hard

"@types/ssh2@npm:^0.5.41, @types/ssh2@npm:^0.5.47":
"@types/ssh2@npm:^0.5.41":
version: 0.5.47
resolution: "@types/ssh2@npm:0.5.47"
dependencies:
Expand Down Expand Up @@ -3714,6 +3714,16 @@ __metadata:
languageName: node
linkType: hard

"common@workspace:*, common@workspace:common":
version: 0.0.0-use.local
resolution: "common@workspace:common"
dependencies:
"@types/node": ^12.7.12
"@types/ssh2": ^0.5.41
typescript: ~4.5.5
languageName: unknown
linkType: soft

"commondir@npm:^1.0.1":
version: 1.0.1
resolution: "commondir@npm:1.0.1"
Expand Down Expand Up @@ -9505,6 +9515,7 @@ resolve@^2.0.0-next.3:
"@types/vscode": ~1.49.0
"@types/webpack": ^4.4.25
"@types/winreg": ^1.2.30
common: "workspace:*"
event-stream: ^4.0.1
jsonc-parser: ^2.0.0
semver: ^7.3.5
Expand All @@ -9518,7 +9529,6 @@ resolve@^2.0.0-next.3:
vsce: ^2.5.1
webpack: ^5.69.1
webpack-cli: ^4.7.2
webview: "workspace:*"
winreg: ^1.2.4
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -9717,7 +9727,7 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"webview@workspace:*, webview@workspace:webview":
"webview@workspace:webview":
version: 0.0.0-use.local
resolution: "webview@workspace:webview"
dependencies:
Expand All @@ -9727,12 +9737,12 @@ resolve@^2.0.0-next.3:
"@types/react": ^17.0.18
"@types/react-dom": ^17.0.9
"@types/react-redux": ^7.1.7
"@types/ssh2": ^0.5.47
"@typescript-eslint/eslint-plugin": ^4.5.0
"@typescript-eslint/parser": ^4.5.0
babel-eslint: ^10.1.0
babel-loader: 8.1.0
babel-preset-react-app: 10.0.0
common: "workspace:*"
css-loader: 4.3.0
css-minimizer-webpack-plugin: ^3.0.2
dotenv: 8.2.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- All dependencies are upgraded within their (package.json-specified) ranges, to get latest patches
- Update to Yarn 3.1.1 and TypeScript ~4.5.5
- Also ditched `@yarnpkg/plugin-version` which wasn't even really used in the first place
- Created a `common` module which now holds `fileSystemConfig.ts` and `webviewMessages.ts`

## v1.24.1 (2021-12-07)

Expand Down
3 changes: 3 additions & 0 deletions common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# Build output
out/
25 changes: 25 additions & 0 deletions common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "common",
"version": "0.1.0",
"private": true,
"exports": {
"./*": "./out/*"
},
"typesVersions": {
">=0": {
"*": [
"out/*"
]
}
},
"scripts": {
"watch": "tsc -w",
"build": "tsc"
},
"devDependencies": {
"@types/node": "^12.7.12",
"@types/ssh2": "^0.5.41",
"typescript": "~4.5.5"
},
"packageManager": "[email protected]"
}
4 changes: 2 additions & 2 deletions src/fileSystemConfig.ts → common/src/fileSystemConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type ConfigLocation = number | string;

/** Might support conditional stuff later, although ssh2/OpenSSH might not support that natively */
export interface EnvironmentVariable {
key: string;
value: string;
key: string;
value: string;
}

export function formatConfigLocation(location?: ConfigLocation): string {
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"strictNullChecks": true,
"module": "esnext",
"moduleResolution": "node",
"target": "ES2019",
"outDir": "out",
"lib": [
"ES2019"
],
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"rootDir": "src"
},
"compileOnSave": true,
"include": [
"src"
]
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
}
},
"scripts": {
"vscode:prepublish": "yarn workspaces foreach -vip -j 2 run build",
"vscode:prepublish": "yarn workspaces foreach -tvip -j 2 run build",
"build": "webpack --mode production",
"compile": "webpack --mode development",
"watch": "webpack --mode development --watch"
Expand All @@ -424,19 +424,20 @@
"webpack-cli": "^4.7.2"
},
"dependencies": {
"common": "workspace:*",
"event-stream": "^4.0.1",
"jsonc-parser": "^2.0.0",
"semver": "^7.3.5",
"socks": "^2.2.0",
"ssh2": "^0.8.9",
"ssh2-streams": "^0.4.10",
"webview": "workspace:*",
"winreg": "^1.2.4"
},
"resolutions": {
"ssh2-streams": "Timmmm/ssh2-streams#patch-1"
},
"workspaces": [
"./common",
"./webview"
],
"packageManager": "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { ConfigLocation, FileSystemConfig, invalidConfigName, parseConnectionString } from 'common/fileSystemConfig';
import { readFile, writeFile } from 'fs';
import { parse as parseJsonc, ParseError } from 'jsonc-parser';
import * as semver from 'semver';
import * as vscode from 'vscode';
import { ConfigLocation, FileSystemConfig, invalidConfigName, parseConnectionString } from './fileSystemConfig';
import { Logging } from './logging';
import { toPromise } from './utils';
import * as semver from 'semver';

// Logger scope with default warning/error options (which enables stacktraces) disabled
const logging = Logging.scope(undefined, false);
Expand Down
2 changes: 1 addition & 1 deletion src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { FileSystemConfig } from 'common/fileSystemConfig';
import { readFile } from 'fs';
import { Socket } from 'net';
import { userInfo } from 'os';
import { Client, ClientChannel, ConnectConfig, SFTPWrapper as SFTPWrapperReal } from 'ssh2';
import { SFTPStream } from 'ssh2-streams';
import * as vscode from 'vscode';
import { getConfig, getFlagBoolean } from './config';
import type { FileSystemConfig } from './fileSystemConfig';
import { Logging } from './logging';
import type { PuttySession } from './putty';
import { toPromise, validatePort } from './utils';
Expand Down
2 changes: 1 addition & 1 deletion src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { EnvironmentVariable, FileSystemConfig } from 'common/fileSystemConfig';
import { posix as path } from 'path';
import * as readline from 'readline';
import type { Client, ClientChannel } from 'ssh2';
import * as vscode from 'vscode';
import { configMatches, getFlagBoolean, loadConfigs } from './config';
import type { EnvironmentVariable, FileSystemConfig } from './fileSystemConfig';
import { Logging, LOGGING_NO_STACKTRACE } from './logging';
import type { SSHPseudoTerminal } from './pseudoTerminal';
import { calculateShellConfig, ShellConfig, tryEcho } from './shellConfig';
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import type { FileSystemConfig } from 'common/fileSystemConfig';
import * as vscode from 'vscode';
import { loadConfigs } from './config';
import type { Connection } from './connection';
import type { FileSystemConfig } from './fileSystemConfig';
import { FileSystemRouter } from './fileSystemRouter';
import { Logging, setDebug } from './logging';
import { Manager } from './manager';
Expand Down
2 changes: 1 addition & 1 deletion src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileSystemConfig, isFileSystemConfig } from 'common/fileSystemConfig';
import * as vscode from 'vscode';
import { FileSystemConfig, isFileSystemConfig } from './fileSystemConfig';

// Since the Extension Development Host runs with debugger, we can use this to detect if we're debugging.
// The only things it currently does is copying Logging messages to the console, while also enabling
Expand Down
4 changes: 2 additions & 2 deletions src/manager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

import type { FileSystemConfig } from 'common/fileSystemConfig';
import type { Navigation } from 'common/webviewMessages';
import * as vscode from 'vscode';
import { getConfig, getFlagBoolean, loadConfigsRaw } from './config';
import { Connection, ConnectionManager } from './connection';
import type { FileSystemConfig } from './fileSystemConfig';
import { Logging, LOGGING_NO_STACKTRACE } from './logging';
import { isSSHPseudoTerminal, replaceVariables, replaceVariablesRecursive } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem';
import { catchingPromise, joinCommands } from './utils';
import type { Navigation } from './webviewMessages';

function commandArgumentToName(arg?: string | FileSystemConfig | Connection): string {
if (!arg) return 'undefined';
Expand Down
2 changes: 1 addition & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import type { FileSystemConfig } from 'common/fileSystemConfig';
import * as dns from 'dns';
import { request } from 'http';
import { SocksClient } from 'socks';
import type { FileSystemConfig } from './fileSystemConfig';
import { Logging } from './logging';
import { toPromise, validatePort } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/pseudoTerminal.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { EnvironmentVariable, FileSystemConfig } from "common/fileSystemConfig";
import * as path from 'path';
import type { ClientChannel, PseudoTtyOptions } from "ssh2";
import * as vscode from "vscode";
import { getFlagBoolean } from './config';
import type { Connection } from './connection';
import type { EnvironmentVariable, FileSystemConfig } from "./fileSystemConfig";
import { Logging, LOGGING_NO_STACKTRACE } from "./logging";
import { environmentToExportString, joinCommands, mergeEnvironment, toPromise } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion src/sshFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import type { FileSystemConfig } from 'common/fileSystemConfig';
import * as path from 'path';
import type * as ssh2 from 'ssh2';
import type * as ssh2s from 'ssh2-streams';
import * as vscode from 'vscode';
import { getFlagBoolean } from './config';
import type { FileSystemConfig } from './fileSystemConfig';
import { Logger, Logging, LOGGING_NO_STACKTRACE, LOGGING_SINGLE_LINE_STACKTRACE, withStacktraceOffset } from './logging';

// This makes it report a single line of the stacktrace of where the e.g. logger.info() call happened
Expand Down
2 changes: 1 addition & 1 deletion src/treeViewManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import { FileSystemConfig, getGroups } from 'common/fileSystemConfig';
import * as vscode from 'vscode';
import { getConfigs, UPDATE_LISTENERS } from './config';
import type { Connection, ConnectionManager } from './connection';
import { FileSystemConfig, getGroups } from './fileSystemConfig';
import type { SSHPseudoTerminal } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem';
import { formatItem } from './ui-utils';
Expand Down
2 changes: 1 addition & 1 deletion src/ui-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import { FileSystemConfig, parseConnectionString } from 'common/fileSystemConfig';
import * as vscode from 'vscode';
import { getConfigs } from './config';
import type { Connection, ConnectionManager } from './connection';
import { FileSystemConfig, parseConnectionString } from './fileSystemConfig';
import type { Manager } from './manager';
import type { SSHPseudoTerminal } from './pseudoTerminal';
import type { SSHFileSystem } from './sshFileSystem';
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EnvironmentVariable } from "./fileSystemConfig";
import { DEBUG } from "./logging";
import type { EnvironmentVariable } from 'common/fileSystemConfig';
import { DEBUG } from './logging';

function prepareStackTraceDefault(error: Error, stackTraces: NodeJS.CallSite[]): string {
return stackTraces.reduce((s, c) => `${s}\n\tat ${c} (${c.getFunction()})`, `${error.name || "Error"}: ${error.message || ""}`);
Expand Down
4 changes: 2 additions & 2 deletions src/webview.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import { getLocations } from 'common/fileSystemConfig';
import type { Message, Navigation } from 'common/webviewMessages';
import * as fs from 'fs';
import * as path from 'path';
import * as vscode from 'vscode';
import { deleteConfig, loadConfigsRaw, updateConfig } from './config';
import { getLocations } from './fileSystemConfig';
import { DEBUG, Logging as _Logging, LOGGING_NO_STACKTRACE } from './logging';
import { toPromise } from './utils';
import type { Message, Navigation } from './webviewMessages';

const Logging = _Logging.scope('WebView');

Expand Down
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@
"compileOnSave": true,
"include": [
"src"
],
"exclude": [
"node_modules",
".vscode-test"
]
}
4 changes: 3 additions & 1 deletion webview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@types/react": "^17.0.18",
"@types/react-dom": "^17.0.9",
"@types/react-redux": "^7.1.7",
"@types/ssh2": "^0.5.47",
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"babel-eslint": "^10.1.0",
Expand Down Expand Up @@ -68,5 +67,8 @@
"presets": [
"react-app"
]
},
"dependencies": {
"common": "workspace:*"
}
}
Loading

0 comments on commit 85f7a69

Please sign in to comment.