Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bun-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.14
1.4.2
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const runBuild = async (
let rendererDir: string | undefined;
const rendererConfig = config.renderer;
if (rendererConfig !== undefined) {
const rendererResult = await buildRenderer(process.cwd(), rendererConfig);
const rendererResult = await buildRenderer(process.cwd(), rendererConfig, 'production');
rendererDir = rendererResult.outDir;
out(`renderer built (${rendererResult.written.join(', ')})`);
}
Expand Down Expand Up @@ -432,7 +432,7 @@ const runDevCommand = async (command: Extract<Command, { kind: 'dev' }>): Promis
const rebuild = async (): Promise<void> => {
// A broken renderer edit must never take the dev loop down with it.
try {
const result = await buildRenderer(dir, rendererConfig);
const result = await buildRenderer(dir, rendererConfig, 'development');
log(`renderer rebuilt (${result.written.join(', ')})`);
} catch (error) {
err(error instanceof Error ? error.message : String(error));
Expand Down
23 changes: 15 additions & 8 deletions src/cli/renderer-build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* The renderer build Bunmaska owns (`config.renderer`). One recipe, deliberately:
* a classic IIFE bundle, because `loadFile` serves `file://` where an ES module
* fails the CORS null-origin check, built with `NODE_ENV=development` because
* Bun's bundler emits `jsxDEV` regardless of tsconfig and the production React
* runtime stubs it out. See .admin/RENDERER-BUILD.md for the derivation.
* fails the CORS null-origin check. `NODE_ENV` is defined per mode: `bunmaska dev`
* builds the development React runtime (warnings, jsxDEV), `bunmaska build` the
* production one. See .admin/RENDERER-BUILD.md for the derivation.
*/

import { cpSync, existsSync, mkdirSync } from 'node:fs';
Expand All @@ -20,17 +20,23 @@ export type RendererBuildResult = {
readonly written: readonly string[];
};

export type RendererMode = 'development' | 'production';

/** The bundler seam: builds `entry` into `outDir`, returns written file names. */
export type RendererBundler = (entry: string, outDir: string) => Promise<readonly string[]>;
export type RendererBundler = (
entry: string,
outDir: string,
mode: RendererMode,
) => Promise<readonly string[]>;

const defaultBundler: RendererBundler = async (entry, outDir) => {
const defaultBundler: RendererBundler = async (entry, outDir, mode) => {
const result = await Bun.build({
entrypoints: [entry],
outdir: outDir,
target: 'browser',
format: 'iife',
// Dev React: Bun transpiles JSX to jsxDEV; the prod runtime stubs it out.
define: { 'process.env.NODE_ENV': JSON.stringify('development') },
// The define picks the JSX runtime too: development emits jsxDEV, production jsx.
define: { 'process.env.NODE_ENV': JSON.stringify(mode) },
naming: '[dir]/[name].[ext]',
});
if (!result.success) {
Expand All @@ -48,6 +54,7 @@ const defaultBundler: RendererBundler = async (entry, outDir) => {
export const buildRenderer = async (
projectDir: string,
renderer: BunmaskaRendererConfig,
mode: RendererMode = 'production',
bundler: RendererBundler = defaultBundler,
): Promise<RendererBuildResult> => {
const entry = resolve(projectDir, renderer.entry);
Expand All @@ -56,7 +63,7 @@ export const buildRenderer = async (
}
const outDir = resolve(projectDir, rendererOutDir(renderer));
mkdirSync(outDir, { recursive: true });
const written = [...(await bundler(entry, outDir))];
const written = [...(await bundler(entry, outDir, mode))];
for (const relPath of renderer.copy ?? []) {
const from = resolve(projectDir, relPath);
if (!existsSync(from)) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/platform/dlopen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { dlopen as bunDlopen, type FFIFunction, type Library, type Pointer } from 'bun:ffi';

/**
* `dlopen` with pointer returns typed as `Pointer | null`. bun-types 1.4 widens a
* `FFIType.ptr` return to `Pointer | bigint | null`, but the runtime hands back a
* number (probed on Bun 1.4.2: `malloc` returns `typeof "number"`), and every
* backend already treats a pointer as one. Narrowing here keeps the `bigint`
* branch out of all the call sites. `u64` returns stay `bigint`.
*/
type NarrowReturn<R> = [R] extends [bigint]
? R
: [Pointer] extends [Extract<R, Pointer>]
? Exclude<R, bigint>
: R;

type NarrowSymbols<S> = {
[K in keyof S]: S[K] extends (...args: infer A) => infer R
? (...args: A) => NarrowReturn<R>
: S[K];
};

export type NarrowLibrary<Fns extends Record<string, FFIFunction>> = Omit<
Library<Fns>,
'symbols'
> & {
readonly symbols: NarrowSymbols<Library<Fns>['symbols']>;
};

export const dlopen = <Fns extends Record<string, FFIFunction>>(
path: string,
fns: Fns,
): NarrowLibrary<Fns> => bunDlopen(path, fns) as unknown as NarrowLibrary<Fns>;
3 changes: 2 additions & 1 deletion src/main/platform/linux/gdbus-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gdk-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gdk-pixbuf-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gio-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/glib-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gobject-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gtk-dialog-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gtk-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import { engineLibPath, prepareEngineForLoad, resolveEngine } from '../../engine/resolve';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/gtk-menu-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/jsc-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/libnotify-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/libsecret-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, type Pointer } from 'bun:ffi';
import { FFIType, type Pointer } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import { cstr } from '../cstr';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/soup-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import { engineLibPath, prepareEngineForLoad, resolveEngine } from '../../engine/resolve';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/webkitgtk-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CString, dlopen, FFIType, type Pointer } from 'bun:ffi';
import { CString, FFIType, type Pointer } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import { engineLibPath, prepareEngineForLoad, resolveEngine } from '../../engine/resolve';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/linux/x11-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/carbon-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { macOSLibraryAccessor } from './objc';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, JSCallback, type Pointer, ptr } from 'bun:ffi';
import { FFIType, JSCallback, type Pointer, ptr } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { cstr } from '../cstr';
import type { Handle } from './objc';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import { LIBOBJC_PATH } from './objc';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-msgsend-variants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { cstr } from '../cstr';
import { type Handle, LIBOBJC_PATH, macOSLibraryAccessor } from './objc';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-power-save-blocker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, ptr } from 'bun:ffi';
import { FFIType, ptr } from 'bun:ffi';
import { dlopen } from '../dlopen';
import type {
NativeBlocker,
PowerSaveBlockerBackend,
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-run-loop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { cstr } from '../cstr';
import { bigIntOut, LIBOBJC_PATH, macOSLibraryAccessor, ptrIn } from './objc';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-runtime-class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BunmaskaError } from '../../../common/errors';
import { dlopen, FFIType, JSCallback } from 'bun:ffi';
import { FFIType, JSCallback } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { cstr } from '../cstr';
import { cocoa } from './cocoa-runtime';
import { type Handle, LIBOBJC_PATH, macOSLibraryAccessor } from './objc';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-screen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, ptr } from 'bun:ffi';
import { FFIType, ptr } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { UnsupportedPlatformError } from '../../../common/errors';
import { currentPlatform } from '../../../common/platform';
import type { Point, RawDisplay, ScreenBackend } from '../../api/screen';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { nsString } from './cocoa-foundation';
import { msgSendPtr, msgSendPtrReturnsU8 } from './cocoa-msgsend-variants';
import { cocoa } from './cocoa-runtime';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/cocoa-window-bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* exactly Electron's `getBounds` contract, so no coordinate flip on reads.
*/

import { dlopen, FFIType, ptr } from 'bun:ffi';
import { FFIType, ptr } from 'bun:ffi';
import { dlopen } from '../dlopen';
import type { Rect } from '../native';
import { nsString } from './cocoa-foundation';
import { msgSendI64, msgSendPtr, msgSendReturnsI64 } from './cocoa-msgsend-variants';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/core-graphics-image-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { macOSLibraryAccessor } from './objc';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/macos/security-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, read } from 'bun:ffi';
import { FFIType, read } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { cstr } from '../cstr';
import { macOSLibraryAccessor } from './objc';

Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/webkit2-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType, ptr } from 'bun:ffi';
import { FFIType, ptr } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { FFIError } from '../../../common/errors';
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-crypt-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-dialog-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-gdiplus-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-registry-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-shcore-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-shell-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/platform/windows/win32-wts-ffi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dlopen, FFIType } from 'bun:ffi';
import { FFIType } from 'bun:ffi';
import { dlopen } from '../dlopen';
import { winLibraryAccessor } from './win32';

/**
Expand Down
Loading
Loading