diff --git a/package.json b/package.json index 45c4537..a5e99cc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "main": "./out/extension", "scripts": { "compile": "tsc -p ./", - "vscode:prepublish": "npm run compile", + "copy-files": "copyfiles -u 1 \"src/result-view/htmlContent/**/*\" out", + "vscode:prepublish": "npm run compile && npm run copy-files", "watch": "tsc -watch -p ./" }, "contributes": { @@ -285,8 +286,10 @@ "onCommand:firebird.runQuery" ], "dependencies": { + "copyfiles": "^2.4.1", "node-firebird": "^0.9.8", - "uuid": "^8.3.0" + "uuid": "^8.3.0", + "vscode-uri": "^3.0.7" }, "devDependencies": { "@types/node": "^14.11.2", diff --git a/src/extension.ts b/src/extension.ts index 39db946..09fb121 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -31,7 +31,7 @@ export function activate(context: ExtensionContext) { const firebirdDatabaseWords = new KeywordsDb(); const firebirdTreeDataProvider = new FirebirdTreeDataProvider(context); const firebirdMockData = new MockData(context.extensionPath); - const firebirdQueryResults = new QueryResultsView(context.extensionPath); + const firebirdQueryResults = new QueryResultsView(context.extensionUri); context.subscriptions.push( window.registerTreeDataProvider(Constants.FirebirdExplorerViewId, firebirdTreeDataProvider), diff --git a/src/firebirdTreeDataProvider.ts b/src/firebirdTreeDataProvider.ts index a06dd50..1f67a95 100644 --- a/src/firebirdTreeDataProvider.ts +++ b/src/firebirdTreeDataProvider.ts @@ -1,5 +1,5 @@ import { TreeDataProvider, EventEmitter, Event, ExtensionContext, TreeItem } from "vscode"; -import * as uuidv1 from "uuid/v1"; +import { v1 as uuidv1} from 'uuid'; import { NodeHost } from "./nodes"; import { ConnectionOptions, FirebirdTree } from "./interfaces"; import { connectionWizard } from "./shared/connection-wizard"; diff --git a/src/result-view/index.ts b/src/result-view/index.ts index fe7c19e..a89261f 100644 --- a/src/result-view/index.ts +++ b/src/result-view/index.ts @@ -1,6 +1,5 @@ -import { Disposable } from "vscode"; +import { Disposable, Uri } from "vscode"; import { TextDecoder } from "util"; -import { join } from "path"; import { QueryResultsView, Message } from "./queryResultsView"; @@ -10,7 +9,7 @@ export default class ResultView extends QueryResultsView implements Disposable { private resultSet?: ResultSet; private recordsPerPage: string; - constructor(private extensionPath: string) { + constructor(private extensionUri: Uri) { super("resultview", "Firebird Query Results"); } @@ -23,7 +22,7 @@ export default class ResultView extends QueryResultsView implements Disposable { * DEV: "src",... * PROD: "out",... */ - this.show(join(this.extensionPath, "out", "result-view", "htmlContent", "index.html")); + this.show(Uri.joinPath(this.extensionUri, "out", "result-view", "htmlContent", "index.html")); } handleMessage(message: Message): void { diff --git a/src/result-view/queryResultsView.ts b/src/result-view/queryResultsView.ts index faf941a..db166d6 100644 --- a/src/result-view/queryResultsView.ts +++ b/src/result-view/queryResultsView.ts @@ -1,8 +1,8 @@ import { WebviewPanel, window, ViewColumn, Disposable, Uri, WebviewPanelOptions, WebviewOptions } from "vscode"; import { EventEmitter } from "events"; -import { dirname } from "path"; import { readFile } from "fs"; import { logger } from "../logger/logger"; +import { Utils as UriUtils } from 'vscode-uri'; export interface Message { command: string; @@ -11,20 +11,18 @@ export interface Message { } export class QueryResultsView extends EventEmitter implements Disposable { - private resourceScheme = "vscode-resource"; private disposable?: Disposable; - private resourcesPath: string; + private resourcesPath?: Uri; private panel: WebviewPanel | undefined; private htmlCache: { [path: string]: string }; constructor(private type: string, private title: string) { super(); - this.resourcesPath = ""; this.htmlCache = {}; } - show(htmlPath: string) { - this.resourcesPath = dirname(htmlPath); + show(htmlPath: Uri) { + this.resourcesPath = UriUtils.dirname(htmlPath); if (!this.panel) { this.init(); } @@ -44,7 +42,7 @@ export class QueryResultsView extends EventEmitter implements Disposable { let options: WebviewPanelOptions & WebviewOptions = { enableScripts: true, retainContextWhenHidden: false, // we dont need to keep the state - localResourceRoots: [Uri.parse(this.resourcesPath).with({ scheme: "vscode-resource" })] + localResourceRoots: [this.resourcesPath] }; this.panel = window.createWebviewPanel(this.type, this.title, ViewColumn.Two, options); @@ -62,25 +60,23 @@ export class QueryResultsView extends EventEmitter implements Disposable { this.disposable = Disposable.from(...subscriptions); } - private readWithCache(path: string, callback: (html: string) => void) { + private readWithCache(uri: Uri, callback: (html: string) => void) { let html: string = ""; - if (path in this.htmlCache) { - html = this.htmlCache[path]; + if (uri.path in this.htmlCache) { + html = this.htmlCache[uri.path]; callback(html); } else { - readFile(path, "utf8", (err, content) => { + readFile(uri.fsPath, "utf8", (err, content) => { html = content || ""; - html = this.replaceUris(html, path); - this.htmlCache[path] = html; + html = this.replaceUris(html, uri); + this.htmlCache[uri.path] = html; callback(html); }); } } - private replaceUris(html: string, htmlPath: string) { - let basePath = Uri.parse(dirname(htmlPath)) - .with({ scheme: this.resourceScheme }) - .toString(); + private replaceUris(html: string, htmlPath: Uri) { + let basePath = this.panel.webview.asWebviewUri(UriUtils.dirname(htmlPath)).toString(); let regex = /(href|src)\=\"(.+?)\"/g; html = html.replace(regex, `$1="${basePath + "$2"}"`); return html; diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts deleted file mode 100644 index a7a297f..0000000 --- a/src/test/extension.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -// -// Note: This example test is leveraging the Mocha test framework. -// Please refer to their documentation on https://mochajs.org/ for help. -// - -// The module 'assert' provides assertion methods from node -import * as assert from 'assert'; - -// You can import and use all API from the 'vscode' module -// as well as import your extension to test it -// import * as vscode from 'vscode'; -// import * as myExtension from '../extension'; - -// Defines a Mocha test suite to group tests of similar kind together -suite("Extension Tests", function () { - - // Defines a Mocha unit test - test("Something 1", function() { - assert.equal(-1, [1, 2, 3].indexOf(5)); - assert.equal(-1, [1, 2, 3].indexOf(0)); - }); -}); \ No newline at end of file diff --git a/src/test/index.ts b/src/test/index.ts deleted file mode 100644 index 9fa2ea0..0000000 --- a/src/test/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -// -// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING -// -// This file is providing the test runner to use when running extension tests. -// By default the test runner in use is Mocha based. -// -// You can provide your own test runner if you want to override it by exporting -// a function run(testRoot: string, clb: (error:Error) => void) that the extension -// host can call to run the tests. The test runner is expected to use console.log -// to report the results back to the caller. When the tests are finished, return -// a possible error to the callback or null if none. - -import * as testRunner from 'vscode/lib/testrunner'; - -// You can directly control Mocha options by uncommenting the following lines -// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info -testRunner.configure({ - ui: 'tdd', // the TDD UI is being used in extension.test.ts (suite, test, etc.) - useColors: true // colored output from test results -}); - -module.exports = testRunner; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7f6ad3b..750498b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,9 +10,9 @@ // "strict": true, /* enable all strict type-checking options */ /* Additional Checks */ "noUnusedLocals": true /* Report errors on unused locals. */, - "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + // "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, - "noUnusedParameters": true /* Report errors on unused parameters. */ + // "noUnusedParameters": true /* Report errors on unused parameters. */ }, "exclude": ["node_modules", ".vscode-test"] }