Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit eb8112e

Browse files
authored
Merge pull request #9 from codeoverflow-org:refactor/prod-build-pkg-list
Refactor buildPackageList into multiple readable functions
2 parents 84b8a41 + 5cce4f9 commit eb8112e

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/install/prompt.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,44 @@ export async function getCompatibleVersions(includeRange: semver.Range = support
124124
* @returns resolved packages with the most up to date patch version.
125125
*/
126126
export async function buildPackageList(version: string, services: string[]): Promise<NpmPackage[]> {
127-
// TODO: split this into multiple methods
128-
const promises = [...corePackages, ...services.map((name) => `nodecg-io-${name}`)].map(async (pkgName) => ({
127+
const servicePackageNames = services.map((name) => `nodecg-io-${name}`);
128+
const packageNames = corePackages.concat(corePackages, servicePackageNames);
129+
130+
const resolvePromises = packageNames.map(async (pkgName) => ({
129131
name: pkgName,
130-
path: pkgName === dashboardPackage ? dashboardPath : pkgName,
131-
version: (await getHighestPatchVersion(pkgName, version)) ?? `${version}.0`,
132-
symlink: pkgName === dashboardPackage ? ["monaco-editor"] : undefined,
132+
path: getPackagePath(pkgName),
133+
version: await getPackageVersion(pkgName, version),
134+
symlink: getPackageSymlinks(pkgName),
133135
}));
134136

135-
return await Promise.all(promises);
137+
return await Promise.all(resolvePromises);
138+
}
139+
140+
function getPackagePath(pkgName: string) {
141+
// Special case: dashboard needs to be in nodecg-io-core/dashboard
142+
if (pkgName === dashboardPackage) {
143+
return dashboardPath;
144+
}
145+
146+
// Normal case: package should go in directory named after the package
147+
// this includes all services.
148+
return pkgName;
149+
}
150+
151+
async function getPackageVersion(pkgName: string, minorVersion: string) {
152+
const version = await getHighestPatchVersion(pkgName, minorVersion);
153+
// if patch part could be found out we will use .0 as it should always exist if the minor version also does.
154+
return version ?? `${version}.0`;
155+
}
156+
157+
function getPackageSymlinks(pkgName: string) {
158+
// special case: dashboard needs monaco-editor to be symlink into the local node_modules directory.
159+
if (pkgName === dashboardPackage) {
160+
return ["monaco-editor"];
161+
}
162+
163+
// normal case: usually we don't need symlinks because node walks up the fs to find the hoisted node_modules directory.
164+
return undefined;
136165
}
137166

138167
/**

0 commit comments

Comments
 (0)