A custom plugin for Bun that enables importing modules from HTTP/HTTPS URLs, similar to Deno's approach. This plugin automatically detects the appropriate loader based on file extensions and supports TypeScript, JavaScript, and JSX files.
✅ Import from URLs: Support for importing modules from HTTP and HTTPS URLs
✅ Auto Loader Detection: Automatically selects the correct loader based on file extension
✅ TypeScript Support: Native support for .ts, .tsx, and .mts files
✅ JavaScript Support: Compatible with .js, .jsx, and .mjs files
✅ Relative & Absolute Paths: Supports relative (./, ../) and absolute (/) path resolution from URL imports
✅ Bun Integration: Works seamlessly with bun build and bun run
mew install buniAfter installing globally, you can use the buni command directly:
# Run a local TypeScript file with HTTP imports
buni main.ts
# Run a remote script directly from URL
buni https://example.com/cli.ts --option1 --flag2
# Build with HTTP imports support
buni build main.ts --outdir ./dist
# Pass any Bun arguments
buni --watch main.ts
buni testRemote Script Execution: The CLI automatically detects URLs (starting with http:// or https://) and downloads them to a temporary file before execution. This allows you to run scripts directly from the internet with HTTP imports support.
Use the plugin with Bun's --preload flag:
bun --preload ./index.js main.tsWith CLI:
# Install globally first
mew install buni
# Run local files
buni main.ts
# Run remote scripts directly
buni https://deno.land/std@0.200.0/examples/chat/server.ts --port 8080Manual:
bun --preload ./index.js main.ts// Import from a TypeScript file
import { helper } from "https://example.com/utils.ts";
// Import from a JavaScript module
import { api } from "https://cdn.skypack.dev/some-package";
// Relative imports work too (when importing from URL modules)
import { config } from "./config.ts";
import { types } from "../types/index.ts";# Build your project with HTTP imports support
bun --preload ./index.js build main.ts --outdir ./distThe plugin implements three main resolve handlers:
- Relative Path Resolution (
./,../): When importing from an HTTP module, resolves relative paths against the base URL - Absolute Path Resolution (
/): Resolves absolute paths against the origin of the HTTP module - Direct HTTP URLs: Handles direct HTTP/HTTPS imports
The plugin automatically selects the appropriate loader based on file extensions:
| Extension | Loader |
|---|---|
.ts, .mts |
ts |
.tsx |
tsx |
.js, .mjs |
js |
.jsx |
jsx |
| default | js |
buni/
├── index.js # Your main entry file
├── buni # Entrypoint
└── package.json
main.ts:
// Import from remote TypeScript module
import { createServer } from "https://deno.land/std@0.200.0/http/server.ts";
import { serve } from "https://deno.land/std@0.200.0/http/mod.ts";
console.log("Server created with remote imports!");Run the project:
bun --preload ./index.js main.tsThe plugin works out of the box with no configuration needed. It registers itself as a Bun plugin with the following settings:
- Name:
http_imports - Supported Protocols: HTTP and HTTPS
- File Extensions: All common web file types (
.ts,.tsx,.js,.jsx,.mjs,.mts)
| Feature | Buni Plugin | Deno |
|---|---|---|
| HTTP/HTTPS imports | ✅ | ✅ |
| TypeScript support | ✅ | ✅ |
| Auto loader detection | ✅ | ✅ |
| Relative path resolution | ✅ | ✅ |
| Build integration | ✅ (via Bun) | ✅ |
| Runtime | Bun | Deno |
The plugin includes robust error handling:
- Network Errors: Failed HTTP requests are properly reported with context
- Invalid URLs: Malformed URLs are caught and reported
- Missing Files: 404 errors include the failed URL for debugging
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by Deno's HTTP import system
- Built for the Bun runtime and ecosystem
- Thanks to the Bun team for the excellent plugin API