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

Commit cacd68b

Browse files
committed
fix: improve windows build support
Fixes #3332
1 parent 80f8690 commit cacd68b

File tree

20 files changed

+189
-54
lines changed

20 files changed

+189
-54
lines changed

.travis.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: node_js
2-
node_js: 8
2+
node_js: 12 # Note: windows requires 10 or higher
33
dist: xenial # Note: dist>=xenial required by microk8s
44
cache: false # as of 20190709 trav-ci.org started loading garbage from the build cache
55

@@ -22,7 +22,8 @@ env:
2222
- WINDOW_HEIGHT=1050 # ! ibid !
2323
- LINUX_BUILD="${TRAVIS_BUILD_DIR}/clients/electron/dist/electron/Kui-linux-x64/Kui" # test against linux electron build
2424
- OSX_BUILD="${TRAVIS_BUILD_DIR}/clients/electron/dist/electron/Kui-darwin-x64/Kui.app/Contents/MacOS/Kui" # test against darwin electron build
25-
- TEST_FROM_BUILD=`[ "$TRAVIS_OS_NAME" == linux ] && echo "$LINUX_BUILD" || echo "$OSX_BUILD"`
25+
- WINDOWS_BUILD="${TRAVIS_BUILD_DIR}/clients/electron/dist/electron/Kui-win32-x64/Kui.exe" # test against darwin electron build
26+
- TEST_FROM_BUILD=`[ "$TRAVIS_OS_NAME" = linux ] && echo "$LINUX_BUILD" || ([ "$TRAVIS_OS_NAME" = osx ] && echo "$OSX_BUILD" || echo "$WINDOWS_BUILD")`
2627
- BUILD_ENV=production # please note: used in dist/electron/build.sh with npm prune --production
2728
- HOMEBREW_NO_AUTO_UPDATE=1 # disable auto update before running brew install, brew upgrade or brew tap
2829

