Skip to content

Commit

Permalink
tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
paperclover committed Feb 6, 2025
1 parent 8f1e521 commit 4bf972c
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 214 deletions.
9 changes: 6 additions & 3 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5309,7 +5309,10 @@ declare module "bun" {

interface PluginBuilder {
/**
* Register a callback which will be invoked when bundling starts.
* Register a callback which will be invoked when bundling starts. When
* using hot module reloading, this is called at the start of each
* incremental rebuild.
*
* @example
* ```ts
* Bun.plugin({
Expand Down Expand Up @@ -5406,9 +5409,9 @@ declare module "bun" {
* - `browser`: The plugin will be applied to browser builds
* - `node`: The plugin will be applied to Node.js builds
*
* If in Bun's runtime, the default target is `bun`.
* If unspecified, it is assumed that the plugin is compatible with all targets.
*
* If unspecified, it is assumed that the plugin is compatible with the default target.
* This field is not read by Bun.plugin
*/
target?: Target;
/**
Expand Down
398 changes: 290 additions & 108 deletions src/bake/DevServer.zig

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions src/bake/hmr-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ if (side === "server") {
};
}

const enumerableEntries = ["id", "exports", "require"];
for (const k in HotModule.prototype) {
if (!enumerableEntries.includes(k)) {
const descriptor = Object.getOwnPropertyDescriptor(HotModule.prototype, k);
if (descriptor) {
Object.defineProperty(HotModule.prototype, k, { ...descriptor, enumerable: false });
}
}
}

function initImportMeta(m: HotModule): ImportMeta {
return {
url: `bun://${m.id}`,
Expand All @@ -118,25 +128,25 @@ type HotDisposeFunction = (data: any) => void;
type HotEventHandler = (data: any) => void;

class Hot {
private _module: HotModule;
#module: HotModule;

data = {};

constructor(module: HotModule) {
this._module = module;
this.#module = module;
}

accept(
arg1: string | readonly string[] | HotAcceptFunction,
arg2: HotAcceptFunction | HotArrayAcceptFunction | undefined,
) {
console.warn("TODO: implement ImportMetaHot.accept (called from " + JSON.stringify(this._module.id) + ")");
console.warn("TODO: implement ImportMetaHot.accept (called from " + JSON.stringify(this.#module.id) + ")");
}

decline() {} // Vite: "This is currently a noop and is there for backward compatibility"

dispose(cb: HotDisposeFunction) {
(this._module._onDispose ??= []).push(cb);
(this.#module._onDispose ??= []).push(cb);
}

prune(cb: HotDisposeFunction) {
Expand Down
13 changes: 11 additions & 2 deletions src/bake/hmr-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,17 @@ const ws = initWebSocket({
// JavaScript modules
if (reader.hasMoreData()) {
const code = td.decode(reader.rest());
const modules = (0, eval)(code);
replaceModules(modules);
try {
const modules = (0, eval)(code);
replaceModules(modules);
} catch (e) {
if (IS_BUN_DEVELOPMENT) {
console.error(e, "Failed to parse HMR payload", { code });
onRuntimeError(e, RuntimeErrorType.fatal);
return;
}
throw e;
}
}
if (isServerSideRouteUpdate) {
performRouteReload();
Expand Down
3 changes: 2 additions & 1 deletion src/bake/hmr-runtime-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare const error: Uint8Array<ArrayBuffer>;
let firstVersionPacket = true;
let currentRouteIndex = -1;

initWebSocket({
const ws = initWebSocket({
[MessageId.version](dv) {
if (firstVersionPacket) {
firstVersionPacket = false;
Expand All @@ -35,6 +35,7 @@ initWebSocket({
// ensure this bundle is enqueued.
location.reload();
}
ws.send("se"); // IncomingMessageId.subscribe with route_update
},

[MessageId.errors]: onErrorMessage,
Expand Down
32 changes: 16 additions & 16 deletions src/bun.js/api/bun/dns_resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1781,22 +1781,22 @@ pub const DNSResolver = struct {
.tag = .DNSResolver,
},

pending_host_cache_cares: PendingCache = PendingCache.init(),
pending_host_cache_native: PendingCache = PendingCache.init(),
pending_srv_cache_cares: SrvPendingCache = SrvPendingCache.init(),
pending_soa_cache_cares: SoaPendingCache = SoaPendingCache.init(),
pending_txt_cache_cares: TxtPendingCache = TxtPendingCache.init(),
pending_naptr_cache_cares: NaptrPendingCache = NaptrPendingCache.init(),
pending_mx_cache_cares: MxPendingCache = MxPendingCache.init(),
pending_caa_cache_cares: CaaPendingCache = CaaPendingCache.init(),
pending_ns_cache_cares: NSPendingCache = NSPendingCache.init(),
pending_ptr_cache_cares: PtrPendingCache = PtrPendingCache.init(),
pending_cname_cache_cares: CnamePendingCache = CnamePendingCache.init(),
pending_a_cache_cares: APendingCache = APendingCache.init(),
pending_aaaa_cache_cares: AAAAPendingCache = AAAAPendingCache.init(),
pending_any_cache_cares: AnyPendingCache = AnyPendingCache.init(),
pending_addr_cache_cares: AddrPendingCache = AddrPendingCache.init(),
pending_nameinfo_cache_cares: NameInfoPendingCache = NameInfoPendingCache.init(),
pending_host_cache_cares: PendingCache = .empty,
pending_host_cache_native: PendingCache = .empty,
pending_srv_cache_cares: SrvPendingCache = .empty,
pending_soa_cache_cares: SoaPendingCache = .empty,
pending_txt_cache_cares: TxtPendingCache = .empty,
pending_naptr_cache_cares: NaptrPendingCache = .empty,
pending_mx_cache_cares: MxPendingCache = .empty,
pending_caa_cache_cares: CaaPendingCache = .empty,
pending_ns_cache_cares: NSPendingCache = .empty,
pending_ptr_cache_cares: PtrPendingCache = .empty,
pending_cname_cache_cares: CnamePendingCache = .empty,
pending_a_cache_cares: APendingCache = .empty,
pending_aaaa_cache_cares: AAAAPendingCache = .empty,
pending_any_cache_cares: AnyPendingCache = .empty,
pending_addr_cache_cares: AddrPendingCache = .empty,
pending_nameinfo_cache_cares: NameInfoPendingCache = .empty,

pub usingnamespace JSC.Codegen.JSDNSResolver;
pub usingnamespace bun.NewRefCounted(@This(), deinit, null);
Expand Down
5 changes: 4 additions & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7461,6 +7461,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
}

fn setRoutes(this: *ThisServer) void {
// TODO: move devserver and plugin logic away
const app = this.app.?;
const any_server = AnyServer.from(this);
const dev_server = this.dev_server;
Expand Down Expand Up @@ -7497,7 +7498,9 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
// an unqueued state. The first thing (HTML Bundle, DevServer)
// that needs plugins will cause the load to happen.
if (needs_plugins and this.plugins == null) if (this.vm.transpiler.options.serve_plugins) |serve_plugins| {
this.plugins = ServePlugins.init(serve_plugins);
if (serve_plugins.len > 0) {
this.plugins = ServePlugins.init(serve_plugins);
}
};

// Setup user websocket routes.
Expand Down
2 changes: 1 addition & 1 deletion src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4023,7 +4023,7 @@ pub fn GenericIndex(backing_int: type, uid: anytype) type {
return @enumFromInt(int);
}

/// Prefer this over @intFromEnum because of type confusion with `.optional`
/// Prefer this over @intFromEnum because of type confusion with `.Optional`
pub inline fn get(i: @This()) backing_int {
bun.assert(@intFromEnum(i) != null_value); // memory corruption
return @intFromEnum(i);
Expand Down
Loading

0 comments on commit 4bf972c

Please sign in to comment.