@@ -6,20 +6,23 @@ import { dirnamePlugin, workspacePlugin } from '@keepkey/common-esbuild-bits'
66import * as esbuild from 'esbuild'
77import * as fs from 'fs'
88import * as path from 'path'
9- import * as pnpapi from 'pnpapi'
109
1110process . env . NODE_ENV ??= 'production'
1211const isDev = process . env . NODE_ENV === 'production'
1312
1413const workspacePath = path . resolve ( __dirname , '..' )
1514const buildPath = path . join ( workspacePath , 'build' )
1615const rootPath = path . normalize ( path . join ( workspacePath , '../..' ) )
17- const appSource = path . join (
18- pnpapi . resolveToUnqualified ( 'keepkey-desktop-app' , workspacePath ) ! ,
19- 'build' ,
20- )
16+
17+ // Use require.resolve instead of pnpapi
18+ const appSourcePackage = require . resolve ( 'keepkey-desktop-app/package.json' , { paths : [ workspacePath ] } )
19+ const appSource = path . join ( path . dirname ( appSourcePackage ) , 'build' )
20+
2121const assetsSource = path . join ( workspacePath , 'assets' )
22- const swaggerUiDistSource = pnpapi . resolveToUnqualified ( 'swagger-ui-dist' , workspacePath ) !
22+
23+ // Use require.resolve for swagger-ui-dist
24+ const swaggerUiDistSource = path . dirname ( require . resolve ( 'swagger-ui-dist/package.json' , { paths : [ workspacePath ] } ) )
25+
2326const firmwareSource = path . join ( rootPath , 'firmware' )
2427const executablesSource = path . join ( rootPath , 'executables' ) ;
2528const executablesPath = path . join ( buildPath , 'executables' ) ;
@@ -112,31 +115,40 @@ const copyFirmware = async () => {
112115const copyPrebuilds = async ( packages : string [ ] ) => {
113116 await Promise . all (
114117 packages . map ( async x => {
115- const prebuildsSource = pnpapi . resolveToUnqualified ( `${ x } /prebuilds` , workspacePath ) !
116- const targetPath = path . join ( nativeModulesPath , x , 'prebuilds' )
117- await fs . promises . mkdir ( targetPath , { recursive : true } )
118- await fs . promises . cp ( prebuildsSource , targetPath , {
119- dereference : true ,
120- recursive : true ,
121- } )
118+ try {
119+ const packagePath = require . resolve ( `${ x } /package.json` , { paths : [ workspacePath ] } )
120+ const prebuildsSource = path . join ( path . dirname ( packagePath ) , 'prebuilds' )
121+ const targetPath = path . join ( nativeModulesPath , x , 'prebuilds' )
122+ await fs . promises . mkdir ( targetPath , { recursive : true } )
123+ await fs . promises . cp ( prebuildsSource , targetPath , {
124+ dereference : true ,
125+ recursive : true ,
126+ } )
127+ } catch ( error ) {
128+ console . warn ( `Could not find prebuilds for ${ x } ` )
129+ }
122130 } ) ,
123131 )
124132}
125133
126134const copyBindings = async ( items : [ source : string , target : string ] [ ] ) => {
127135 await Promise . all (
128136 items . map ( async ( [ source , target ] ) => {
129- const targetPath = pnpapi . resolveToUnqualified ( source , workspacePath ) !
130- if (
131- ! ( await fs . promises
132- . stat ( targetPath )
133- . then ( ( ) => true )
134- . catch ( ( ) => false ) )
135- )
136- return
137-
138- await fs . promises . mkdir ( path . dirname ( path . join ( buildPath , target ) ) , { recursive : true } )
139- await fs . promises . copyFile ( targetPath , path . join ( buildPath , target ) )
137+ try {
138+ const targetPath = require . resolve ( source , { paths : [ workspacePath ] } )
139+ if (
140+ ! ( await fs . promises
141+ . stat ( targetPath )
142+ . then ( ( ) => true )
143+ . catch ( ( ) => false ) )
144+ )
145+ return
146+
147+ await fs . promises . mkdir ( path . dirname ( path . join ( buildPath , target ) ) , { recursive : true } )
148+ await fs . promises . copyFile ( targetPath , path . join ( buildPath , target ) )
149+ } catch ( error ) {
150+ console . warn ( `Could not find binding ${ source } ` )
151+ }
140152 } ) ,
141153 )
142154}
@@ -149,7 +161,7 @@ const runEsbuild = async (
149161 bundle : true ,
150162 absWorkingDir : rootPath ,
151163 outdir : buildPath ,
152- external : [ '/resources/*' , 'electron' , 'pnpapi' ] ,
164+ external : [ '/resources/*' , 'electron' ] ,
153165 loader : {
154166 '.png' : 'file' ,
155167 '.svg' : 'file' ,
@@ -180,10 +192,10 @@ const runEsbuild = async (
180192export const build = async ( ) => {
181193 await sanitizeBuildDir ( )
182194
183- const specPath = path . join (
184- pnpapi . resolveToUnqualified ( 'keepkey-sdk-server' , workspacePath ) ! ,
185- 'dist/swagger.json' ,
186- )
195+ // Use require.resolve for keepkey-sdk-server
196+ const sdkServerPackage = require . resolve ( 'keepkey-sdk-server/package.json ' , { paths : [ workspacePath ] } )
197+ const specPath = path . join ( path . dirname ( sdkServerPackage ) , 'dist/swagger.json' )
198+
187199 await fs . promises . copyFile ( specPath , path . join ( apiPath , 'swagger.json' ) )
188200
189201 const esbuild = collectDefines ( ) . then ( defines =>
0 commit comments