Skip to content

Commit

Permalink
feat: always listen for deps:status messages and keep the usePackageJ…
Browse files Browse the repository at this point in the history
…son context up to date
  • Loading branch information
1egoman committed Oct 23, 2024
1 parent df2229c commit fa9eaeb
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions packages/web/src/components/apps/use-package-json.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export function PackageJsonProvider({ channel, children }: ProviderPropsType) {
}, [channel]);

useEffect(() => {
const callback = ({ status }: DepsInstallStatusPayloadType) => {
setStatus(status);
const callback = (payload: DepsInstallStatusPayloadType) => {
setStatus(payload.status);
};
channel.on('deps:install:status', callback);

Expand Down Expand Up @@ -82,20 +82,27 @@ export function PackageJsonProvider({ channel, children }: ProviderPropsType) {
};
channel.on('deps:install:log', logCallback);

const statusCallback = ({ status, code }: DepsInstallStatusPayloadType) => {
channel.off('deps:install:log', logCallback);
channel.off('deps:install:status', statusCallback);

addLog(
'info',
'srcbook',
`${!packages ? 'npm install' : `npm install ${packages.join(' ')}`} exited with status code ${code}`,
);

if (status === 'complete') {
resolve();
} else {
reject(new Error(`Error running npm install: ${contents}`));
const statusCallback = (payload: DepsInstallStatusPayloadType) => {
switch (payload.status) {
case "installing":
break;
case "failed":
case "complete":
channel.off('deps:install:log', logCallback);
channel.off('deps:install:status', statusCallback);

addLog(
'info',
'srcbook',
`${!packages ? 'npm install' : `npm install ${packages.join(' ')}`} exited with status code ${payload.code}`,
);

if (payload.status === 'complete') {
resolve();
} else {
reject(new Error(`Error running npm install: ${contents}`));
}
break;
}
};
channel.on('deps:install:status', statusCallback);
Expand Down

0 comments on commit fa9eaeb

Please sign in to comment.