Skip to content

Commit 0583678

Browse files
committed
Merge branch 'fix test hangs in __DEV__ mode'
* Branch commit log: ui/index.html: use __DEV__ flag for debug() function vite.config.ts: use version.json for __DEV__, enable proxy for DEVPORT_MKDOCS electron/Makefile.mk: add revdate and use __DEV__ flag for app/package.json Makefile.mk: introduce __DEV__ flag and shrink config.sh ui/b/app.js: call async_modal_dialog on Shell instead of this.shell
2 parents b6f1570 + b82bd2d commit 0583678

5 files changed

Lines changed: 17 additions & 19 deletions

File tree

Makefile.mk

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ override MODE != case "$(MODE)" in \
7979
.config.defaults += MODE
8080
$(info $S MODE $(MODE))
8181
.config.defaults += INSN
82+
__DEV__ := $(if $(filter production,$(MODE)),false,true)
8283

8384
# == Dirctories ==
8485
prefix ?= /usr/local
@@ -242,7 +243,7 @@ CLEANDIRS += $>/codegen/
242243
define PACKAGE_VERSIONS
243244
"version": "$(version_short)",
244245
"revdate": "$(version_date)",
245-
"mode": "$(MODE)"
246+
"__DEV__": $(__DEV__)
246247
endef
247248

248249
# == config.sh ==
@@ -251,9 +252,6 @@ $>/config.sh: $(wildcard config-defaults.mk) | $>/
251252
$Q echo 'srcdir="$(abspath .)"' > $@.tmp
252253
$Q echo 'outdir="$(abspath $>)"' >> $@.tmp
253254
$Q echo 'pkgdir="$(abspath $(pkgdir))"' >> $@.tmp
254-
$Q echo 'version="$(version_short)"' >> $@.tmp
255-
$Q echo 'revdate="$(version_date)"' >> $@.tmp
256-
$Q echo 'mode="$(MODE)"' >> $@.tmp
257255
$Q mv $@.tmp $@
258256
ALL_TARGETS += $>/config.sh
259257

electron/Makefile.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# ELECTRON_PKG_NAME determines the default name of app.getPath('appData')
44
ELECTRON_PKG_NAME := Anklang
55
ELECTRON_VERSION := $(version_short)
6-
ELECTRON_DEV := false
6+
ELECTRON_REVDATE := $(version_date)
7+
ELECTRON_DEV := $(__DEV__)
78
ELECTRON_SOURCES := electron/main.js electron/sourcemapping.js electron/preload.js electron/htmlgui.svg
89
ELECTRON_DEPS := node_modules/.npm.done
910
ELECTRON_INSTALLDIR := $(pkgdir)/electron
@@ -23,6 +24,7 @@ $>/electron/htmlgui: electron/Makefile.mk $(ELECTRON_SOURCES) $(ELECTRON_DEPS)
2324
$Q echo '{ "private": true,' > $(@D)/resources/app/package.json
2425
$Q echo ' "name": "$(ELECTRON_PKG_NAME)",' >> $(@D)/resources/app/package.json
2526
$Q echo ' "version": "$(ELECTRON_VERSION)",' >> $(@D)/resources/app/package.json
27+
$Q echo ' "revdate": "$(ELECTRON_REVDATE)",' >> $(@D)/resources/app/package.json
2628
$Q echo ' "__DEV__": "$(ELECTRON_DEV)",' >> $(@D)/resources/app/package.json
2729
$Q echo ' "main": "main.js" }' >> $(@D)/resources/app/package.json
2830
$Q chmod g-w -R $>/electron/

ui/b/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class AppClass {
197197
buttons,
198198
emblem,
199199
};
200-
return this.shell.async_modal_dialog (dialog_setup);
200+
return Shell.async_modal_dialog (dialog_setup);
201201
}
202202
zmoves_add = Mouse.zmove_add;
203203
zmove = Mouse.zmove_trigger;

