Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/clients/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Build artifacts
*.js
*.js.map
*.d.ts
*.d.ts.map

# Keep specific files
!fix-imports.js

# Dependencies
node_modules/
41 changes: 32 additions & 9 deletions src/clients/deno/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
# @justbe/webview Deno Client
# @justbe/webview

A light, cross-platform library for building web-based desktop apps with
[Deno](https://deno.com/).
A light, cross-platform library for building web-based desktop apps. This package provides a universal client that is compatible with Deno, Node.js, and Bun.

## Compatibility

- ✅ **Node.js** 18+ (fully supported)
- ✅ **Deno** (original implementation, fully supported)
- ⚠️ **Bun** (limited support - older versions may have issues)

## Installation

### Node.js
```bash
npm install @justbe/webview
```

### Deno
```typescript
import { createWebView } from "jsr:@justbe/webview";
```

### Bun
```bash
bun install @justbe/webview
```

## Example

```typescript
import { createWebView } from "jsr:@justbe/webview";
import { createWebView } from "@justbe/webview";

using webview = await createWebView({
title: "Example",
html: "<h1>Hello, World!</h1>",
load: { html: "<h1>Hello, World!</h1>" },
devtools: true,
});

Expand All @@ -28,10 +44,17 @@ webview.on("started", async () => {
await webview.waitUntilClosed();
```

You can run this yourself with:
### Running Examples

**Node.js:**
```bash
npm run build
node examples/simple.js
```

```sh
deno run https://raw.githubusercontent.com/zephraph/webview/refs/heads/main/examples/simple.ts
**Deno:**
```bash
deno run --allow-all examples/simple.ts
```

Check out the [examples directory](examples/) for more examples.
Expand Down Expand Up @@ -76,4 +99,4 @@ process. In this case, only one permission is needed:

Note that this environment variable will never be _explicitly_ requested. If the
script detects it's not allowed to read this env var it just skips this code
path altogether.
path altogether.
17 changes: 0 additions & 17 deletions src/clients/deno/deno.json

This file was deleted.

83 changes: 0 additions & 83 deletions src/clients/deno/deno.lock

This file was deleted.

2 changes: 1 addition & 1 deletion src/clients/deno/examples/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebView } from "../main.ts";
import { createWebView } from "../main";

using webview = await createWebView({
title: "Simple",
Expand Down
2 changes: 1 addition & 1 deletion src/clients/deno/examples/load-html.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebView } from "../main.ts";
import { createWebView } from "../main";

using webview = await createWebView({
title: "Load Html Example",
Expand Down
2 changes: 1 addition & 1 deletion src/clients/deno/examples/load-url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebView } from "../main.ts";
import { createWebView } from "../main";

using webview = await createWebView({
title: "Load Url Example",
Expand Down
2 changes: 1 addition & 1 deletion src/clients/deno/examples/simple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebView } from "../main.ts";
import { createWebView } from "../main";

using webview = await createWebView({
title: "Simple",
Expand Down
16 changes: 6 additions & 10 deletions src/clients/deno/examples/tldraw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createWebView } from "../main.ts";
import * as esbuild from "https://deno.land/x/[email protected]/wasm.js";
import { createWebView } from "../main";

// Note: This example has been simplified for Node.js compatibility
// For full functionality, you'll need to use a bundler like esbuild, webpack, or vite

const tldrawApp = `
import { Tldraw } from "tldraw";
Expand All @@ -18,14 +20,8 @@ function App() {
createRoot(document.querySelector("main")).render(<App />);
`;

const app = await esbuild.transform(tldrawApp, {
loader: "jsx",
jsx: "automatic",
target: "esnext",
format: "esm",
minify: false,
sourcemap: false,
});
// Pre-compiled version for demo purposes
const app = { code: tldrawApp.replace(/<App \/>/g, 'React.createElement(App)') };

using webview = await createWebView({
title: "TLDraw",
Expand Down
2 changes: 1 addition & 1 deletion src/clients/deno/examples/window-size.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createWebView } from "../main.ts";
import { createWebView } from "../main";

using webview = await createWebView({
title: "Window Size",
Expand Down
56 changes: 56 additions & 0 deletions src/clients/deno/fix-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node

import { readFileSync, writeFileSync } from 'node:fs';
import { glob } from 'glob';

/**
* Post-build script to add .js extensions to local imports in compiled JavaScript files
* This allows extensionless imports in TypeScript source while generating Node.js-compatible output
*/

async function fixImports() {
// Find all JavaScript files
const jsFiles = await glob('**/*.js', {
ignore: ['node_modules/**', 'fix-imports.js']
});

for (const file of jsFiles) {
let content = readFileSync(file, 'utf8');
let modified = false;

// Fix relative imports without extensions (add .js)
// Matches: import ... from "./something" or "../something"
// Doesn't match: import ... from "package-name" or "./something.js"
content = content.replace(
/import\s+([^'"]*)\s+from\s+['"](\.[^'"]*?)['"];?/g,
(match, imports, path) => {
// Only add .js if the path doesn't already have an extension
if (!path.match(/\.[a-zA-Z0-9]+$/)) {
modified = true;
return `import ${imports} from '${path}.js';`;
}
return match;
}
);

// Fix export ... from statements
content = content.replace(
/export\s+([^'"]*)\s+from\s+['"](\.[^'"]*?)['"];?/g,
(match, exports, path) => {
// Only add .js if the path doesn't already have an extension
if (!path.match(/\.[a-zA-Z0-9]+$/)) {
modified = true;
return `export ${exports} from '${path}.js';`;
}
return match;
}
);

if (modified) {
writeFileSync(file, content, 'utf8');
console.log(`Fixed imports in: ${file}`);
}
}
}

fixImports().catch(console.error);
Loading
Loading