client-side entry point works and also generates a correct url on the server

Former-commit-id: 272e52f55e44e998b9238e4173de37bfc6a05a94
This commit is contained in:
Jarred Sumner
2021-08-11 00:02:08 -07:00
parent 10b4b872a2
commit ca90126cc4
5 changed files with 346 additions and 34 deletions

View File

@@ -110,6 +110,34 @@ pub const Wundle = struct {
return ZigString.init(VirtualMachine.vm.main).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getRoutesDir(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
) js.JSValueRef {
if (!VirtualMachine.vm.bundler.options.routes.routes_enabled or VirtualMachine.vm.bundler.options.routes.dir.len > 0) {
return js.JSValueMakeUndefined(ctx);
}
return ZigString.init(VirtualMachine.vm.bundler.options.routes.dir).toValue(VirtualMachine.vm.global).asRef();
}
pub fn routeByName(
this: void,
ctx: js.JSContextRef,
thisObject: js.JSValueRef,
prop: js.JSStringRef,
exception: js.ExceptionRef,
) js.JSValueRef {
if (!VirtualMachine.vm.bundler.options.routes.routes_enabled) {
return js.JSValueMakeUndefined(ctx);
}
return ZigString.init(VirtualMachine.vm.bundler.options.routes.dir).toValue(VirtualMachine.vm.global).asRef();
}
pub fn getImportedStyles(
this: void,
ctx: js.JSContextRef,
@@ -181,6 +209,10 @@ pub const Wundle = struct {
.get = getOrigin,
.ts = d.ts{ .name = "origin", .@"return" = "string" },
},
.routesDir = .{
.get = getRoutesDir,
.ts = d.ts{ .name = "routesDir", .@"return" = "string" },
},
},
);
};
@@ -349,6 +381,7 @@ pub const VirtualMachine = struct {
0,
fd,
hash,
null,
) orelse {
return error.ParseError;
};