From e24cc50bc36927e695a9cae182a6b7366898b5e3 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sun, 28 Mar 2021 22:46:16 +0200 Subject: [PATCH] Deps galore --- package-lock.json | 55 ++++++++++++++++------- package.json | 5 ++- src/abortable-promise.ts | 96 ---------------------------------------- src/alpr.ts | 49 ++++++++++---------- src/index.ts | 2 +- 5 files changed, 67 insertions(+), 140 deletions(-) delete mode 100644 src/abortable-promise.ts diff --git a/package-lock.json b/package-lock.json index 131f4d4..86d4653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,10 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "abortable-promise": "git+https://git.kuba-orlik.name/kuba/abortable-promises.git#ee3d998", - "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#7ee6a21", + "abortable-gen-promises": "^0.1.0", + "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2b", "emittery": "^0.8.1", + "perspective-shift": "git+https://git.kuba-orlik.name/kuba/perspective-shift.git#f4769d3", "tempy": "^1.0.1" }, "devDependencies": { @@ -51,15 +52,15 @@ } }, "node_modules/@types/node": { - "version": "14.14.35", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.35.tgz", - "integrity": "sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==" + "version": "14.14.37", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.37.tgz", + "integrity": "sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==" }, - "node_modules/abortable-promise": { + "node_modules/abortable-gen-promises": { "version": "0.1.0", - "resolved": "git+https://git.kuba-orlik.name/kuba/abortable-promises.git#ee3d998c08b43a2efb15d921f592e8fdc433f487", + "resolved": "https://registry.npmjs.org/abortable-gen-promises/-/abortable-gen-promises-0.1.0.tgz", + "integrity": "sha512-DGEempJ6OYZiDmupX17AsSP6iVNe8fFS8UIolETKquW0muDCgreqMgpk8xnHPxV6dSHpGzGYi2jKGXgcf99leA==", "hasInstallScript": true, - "license": "ISC", "dependencies": { "@types/node": "^14.14.19", "emittery": "^0.8.1" @@ -87,7 +88,7 @@ }, "node_modules/async-spawner": { "version": "0.1.7", - "resolved": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#7ee6a21f38834b0a40f75a190e1bbfd0a2b01ead", + "resolved": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2bc27a345263db870dd7e7c3494307d857c", "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -428,6 +429,16 @@ "node": ">=8" } }, + "node_modules/perspective-shift": { + "version": "0.1.0", + "resolved": "git+https://git.kuba-orlik.name/kuba/perspective-shift.git#f4769d3eb045ddff1454916d8843f034ef286c61", + "license": "ISC", + "dependencies": { + "abortable-gen-promises": "^0.1.0", + "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2bc27a3", + "tempy": "^1.0.1" + } + }, "node_modules/picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", @@ -614,13 +625,14 @@ } }, "@types/node": { - "version": "14.14.35", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.35.tgz", - "integrity": "sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==" + "version": "14.14.37", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.37.tgz", + "integrity": "sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==" }, - "abortable-promise": { - "version": "git+https://git.kuba-orlik.name/kuba/abortable-promises.git#ee3d998c08b43a2efb15d921f592e8fdc433f487", - "from": "abortable-promise@git+https://git.kuba-orlik.name/kuba/abortable-promises.git#ee3d998", + "abortable-gen-promises": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/abortable-gen-promises/-/abortable-gen-promises-0.1.0.tgz", + "integrity": "sha512-DGEempJ6OYZiDmupX17AsSP6iVNe8fFS8UIolETKquW0muDCgreqMgpk8xnHPxV6dSHpGzGYi2jKGXgcf99leA==", "requires": { "@types/node": "^14.14.19", "emittery": "^0.8.1" @@ -641,8 +653,8 @@ "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==" }, "async-spawner": { - "version": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#7ee6a21f38834b0a40f75a190e1bbfd0a2b01ead", - "from": "async-spawner@git+https://git.kuba-orlik.name/kuba/async-spawner.git#7ee6a21", + "version": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2bc27a345263db870dd7e7c3494307d857c", + "from": "async-spawner@git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2b", "requires": { "@types/node": "^14.14.19", "emittery": "^0.8.0" @@ -891,6 +903,15 @@ "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" }, + "perspective-shift": { + "version": "git+https://git.kuba-orlik.name/kuba/perspective-shift.git#f4769d3eb045ddff1454916d8843f034ef286c61", + "from": "perspective-shift@git+https://git.kuba-orlik.name/kuba/perspective-shift.git#f4769d3", + "requires": { + "abortable-gen-promises": "^0.1.0", + "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2bc27a3", + "tempy": "^1.0.1" + } + }, "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", diff --git a/package.json b/package.json index e744dc8..74b1bd7 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ "author": "", "license": "ISC", "dependencies": { - "abortable-promise": "git+https://git.kuba-orlik.name/kuba/abortable-promises.git#4a316bb", - "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#cdbb47d", + "abortable-gen-promises": "^0.1.0", + "async-spawner": "git+https://git.kuba-orlik.name/kuba/async-spawner.git#a3d1a2b", "emittery": "^0.8.1", + "perspective-shift": "git+https://git.kuba-orlik.name/kuba/perspective-shift.git#f4769d3", "tempy": "^1.0.1" }, "devDependencies": { diff --git a/src/abortable-promise.ts b/src/abortable-promise.ts deleted file mode 100644 index 54829cd..0000000 --- a/src/abortable-promise.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { deferedSpawn } from "async-spawner"; -import Emittery from "emittery"; -import { promisify } from "util"; - -//needed to pass information on wether or not the promise has been aborted witout 'this' -class AbortableEmittery extends Emittery { - public aborted = false; - - abort() { - this.aborted = true; - this.emit("abort"); - } -} - -class AbortablePromise extends Promise { - private emitter: AbortableEmittery; - - constructor( - make_generator: ( - await_or_abort: ( - promise: Promise, - on_abort: () => void - ) => Promise - ) => AsyncGenerator - ) { - const emitter = new AbortableEmittery(); - const await_or_abort = ( - promise: Promise, - on_abort: () => void - ) => { - return new Promise((resolve, reject) => { - let resolved = false; - emitter.on("abort", () => { - if (!resolved) { - on_abort(); - resolve(null); - resolved = true; - } - }); - promise - .then((result) => { - if (!resolved) { - resolve(result); - resolved = true; - } - }) - .catch(reject); - }); - }; - super(async (resolve, reject) => { - let step_value; - const generator = make_generator(await_or_abort); - do { - if (emitter.aborted) { - resolve(null); - return; - } - step_value = await generator.next(); - } while (!step_value.done); - }); - this.emitter = emitter; - } - - abort() { - this.emitter.abort(); - } -} - -// const sleep = promisify((timeout: number, callback: (...args: any[]) => void) => -// setTimeout(callback, timeout) -// ); - -// const a = new AbortablePromise(async function* () { -// yield await sleep(1000); -// console.log("awaited 100"); -// yield await sleep(2000); -// console.log("awaited 200"); -// yield await sleep(3000); -// console.log("awaited 300"); -// }); - -// setTimeout(() => a.abort(), 1500); - -const b = new AbortablePromise(async function* (await_or_abort) { - const ping = await deferedSpawn("ping", ["8.8.8.8"]); - while (true) { - console.log( - await await_or_abort(ping.waitForNextData(), () => { - ping.kill(); - }) - ); - yield; - } -}); - -setTimeout(() => b.abort(), 5000); diff --git a/src/alpr.ts b/src/alpr.ts index 259f60c..348eb30 100644 --- a/src/alpr.ts +++ b/src/alpr.ts @@ -1,4 +1,4 @@ -import AbortablePromise from "abortable-promise"; +import AbortablePromise from "abortable-gen-promises"; import { deferedSpawn } from "async-spawner"; import tempy from "tempy"; import { @@ -7,30 +7,31 @@ import { transformDesc, transforms, } from "./transforms"; +import perspectiveShift from "perspective-shift"; -function perspectiveShift( - input: string, - shift: transformCoefs -): AbortablePromise { - return new AbortablePromise(async function* (await_or_abort) { - const output = tempy.file({ extension: "jpg" }); - const args = [ - "-verbose", - input, - "-virtual-pixel", - "Transparent", - "-distort", - "PerspectiveProjection", - shift.join(","), - output, - ]; - const def = await deferedSpawn("convert", args); - const next_data_promise = def.waitForNextData(); - yield; - await await_or_abort(next_data_promise, () => def.kill()); - return output; - }); -} +// function perspectiveShift( +// input: string, +// shift: transformCoefs +// ): AbortablePromise { +// return new AbortablePromise(async function* (await_or_abort) { +// const output = tempy.file({ extension: "jpg" }); +// const args = [ +// "-verbose", +// input, +// "-virtual-pixel", +// "Transparent", +// "-distort", +// "PerspectiveProjection", +// shift.join(","), +// output, +// ]; +// const def = await deferedSpawn("convert", args); +// const next_data_promise = def.waitForNextData(); +// yield; +// await await_or_abort(next_data_promise, () => def.kill()); +// return output; +// }); +// } type coordinates = { x: number; y: number }; type alpr_candidate = { diff --git a/src/index.ts b/src/index.ts index 8c73988..859a907 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import simpleSpawn, { deferedSpawn } from "async-spawner"; import { promises as fs } from "fs"; import path from "path"; -import AbortablePromise from "../../abortable-promise/@types"; +import AbortablePromise from "abortable-gen-promises"; import { alprMultiPersp, alpr_response } from "./alpr"; async function run(): Promise {