refactor(jsdos): trim comments and inline a single-use constant

Review-polish pass: cut the js-dos docstrings and the CDN-base comment back to
the non-obvious fact, drop JSDOS_BUNDLE_EXTENSION now that it has one call site
whose meaning is plain, and remove a redundant Partial<SimpleRom> cast from the
new fixture helper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-08-29 11:44:18 -04:00
parent 74be063522
commit 0708216236
4 changed files with 10 additions and 20 deletions

View File

@@ -148,8 +148,7 @@ describe("isJsDosEmulationSupported", () => {
});
describe("isJsDosBundle", () => {
const withExt = (fs_extension: string) =>
makeRom({ fs_extension } as Partial<SimpleRom>);
const withExt = (fs_extension: string) => makeRom({ fs_extension });
it("accepts a .jsdos bundle regardless of case", () => {
expect(isJsDosBundle(withExt("jsdos"))).toBe(true);

View File

@@ -702,9 +702,6 @@ export function isRuffleEmulationSupported(
return ["flash", "browser"].includes(slug.toLowerCase());
}
/** File extension of a js-dos bundle. */
export const JSDOS_BUNDLE_EXTENSION = "jsdos";
/**
* Check if js-dos emulation is supported for a given platform.
*
@@ -727,16 +724,14 @@ export function isJsDosEmulationSupported(
/**
* Check if a ROM file is a js-dos bundle.
*
* js-dos boots only its own bundle format: an archive carrying
* `.jsdos/dosbox.conf`. Handed a bare game folder or a plain archive it panics
* with "Broken bundle", so the play routes gate on the extension rather than
* offering a player that cannot start.
* js-dos panics on anything that is not an archive carrying
* `.jsdos/dosbox.conf`.
*
* @param rom The ROM to check.
* @returns True if the file is a js-dos bundle, false otherwise.
*/
export function isJsDosBundle(rom: SimpleRom | null | undefined) {
return rom?.fs_extension.toLowerCase() === JSDOS_BUNDLE_EXTENSION;
return rom?.fs_extension.toLowerCase() === "jsdos";
}
export type PlayingStatus =

View File

@@ -27,11 +27,9 @@ import { useSnackbar } from "@/v2/composables/useSnackbar";
import storeGalleryRoms from "@/v2/stores/galleryRoms";
import { isJsResource, loadScript } from "./scriptLoader";
// The full image serves the runtime same-origin. Slim images and the dev
// server ship no local copy, so fall back to jsDelivr: it serves the same
// pinned dist with `cross-origin-resource-policy: cross-origin`, which the
// player's COEP requires. Keep the version in step with docker/Dockerfile.
const JSDOS_LOCAL_BASE = "/assets/jsdos";
// Fallback for slim images and the dev server, which ship no local copy. Pinned
// to the image's JSDOS_VERSION; jsDelivr sends the CORP the player's COEP needs.
const JSDOS_CDN_BASE = "https://cdn.jsdelivr.net/npm/js-dos@8.4.1/dist";
// Where the runtime actually came from, so the emulator payloads follow it.

View File

@@ -1,6 +1,5 @@
// Shared runtime injection for the player views. EmulatorJS and js-dos both
// ship their runtime as a local asset in the full image and fall back to a CDN
// in slim images and under the dev server, which serve no local copy.
// Shared runtime injection for the player views. EmulatorJS and js-dos serve
// their runtime locally in the full image and fall back to a CDN without it.
/** Inject a <script> and resolve once it has executed. */
export function loadScript(src: string): Promise<void> {
@@ -17,9 +16,8 @@ export function loadScript(src: string): Promise<void> {
/**
* Check that a URL really serves JavaScript.
*
* The Vite dev server (and many SPA hosts) answer a missing asset with 200 plus
* index.html. A <script> tag happily "loads" that, so onerror never fires and a
* plain fallback never runs; only the parser complains, much later.
* The Vite dev server and many SPA hosts answer a missing asset with 200 plus
* index.html, which a <script> tag loads without ever firing onerror.
*
* @param url The script URL to pre-flight.
* @returns True when the body is JavaScript, false otherwise.