@@ -17,11 +17,11 @@ type ApiPackageJson = PackageJson & {
1717
1818/**
1919 * Map of workspace packages to vendor into production builds.
20- * Key: package name, Value: relative path from api/ to the package directory
20+ * Key: package name, Value: path from monorepo root to the package directory
2121 */
2222const WORKSPACE_PACKAGES_TO_VENDOR = {
23- '@unraid/shared' : '../../ packages/unraid-shared' ,
24- 'unraid-api-plugin-connect' : '../../ packages/unraid-api-plugin-connect' ,
23+ '@unraid/shared' : 'packages/unraid-shared' ,
24+ 'unraid-api-plugin-connect' : 'packages/unraid-api-plugin-connect' ,
2525} as const ;
2626
2727/**
@@ -33,9 +33,7 @@ const packAndInstallWorkspacePackage = async (pkgName: string, pkgPath: string,
3333 console . warn ( `Workspace package ${ pkgName } not found at ${ fullPkgPath } . Skipping.` ) ;
3434 return ;
3535 }
36-
3736 console . log ( `Building and packing workspace package ${ pkgName } ...` ) ;
38-
3937 // Pack the package to a tarball
4038 const packedResult = await $ `pnpm --filter ${ pkgName } pack --pack-destination ${ fullTempDir } ` ;
4139 const tarballPath = packedResult . lines ( ) . at ( - 1 ) ! ;
@@ -46,6 +44,16 @@ const packAndInstallWorkspacePackage = async (pkgName: string, pkgPath: string,
4644 await $ `npm install ${ tarballPattern } ` ;
4745} ;
4846
47+ /**------------------------------------------------------------------------
48+ * Build Script
49+ *
50+ * Builds & vendors the API for deployment to an Unraid server.
51+ *
52+ * Places artifacts in the `deploy/` folder:
53+ * - release/ contains source code & assets
54+ * - node-modules-archive/ contains tarball of node_modules
55+ *------------------------------------------------------------------------**/
56+
4957try {
5058 // Create release and pack directories
5159 await mkdir ( './deploy/release' , { recursive : true } ) ;
@@ -100,17 +108,16 @@ try {
100108 /** After npm install, vendor workspace packages via pack/install */
101109 if ( workspaceDeps . length > 0 ) {
102110 console . log ( 'Vendoring workspace packages...' ) ;
103- const tempDir = '../temp- packages' ;
111+ const tempDir = './ packages' ;
104112 await mkdir ( tempDir , { recursive : true } ) ;
105113
106114 for ( const dep of workspaceDeps ) {
107115 const pkgPath =
108116 WORKSPACE_PACKAGES_TO_VENDOR [ dep as keyof typeof WORKSPACE_PACKAGES_TO_VENDOR ] ;
109- await packAndInstallWorkspacePackage ( dep , join ( '../' , pkgPath ) , tempDir ) ;
117+ // The extra '../../../' prefix adjusts for the fact that we're in the pack directory.
118+ // this way, pkgPath can be defined relative to the monorepo root.
119+ await packAndInstallWorkspacePackage ( dep , join ( '../../../' , pkgPath ) , tempDir ) ;
110120 }
111-
112- // Clean up temp directory
113- await $ `rm -rf ${ tempDir } ` ;
114121 }
115122
116123 const compressionLevel = process . env . WATCH_MODE ? '-1' : '-5' ;
0 commit comments