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

Commit b7562ad

Browse files
starpitk8s-ci-robot
authored andcommitted
fix: electron builder fails for clients that want to use webpack to build headless bundles
part of #7557
1 parent 7d4456b commit b7562ad

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

packages/builder/dist/electron/builders/electron.js

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const { arch: osArch } = require('os')
4545
const { createGunzip } = require('zlib')
4646
const { basename, join } = require('path')
4747
const packager = require('electron-packager')
48+
const { serialHooks } = require('electron-packager/src/hooks')
4849
const { copy, emptyDir, remove } = require('fs-extra')
4950
const { createReadStream, createWriteStream, readdir } = require('fs')
5051
const { exec } = require('child_process')
@@ -60,7 +61,7 @@ const nodePty = 'node-pty-prebuilt-multiarch'
6061
* @param this baseArgs from package() below
6162
*
6263
*/
63-
async function buildWebpack(buildPath, electronVersion, targetPlatform, targetArch, callback) {
64+
async function buildWebpack(buildPath, electronVersion, targetPlatform, targetArch) {
6465
const CLIENT_HOME = this.dir
6566

6667
console.log('buildPath', buildPath)
@@ -106,24 +107,19 @@ async function buildWebpack(buildPath, electronVersion, targetPlatform, targetAr
106107
)
107108

108109
await Promise.all(asyncs)
109-
callback()
110110
}
111111

112112
/** afterCopy hook to copy in the platform-specific node-pty build */
113-
async function copyNodePty(buildPath, electronVersion, targetPlatform, targetArch, callback) {
114-
console.log('copying node pty')
115-
/* if (process.platform === targetPlatform && targetArch === osArch()) {
116-
// if the current platform matches the target platform, there is
117-
// nothing to do
118-
callback()
119-
} else */ {
113+
function copyNodePty(buildPath, electronVersion, targetPlatform, targetArch) {
114+
return new Promise((resolve, reject) => {
115+
console.log('copying node pty')
120116
const target = `${targetPlatform}-${targetArch}`
121117
const sourceDir = join(process.env.BUILDER_HOME, 'dist/electron/vendor', nodePty, 'build', target, 'electron')
122118
console.log('sourceDir', sourceDir)
123119

124120
readdir(sourceDir, async (err, files) => {
125121
if (err) {
126-
callback(err)
122+
reject(err)
127123
} else {
128124
try {
129125
await Promise.all(
@@ -149,32 +145,26 @@ async function copyNodePty(buildPath, electronVersion, targetPlatform, targetArc
149145
})
150146
)
151147
)
152-
callback()
148+
resolve()
153149
} catch (err) {
154-
callback(err)
150+
reject(err)
155151
}
156152
}
157153
})
158-
}
154+
})
159155
}
160156

161157
/** afterCopy hook to copy in headless build, etc. things that need to be codesigned */
162-
async function copySignableBits(buildPath, electronVersion, targetPlatform, targetArch, callback) {
158+
async function copySignableBits(buildPath, electronVersion, targetPlatform, targetArch) {
163159
// copy in launcher? it is important to copy this in before
164160
// signing and notarizing, otherwise macOS/windows, when launching
165161
// the app, will see unsigned content in the application bundle
166-
try {
167-
if (this.launcher) {
168-
const source = this.launcher
169-
const target = join(buildPath, '..', basename(source)) // e.g. buildPath is Contents/Resources/app on macOS
170-
console.log(`Copying in launcher for ${targetPlatform} ${targetArch} from ${source} to ${target}`)
171-
await copy(source, target)
172-
await remove(source)
173-
}
174-
} catch (err) {
175-
console.error(`Error copying in launcher for ${targetPlatform} ${targetArch}`)
176-
console.error(err)
177-
callback(err)
162+
if (this.launcher) {
163+
const source = this.launcher
164+
const target = join(buildPath, '..', basename(source)) // e.g. buildPath is Contents/Resources/app on macOS
165+
console.log(`Copying in launcher for ${targetPlatform} ${targetArch} from ${source} to ${target}`)
166+
await copy(source, target)
167+
// NO!!! TODO find a better way to remove kubect-kui await remove(source)
178168
}
179169

180170
// copy in the headless build?
@@ -185,8 +175,6 @@ async function copySignableBits(buildPath, electronVersion, targetPlatform, targ
185175
await emptyDir(target)
186176
await copy(source, target)
187177
}
188-
189-
callback()
190178
}
191179
/**
192180
* Use electron-packager to create the application package
@@ -225,7 +213,7 @@ function package(baseArgs /*: { dir: string, name: string, platform: string, arc
225213
},
226214

227215
// lifecycle hooks to copy in our extra bits
228-
afterCopy: [buildWebpack.bind(baseArgs), copyNodePty, copySignableBits.bind(baseArgs)]
216+
afterCopy: [serialHooks([buildWebpack.bind(baseArgs), copyNodePty, copySignableBits.bind(baseArgs)])]
229217
})
230218

231219
console.log('args', args)

packages/webpack/headless-webpack.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ if (process.env.NO_OPT) {
4646
console.log('mode?', mode)
4747
console.log('target?', target)
4848

49-
/** point webpack to the root directory */
50-
const stageDir = process.cwd()
51-
console.log('stageDir', stageDir)
52-
5349
/** point webpack to the output directory */
54-
const buildDir = path.join(stageDir, 'dist/headless')
50+
const buildDir = path.join(process.env.CLIENT_HOME, 'dist/headless')
5551
console.log('buildDir', buildDir)
5652

5753
/** this is the full path in which will be serving up bundles */

0 commit comments

Comments
 (0)