Skip to content

Commit

Permalink
Merge branch 'master' into sd/initialization-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Sep 3, 2024
2 parents 2256e50 + c06a9a4 commit bd16e4d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/asset-serving/asset-serving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include("http.jl")
Path to serve downloaded dependencies
"""
dependency_path(paths...) = joinpath(@__DIR__, "..", "..", "js_dependencies", paths...)
dependency_path(paths...) = @path joinpath(@__DIR__, "..", "..", "js_dependencies", paths...)

const BonitoLib = ES6Module(dependency_path("Bonito.js"))
const Websocket = ES6Module(dependency_path("Websocket.js"))
Expand Down
2 changes: 1 addition & 1 deletion src/asset-serving/asset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function Asset(path_or_url::Union{String,Path}; name=nothing, es6module=false, c
local_path = normalize_path(path_or_url; check_isfile=check_isfile)
end
_bundle_dir = isnothing(bundle_dir) ? dirname(local_path) : bundle_dir
return Asset(name, es6module, mediatype, real_online_path, local_path, _bundle_dir)
return Asset(name, es6module, mediatype, real_online_path, local_path, @path _bundle_dir)
end

function ES6Module(path)
Expand Down
8 changes: 6 additions & 2 deletions src/asset-serving/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ using .HTTPServer: has_route, get_route, route!

mutable struct HTTPAssetServer <: AbstractAssetServer
# Reference count the files/binary assets, so we can clean them up for child sessions
registered_files::Dict{String,Tuple{Set{UInt},Union{String, BinaryAsset}}}
registered_files::Dict{
String,Tuple{Set{UInt},Union{Path, String, BinaryAsset}}
}
server::Server
lock::ReentrantLock
end
Expand Down Expand Up @@ -63,7 +65,9 @@ function Base.close(server::ChildAssetServer)
end
end

serving_target(asset::Asset) = normpath(abspath(expanduser(local_path(asset))))
serving_target(path::Path) = path
serving_target(path::AbstractString) = normpath(abspath(expanduser(path)))
serving_target(asset::Asset) = serving_target(local_path(asset))
serving_target(asset::AbstractAsset) = asset

function refs_and_url(server, asset::AbstractAsset)
Expand Down
2 changes: 1 addition & 1 deletion src/interactive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ routes, task, server = interactive_server(Website.asset_paths()) do
)
end
# Once everything looks goo, export the static site
# Once everything looks good, export the static site
dir = joinpath(@__DIR__, "docs")
# only delete the bonito generated files
rm(joinpath(dir, "bonito"); recursive=true, force=true)
Expand Down
9 changes: 9 additions & 0 deletions test/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@
close(server)
Bonito.set_cleanup_time!(0.0)
end

using RelocatableFolders

@testset "Asset serving and Path" begin
asset = Asset(@path joinpath(@__DIR__, "serialization.jl"))
@test Bonito.serving_target(asset) isa RelocatableFolders.Path
@test isfile(Bonito.serving_target(asset))
@test read(Bonito.serving_target(asset)) isa Vector{UInt8}
end

0 comments on commit bd16e4d

Please sign in to comment.