klenod-runtime 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/klenod/runtime/asset_url.rb +55 -0
- data/lib/klenod/runtime/bundle.rb +47 -6
- data/lib/klenod/runtime/bundle_format.rb +10 -5
- data/lib/klenod/runtime/version.rb +1 -1
- data/lib/klenod/runtime.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 145f6247c62ae08faacd7baa15b37b0422a724ba09510994955514feeee51707
|
|
4
|
+
data.tar.gz: 3c5c4fd66d2031904819cebcb44f86a1eef40decda92205e8e3db080f2e420e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 739c11f8fdf87d492cb728858cecb9ba845cc07efeb1cf9bc2b6b2940f3c65367f63a0d31e253f706113903133d495a358a1ca177dbfa9d4702cc1369919eced
|
|
7
|
+
data.tar.gz: fadecdf29f49ce9482507b2a973508a6efd5c11bf8d43a192e264651791132f7962aa3854a916cc2864c95a4a253fa26e591ad6d50a1740c999d6d8bf509e58b
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Klenod
|
|
6
|
+
module Runtime
|
|
7
|
+
module AssetUrl
|
|
8
|
+
DEFAULT_BASE = "/assets/"
|
|
9
|
+
LEGACY_OUTPUT_PREFIX = "/assets/"
|
|
10
|
+
|
|
11
|
+
module_function
|
|
12
|
+
|
|
13
|
+
def normalize(base)
|
|
14
|
+
value = base.to_s
|
|
15
|
+
value = DEFAULT_BASE if value.empty?
|
|
16
|
+
uri = URI.parse(value)
|
|
17
|
+
|
|
18
|
+
if uri.scheme
|
|
19
|
+
unless %w[http https].include?(uri.scheme) && uri.host && !uri.query && !uri.fragment
|
|
20
|
+
raise ArgumentError, "asset base must be an absolute HTTP(S) URL without a query or fragment: #{base.inspect}"
|
|
21
|
+
end
|
|
22
|
+
elsif !value.start_with?("/") || uri.query || uri.fragment
|
|
23
|
+
raise ArgumentError, "asset base must be an absolute path or HTTP(S) URL: #{base.inspect}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
value.end_with?("/") ? value : "#{value}/"
|
|
27
|
+
rescue URI::InvalidURIError
|
|
28
|
+
raise ArgumentError, "asset base must be an absolute path or HTTP(S) URL: #{base.inspect}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def join(base, output_path)
|
|
32
|
+
path = output_path.to_s
|
|
33
|
+
unless path.start_with?("/") && !path.start_with?("//")
|
|
34
|
+
raise ArgumentError, "asset output path must be root-relative: #{output_path.inspect}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
"#{normalize(base)}#{path.delete_prefix("/")}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def legacy_join(base, output_path)
|
|
41
|
+
join(base, output_path.delete_prefix(LEGACY_OUTPUT_PREFIX).prepend("/"))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def path_prefix(base)
|
|
45
|
+
normalized = normalize(base)
|
|
46
|
+
normalized if normalized.start_with?("/")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def origin(base)
|
|
50
|
+
uri = URI.parse(normalize(base))
|
|
51
|
+
uri.origin if uri.is_a?(URI::HTTP)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative "asset_url"
|
|
4
|
+
|
|
3
5
|
module Klenod
|
|
4
6
|
module Runtime
|
|
5
7
|
ModuleSpec =
|
|
@@ -9,11 +11,22 @@ module Klenod
|
|
|
9
11
|
DefaultImport = Data.define(:name)
|
|
10
12
|
|
|
11
13
|
AssetSpec =
|
|
12
|
-
Data.define(:logical_name, :content_hash, :output_path, :content_type, :metadata)
|
|
14
|
+
Data.define(:logical_name, :content_hash, :output_path, :content_type, :metadata, :url) do
|
|
15
|
+
def initialize(logical_name = nil, content_hash = nil, output_path = nil, content_type = nil, metadata = nil, url = nil, **keywords)
|
|
16
|
+
logical_name = keywords.fetch(:logical_name, logical_name)
|
|
17
|
+
content_hash = keywords.fetch(:content_hash, content_hash)
|
|
18
|
+
output_path = keywords.fetch(:output_path, output_path)
|
|
19
|
+
content_type = keywords.fetch(:content_type, content_type)
|
|
20
|
+
metadata = keywords.fetch(:metadata, metadata)
|
|
21
|
+
url = keywords.fetch(:url, url)
|
|
22
|
+
url ||= output_path
|
|
23
|
+
super(logical_name:, content_hash:, output_path:, content_type:, metadata:, url:)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
13
26
|
AssetReference = Data.define(:index, :asset)
|
|
14
27
|
|
|
15
28
|
class Bundle
|
|
16
|
-
attr_reader :entrypoints, :modules, :assets, :source_root
|
|
29
|
+
attr_reader :entrypoints, :modules, :assets, :source_root, :base, :asset_origin
|
|
17
30
|
|
|
18
31
|
def self.load(source, source_root: nil)
|
|
19
32
|
BundleFormat.load(source, source_root: source_root)
|
|
@@ -23,11 +36,13 @@ module Klenod
|
|
|
23
36
|
load(path, source_root: source_root)
|
|
24
37
|
end
|
|
25
38
|
|
|
26
|
-
def initialize(entrypoints, modules, assets, source_root: nil)
|
|
39
|
+
def initialize(entrypoints, modules, assets, source_root: nil, base: AssetUrl::DEFAULT_BASE)
|
|
27
40
|
@entrypoints = entrypoints
|
|
28
41
|
@modules = modules
|
|
29
|
-
@assets = assets
|
|
30
42
|
@source_root = source_root
|
|
43
|
+
@base = AssetUrl.normalize(base)
|
|
44
|
+
@asset_origin = AssetUrl.origin(@base)
|
|
45
|
+
@assets = bind_asset_urls(assets)
|
|
31
46
|
@mods = {}
|
|
32
47
|
end
|
|
33
48
|
|
|
@@ -85,6 +100,17 @@ module Klenod
|
|
|
85
100
|
@assets.fetch(output_path)
|
|
86
101
|
end
|
|
87
102
|
|
|
103
|
+
def asset_url(asset_or_output_path)
|
|
104
|
+
if asset_or_output_path.respond_to?(:output_path)
|
|
105
|
+
asset = @assets.fetch(asset_or_output_path.output_path, asset_or_output_path)
|
|
106
|
+
return asset.url || AssetUrl.join(base, asset.output_path)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
@assets.fetch(asset_or_output_path).url
|
|
110
|
+
rescue KeyError
|
|
111
|
+
AssetUrl.join(base, asset_or_output_path)
|
|
112
|
+
end
|
|
113
|
+
|
|
88
114
|
def assets_for(logical_name)
|
|
89
115
|
@assets.values.select { |asset| asset.logical_name == logical_name.to_s }
|
|
90
116
|
end
|
|
@@ -121,11 +147,14 @@ module Klenod
|
|
|
121
147
|
end
|
|
122
148
|
|
|
123
149
|
def marshal_dump
|
|
124
|
-
[@entrypoints, @modules, @assets, @source_root]
|
|
150
|
+
[@entrypoints, @modules, @assets, @source_root, @base]
|
|
125
151
|
end
|
|
126
152
|
|
|
127
153
|
def marshal_load(data)
|
|
128
|
-
@entrypoints, @modules,
|
|
154
|
+
@entrypoints, @modules, assets, @source_root, base = data
|
|
155
|
+
@base = AssetUrl.normalize(base)
|
|
156
|
+
@asset_origin = AssetUrl.origin(@base)
|
|
157
|
+
@assets = bind_asset_urls(assets)
|
|
129
158
|
@mods = {}
|
|
130
159
|
end
|
|
131
160
|
|
|
@@ -145,6 +174,18 @@ module Klenod
|
|
|
145
174
|
|
|
146
175
|
private
|
|
147
176
|
|
|
177
|
+
def bind_asset_urls(assets)
|
|
178
|
+
assets.to_h do |output_path, asset|
|
|
179
|
+
legacy_url = asset.url.nil? || (asset.url == asset.output_path && base != AssetUrl::DEFAULT_BASE)
|
|
180
|
+
url = legacy_output_path?(asset.output_path) ? AssetUrl.legacy_join(base, asset.output_path) : AssetUrl.join(base, asset.output_path)
|
|
181
|
+
[output_path, legacy_url ? asset.with(url:) : asset]
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def legacy_output_path?(output_path)
|
|
186
|
+
output_path.start_with?(AssetUrl::LEGACY_OUTPUT_PREFIX)
|
|
187
|
+
end
|
|
188
|
+
|
|
148
189
|
def assets_for_runtime_module(module_id)
|
|
149
190
|
module_spec = @modules.fetch(module_id)
|
|
150
191
|
logical_names = [module_spec.id, module_spec.source_path].uniq
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require_relative "asset_url"
|
|
5
6
|
require_relative "version"
|
|
6
7
|
require_relative "source_map"
|
|
7
8
|
|
|
@@ -12,7 +13,7 @@ module Klenod
|
|
|
12
13
|
|
|
13
14
|
module BundleFormat
|
|
14
15
|
MAGIC = "MODPACK_BUNDLE_V1\n"
|
|
15
|
-
FORMAT_VERSION =
|
|
16
|
+
FORMAT_VERSION = 3
|
|
16
17
|
|
|
17
18
|
module_function
|
|
18
19
|
|
|
@@ -39,6 +40,7 @@ module Klenod
|
|
|
39
40
|
"format_version" => FORMAT_VERSION,
|
|
40
41
|
"runtime_version" => Runtime::VERSION,
|
|
41
42
|
"source_root" => encode_value(bundle.source_root),
|
|
43
|
+
"base" => bundle.base,
|
|
42
44
|
"entrypoints" => encode_value(bundle.entrypoints),
|
|
43
45
|
"modules" => encode_modules(bundle.modules),
|
|
44
46
|
"assets" => encode_assets(bundle.assets)
|
|
@@ -53,7 +55,8 @@ module Klenod
|
|
|
53
55
|
decode_value(payload.fetch("entrypoints")),
|
|
54
56
|
decode_modules(payload.fetch("modules")),
|
|
55
57
|
decode_assets(payload.fetch("assets")),
|
|
56
|
-
source_root: decode_value(payload["source_root"])
|
|
58
|
+
source_root: decode_value(payload["source_root"]),
|
|
59
|
+
base: payload.key?("base") ? payload.fetch("base") : AssetUrl::DEFAULT_BASE
|
|
57
60
|
)
|
|
58
61
|
bundle.source_root = source_root if source_root
|
|
59
62
|
bundle
|
|
@@ -67,7 +70,7 @@ module Klenod
|
|
|
67
70
|
raise BundleFormatError, "Malformed Klenod bundle payload" unless payload.is_a?(Hash)
|
|
68
71
|
|
|
69
72
|
version = payload["format_version"]
|
|
70
|
-
unless
|
|
73
|
+
unless [1, 2, FORMAT_VERSION].include?(version)
|
|
71
74
|
raise BundleFormatError, "Unsupported Klenod bundle format version: #{version.inspect}"
|
|
72
75
|
end
|
|
73
76
|
|
|
@@ -157,7 +160,8 @@ module Klenod
|
|
|
157
160
|
"content_hash" => asset.content_hash,
|
|
158
161
|
"output_path" => asset.output_path,
|
|
159
162
|
"content_type" => asset.content_type,
|
|
160
|
-
"metadata" => encode_value(asset.metadata)
|
|
163
|
+
"metadata" => encode_value(asset.metadata),
|
|
164
|
+
"url" => asset.url
|
|
161
165
|
}
|
|
162
166
|
]
|
|
163
167
|
end
|
|
@@ -173,7 +177,8 @@ module Klenod
|
|
|
173
177
|
asset_payload.fetch("content_hash"),
|
|
174
178
|
asset_payload.fetch("output_path"),
|
|
175
179
|
asset_payload.fetch("content_type"),
|
|
176
|
-
decode_value(asset_payload.fetch("metadata"))
|
|
180
|
+
decode_value(asset_payload.fetch("metadata")),
|
|
181
|
+
asset_payload["url"]
|
|
177
182
|
)
|
|
178
183
|
]
|
|
179
184
|
end
|
data/lib/klenod/runtime.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "runtime/version"
|
|
|
4
4
|
require_relative "runtime/source_map"
|
|
5
5
|
require_relative "runtime/backtrace_rewriter"
|
|
6
6
|
require_relative "runtime/mod"
|
|
7
|
+
require_relative "runtime/asset_url"
|
|
7
8
|
require_relative "runtime/bundle"
|
|
8
9
|
require_relative "runtime/bundle_format"
|
|
9
10
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-runtime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
|
18
18
|
files:
|
|
19
19
|
- README.md
|
|
20
20
|
- lib/klenod/runtime.rb
|
|
21
|
+
- lib/klenod/runtime/asset_url.rb
|
|
21
22
|
- lib/klenod/runtime/backtrace_rewriter.rb
|
|
22
23
|
- lib/klenod/runtime/bundle.rb
|
|
23
24
|
- lib/klenod/runtime/bundle_format.rb
|
|
@@ -37,7 +38,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
37
38
|
requirements:
|
|
38
39
|
- - ">="
|
|
39
40
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 4.0
|
|
41
|
+
version: '4.0'
|
|
41
42
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
43
|
requirements:
|
|
43
44
|
- - ">="
|