From 4f3d6ebaf19b6274ad80007c622f17c60444efe8 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 6 Feb 2019 14:55:34 -0500 Subject: [PATCH 1/3] fix: depend on pify --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 51c322b1..d2b4c375 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,9 @@ "dependencies": { "ajv": "6.3.0", "async": "2.6.0", + "gzip-js": "0.3.2", "jszip": "3.1.5", - "gzip-js": "0.3.2" + "pify": "4.0.1" }, "devDependencies": { "@commitlint/cli": "7.2.1", From 4c17e4e137716165dbe69df00da0f2677bf29a76 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 6 Feb 2019 14:56:42 -0500 Subject: [PATCH 2/3] fix(perf): replace async waterfall with promise chain --- index.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/index.js b/index.js index 310e42a2..3389c34d 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ -var async = require('async'); +var pify = require('pify'); -var unpack = require('./lib/unpack'); -var parse = require('./lib/parse'); -var validate = require('./lib/validate'); +var unpack = pify(require('./lib/unpack')); +var parse = pify(require('./lib/parse')); +var validate = pify(require('./lib/validate')); /** * Unpacks, parses, validates, and analyzes Scratch projects. If successful, @@ -12,23 +12,15 @@ var validate = require('./lib/validate'); * @param {Function} callback Returns error or project data */ module.exports = function (input, isSprite, callback) { - // First unpack the input (need this outside of the async waterfall so that - // unpackedProject can be refered to again) - unpack(input, isSprite, function (err, unpackedProject) { - if (err) return callback(err); - - async.waterfall([ - function (cb) { - parse(unpackedProject[0], cb); - }, - // TODO is there a better way to pass this arg - // than partially applying this funciton? - validate.bind(null, isSprite) - ], function (error, validatedInput) { - // One more callback wrapper so that we can re-package everything - // with the possible zip returned from unpack - if (error) return callback(error); - callback(null, [validatedInput, unpackedProject[1]]); - }); - }); + // Unpack the input and further transform the json portion by parsing and + // validating it. + unpack(input, isSprite) + .then(function (unpackedProject) { + return parse(unpackedProject[0]) + .then(validate.bind(null, isSprite)) + .then(function (validatedProject) { + return [validatedProject, unpackedProject[1]]; + }); + }) + .then(callback.bind(null, null), callback); }; From b78d01775b0c3776ecccf28a0bb87c7850c9ed74 Mon Sep 17 00:00:00 2001 From: "Michael \"Z\" Goddard" Date: Wed, 6 Feb 2019 14:57:21 -0500 Subject: [PATCH 3/3] fix(perf): remove async dependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index d2b4c375..f8a3e8ff 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ }, "dependencies": { "ajv": "6.3.0", - "async": "2.6.0", "gzip-js": "0.3.2", "jszip": "3.1.5", "pify": "4.0.1"