|
7 | 7 | buildNpmPackagePath, |
8 | 8 | downloadNpmPackage, |
9 | 9 | createNpmSymlinks, |
| 10 | + getSubPackages, |
10 | 11 | } from "../npm"; |
11 | 12 | import { directoryExists, ensureDirectory } from "../fsUtils"; |
12 | 13 | import { logger } from "../log"; |
@@ -53,14 +54,25 @@ export function diffPackages( |
53 | 54 | requested: NpmPackage[], |
54 | 55 | current: NpmPackage[], |
55 | 56 | ): { pkgInstall: NpmPackage[]; pkgRemove: NpmPackage[] } { |
| 57 | + // currently installed but not requested exactly anymore |
| 58 | + const pkgRemove = current.filter((a) => !requested.find((b) => isPackageEquals(a, b))); |
| 59 | + |
| 60 | + // requested and not already exactly installed (e.g. version change) |
| 61 | + const pkgInstall = requested.filter((a) => !current.find((b) => isPackageEquals(a, b))); |
| 62 | + |
| 63 | + // Gets sub-packages of packages in pkgInstall that might not be in there. |
| 64 | + // E.g. core got upgraded => nodecg-io-core will be removed and reinstalled |
| 65 | + // nodecg-io-dashboard will also be removed because it is in nodecg-io-core and |
| 66 | + // contained in the directory of the core package. This ensures that the dashboard will |
| 67 | + // also be reinstalled, even though it got no upgrade. |
| 68 | + const installAdditional = pkgInstall.map((pkg) => getSubPackages(requested, pkg)).flat(); |
| 69 | + |
56 | 70 | return { |
57 | | - pkgInstall: requested.filter((a) => !current.find((b) => isPackageEquals(a, b))), // requested and not already exactly installed (e.g. version change) |
58 | | - pkgRemove: current.filter((a) => !requested.find((b) => isPackageEquals(a, b))), // currently installed but not requested exactly anymore |
| 71 | + pkgRemove, |
| 72 | + pkgInstall: [...new Set(pkgInstall.concat(installAdditional))], |
59 | 73 | }; |
60 | 74 | } |
61 | 75 |
|
62 | | -// TODO: handle when e.g. core upgrades and removes nodecg-io-core directory. Need to re-download dashboard because it got deleted (or don't delete it). |
63 | | - |
64 | 76 | /** |
65 | 77 | * Removes a list of packages from a production nodecg-io install. |
66 | 78 | * @param pkgs the packages that should be removed |
|
0 commit comments