Skip to content

Commit

Permalink
fix: remove ancient non-KUI_HEADLESS_WEBPACK support
Browse files Browse the repository at this point in the history
This was from before we used webpack to build the headless bundles.

BREAKING CHANGE: this removes all support for running kui from non-webpack headless
  • Loading branch information
starpit committed Sep 4, 2022
1 parent 1299d32 commit 0dbbc3e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 73 deletions.
4 changes: 0 additions & 4 deletions bin/kubectl-kui
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export KUI_POPUP_WINDOW_RESIZE=true
export NODE_NO_WARNINGS=1
export NODE_OPTIONS="--no-warnings"

# This tells the core Kui plugin resolver that we are using webpack to
# build our headless bundles, not the old headless hacks.
export KUI_HEADLESS_WEBPACK=true

SCRIPTDIR=$(cd $(dirname "$0") && pwd)

if [ -f "${SCRIPTDIR}"/../node_modules/electron/dist/Electron.app/Contents/MacOS/Electron ]; then
Expand Down
4 changes: 0 additions & 4 deletions bin/kui
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
export NODE_NO_WARNINGS=1
export NODE_OPTIONS="--no-warnings"

# This tells the core Kui plugin resolver that we are using webpack to
# build our headless bundles, not the old headless hacks
export KUI_HEADLESS_WEBPACK=true

SCRIPTDIR=$(cd $(dirname "$0") && pwd)

if [ -f "${SCRIPTDIR}"/../node_modules/electron/dist/Electron.app/Contents/MacOS/Electron ]; then
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
"test3": "PORT_OFFSET=2 npm run test",
"test4": "PORT_OFFSET=3 npm run test",
"test5": "PORT_OFFSET=4 npm run test",
"build:electron:mac:amd64": "KUI_HEADLESS_WEBPACK=true PLATFORM=mac ARCH=x64 kui-build-electron",
"build:electron:mac:arm64": "KUI_HEADLESS_WEBPACK=true PLATFORM=mac ARCH=arm64 kui-build-electron",
"build:electron:osx:amd64": "KUI_HEADLESS_WEBPACK=true npm run build:electron:mac:amd64",
"build:electron:osx:arm64": "KUI_HEADLESS_WEBPACK=true npm run build:electron:mac:arm64",
"build:electron:linux:amd64": "KUI_HEADLESS_WEBPACK=true PLATFORM=linux ARCH=x64 kui-build-electron",
"build:electron:linux:arm64": "KUI_HEADLESS_WEBPACK=true PLATFORM=linux ARCH=arm64 kui-build-electron",
"build:electron:win32:amd64": "KUI_HEADLESS_WEBPACK=true PLATFORM=win32 ARCH=x64 kui-build-electron",
"build:electron:windows:amd64": "KUI_HEADLESS_WEBPACK=true PLATFORM=win32 ARCH=x64 kui-build-electron",
"build:electron:all": "KUI_HEADLESS_WEBPACK=true kui-build-electron",
"build:electron:mac:amd64": "PLATFORM=mac ARCH=x64 kui-build-electron",
"build:electron:mac:arm64": "PLATFORM=mac ARCH=arm64 kui-build-electron",
"build:electron:osx:amd64": "npm run build:electron:mac:amd64",
"build:electron:osx:arm64": "npm run build:electron:mac:arm64",
"build:electron:linux:amd64": "PLATFORM=linux ARCH=x64 kui-build-electron",
"build:electron:linux:arm64": "PLATFORM=linux ARCH=arm64 kui-build-electron",
"build:electron:win32:amd64": "PLATFORM=win32 ARCH=x64 kui-build-electron",
"build:electron:windows:amd64": "PLATFORM=win32 ARCH=x64 kui-build-electron",
"build:electron:all": "kui-build-electron",
"_kill": "if [ -f /tmp/kuiwatch-$T.pid ]; then PID=$(cat /tmp/kuiwatch-$T.pid); if [ -n \"$PID\" ]; then kill $PID > /dev/null 2> /dev/null || true; fi; fi",
"kill": "T=client npm run _kill; T=headless npm run _kill",
"kill:proxy": "if [ -f /tmp/kuiproxy.pid ]; then PID=$(cat /tmp/kuiproxy.pid); if [ -n \"$PID\" ]; then kill $PID > /dev/null 2> /dev/null || true; fi; rm -f /tmp/kuiproxy.pid; fi",
"kill:cproxy": "kill $(lsof -t -i:9081) > /dev/null 2> /dev/null || true",
"_watch": "bash -c \"npm run kill; export CSP_ALLOWED_HOSTS='http: https: data: filesystem: about: blob: ws: wss:'; kui-watch-webpack\"",
"watch:webpack": "bash -c \"npm run kill; npm run pty:nodejs && KUI_HEADLESS_WEBPACK=true npm run _watch $WATCH_ARGS\"",
"watch:electron": "bash -c \"npm run pty:electron && KUI_HEADLESS_WEBPACK=true TARGET=electron-renderer npm run _watch\"",
"watch:webpack": "bash -c \"npm run kill; npm run pty:nodejs && npm run _watch $WATCH_ARGS\"",
"watch:electron": "bash -c \"npm run pty:electron && TARGET=electron-renderer npm run _watch\"",
"watch": "bash -c \"npm run kill; npm run compile && npm run link && concurrently -n ES6,WEBPACK --kill-others 'npm run watch:source' 'npm run watch:electron'\"",
"proxy": "export PORT=8081; npm run kill:proxy; export KUI_USE_HTTP=true; cd packages/proxy/app && npm install && ../../../tools/travis/proxy.sh ../../..",
"watch:source": "tsc --build tsconfig.json --watch",
Expand Down
1 change: 0 additions & 1 deletion packages/builder/dist/electron/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export BUILDER_HOME="$CLIENT_HOME"/node_modules/@kui-shell/builder
MODULE_HOME="$CLIENT_HOME"/node_modules/@kui-shell
export BUILDDIR="$CLIENT_HOME"/dist/electron
export HEADLESS_BUILDDIR="$CLIENT_HOME"/dist/headless
export KUI_HEADLESS_WEBPACK

