com.robotsquid.squidhub 0.5.1 → 0.5.2
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.
- package/CHANGELOG.md +22 -0
- package/Editor/SquidHubBuildProcessor.cs +4 -0
- package/Editor/SquidHubHtml.cs +41 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
⚠️ **Fixes `Unable to load file Build/<name>.br!` — a Unity build that reached
|
|
6
|
+
the portal, rendered the shell and then could not load itself.**
|
|
7
|
+
|
|
8
|
+
`squidhub-release` stores a precompressed `web.wasm.br` under the key
|
|
9
|
+
`web.wasm` and records `Content-Encoding: br`, so the browser decodes it
|
|
10
|
+
natively. Unity's loader asks for the name as it appears on disk —
|
|
11
|
+
`Build/web.wasm.br` — and gets a 404, because nothing is stored there.
|
|
12
|
+
|
|
13
|
+
The build step now points those URLs at the key they are actually stored under.
|
|
14
|
+
That is also what makes the loader behave: Unity decides whether to run its own
|
|
15
|
+
JavaScript decompressor by looking for a `.br` or `.gz` on the URL, and with the
|
|
16
|
+
suffix gone it fetches normally and lets the browser decode — which is what the
|
|
17
|
+
stored headers were asking for all along.
|
|
18
|
+
|
|
19
|
+
⚠️ Not Unity-specific despite the trigger: **any** reference a build makes to a
|
|
20
|
+
file it ships as `X.br` breaks identically, because the upload strips the suffix
|
|
21
|
+
from every one of them. The rewrite covers `.data`, `.wasm`, `.js`, `.json` and
|
|
22
|
+
`.symbols.json` in both `.br` and `.gz` form, and leaves alone a path that
|
|
23
|
+
merely ends in `-br`.
|
|
24
|
+
|
|
3
25
|
## 0.5.1
|
|
4
26
|
|
|
5
27
|
⚠️ **Fixes an install that logged an error per file on every refresh.** 0.5.0
|
|
@@ -79,6 +79,10 @@ namespace SquidHub.Editor
|
|
|
79
79
|
if (result.Extracted.Count == 0)
|
|
80
80
|
log.Append(" · no inline scripts to hoist\n");
|
|
81
81
|
|
|
82
|
+
if (result.SuffixesStripped > 0)
|
|
83
|
+
log.Append(" ✓ pointed ").Append(result.SuffixesStripped)
|
|
84
|
+
.Append(" compressed asset URL(s) at the key they are stored under\n");
|
|
85
|
+
|
|
82
86
|
File.WriteAllText(indexPath, result.Html);
|
|
83
87
|
foreach (var note in result.Notes) log.Append(" ✓ ").Append(note).Append('\n');
|
|
84
88
|
|
package/Editor/SquidHubHtml.cs
CHANGED
|
@@ -25,6 +25,8 @@ namespace SquidHub.Editor
|
|
|
25
25
|
public readonly List<KeyValuePair<string, string>> Extracted =
|
|
26
26
|
new List<KeyValuePair<string, string>>();
|
|
27
27
|
public readonly List<string> Notes = new List<string>();
|
|
28
|
+
/// <summary>How many compressed-asset URLs had their suffix stripped.</summary>
|
|
29
|
+
public int SuffixesStripped;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
private static readonly Regex ScriptTag = new Regex(
|
|
@@ -49,6 +51,36 @@ namespace SquidHub.Editor
|
|
|
49
51
|
"text/ecmascript", "application/ecmascript",
|
|
50
52
|
};
|
|
51
53
|
|
|
54
|
+
// ⚠️ squidhub-release stores `web.wasm.br` at the key `web.wasm` and
|
|
55
|
+
// records Content-Encoding: br, so the browser decodes it natively. But
|
|
56
|
+
// Unity's loader asks for the name on disk — `Build/web.wasm.br` — and
|
|
57
|
+
// gets a 404, because nothing is stored under that key.
|
|
58
|
+
//
|
|
59
|
+
// ⚠️ Rewriting the URL is also what makes the loader behave. Unity
|
|
60
|
+
// decides whether to run its own JS decompressor by looking for a .br
|
|
61
|
+
// or .gz on the URL; with the suffix gone it fetches normally and lets
|
|
62
|
+
// the browser decode, which is exactly what the stored headers want.
|
|
63
|
+
//
|
|
64
|
+
// ⚠️ Not Unity-specific, despite the trigger. ANY reference a build
|
|
65
|
+
// makes to a file it ships as `X.br` is broken the same way, because
|
|
66
|
+
// the upload strips the suffix from every one of them.
|
|
67
|
+
private static readonly Regex CompressedAssetUrl = new Regex(
|
|
68
|
+
@"([""'])([^""']+\.(?:data|wasm|js|json|symbols\.json))\.(?:br|gz)\1",
|
|
69
|
+
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
|
70
|
+
|
|
71
|
+
/// <summary>Points compressed-asset URLs at the key they are actually stored under.</summary>
|
|
72
|
+
internal static string StripCompressionSuffixes(string source, out int stripped)
|
|
73
|
+
{
|
|
74
|
+
var count = 0;
|
|
75
|
+
var result = CompressedAssetUrl.Replace(source, match =>
|
|
76
|
+
{
|
|
77
|
+
count++;
|
|
78
|
+
return match.Groups[1].Value + match.Groups[2].Value + match.Groups[1].Value;
|
|
79
|
+
});
|
|
80
|
+
stripped = count;
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
52
84
|
public static Result Apply(string html, string bridgeFileName)
|
|
53
85
|
{
|
|
54
86
|
var result = new Result { Html = html };
|
|
@@ -73,6 +105,9 @@ namespace SquidHub.Editor
|
|
|
73
105
|
if (!IsExecutable(attrs)) return match.Value; // data, not code
|
|
74
106
|
|
|
75
107
|
var name = "squidhub-inline-" + index++ + ".js";
|
|
108
|
+
int strippedHere;
|
|
109
|
+
body = StripCompressionSuffixes(body, out strippedHere);
|
|
110
|
+
result.SuffixesStripped += strippedHere;
|
|
76
111
|
result.Extracted.Add(new KeyValuePair<string, string>(name, body));
|
|
77
112
|
|
|
78
113
|
// ⚠️ Attributes are carried across verbatim. Dropping a
|
|
@@ -82,6 +117,12 @@ namespace SquidHub.Editor
|
|
|
82
117
|
return "<script" + carried + " src=\"" + name + "\"></script>";
|
|
83
118
|
});
|
|
84
119
|
|
|
120
|
+
// The document itself can carry them too — a template that lists the
|
|
121
|
+
// build files, or a preload hint.
|
|
122
|
+
int strippedInHtml;
|
|
123
|
+
rewritten = StripCompressionSuffixes(rewritten, out strippedInHtml);
|
|
124
|
+
result.SuffixesStripped += strippedInHtml;
|
|
125
|
+
|
|
85
126
|
var tag = "<script src=\"" + bridgeFileName + "\"></script>";
|
|
86
127
|
result.Html = InsertBridge(rewritten, tag, result);
|
|
87
128
|
result.Changed = !ReferenceEquals(result.Html, html) && result.Html != html;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.robotsquid.squidhub",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"displayName": "SquidHub",
|
|
5
5
|
"description": "Cloud saves, analytics and the coin economy for Unity WebGL games published on SquidHub. Installs the C# wrapper, the .jslib half and the page bridge, and rewrites the exported index.html so it survives the platform's CSP.",
|
|
6
6
|
"unity": "2021.3",
|