Skip to content

Commit

Permalink
feat: pass progressData with event, expose type on it
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
progressDataEvent.type was moved to progressDataEvent.progressData.type
  • Loading branch information
medikoo committed Nov 14, 2018
1 parent 9dc1847 commit 3c2f8c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/private/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async (command, packageName, inputOptions) => {
};
const updateProgress = () => {
cliFooter.updateProgress(
Array.from(installsInProgress, ([inProgressPackageName, { type }]) =>
Array.from(installsInProgress, ([inProgressPackageName, { progressData: { type } }]) =>
format(`${ logWordForms.present[type] } %s`, inProgressPackageName)
)
);
Expand All @@ -39,7 +39,7 @@ module.exports = async (command, packageName, inputOptions) => {
updateProgress();
});
installPromise.on("end", ({ name: endedPackageName }) => {
const { type } = installsInProgress.get(endedPackageName);
const { progressData: { type } } = installsInProgress.get(endedPackageName);
installsInProgress.delete(endedPackageName);
log.notice(`${ logWordForms.past[type] } %s`, endedPackageName);
updateProgress();
Expand Down
12 changes: 8 additions & 4 deletions lib/private/install-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const finalize = async ({ name }, progressData) => {
for (const job of jobs) await job();
clear.call(jobs);
}
progressData.emit("end", { name });
progressData.emit("end", { name, progressData: packageProgressData });
};

module.exports = async (packageContext, userConfiguration, inputOptions, progressData) => {
Expand All @@ -39,11 +39,15 @@ module.exports = async (packageContext, userConfiguration, inputOptions, progres
}
const meta = (packageContext.meta = packagesMeta[name]);
const path = (packageContext.path = resolve(packagesPath, name));

progressData.emit("start", { name, type: (await isDirectory(path)) ? "update" : "install" });
const packageProgressData = {
type: (await isDirectory(path)) ? "update" : "install",
hooks: { after: [] }
};

log.debug("mark %s as ongoing", name);
ongoing.set(name, { hooks: { after: [] } });
ongoing.set(name, packageProgressData);

progressData.emit("start", { name, progressData: packageProgressData });

// Ensure repository is up to date
await setupRepository(path, meta.repoUrl, inputOptions);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = async (packageContext, userConfiguration, inputOptions, progres
// Ensure to emit "start" event in next event loop
await wait();

progressData.emit("start", { name, type: "update" });
progressData.emit("start", { name, progressData: { type: "update" } });

// Cleanup outcome of eventual previous npm crashes
await cleanupNpmInstall(packageContext);
Expand Down

0 comments on commit 3c2f8c3

Please sign in to comment.