refactor(web): load zip.js from pinned cdn version

This commit is contained in:
boykopovar 2026-10-13 14:02:46 +03:00
parent 78df1e3244
commit 57801875db
7 changed files with 24 additions and 24 deletions

3
.gitmodules vendored
View File

@ -37,6 +37,3 @@
[submodule "3rdparty/libusb-cmake"]
path = 3rdparty/libusb-cmake
url = https://github.com/libusb/libusb-cmake.git
[submodule "3rdparty/zip.js"]
path = 3rdparty/zip.js
url = https://github.com/gildas-lormeau/zip.js.git

1
3rdparty/zip.js vendored

@ -1 +0,0 @@
Subproject commit b608211a036192b665b5fd19589fa2454a315017

View File

@ -1,4 +1,4 @@
import { BlobReader, Uint8ArrayReader, ZipReader, ZipWriter, configure } from "./vendor/zip/zip-no-worker.js";
import { BlobReader, Uint8ArrayReader, ZipReader, ZipWriter, configure } from "https://cdn.jsdelivr.net/npm/@zip.js/zip.js@2.7.57/lib/zip-no-worker.js/+esm";
configure({ useWebWorkers: false, useCompressionStream: false, chunkSize: 65536 });

View File

@ -2,10 +2,13 @@ import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { pathToFileURL } from "node:url";
import path from "node:path";
import { register } from "node:module";
register("./cdn-loader.mjs", import.meta.url, { data: { url: process.env.ANYPS5_TEST_ZIP_URL, path: process.env.ANYPS5_TEST_ZIP_PATH } });
const site = name => pathToFileURL(path.join(process.argv[2], name)).href;
const { Archive, memoryEstimate, MEMORY_LIMIT, packageArchive } = await import(site("archive.mjs"));
const { BlobReader, BlobWriter, Uint8ArrayReader, Uint8ArrayWriter, ZipReader, ZipWriter } = await import(site("vendor/zip/zip-no-worker.js"));
const { BlobReader, BlobWriter, Uint8ArrayReader, Uint8ArrayWriter, ZipReader, ZipWriter } = await import(process.env.ANYPS5_TEST_ZIP_URL);
const { default: createRelinker } = await import(site("native/relinker_wasm.mjs"));
const native = await createRelinker();
const executable = new Uint8Array(await readFile(path.join(process.argv[3], "main.elf")));

View File

@ -0,0 +1,9 @@
let library;
export function initialize(data) {
library = data;
}
export function resolve(specifier, context, nextResolve) {
return nextResolve(specifier === library.url ? library.path : specifier, context);
}

View File

@ -16,23 +16,6 @@ def copy_sources(output):
for file in source.iterdir():
if file.is_file():
shutil.copy2(file, output / file.name)
library = ROOT / "3rdparty/zip.js/lib"
pending = [library / "zip-no-worker.js"]
copied = set()
while pending:
file = pending.pop().resolve()
if file in copied:
continue
if not file.is_relative_to(library.resolve()):
raise ValueError(f"ZIP source import escapes library: {file}")
text = file.read_text(encoding="utf-8")
copied.add(file)
destination = output / "vendor/zip" / file.relative_to(library.resolve())
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(file, destination)
for name in re.findall(r"(?:from\s+|import\s*)[\"'](\.[^\"']+)[\"']", text):
pending.append(file.parent / name)
shutil.copy2(ROOT / "3rdparty/zip.js/LICENSE", output / "vendor/zip/LICENSE")
(output / ".nojekyll").touch()

View File

@ -1,8 +1,11 @@
import argparse
import os
from pathlib import Path
import re
import subprocess
import sys
import tempfile
import urllib.request
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "core/relinker/relinker/tests"))
@ -18,7 +21,13 @@ def main():
fixture = Path(directory)
(fixture / "main.elf").write_bytes(main_fixture())
(fixture / "module.elf").write_bytes(module_with_symbol(True))
subprocess.run(["node", str(ROOT / "demo/web/tests/archive.test.mjs"), str(args.build.resolve() / "web"), str(fixture)], check=True)
source = (args.build / "web/archive.mjs").read_text(encoding="utf-8")
url = re.search(r'from "(https://cdn.jsdelivr.net/[^"\n]+)"', source).group(1)
library = fixture / "zip.mjs"
with urllib.request.urlopen(url, timeout=30) as response:
library.write_bytes(response.read())
environment = dict(os.environ, ANYPS5_TEST_ZIP_URL=url, ANYPS5_TEST_ZIP_PATH=library.as_uri())
subprocess.run(["node", str(ROOT / "demo/web/tests/archive.test.mjs"), str(args.build.resolve() / "web"), str(fixture)], env=environment, check=True)
if __name__ == "__main__":