#
# client version; note rcedit.exe fails if the VERSION is "dev"
Expand Down
50 changes: 23 additions & 27 deletions packages/builder/dist/electron/builders/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,24 @@ async function buildWebpack(buildPath, electronVersion, targetPlatform, targetAr
KUI_BUILDER_HOME: `${CLIENT_HOME}/node_modules/@kui-shell/builder`
})

if (process.env.KUI_HEADLESS_WEBPACK) {
console.log('Building headless bundles via webpack')
asyncs.push(
new Promise((resolve, reject) => {
exec(
`npx --no-install webpack-cli --mode=production --config "${CLIENT_HOME}/node_modules/@kui-shell/webpack/headless-webpack.config.js"`,
{ env },
(err, stdout, stderr) => {
console.log('stdout', stdout)
if (err) {
console.error(err)
reject(stderr)
} else {
resolve()
}
console.log('Building headless bundles via webpack')
asyncs.push(
new Promise((resolve, reject) => {
exec(
`npx --no-install webpack-cli --mode=production --config "${CLIENT_HOME}/node_modules/@kui-shell/webpack/headless-webpack.config.js"`,
{ env },
(err, stdout, stderr) => {
console.log('stdout', stdout)
if (err) {
console.error(err)
reject(stderr)
} else {
resolve()
}
)
})
)
}
}
)
})
)

console.log('Building electron bundles via webpack')
asyncs.push(
Expand Down Expand Up @@ -215,14 +213,12 @@ async function copySignableBits(buildPath, electronVersion, targetPlatform, targ
// NO!!! TODO find a better way to remove kubect-kui await remove(source)
}

// copy in the headless build?
if (process.env.KUI_HEADLESS_WEBPACK) {
const source = process.env.HEADLESS_BUILDDIR
const target = join(buildPath, 'dist', basename(source)) // e.g. buildPath is Contents/Resources/app on macOS
console.log(`Copying in headless build for ${targetPlatform} ${targetArch} to ${target}`)
await emptyDir(target)
await copy(source, target)
}
// copy in the headless build
const source = process.env.HEADLESS_BUILDDIR
const target = join(buildPath, 'dist', basename(source)) // e.g. buildPath is Contents/Resources/app on macOS
console.log(`Copying in headless build for ${targetPlatform} ${targetArch} to ${target}`)
await emptyDir(target)
await copy(source, target)
}
/**
* Use electron-packager to create the application package
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/plugins/preloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ debug('loading')
import { PrescanModel } from './prescan'

import { Tab } from '../webapp/tab'
import { mainPath, webpackPath } from './path'
import { isHeadless } from '../core/capabilities'
import { webpackPath } from './path'
import { MetadataBearing } from '../models/entity'
import { ImplForPlugins } from '../core/command-tree'
import { registerSidecarBadge as registerBadge, BadgeRegistration } from '../webapp/views/registrar/badges'
Expand Down Expand Up @@ -77,8 +76,6 @@ export default async (prescan: PrescanModel) => {
const registrationRef =
module.path.charAt(0) === '/'
? await import(/* webpackIgnore: true */ module.path)
: isHeadless() && !process.env.KUI_HEADLESS_WEBPACK
? await import(/* webpackIgnore: true */ mainPath(module.path))
: module.route === 'client'
? require('@kui-shell/client/' + 'mdist/preload')
: await import('@kui-shell/plugin-' + webpackPath(module.route) + '/mdist/preload')
Expand Down Expand Up @@ -118,8 +115,6 @@ export default async (prescan: PrescanModel) => {
const registrationRef =
module.path.charAt(0) === '/'
? await import(/* webpackIgnore: true */ module.path)
: isHeadless() && !process.env.KUI_HEADLESS_WEBPACK
? await import(/* webpackIgnore: true */ mainPath(module.path))
: module.route === 'client'
? require(/* webpackMode: "lazy" */ '@kui-shell/client/' + 'mdist/preload')
: await import(
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/plugins/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ import Debug from 'debug'

import { PrescanModel } from './prescan'

import { mainPath, webpackPath } from './path'
import { webpackPath } from './path'
import { proxy } from '../core/command-tree'
import { CommandBase } from '../models/command'
import { isHeadless } from '../core/capabilities'
import { KuiPlugin, PluginRegistration } from '../models/plugin'

const debug = Debug('core/plugins/resolver')
Expand Down Expand Up @@ -81,8 +80,6 @@ const prequire = async (
const registrationRef =
module.path.charAt(0) === '/'
? await import(/* webpackIgnore: true */ module.path)
: isHeadless() && !process.env.KUI_HEADLESS_WEBPACK
? await import(/* webpackIgnore: true */ mainPath(module.path))
: module.route === 'client'
? await import('@kui-shell/clien' + webpackPath(module.route).slice(5) + '/mdist/plugin')
: await import('@kui-shell/plugin-' + webpackPath(module.route) + '/mdist/plugin')
Expand Down
1 change: 0 additions & 1 deletion packages/proxy/app/routes/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ function main(cmdline, execOptions, server, port, hostname, existingSession, loc
SHELL: execOptions.env.SHELL || process.env.SHELL,
KUBECONFIG: process.env.KUBECONFIG,
KUI_HEADLESS: true,
KUI_HEADLESS_WEBPACK: true,
KUI_REPL_MODE: 'stdout',
KUI_EXEC_OPTIONS: JSON.stringify(execOptions)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function kubeconfig {
function webpack {
echo "Building webpack bundles"
rm -rf "$BUILDDIR"/*
KUI_PROXY_WEBPACK=true KUI_HEADLESS_WEBPACK=true npx kui-build-webpack
KUI_PROXY_WEBPACK=true npx kui-build-webpack
}

function nginx {
Expand Down
18 changes: 8 additions & 10 deletions packages/webpack/bin/watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,15 @@ else
rm -f $LOCKFILE
fi

if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
echo "Watching Kui Headless bundles via webpack"
if [ -n "$LOCKFILE" ]; then
LOCKFILE2=/tmp/kui-build-lock2.${PORT_OFFSET-0}
rm -f $LOCKFILE2
fi

LOCKFILE=$LOCKFILE2 npx --no-install webpack watch --progress --config "$HEADLESS_CONFIG" &
echo $! > /tmp/kuiwatch-headless.pid
echo "Watching Kui Headless bundles via webpack"
if [ -n "$LOCKFILE" ]; then
LOCKFILE2=/tmp/kui-build-lock2.${PORT_OFFSET-0}
rm -f $LOCKFILE2
fi

LOCKFILE=$LOCKFILE2 npx --no-install webpack watch --progress --config "$HEADLESS_CONFIG" &
echo $! > /tmp/kuiwatch-headless.pid

echo "Watching Kui Client bundles via webpack"
LOCKFILE=$LOCKFILE npx --no-install webpack serve --progress --config "$CONFIG" $OPEN &
echo $! > /tmp/kuiwatch-client.pid
Expand All @@ -92,7 +90,7 @@ elif [ "$WATCH_ARGS" = "wait" ]; then
wait
fi

if [ -n "$KUI_HEADLESS_WEBPACK" ] && [ "$TARGET" != "electron-renderer" ]; then
if [ "$TARGET" != "electron-renderer" ]; then
npm run proxy &

if [ -z "$RUNNING_KUI_TEST" ]; then
Expand Down
6 changes: 2 additions & 4 deletions packages/webpack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ function webpack {
pushd "$STAGING" > /dev/null
rm -f "$BUILDDIR"/*.js*

if [ -n "$KUI_HEADLESS_WEBPACK" ]; then
echo "Buildinging Kui Headless bundles via webpack"
NEEDS_KUI_PROXY=true npx --no-install webpack-cli --config ./node_modules/@kui-shell/webpack/headless-webpack.config.js --mode=$MODE &
fi
echo "Buildinging Kui Headless bundles via webpack"
NEEDS_KUI_PROXY=true npx --no-install webpack-cli --config ./node_modules/@kui-shell/webpack/headless-webpack.config.js --mode=$MODE &

echo "Building Kui Client bundles via webpack"
npx --no-install webpack-cli --config ./node_modules/@kui-shell/webpack/webpack.config.js --mode $MODE
Expand Down

0 comments on commit 0dbbc3e

Please sign in to comment.