Skip to content

Commit 2b75225

Browse files
committed
Complete PnP to node_modules migration - Remove remaining pnpapi imports from keepkey-sdk getSpec.ts - Replace all pnpapi usage in keepkey-desktop build.ts with require.resolve - Remove pnpapi from external lists in esbuild configs - Fix Windows Electron packaging silent crash issue
1 parent 42b7b99 commit 2b75225

3 files changed

Lines changed: 46 additions & 32 deletions

File tree

packages/keepkey-desktop-app/scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ const runEsbuild = async (defines: Record<string, string>) => {
211211
bundle: true,
212212
absWorkingDir: rootPath,
213213
outdir: buildPath,
214-
external: ['/public/*', 'electron', 'pnpapi'],
214+
external: ['/public/*', 'electron'],
215215
loader: {
216216
'.png': 'file',
217217
'.svg': 'file',

packages/keepkey-desktop/scripts/build.ts

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ import { dirnamePlugin, workspacePlugin } from '@keepkey/common-esbuild-bits'
66
import * as esbuild from 'esbuild'
77
import * as fs from 'fs'
88
import * as path from 'path'
9-
import * as pnpapi from 'pnpapi'
109

1110
process.env.NODE_ENV ??= 'production'
1211
const isDev = process.env.NODE_ENV === 'production'
1312

1413
const workspacePath = path.resolve(__dirname, '..')
1514
const buildPath = path.join(workspacePath, 'build')
1615
const 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+
2121
const 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+
2326
const firmwareSource = path.join(rootPath, 'firmware')
2427
const executablesSource = path.join(rootPath, 'executables');
2528
const executablesPath = path.join(buildPath, 'executables');
@@ -112,31 +115,40 @@ const copyFirmware = async () => {
112115
const 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

126134
const 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 (
180192
export 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 =>

packages/keepkey-sdk/scripts/getSpec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import * as fs from 'fs'
44
import * as path from 'path'
5-
import * as pnpapi from 'pnpapi'
65

76
const workspacePath = path.resolve(__dirname, '..')
87
const buildPath = path.join(workspacePath, 'dist')
8+
9+
// Use require.resolve instead of pnpapi
10+
const keepkeySdkServerPath = require.resolve('keepkey-sdk-server/package.json', { paths: [workspacePath] })
911
const specPath = path.join(
10-
pnpapi.resolveToUnqualified('keepkey-sdk-server', workspacePath)!,
12+
path.dirname(keepkeySdkServerPath),
1113
'dist/swagger.json',
1214
)
1315

0 commit comments

Comments
 (0)