From 05cd33282eb25f03063b10668d41713c0140111d Mon Sep 17 00:00:00 2001 From: Matthew Forrester Date: Mon, 1 Nov 2021 20:05:40 +0000 Subject: [PATCH] feat: fix not working in Ubuntu 20.04 ( https://github.com/Boscop/web-view/issues/289 ) --- js-lib/package-lock.json | 113 ++++++++++++++++++++++++++++--- js-lib/package.json | 6 +- js-lib/src/wv-linewise-fetch.ts | 4 +- js-lib/src/wv-linewise.ts | 23 +++++++ js-lib/test/wv-linewise-fetch.ts | 6 +- 5 files changed, 138 insertions(+), 14 deletions(-) diff --git a/js-lib/package-lock.json b/js-lib/package-lock.json index 97da51e..eda04f4 100644 --- a/js-lib/package-lock.json +++ b/js-lib/package-lock.json @@ -1,6 +1,6 @@ { "name": "wv-linewise-js-lib", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -563,11 +563,15 @@ "delayed-stream": "~1.0.0" } }, + "command-exists": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.6.tgz", + "integrity": "sha512-Qst/zUUNmS/z3WziPxyqjrcz09pm+2Knbs5mAZL4VAE0sSrNY1/w8+/YxeHcoBTsO6iojA6BW7eFf27Eg2MRuw==" + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "commondir": { "version": "1.0.1", @@ -651,6 +655,11 @@ } } }, + "crypto-random-string": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz", + "integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=" + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -1061,8 +1070,7 @@ "graceful-fs": { "version": "4.2.4", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", - "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", - "dev": true + "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==" }, "handlebars": { "version": "4.7.6", @@ -1532,7 +1540,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, "requires": { "graceful-fs": "^4.1.6" } @@ -1884,6 +1891,11 @@ "own-or": "^1.0.0" } }, + "p-debounce": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-debounce/-/p-debounce-1.0.0.tgz", + "integrity": "sha1-y38svu/YegnrqGHhErZ1J+Yh4v0=" + }, "p-limit": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", @@ -3723,6 +3735,20 @@ "diff-frag": "^1.0.1" } }, + "temp-dir": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-1.0.0.tgz", + "integrity": "sha1-CnwOom06Oa+n4OvqnB/AvE2qAR0=" + }, + "tempy": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/tempy/-/tempy-0.2.1.tgz", + "integrity": "sha512-LB83o9bfZGrntdqPuRdanIVCPReam9SOZKW0fOy5I9X3A854GGWi0tjCqoXEk84XIEYBc/x9Hq3EFop/H5wJaw==", + "requires": { + "temp-dir": "^1.0.0", + "unique-string": "^1.0.0" + } + }, "test-exclude": { "version": "5.2.3", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-5.2.3.tgz", @@ -3918,6 +3944,32 @@ "integrity": "sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==", "dev": true }, + "typescript-language-server": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/typescript-language-server/-/typescript-language-server-0.5.1.tgz", + "integrity": "sha512-60Kguhwk/R1BB4pEIb6B9C7Ix7JzLzYnsODlmorYMPjMeEV0rCBqTR6FGAj4wVw/eHrHcpwLENmmURKUd8aybA==", + "requires": { + "command-exists": "1.2.6", + "commander": "^2.11.0", + "fs-extra": "^7.0.0", + "p-debounce": "^1.0.0", + "tempy": "^0.2.1", + "vscode-languageserver": "^5.3.0-next", + "vscode-uri": "^1.0.5" + }, + "dependencies": { + "fs-extra": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", + "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + } + } + }, "uglify-js": { "version": "3.9.4", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.4.tgz", @@ -3955,11 +4007,18 @@ } } }, + "unique-string": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-1.0.0.tgz", + "integrity": "sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo=", + "requires": { + "crypto-random-string": "^1.0.0" + } + }, "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "uri-js": { "version": "4.4.0", @@ -4003,6 +4062,44 @@ "integrity": "sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==", "dev": true }, + "vscode-jsonrpc": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz", + "integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==" + }, + "vscode-languageserver": { + "version": "5.3.0-next.10", + "resolved": "https://registry.npmjs.org/vscode-languageserver/-/vscode-languageserver-5.3.0-next.10.tgz", + "integrity": "sha512-QL7Fe1FT6PdLtVzwJeZ78pTic4eZbzLRy7yAQgPb9xalqqgZESR0+yDZPwJrM3E7PzOmwHBceYcJR54eQZ7Kng==", + "requires": { + "vscode-languageserver-protocol": "^3.15.0-next.8", + "vscode-textbuffer": "^1.0.0" + } + }, + "vscode-languageserver-protocol": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz", + "integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==", + "requires": { + "vscode-jsonrpc": "6.0.0", + "vscode-languageserver-types": "3.16.0" + } + }, + "vscode-languageserver-types": { + "version": "3.16.0", + "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz", + "integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA==" + }, + "vscode-textbuffer": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vscode-textbuffer/-/vscode-textbuffer-1.0.0.tgz", + "integrity": "sha512-zPaHo4urgpwsm+PrJWfNakolRpryNja18SUip/qIIsfhuEqEIPEXMxHOlFPjvDC4JgTaimkncNW7UMXRJTY6ow==" + }, + "vscode-uri": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-1.0.8.tgz", + "integrity": "sha512-obtSWTlbJ+a+TFRYGaUumtVwb+InIUVI0Lu0VBUAPmj2cU5JutEXg3xUE0c2J5Tcy7h2DEKVJBFi+Y9ZSFzzPQ==" + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/js-lib/package.json b/js-lib/package.json index 726d0fc..5f6c53e 100644 --- a/js-lib/package.json +++ b/js-lib/package.json @@ -1,6 +1,6 @@ { "name": "wv-linewise-js-lib", - "version": "0.0.2", + "version": "0.0.3", "repository": { "type": "git", "url": "https://github.com/forbesmyester/wv-linewise" @@ -14,7 +14,9 @@ }, "author": "Matt Forrester ", "license": "MIT", - "dependencies": {}, + "dependencies": { + "typescript-language-server": "^0.5.1" + }, "typings": "./dist/main.d.ts", "devDependencies": { "@rollup/plugin-typescript": "^4.1.2", diff --git a/js-lib/src/wv-linewise-fetch.ts b/js-lib/src/wv-linewise-fetch.ts index bf12a76..83d4b0d 100644 --- a/js-lib/src/wv-linewise-fetch.ts +++ b/js-lib/src/wv-linewise-fetch.ts @@ -281,9 +281,7 @@ export function getWvLinewiseFetch(wvl: WvLinewise, responseStream: string) { function wvLinewiseFetchSerialize(request: WvLinewiseRequest): string { let m = (request.opts.method || 'GET').toUpperCase(); - let o = {...request.opts}; - delete o.method; - return `REQUEST: ${request.id}: ${m}: ${request.url} ${JSON.stringify(o)}`; + return `REQUEST: ${request.id}: ${m}: ${request.url} ${request.opts.body || '{}'}`; } wvLinewiseFetch.request = wvLinewiseFetchRequest; diff --git a/js-lib/src/wv-linewise.ts b/js-lib/src/wv-linewise.ts index 2aae39a..d115c35 100644 --- a/js-lib/src/wv-linewise.ts +++ b/js-lib/src/wv-linewise.ts @@ -412,6 +412,29 @@ export class WvLinewise { } export function runningInWvLinewise(): boolean { + + if ((window as any).webkit && (window as any).webkit.messageHandlers && (window as any).webkit.messageHandlers.external && (window as any).webkit.messageHandlers.external.postMessage) { + (window as any).external = { + invoke: (e: string) => { + (window as any).webkit.messageHandlers.external.postMessage(e); + } + }; + return true; + } + return !!((window as any).external && (window.external as any).invoke); } +export function externalInvoke(e: any) { + + if ((window as any).webkit && (window as any).webkit.messageHandlers && (window as any).webkit.messageHandlers.external && (window as any).webkit.messageHandlers.external.postMessage) { + return (window as any).webkit.messageHandlers.external.postMessage(e); + } + + if ((window as any).external && (window.external as any).invoke) { + return (window.external as any).invoke(e); + } + + throw new Error("WV Linewise: Could not post message: " + JSON.stringify(e)); +} + diff --git a/js-lib/test/wv-linewise-fetch.ts b/js-lib/test/wv-linewise-fetch.ts index 5ec4c59..7c3c591 100644 --- a/js-lib/test/wv-linewise-fetch.ts +++ b/js-lib/test/wv-linewise-fetch.ts @@ -61,7 +61,11 @@ tap.test('testSerialize', function testSerialize(test) { test.is( fet.serialize({ opts: { cache: "no-cache", method: "post", body: JSON.stringify({ a: 2 }) }, id: 3, url: '/snow' }), - 'REQUEST: 3: POST: /snow {"cache":"no-cache","body":"{\\"a\\":2}"}' + 'REQUEST: 3: POST: /snow {"a":2}' + ); + test.is( + fet.serialize({ opts: { cache: "no-cache", method: "get" }, id: 3, url: '/snow' }), + 'REQUEST: 3: GET: /snow {}' ); test.end()