@@ -43,6 +44,10 @@ jobs:
4344
- KUI_USE_PROXY=true
4445
- <<: *test-core
4546
os: osx
47+
- stage: test
48+
os: windows
49+
before_install: npm config set script-shell C:\\Program\ Files\\git\\bin\\bash.exe
50+
env: LAYERS=core MOCHA_TARGETS="electron" TEST_FILTER='about'
4651
- stage: test
4752
env:
4853
- WAIT_LAYERS="bash-like-wait"

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "kui-shell",
33
"version": "5.1.0",
44
"description": "This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool",
5-
"main": "node_modules/@kui-shell/core/dist/src/main/main.js",
5+
"main": "node_modules/@kui-shell/core/main/main.js",
66
"scripts": {
77
"lint": "eslint '**/*.{js,ts}'",
88
"format": "prettier --write '**/*.{css,html,js,json,md,ts}'",
@@ -18,12 +18,12 @@
1818
"clean": "npm run compile:clean; rm -rf node_modules; for i in plugins/*; do rm -rf $i/node_modules; done; for i in packages/*; do rm -rf $i/node_modules; done",
1919
"purge": "npm run clean; rm -f package-lock.json",
2020
"pack": "./bin/pack.sh",
21-
"pty:rebuild": "cd node_modules/node-pty-prebuilt-multiarch && npm run install",
22-
"pty:electron": "rm -f .npmrc; cp packages/builder/npmrc node_modules/node-pty-prebuilt-multiarch/.npmrc && npm run pty:rebuild",
23-
"pty:nodejs": "rm -f node_modules/node-pty-prebuilt-multiarch/.npmrc; npm run pty:rebuild",
24-
"build:html": "CLIENT=${CLIENT-default}; rm -f node_modules/@kui-shell/settings/config-dev.json; npm run pty:electron && CLIENT_HOME=\"$(cd ./clients/$CLIENT && pwd)\" node packages/builder/lib/configure.js && CLIENT_HOME=./clients/$CLIENT ./packages/builder/dist/dev/build.sh && CLIENT_HOME=./clients/$CLIENT ./packages/builder/bin/seticon.js",
21+
"pty:rebuild": "kui-pty-rebuild",
22+
"pty:electron": "npm run pty:rebuild electron",
23+
"pty:nodejs": "npm run pty:rebuild node",
24+
"build:html": "CLIENT=${CLIENT-default}; rm -f node_modules/@kui-shell/settings/config-dev.json; npm run pty:electron && CLIENT_HOME=\"$(cd ./clients/$CLIENT && pwd)\" node packages/builder/lib/configure.js && CLIENT_HOME=\"$(cd ./clients/$CLIENT && pwd)\" ./packages/builder/dist/dev/build.sh && CLIENT_HOME=\"$(cd ./clients/$CLIENT && pwd)\" ./packages/builder/bin/seticon.js",
2525
"postinstall": "npm run build:html && npm run compile",
26-
"start": "node bin/kui shell"
26+
"start": "electron . shell"
2727
},
2828
"engines": {
2929
"node": ">=8.15.0",

packages/builder/bin/pty-rebuild.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "$1" ]; then
4+
echo "please provide a prebuild target, such as electron or nodejs"
5+
exit 1
6+
fi
7+
8+
# Notes: keep the prebuild --target in sync with the major version of
9+
# electron desired for this client; see the dependencies section of
10+
# ../package.json
11+
if [ "$1" = "electron" ]; then
12+
# create an electron dist to test against
13+
PLATFORM=$(node -e 'console.log(process.platform)')
14+
echo "node-pty PLATFORM=$PLATFORM"
15+
mkdir -p node_modules/node-pty-prebuilt-multiarch/build/Release
16+
rm -f node_modules/node-pty-prebuilt-multiarch/build/Release/*
17+
cp node_modules/@kui-shell/builder/dist/electron/vendor/node-pty-prebuilt-multiarch/build/$PLATFORM/electron/* node_modules/node-pty-prebuilt-multiarch/build/Release
18+
gunzip node_modules/node-pty-prebuilt-multiarch/build/Release/*.gz
19+
ls node_modules/node-pty-prebuilt-multiarch/build/Release
20+
else
21+
if [ -e ./node_modules/.bin/rc ] && [ ! -L ./node_modules/.bin/rc ]; then
22+
echo "rc is not a symlink"
23+
(cd node_modules/.bin && rm -f rc && node -e 'require("fs").symlinkSync("../rc/cli.js", "rc")')
24+
fi
25+
if [ -e ./node_modules/.bin/prebuild-install ] && [ ! -L ./node_modules/.bin/prebuild-install ]; then
26+
echo "prebuild-install is not a symlink"
27+
(cd node_modules/.bin && rm -f prebuild-install && node -e 'require("fs").symlinkSync("../prebuild-install/bin.js", "prebuild-install")')
28+
fi
29+
30+
cd node_modules/node-pty-prebuilt-multiarch
31+
prebuild-install --force --download --runtime $1
32+
fi
33+
34+
# Notes: why --force --download? for some reason, when run from `npm
35+
# run ...` prebuild-install insists on the --build-from-source option,
36+
# and nothing we do, short of --force, seems to override this

packages/builder/dist/bin/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function codecov() {
3333
? join(process.env.TRAVIS_BUILD_DIR, 'packages/test/.nyc_output')
3434
: join(process.env.TEST_ROOT, '.nyc_output')
3535

36-
process.chdir('/tmp')
36+
process.chdir(require('os').tmpdir())
3737

3838
// Create the nyc instance
3939
const tempDirectory = codeCoverageTempDirectory()

packages/builder/dist/dev/build.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ STAGING="${TOPDIR}"/node_modules/@kui-shell/build
2222

2323
(cd "$STAGING" && rm -f css && ln -s "$TOPDIR"/packages/core/web/css)
2424

25-
THEME=$(cd "$CLIENT_HOME"/theme && pwd)
25+
# (darwin doesn't support uname -o, but linux and git bash on windows both do)
26+
if [ "$(uname)" != "Darwin" ] && [ "$(uname -o)" = "Msys" ]; then
27+
# a bit of a hack for windows, given that clients/default/theme is
28+
# a symlink
29+
THEME=$(cd "$TOPDIR"/packages/builder/examples/build-configs/default/theme && pwd)
30+
else
31+
THEME=$(cd "$CLIENT_HOME"/theme && pwd)
32+
fi
2633
if [ ! -d "$THEME" ]; then
2734
echo "Cannot find THEME"
2835
exit 1

packages/builder/dist/electron/build.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ function configure {
117117
echo '{ "name": "@kui-shell/settings", "version": "0.0.1" }' > "$STAGING"/settings/package.json
118118
npm install --save --no-package-lock --ignore-scripts ./settings
119119

120+
if [ "$(uname)" != "Darwin" ] && [ "$(uname -o)" = "Msys" ]; then
121+
echo "for some reason, npm install to a relative path creates absolute-path symlinks on windows. fixing"
122+
(cd node_modules/@kui-shell && rm settings && ln -s ../../settings)
123+
fi
124+
120125
CLIENT_HOME="$CLIENT_HOME" KUI_STAGE="$STAGING" node "$BUILDER_HOME"/lib/configure.js
121126
UGLIFY=true npx --no-install kui-prescan
122127
}
@@ -346,18 +351,30 @@ function tarball {
346351
wait
347352
}
348353

349-
# copy the npmrc into the client staging area
350-
function npmrc {
351-
cp "$BUILDER_HOME"/npmrc "$STAGING/.npmrc"
352-
(cd "$STAGING" && npm rebuild --update-binary node-pty-prebuilt-multiarch)
354+
# make sure we have the needed native modules compiled and ready
355+
function native {
356+
(cd "$STAGING" && npx --no-install kui-pty-rebuild electron)
357+
}
358+
359+
# windows-specific bits
360+
function windows {
361+
if [ "$(uname)" != "Darwin" ] && [ "$(uname -o)" = "Msys" ]; then
362+
echo "handling windows idiosyncracies"
363+
if [ ! -d theme ]; then
364+
echo "handling symlink issues for windows"
365+
rm -f theme
366+
cp -a node_modules/@kui-shell/builder/examples/build-configs/default/theme theme
367+
fi
368+
fi
353369
}
354370

355371
# this is the main routine
356372
function build {
373+
echo "windows" && windows
357374
echo "prereq" && prereq
358375
echo "init" && init
359376
echo "tarCopy" && tarCopy
360-
echo "npmrc" && npmrc
377+
echo "native" && native
361378
echo "configure" && configure
362379
echo "assembleHTMLPieces" && assembleHTMLPieces
363380
echo "win32" && win32

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
const { join } = require('path')
4545
const { createGunzip } = require('zlib')
46-
const { createReadStream, createWriteStream } = require('fs')
46+
const { createReadStream, createWriteStream, readdir } = require('fs')
4747
const packager = require('electron-packager')
4848

4949
process.argv.shift()
@@ -57,23 +57,49 @@ async function copyNodePty(buildPath, electronVersion, targetPlatform, arch, cal
5757
// nothing to do
5858
callback()
5959
} else {
60-
const source = join(
60+
const sourceDir = join(
6161
process.env.BUILDER_HOME,
6262
'dist/electron/vendor',
6363
nodePty,
6464
'build',
6565
targetPlatform,
66-
'electron/pty.node.gz'
66+
'electron'
6767
)
68-
const target = join(buildPath, 'node_modules', nodePty, 'build/Release/pty.node')
69-
console.log(`node-pty source: ${source}`)
70-
console.log(`node-pty target: ${target}`)
7168

72-
createReadStream(source)
73-
.pipe(createGunzip())
74-
.pipe(createWriteStream(target))
75-
.on('error', callback)
76-
.on('finish', () => callback())
69+
readdir(sourceDir, async (err, files) => {
70+
if (err) {
71+
callback(err)
72+
} else {
73+
try {
74+
await Promise.all(
75+
files.map(
76+
sourceFileGz =>
77+
new Promise((resolve, reject) => {
78+
const source = join(sourceDir, sourceFileGz)
79+
const target = join(
80+
buildPath,
81+
'node_modules',
82+
nodePty,
83+
'build/Release',
84+
sourceFileGz.replace(/\.gz$/, '')
85+
)
86+
console.log(`node-pty source: ${source}`)
87+
console.log(`node-pty target: ${target}`)
88+
89+
createReadStream(source)
90+
.pipe(createGunzip())
91+
.pipe(createWriteStream(target))
92+
.on('error', reject)
93+
.on('finish', resolve)
94+
})
95+
)
96+
)
97+
callback()
98+
} catch (err) {
99+
callback(err)
100+
}
101+
}
102+
})
77103
}
78104
}
79105

@@ -95,7 +121,7 @@ const args = {
95121
ignore: process.env.IGNORE,
96122

97123
// default settings
98-
asar: true,
124+
asar: process.platform !== 'win32', // node-pty loading native modules versus asar :(
99125
overwrite: true,
100126

101127
// and finally, this is the reason we are here:

packages/builder/dist/electron/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
"license": "Apache-2.0",
1111
"devDependencies": {
1212
"debug": "4.1.1",
13-
"electron": "6.0.12",
14-
"electron-installer-debian": "2.0.1",
15-
"electron-installer-dmg": "3.0.0",
16-
"electron-packager": "14.0.6",
17-
"glob": "7.1.4",
13+
"electron": "6.1.5",
14+
"electron-packager": "14.1.1",
15+
"glob": "7.1.6",
1816
"minifier": "0.8.1"
17+
},
18+
"optionalDependencies": {
19+
"electron-installer-debian": "2.0.1",
20+
"electron-installer-dmg": "3.0.0"
1921
}
2022
}

0 commit comments

Comments
 (0)