Skip to content

Commit 557c4a0

Browse files
committed
Merge upstream into branch.
2 parents c009505 + 6f8bfb1 commit 557c4a0

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

src/imports.jl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,57 @@ struct Sync
55
end
66

77
function islocal(x)
8-
!any(startswith.((x,), ["//", "https://", "http://", "ftp://"]))
8+
!any(startswith.(x, ("//", "https://", "http://", "ftp://")))
99
end
1010

11-
function lowerdeps(name, imp)
12-
query_parts = split(imp, "?") # remove anything after ?
13-
imp_path = query_parts[1]
14-
15-
if startswith(imp_path, "/pkg/")
16-
Base.warn_once("/pkg/ URLs are deprecated, load files with their absolute path in Scope")
17-
url = baseurl[] * imp
18-
elseif islocal(imp_path) && isfile(abspath(imp_path))
19-
path = abspath(imp_path)
11+
function path2url(path::AbstractString)
12+
if startswith(path, "/pkg/")
13+
@warn("/pkg/ URLs are deprecated, load files with their absolute path in Scope")
14+
return path
15+
elseif isfile(abspath(path))
16+
path = abspath(path)
2017
# first lookup to see if any of the file itself or any of the parent
2118
# directories are registered.
19+
AssetRegistry.isregistered(path) && AssetRegistry.getkey(path)
2220
cur_path = path
23-
if AssetRegistry.isregistered(cur_path)
24-
url = AssetRegistry.getkey(cur_path)
25-
@goto dict
26-
end
2721
while true
2822
if AssetRegistry.isregistered(cur_path) && isdir(cur_path)
2923
key = AssetRegistry.getkey(cur_path)
30-
url = baseurl[] * key * "/" * replace(path, cur_path => "")
31-
break
24+
url = key * "/" * replace(path, cur_path => "")
25+
return url
3226
end
3327
cur_path1 = dirname(cur_path)
3428
if cur_path1 == cur_path
3529
# this means we have reached root directory,
3630
# and none of the parents are in registry
3731
# register the original path uniquely
38-
url = AssetRegistry.register(imp_path)
39-
break
32+
return AssetRegistry.register(path)
4033
end
4134
cur_path = cur_path1
4235
end
43-
if length(query_parts) > 1
44-
url *= "?" * join(query_parts[2:end], "?")
45-
end
4636
else
47-
url = imp
37+
error("File $path not found")
4838
end
39+
end
4940

50-
allowed_types = ["js", "css", "html"]
41+
function dep2url(dep::AbstractString)
42+
# if is an url, we are done :)
43+
islocal(dep) || return dep
44+
query_parts = split(dep, "?") # remove anything after ?
45+
file_path = first(query_parts)
46+
query_part = length(query_parts) == 2 ? query_parts[2] : ""
47+
url = path2url(file_path)
48+
return string(baseurl[], url, query_part)
49+
end
5150

52-
if !any(endswith.((imp_path,), allowed_types))
51+
function lowerdeps(name, imp)
52+
url = dep2url(imp)
53+
extension = split(url, '.')[end]
54+
if !(extension in ("js", "css", "html"))
5355
error("WebIO can't load dependency of unknown type $url")
5456
end
55-
56-
@label dict
57-
5857
return Dict{String,Any}(
59-
"type" => split(imp_path, ".")[end],
58+
"type" => extension,
6059
"name" => name,
6160
"url" => url
6261
)

src/providers/generic_http.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function serve_assets(req)
2525
if isfile(filepath)
2626
return HTTP.Response(
2727
200,
28-
["Content-Type" => "application/octet-stream"],
28+
[],
2929
body = read(filepath)
3030
)
3131
end

0 commit comments

Comments
 (0)