Skip to content

Commit

Permalink
feat: expose progressData on result instead of just events
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
Events are no longer exposed on result promise(instead they're accessible on promise.progressData)
  • Loading branch information
medikoo committed Nov 14, 2018
1 parent 3c2f8c3 commit ebcc284
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions install-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const toPlainObject = require("es5-ext/object/normalize-options")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, ee = require("event-emitter")
, unifyEmitters = require("event-emitter/unify")
, ensureConfiguration = require("./lib/private/ensure-user-configuration")
, createProgressData = require("./lib/private/create-progress-data")
, installPackage = require("./lib/private/install-package");
Expand All @@ -16,6 +15,6 @@ module.exports = (name, configuration, options = {}) => {
toPlainObject(options), progressData
)
);
unifyEmitters(progressData, promise);
promise.progressData = progressData;
return promise;
};
3 changes: 1 addition & 2 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const toPlainObject = require("es5-ext/object/normalize-options")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, ee = require("event-emitter")
, unifyEmitters = require("event-emitter/unify")
, { resolve } = require("path")
, ensureConfiguration = require("./lib/private/ensure-user-configuration")
, createProgressData = require("./lib/private/create-progress-data")
Expand All @@ -15,6 +14,6 @@ module.exports = (path, configuration, options = {}) => {
const promise = ee(
install({ path }, ensureConfiguration(configuration), toPlainObject(options), progressData)
);
unifyEmitters(progressData, promise);
promise.progressData = progressData;
return promise;
};
5 changes: 3 additions & 2 deletions lib/private/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = async (command, packageName, inputOptions) => {
? installPackage(packageName, userConfiguration, inputOptions)
: install(process.cwd(), userConfiguration, inputOptions);
})();
const { progressData } = installPromise;
const installsInProgress = new Map();

const logWordForms = {
Expand All @@ -34,11 +35,11 @@ module.exports = async (command, packageName, inputOptions) => {
)
);
};
installPromise.on("start", event => {
progressData.on("start", event => {
installsInProgress.set(event.name, event);
updateProgress();
});
installPromise.on("end", ({ name: endedPackageName }) => {
progressData.on("end", ({ name: endedPackageName }) => {
const { progressData: { type } } = installsInProgress.get(endedPackageName);
installsInProgress.delete(endedPackageName);
log.notice(`${ logWordForms.past[type] } %s`, endedPackageName);
Expand Down
3 changes: 1 addition & 2 deletions update-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const toPlainObject = require("es5-ext/object/normalize-options")
, ee = require("event-emitter")
, unifyEmitters = require("event-emitter/unify")
, ensureConfiguration = require("./lib/private/ensure-user-configuration")
, createProgressData = require("./lib/private/create-progress-data")
, updateAll = require("./lib/private/update-all");
Expand All @@ -12,6 +11,6 @@ module.exports = (configuration, options = {}) => {
const promise = ee(
updateAll(ensureConfiguration(configuration), toPlainObject(options), progressData)
);
unifyEmitters(progressData, promise);
promise.progressData = progressData;
return promise;
};

0 comments on commit ebcc284

Please sign in to comment.