ui/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Object.defineProperty (globalThis, '_', { value: t9n => t9n });
2727
Object.defineProperty (globalThis, 'CONFIG', { value: __VITE_CONFIG__ });
2828
Object.defineProperty (globalThis, '__DEV__', { value: !!CONFIG.__DEV__ });
29-
Object.defineProperty (globalThis, 'debug', { value: CONFIG.mode != "production" ? console.log : () => undefined });
29+
Object.defineProperty (globalThis, 'debug', { value: CONFIG.__DEV__ ? console.log : () => undefined });
3030
Object.defineProperty (globalThis, 'assert', { value: console.assert });
3131
Object.defineProperty (globalThis, 'Extra_css', { value: () => undefined });
3232
Object.defineProperty (document, 'skipViewTransition', { value: func => func() });

vite.config.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,30 @@ import extra_css from './ui/extra-css';
1818
import stylelint from 'stylelint';
1919
import stylelintrc from './ui/stylelintrc.cjs';
2020
import postcssReporter from "postcss-reporter";
21-
2221
const BUILDDIR = path.resolve (process.env.BUILDDIR || 'out/');
2322
const gen_path = path.resolve (BUILDDIR + "/gen/");
23+
const __VITE_CONFIG__ = JSON.parse (fs.readFileSync (path.resolve (BUILDDIR + "/version.json"), 'utf8'));
24+
const __DEV__ = __VITE_CONFIG__.__DEV__;
2425
// Note: For development, ports are hard coded, synchronize port numbers with serve.sh
25-
const DEVPORT_ANKLANG = process.env.DEVPORT_ANKLANG || 1776;
2626
const DEVPORT_VITE = process.env.DEVPORT_VITE || 1777;
27-
const DEVPORT_MKDOCS = process.env.DEVPORT_MKDOCS || 1778;
27+
const DEVPORT_ANKLANG = process.env.DEVPORT_ANKLANG || 0;
28+
const DEVPORT_MKDOCS = process.env.DEVPORT_MKDOCS || 0;
2829

2930
// Debug Info:
3031
console.log (`VITE: CWD=${process.cwd()} BUILDDIR=${BUILDDIR} gen_path=${gen_path}`);
3132

3233
// Plugin to inject __VITE_CONFIG__ into html
33-
const html_inject_vite_config = (__DEV__: Boolean) => {
34-
build_config_json.__DEV__ = __DEV__;
35-
if (__DEV__) {
36-
build_config_json.ws_port = DEVPORT_ANKLANG;
34+
const html_inject_vite_config = () => {
35+
if (__DEV__ && DEVPORT_ANKLANG) {
36+
__VITE_CONFIG__.ws_port = DEVPORT_ANKLANG;
3737
}
3838
return {
3939
name: 'html_inject_vite_config',
4040
transformIndexHtml (html, ctx) {
41-
return html.replace ('__VITE_CONFIG__', JSON.stringify (build_config_json));
41+
return html.replace ('__VITE_CONFIG__', JSON.stringify (__VITE_CONFIG__));
4242
},
4343
}
4444
};
45-
const build_config_json = JSON.parse (fs.readFileSync (path.resolve (BUILDDIR + "/version.json"), 'utf8'));
4645

4746
// Plugin to force full reloads if anything changed
4847
const full_reload_always: PluginOption = {
@@ -73,7 +72,6 @@ function postcss_formatter (input)
7372
// Mode dependent vite config
7473
function vite_config ({ mode })
7574
{
76-
const __DEV__ = mode == 'development';
7775
console.log (`VITE: mode=${mode}`);
7876
return defineConfig ({
7977
root: "ui/",
@@ -84,7 +82,7 @@ function vite_config ({ mode })
8482
}, },
8583
server: {
8684
// open: "index.html",
87-
proxy: {
85+
proxy: !DEVPORT_MKDOCS ? {} : {
8886
'/anklang/': {
8987
target: 'http://localhost:' + String (DEVPORT_MKDOCS) + '/',
9088
changeOrigin: true, // Adjusts the origin header
@@ -130,7 +128,7 @@ function vite_config ({ mode })
130128
tailwindcss(),
131129
extra_css(),
132130
solidPlugin(),
133-
html_inject_vite_config (__DEV__),
131+
html_inject_vite_config(),
134132
...maybe_full_reload_always,
135133
],
136134

0 commit comments

Comments
 (0)