From 32e47943ce21cf8311ededfc8b5d79359420a598 Mon Sep 17 00:00:00 2001 From: David Xu Date: Sat, 20 Aug 2022 21:32:31 -0700 Subject: [PATCH 1/6] works? --- bench/index.js | 1 + lib/index.js | 36 +++++--- package-lock.json | 225 ++++++++++++++++++--------------------------- package.json | 5 +- test/index.test.js | 14 +-- 5 files changed, 118 insertions(+), 163 deletions(-) diff --git a/bench/index.js b/bench/index.js index 474e016..1458aa9 100644 --- a/bench/index.js +++ b/bench/index.js @@ -51,6 +51,7 @@ files.filter((file) => { }); // Run the benchmark suite. +console.log(...benchmarks) b.suite( 'calipers', ...benchmarks, diff --git a/lib/index.js b/lib/index.js index 2ad3380..0eccb45 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,28 +1,34 @@ 'use strict'; var fs = require('fs'); -var Promise = require('bluebird'); -var popen = Promise.promisify(fs.open); -var pclose = Promise.promisify(fs.close); +var util = require('util'); +var popen = util.promisify(fs.open); +var pclose = util.promisify(fs.close); var detect = require('./detect'); -function measure (plugins, path, callback) { +async function measure (plugins, path, callback) { var fileDescriptor; - return popen(path, 'r') - .then(function (fd) { + try { + const fd = await popen(path, 'r'); fileDescriptor = fd; - return detect(fd, plugins); - }) - .then(function (plugin) { - return plugin.measure(path, fileDescriptor); - }) - .finally(function () { + const plugin = await detect(fd, plugins); + if (callback) { + return callback(undefined, await plugin.measure(path, fileDescriptor)); + } + return await plugin.measure(path, fileDescriptor); + } + catch (err) { + if (callback) { + return callback(err, undefined); + } + return err; + } + finally { if (fileDescriptor) { - return pclose(fileDescriptor); + pclose(fileDescriptor); } - }) - .asCallback(callback); + } } module.exports = function () { diff --git a/package-lock.json b/package-lock.json index 017cfce..9becda8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,11 @@ "name": "calipers", "version": "2.0.1", "license": "MIT", - "dependencies": { - "bluebird": "3.x.x" - }, "devDependencies": { "@types/jest": "^26.0.15", "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", - "benny": "^3.6.15", + "benny": "^3.7.1", "calipers-png": "2.x.x", "eslint": "^7.13.0", "eslint-config-standard": "^16.0.1", @@ -1419,15 +1416,6 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "dev": true }, - "node_modules/at-least-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true, - "engines": { - "node": ">= 4.0.0" - } - }, "node_modules/atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -1608,27 +1596,30 @@ } }, "node_modules/benny": { - "version": "3.6.15", - "resolved": "https://registry.npmjs.org/benny/-/benny-3.6.15.tgz", - "integrity": "sha512-kq6XVGGYVou3Y8KNPs3SEF881vi5fJ8sIf9w69D2rreiNfRicWVWK6u6/mObMw6BiexoHHumtipn5gcu0Tngng==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/benny/-/benny-3.7.1.tgz", + "integrity": "sha512-USzYxODdVfOS7JuQq/L0naxB788dWCiUgUTxvN+WLPt/JfcDURNNj8kN/N+uK6PDvuR67/9/55cVKGPleFQINA==", "dev": true, "dependencies": { "@arrows/composition": "^1.0.0", "@arrows/dispatch": "^1.0.2", "@arrows/multimethod": "^1.1.6", "benchmark": "^2.1.4", - "fs-extra": "^9.0.1", - "json2csv": "^5.0.4", - "kleur": "^4.1.3", - "log-update": "^4.0.0", - "prettier": "^2.1.2", - "stats-median": "^1.0.1" + "common-tags": "^1.8.0", + "fs-extra": "^10.0.0", + "json2csv": "^5.0.6", + "kleur": "^4.1.4", + "log-update": "^4.0.0" + }, + "engines": { + "node": ">=12" } }, "node_modules/bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "dev": true }, "node_modules/brace-expansion": { "version": "1.1.11", @@ -1941,6 +1932,24 @@ "node": ">= 0.8" } }, + "node_modules/commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, + "node_modules/common-tags": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz", + "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==", + "dev": true, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -3194,18 +3203,17 @@ } }, "node_modules/fs-extra": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz", - "integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", "dev": true, "dependencies": { - "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", - "universalify": "^1.0.0" + "universalify": "^2.0.0" }, "engines": { - "node": ">=10" + "node": ">=12" } }, "node_modules/fs.realpath": { @@ -4939,9 +4947,9 @@ "dev": true }, "node_modules/json2csv": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.5.tgz", - "integrity": "sha512-/UyvnfuUghRM+C/AiQ02X0LS+/AKfugcwaWo/gAz1pi203v29sUMrMSNEC088i+h0EG39eSsmeL9Z0iK+9MM0A==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.7.tgz", + "integrity": "sha512-YRZbUnyaJZLZUJSRi2G/MqahCyRv9n/ds+4oIetjDF3jWQA7AG7iSeKTiZiCNqtMZM7HDyt0e/W6lEnoGEmMGA==", "dev": true, "dependencies": { "commander": "^6.1.0", @@ -4956,15 +4964,6 @@ "npm": ">= 6.13.0" } }, - "node_modules/json2csv/node_modules/commander": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.0.tgz", - "integrity": "sha512-zP4jEKbe8SHzKJYQmq8Y9gYjtO/POJLgIdKgV7B9qNmABVFVc+ctqSX6iXh4mCpJfRBOabiZ2YKPg8ciDw6C+Q==", - "dev": true, - "engines": { - "node": ">= 6" - } - }, "node_modules/json5": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", @@ -4983,23 +4982,16 @@ "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "dev": true, "dependencies": { - "graceful-fs": "^4.1.6", "universalify": "^2.0.0" - } - }, - "node_modules/jsonfile/node_modules/universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true, - "engines": { - "node": ">= 10.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" } }, "node_modules/jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", - "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", + "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==", "dev": true, "engines": [ "node >= 0.2.0" @@ -5015,9 +5007,9 @@ } }, "node_modules/kleur": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.3.tgz", - "integrity": "sha512-H1tr8QP2PxFTNwAFM74Mui2b6ovcY9FoxJefgrwxY+OCJcq01k5nvhf4M/KnizzrJvLRap5STUy7dgDV35iUBw==", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", + "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", "dev": true, "engines": { "node": ">=6" @@ -5088,7 +5080,7 @@ "node_modules/lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", "dev": true }, "node_modules/lodash.memoize": { @@ -5801,18 +5793,6 @@ "node": ">= 0.8.0" } }, - "node_modules/prettier": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", - "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", - "dev": true, - "bin": { - "prettier": "bin-prettier.js" - }, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", @@ -6711,12 +6691,6 @@ "node": ">=0.10.0" } }, - "node_modules/stats-median": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/stats-median/-/stats-median-1.0.1.tgz", - "integrity": "sha512-IYsheLg6dasD3zT/w9+8Iq9tcIQqqu91ZIpJOnIEM25C3X/g4Tl8mhXwW2ZQpbrsJISr9+wizEYgsibN5/b32Q==", - "dev": true - }, "node_modules/string-length": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.1.tgz", @@ -7287,9 +7261,9 @@ } }, "node_modules/universalify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", - "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", "dev": true, "engines": { "node": ">= 10.0.0" @@ -8992,12 +8966,6 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "dev": true }, - "at-least-node": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", - "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", - "dev": true - }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -9147,27 +9115,27 @@ } }, "benny": { - "version": "3.6.15", - "resolved": "https://registry.npmjs.org/benny/-/benny-3.6.15.tgz", - "integrity": "sha512-kq6XVGGYVou3Y8KNPs3SEF881vi5fJ8sIf9w69D2rreiNfRicWVWK6u6/mObMw6BiexoHHumtipn5gcu0Tngng==", + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/benny/-/benny-3.7.1.tgz", + "integrity": "sha512-USzYxODdVfOS7JuQq/L0naxB788dWCiUgUTxvN+WLPt/JfcDURNNj8kN/N+uK6PDvuR67/9/55cVKGPleFQINA==", "dev": true, "requires": { "@arrows/composition": "^1.0.0", "@arrows/dispatch": "^1.0.2", "@arrows/multimethod": "^1.1.6", "benchmark": "^2.1.4", - "fs-extra": "^9.0.1", - "json2csv": "^5.0.4", - "kleur": "^4.1.3", - "log-update": "^4.0.0", - "prettier": "^2.1.2", - "stats-median": "^1.0.1" + "common-tags": "^1.8.0", + "fs-extra": "^10.0.0", + "json2csv": "^5.0.6", + "kleur": "^4.1.4", + "log-update": "^4.0.0" } }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "dev": true }, "brace-expansion": { "version": "1.1.11", @@ -9428,6 +9396,18 @@ "delayed-stream": "~1.0.0" } }, + "commander": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.1.tgz", + "integrity": "sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==", + "dev": true + }, + "common-tags": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.2.tgz", + "integrity": "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA==", + "dev": true + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -10452,15 +10432,14 @@ } }, "fs-extra": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz", - "integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", "dev": true, "requires": { - "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", - "universalify": "^1.0.0" + "universalify": "^2.0.0" } }, "fs.realpath": { @@ -11837,22 +11816,14 @@ "dev": true }, "json2csv": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.5.tgz", - "integrity": "sha512-/UyvnfuUghRM+C/AiQ02X0LS+/AKfugcwaWo/gAz1pi203v29sUMrMSNEC088i+h0EG39eSsmeL9Z0iK+9MM0A==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/json2csv/-/json2csv-5.0.7.tgz", + "integrity": "sha512-YRZbUnyaJZLZUJSRi2G/MqahCyRv9n/ds+4oIetjDF3jWQA7AG7iSeKTiZiCNqtMZM7HDyt0e/W6lEnoGEmMGA==", "dev": true, "requires": { "commander": "^6.1.0", "jsonparse": "^1.3.1", "lodash.get": "^4.4.2" - }, - "dependencies": { - "commander": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-6.2.0.tgz", - "integrity": "sha512-zP4jEKbe8SHzKJYQmq8Y9gYjtO/POJLgIdKgV7B9qNmABVFVc+ctqSX6iXh4mCpJfRBOabiZ2YKPg8ciDw6C+Q==", - "dev": true - } } }, "json5": { @@ -11872,20 +11843,12 @@ "requires": { "graceful-fs": "^4.1.6", "universalify": "^2.0.0" - }, - "dependencies": { - "universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", - "dev": true - } } }, "jsonparse": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", - "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=", + "integrity": "sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==", "dev": true }, "kind-of": { @@ -11895,9 +11858,9 @@ "dev": true }, "kleur": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.3.tgz", - "integrity": "sha512-H1tr8QP2PxFTNwAFM74Mui2b6ovcY9FoxJefgrwxY+OCJcq01k5nvhf4M/KnizzrJvLRap5STUy7dgDV35iUBw==", + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz", + "integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==", "dev": true }, "leven": { @@ -11953,7 +11916,7 @@ "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", - "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", "dev": true }, "lodash.memoize": { @@ -12522,12 +12485,6 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, - "prettier": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.1.2.tgz", - "integrity": "sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==", - "dev": true - }, "pretty-format": { "version": "26.6.2", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", @@ -13275,12 +13232,6 @@ } } }, - "stats-median": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/stats-median/-/stats-median-1.0.1.tgz", - "integrity": "sha512-IYsheLg6dasD3zT/w9+8Iq9tcIQqqu91ZIpJOnIEM25C3X/g4Tl8mhXwW2ZQpbrsJISr9+wizEYgsibN5/b32Q==", - "dev": true - }, "string-length": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.1.tgz", @@ -13734,9 +13685,9 @@ } }, "universalify": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", - "integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", "dev": true }, "unset-value": { diff --git a/package.json b/package.json index 0c8c4d9..b195160 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@types/jest": "^26.0.15", "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", - "benny": "^3.6.15", + "benny": "^3.7.1", "calipers-png": "2.x.x", "eslint": "^7.13.0", "eslint-config-standard": "^16.0.1", @@ -49,8 +49,5 @@ "ts-jest": "^26.4.4", "ts-node": "^9.0.0", "typescript": "^4.0.5" - }, - "dependencies": { - "bluebird": "3.x.x" } } diff --git a/test/index.test.js b/test/index.test.js index 7910619..1d4a0aa 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2,7 +2,7 @@ var path = require('path'); -describe('index', function () { +describe('index', () => { var txtPath = path.resolve(__dirname, 'fixtures/file.txt'); var pngPath = path.resolve(__dirname, 'fixtures/123x456.png'); @@ -12,21 +12,21 @@ describe('index', function () { }; var fakeTruePlugin = { - detect: function (buffer) { + detect: (buffer) => { return buffer.toString('ascii', 0, 12) === 'A text file.'; }, - measure: function () { + measure: () => { return output; } }; var fakeFalsePlugin = { - detect: function () { + detect: () => { return false; } }; - it('works with callbacks', function (done) { + it('works with callbacks', (done) => { var calipers = require('../lib/index')(fakeFalsePlugin, 'png', fakeTruePlugin); calipers.measure(txtPath, function (err, result) { expect(result).toBe(output); @@ -34,7 +34,7 @@ describe('index', function () { }); }); - it('works with promises', function () { + it('works with promises', () => { var calipers = require('../lib/index')(fakeFalsePlugin, fakeTruePlugin, 'png'); return calipers.measure(txtPath) .then(function (result) { @@ -42,7 +42,7 @@ describe('index', function () { }); }); - it('works with required plugins', function () { + it('works with required plugins', () => { var calipers = require('../lib/index')(fakeFalsePlugin, fakeTruePlugin, 'png'); return calipers.measure(pngPath) .then(function (result) { From aa42470322c875481291124ba683cdd5b635cfc4 Mon Sep 17 00:00:00 2001 From: David Xu Date: Sat, 20 Aug 2022 21:34:55 -0700 Subject: [PATCH 2/6] remove console.log --- bench/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bench/index.js b/bench/index.js index 1458aa9..474e016 100644 --- a/bench/index.js +++ b/bench/index.js @@ -51,7 +51,6 @@ files.filter((file) => { }); // Run the benchmark suite. -console.log(...benchmarks) b.suite( 'calipers', ...benchmarks, From 2009e6197f6838fc5fa5f3f787505cdb0cc7ac76 Mon Sep 17 00:00:00 2001 From: David Xu Date: Sat, 20 Aug 2022 21:44:23 -0700 Subject: [PATCH 3/6] cleanup if --- lib/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0eccb45..459d11c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,16 +13,16 @@ async function measure (plugins, path, callback) { const fd = await popen(path, 'r'); fileDescriptor = fd; const plugin = await detect(fd, plugins); - if (callback) { - return callback(undefined, await plugin.measure(path, fileDescriptor)); - } - return await plugin.measure(path, fileDescriptor); + + if (callback) return callback(undefined, await plugin.measure(path, fileDescriptor)); + + const measurement = await plugin.measure(path, fileDescriptor); + return measurement; } catch (err) { - if (callback) { - return callback(err, undefined); - } - return err; + if (callback) return err; + + return callback(err, undefined); } finally { if (fileDescriptor) { From f55b41ad064daad27b67f459a9843c95d7fa32d6 Mon Sep 17 00:00:00 2001 From: David Xu Date: Sat, 20 Aug 2022 23:07:20 -0700 Subject: [PATCH 4/6] try without g++ --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 049c9cb..a8d1643 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,6 @@ jobs: sudo apt-get -y install \ libpoppler-cpp-dev \ libpoppler-private-dev \ - g++ # Setup this version of Node # Cache is saved and restored by actions/setup-node - name: Use Node ${{ matrix.node-version }} From c405426c7ee862b90665559cd25fd3022281fece Mon Sep 17 00:00:00 2001 From: David Xu Date: Tue, 23 Aug 2022 21:40:24 -0700 Subject: [PATCH 5/6] fix callback --- lib/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 459d11c..9cbb263 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,9 +20,9 @@ async function measure (plugins, path, callback) { return measurement; } catch (err) { - if (callback) return err; + if (callback) callback(err, undefined); - return callback(err, undefined); + throw err; } finally { if (fileDescriptor) { From aaf8a981e904129b5e4d66ca0b7ed81556165526 Mon Sep 17 00:00:00 2001 From: David Xu Date: Wed, 24 Aug 2022 09:41:07 -0700 Subject: [PATCH 6/6] extra tests --- package-lock.json | 42 +++++++++++++++++++++++++++++++----------- package.json | 2 +- test/index.test.js | 19 +++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9becda8..4cb8b7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", "benny": "^3.7.1", - "calipers-png": "2.x.x", + "calipers-png": "2.1.0", "eslint": "^7.13.0", "eslint-config-standard": "^16.0.1", "eslint-plugin-import": "^2.22.1", @@ -1619,7 +1619,8 @@ "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true + "dev": true, + "peer": true }, "node_modules/brace-expansion": { "version": "1.1.11", @@ -1696,15 +1697,25 @@ "node": ">=0.10.0" } }, - "node_modules/calipers-png": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/calipers-png/-/calipers-png-2.0.0.tgz", - "integrity": "sha1-HQ0g5cGuX3m3TVKGoul/Wbtwtlg=", + "node_modules/calipers": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/calipers/-/calipers-2.0.1.tgz", + "integrity": "sha512-AP4Ui2Z8fZf69d8Dx4cfJgPjQHY3m+QXGFCaAGu8pfNQjyajkosS+Kkf1n6pQDMZcelN5h3MdcjweUqxcsS4pg==", "dev": true, + "peer": true, "dependencies": { "bluebird": "3.x.x" } }, + "node_modules/calipers-png": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/calipers-png/-/calipers-png-2.1.0.tgz", + "integrity": "sha512-Iu4kwHtEXoNowsoR9CUUDc+KyFJSFhgVI0AsfYXYmo9kfEoTaQM/tLgWGzO3oisxkdeb5II3TMPDvpI+HDykjw==", + "dev": true, + "peerDependencies": { + "calipers": "2.x.x" + } + }, "node_modules/call-bind": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz", @@ -9135,7 +9146,8 @@ "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true + "dev": true, + "peer": true }, "brace-expansion": { "version": "1.1.11", @@ -9203,15 +9215,23 @@ "unset-value": "^1.0.0" } }, - "calipers-png": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/calipers-png/-/calipers-png-2.0.0.tgz", - "integrity": "sha1-HQ0g5cGuX3m3TVKGoul/Wbtwtlg=", + "calipers": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/calipers/-/calipers-2.0.1.tgz", + "integrity": "sha512-AP4Ui2Z8fZf69d8Dx4cfJgPjQHY3m+QXGFCaAGu8pfNQjyajkosS+Kkf1n6pQDMZcelN5h3MdcjweUqxcsS4pg==", "dev": true, + "peer": true, "requires": { "bluebird": "3.x.x" } }, + "calipers-png": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/calipers-png/-/calipers-png-2.1.0.tgz", + "integrity": "sha512-Iu4kwHtEXoNowsoR9CUUDc+KyFJSFhgVI0AsfYXYmo9kfEoTaQM/tLgWGzO3oisxkdeb5II3TMPDvpI+HDykjw==", + "dev": true, + "requires": {} + }, "call-bind": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.0.tgz", diff --git a/package.json b/package.json index b195160..a87b460 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@typescript-eslint/eslint-plugin": "^4.8.1", "@typescript-eslint/parser": "^4.8.1", "benny": "^3.7.1", - "calipers-png": "2.x.x", + "calipers-png": "2.1.0", "eslint": "^7.13.0", "eslint-config-standard": "^16.0.1", "eslint-plugin-import": "^2.22.1", diff --git a/test/index.test.js b/test/index.test.js index 1d4a0aa..6f6f9ae 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -34,6 +34,15 @@ describe('index', () => { }); }); + it('errors out correctly with callbacks', (done) => { + var calipers = require('../lib/index')(fakeFalsePlugin, 'png', fakeFalsePlugin); + calipers.measure(txtPath, function (err, result) { + }).catch((err) => { + expect(err.message).toMatch('File type not supported'); + done() + }); + }); + it('works with promises', () => { var calipers = require('../lib/index')(fakeFalsePlugin, fakeTruePlugin, 'png'); return calipers.measure(txtPath) @@ -42,6 +51,16 @@ describe('index', () => { }); }); + it('errors with promises', async () => { + var calipers = require('../lib/index')(fakeFalsePlugin, fakeFalsePlugin, 'png'); + try { + await calipers.measure(txtPath); + } catch(err) { + expect(err.message).toMatch('File type not supported'); + } + + }); + it('works with required plugins', () => { var calipers = require('../lib/index')(fakeFalsePlugin, fakeTruePlugin, 'png'); return calipers.measure(pngPath)