@@ -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 */
126126export 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