From 82e8a00a0d9dff6bcb4ca754ded9dbe1f42407cd Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 30 Oct 2020 03:26:30 -0400 Subject: [PATCH] Fix CI --- src/node/plugin.ts | 36 ++++++++++++++++------------------ test/plugin.test.ts | 31 ++++++++++++++++------------- test/test-plugin/src/index.ts | 16 ++++++++------- test/test-plugin/tsconfig.json | 14 ++++++------- 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 2ae29b967..ab2af5d66 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -1,12 +1,12 @@ -import * as path from "path" -import * as util from "./util" -import * as pluginapi from "../../typings/plugin" -import * as fs from "fs" -import * as semver from "semver" -import { version } from "./constants" -const fsp = fs.promises import { Logger, field } from "@coder/logger" import * as express from "express" +import * as fs from "fs" +import * as path from "path" +import * as semver from "semver" +import * as pluginapi from "../../typings/plugin" +import { version } from "./constants" +import * as util from "./util" +const fsp = fs.promises // These fields are populated from the plugin's package.json. interface Plugin extends pluginapi.Plugin { @@ -34,7 +34,7 @@ export class PluginAPI { */ private readonly csPlugin = "", private readonly csPluginPath = `${path.join(util.paths.data, "plugins")}:/usr/share/code-server/plugins`, - ){ + ) { this.logger = logger.named("pluginapi") } @@ -44,7 +44,7 @@ export class PluginAPI { */ public async applications(): Promise { const apps = new Array() - for (let p of this.plugins) { + for (const p of this.plugins) { const pluginApps = await p.applications() // TODO prevent duplicates @@ -62,7 +62,7 @@ export class PluginAPI { * mount mounts all plugin routers onto r. */ public mount(r: express.Router): void { - for (let p of this.plugins) { + for (const p of this.plugins) { r.use(`/${p.name}`, p.router()) } } @@ -75,14 +75,14 @@ export class PluginAPI { // Built-in plugins. await this._loadPlugins(path.join(__dirname, "../../plugins")) - for (let dir of this.csPluginPath.split(":")) { + for (const dir of this.csPluginPath.split(":")) { if (!dir) { continue } await this._loadPlugins(dir) } - for (let dir of this.csPlugin.split(":")) { + for (const dir of this.csPlugin.split(":")) { if (!dir) { continue } @@ -93,7 +93,7 @@ export class PluginAPI { private async _loadPlugins(dir: string): Promise { try { const entries = await fsp.readdir(dir, { withFileTypes: true }) - for (let ent of entries) { + for (const ent of entries) { if (!ent.isDirectory()) { continue } @@ -124,14 +124,12 @@ export class PluginAPI { private _loadPlugin(dir: string, packageJSON: PackageJSON): Plugin { const logger = this.logger.named(packageJSON.name) - logger.debug("loading plugin", - field("plugin_dir", dir), - field("package_json", packageJSON), - ) + logger.debug("loading plugin", field("plugin_dir", dir), field("package_json", packageJSON)) if (!semver.satisfies(version, packageJSON.engines["code-server"])) { - throw new Error(`plugin range ${q(packageJSON.engines["code-server"])} incompatible` + - ` with code-server version ${version}`) + throw new Error( + `plugin range ${q(packageJSON.engines["code-server"])} incompatible` + ` with code-server version ${version}`, + ) } if (!packageJSON.name) { throw new Error("plugin missing name") diff --git a/test/plugin.test.ts b/test/plugin.test.ts index 05a72028a..a77b1cf43 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -1,8 +1,8 @@ -import { describe } from "mocha" -import { PluginAPI } from "../src/node/plugin" import { logger } from "@coder/logger" -import * as path from "path" import * as assert from "assert" +import { describe } from "mocha" +import * as path from "path" +import { PluginAPI } from "../src/node/plugin" /** * Use $LOG_LEVEL=debug to see debug logs. @@ -15,17 +15,20 @@ describe("plugin", () => { // We remove the function fields from the application's plugins. const apps = JSON.parse(JSON.stringify(await papi.applications())) - assert.deepEqual([ - { - name: "goland", - version: "4.0.0", - iconPath: "icon.svg", - plugin: { - name: "test-plugin", - version: "1.0.0", - description: "Fake plugin for testing code-server's plugin API", + assert.deepEqual( + [ + { + name: "goland", + version: "4.0.0", + iconPath: "icon.svg", + plugin: { + name: "test-plugin", + version: "1.0.0", + description: "Fake plugin for testing code-server's plugin API", + }, }, - }, - ], apps) + ], + apps, + ) }) }) diff --git a/test/test-plugin/src/index.ts b/test/test-plugin/src/index.ts index b601cb3c0..83575533b 100644 --- a/test/test-plugin/src/index.ts +++ b/test/test-plugin/src/index.ts @@ -1,6 +1,6 @@ -import * as pluginapi from "../../../typings/plugin" import * as express from "express" -import * as path from "path"; +import * as path from "path" +import * as pluginapi from "../../../typings/plugin" export function init(config: pluginapi.PluginConfig) { config.logger.debug("test-plugin loaded!") @@ -15,9 +15,11 @@ export function router(): express.Router { } export function applications(): pluginapi.Application[] { - return [{ - name: "goland", - version: "4.0.0", - iconPath: "icon.svg", - }] + return [ + { + name: "goland", + version: "4.0.0", + iconPath: "icon.svg", + }, + ] } diff --git a/test/test-plugin/tsconfig.json b/test/test-plugin/tsconfig.json index 86e4897bb..0956ead88 100644 --- a/test/test-plugin/tsconfig.json +++ b/test/test-plugin/tsconfig.json @@ -4,8 +4,8 @@ /* Basic Options */ // "incremental": true, /* Enable incremental compilation */ - "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + "target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, + "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, // "lib": [], /* Specify library files to be included in the compilation. */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ @@ -14,7 +14,7 @@ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ - "outDir": "./out", /* Redirect output structure to the directory. */ + "outDir": "./out" /* Redirect output structure to the directory. */, // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ @@ -25,7 +25,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ + "strict": true /* Enable all strict type-checking options. */, // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -48,7 +48,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ @@ -63,7 +63,7 @@ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ /* Advanced Options */ - "skipLibCheck": true, /* Skip type checking of declaration files. */ - "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + "skipLibCheck": true /* Skip type checking of declaration files. */, + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ } }