Skip to content

Commit becce39

Browse files
danielhjacobstorokati44
authored andcommitted
web: Don't unnecessarily duplicate the module for single WASM builds
1 parent c36a013 commit becce39

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

web/packages/core/src/internal/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RuffleInstanceBuilder } from "../../dist/ruffle_web";
1+
import type { RuffleInstanceBuilder } from "../../dist/ruffle_web-wasm_extensions";
22
import { BaseLoadOptions, Duration, SecsDuration } from "../public/config";
33

44
/**

web/packages/core/src/internal/player/inner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RuffleHandle, ZipWriter } from "../../../dist/ruffle_web";
1+
import type { RuffleHandle, ZipWriter } from "../../../dist/ruffle_web-wasm_extensions";
22
import {
33
AutoPlay,
44
ContextMenu,

web/packages/core/src/load-ruffle.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
signExtensions,
1010
referenceTypes,
1111
} from "wasm-feature-detect";
12-
import type { RuffleInstanceBuilder, ZipWriter } from "../dist/ruffle_web";
12+
import type {
13+
RuffleInstanceBuilder,
14+
ZipWriter,
15+
} from "../dist/ruffle_web-wasm_extensions";
1316
import { setPolyfillsOnLoad } from "./js-polyfills";
1417

1518
import { internalSourceApi } from "./internal/internal-source-api";
@@ -45,7 +48,10 @@ async function fetchRuffle(
4548
])
4649
).every(Boolean);
4750

48-
if (!extensionsSupported) {
51+
// @ts-expect-error TS2367 %FALLBACK_WASM% gets replaced in set_version.ts.
52+
// %FALLBACK_WASM% is "ruffle_web" if this is a dual-wasm build.
53+
// We don't say we're falling back if we have only an extension build.
54+
if (!extensionsSupported && "%FALLBACK_WASM%" === "ruffle_web") {
4955
console.log(
5056
"Some WebAssembly extensions are NOT available, falling back to the vanilla WebAssembly module",
5157
);
@@ -63,11 +69,12 @@ async function fetchRuffle(
6369
ZipWriter,
6470
} = await (extensionsSupported
6571
? import("../dist/ruffle_web-wasm_extensions")
66-
: import("../dist/ruffle_web"));
72+
: // @ts-expect-error TS2307 TypeScript compiler is trying to do the import.
73+
import("../dist/%FALLBACK_WASM%"));
6774
let response;
6875
const wasmUrl = extensionsSupported
6976
? new URL("../dist/ruffle_web-wasm_extensions_bg.wasm", import.meta.url)
70-
: new URL("../dist/ruffle_web_bg.wasm", import.meta.url);
77+
: new URL("../dist/%FALLBACK_WASM%_bg.wasm", import.meta.url);
7178
const wasmResponse = await fetch(wasmUrl);
7279
// The Pale Moon browser lacks full support for ReadableStream.
7380
// However, ReadableStream itself is defined.

web/packages/core/tools/build_wasm.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ function buildWasm(
140140
});
141141
}
142142
}
143-
function copyStandIn(from: string, to: string) {
144-
const suffixes = [`_bg.wasm`, `_bg.wasm.d.ts`, `.js`, `.d.ts`];
145-
console.log(`Copying ${from} as a stand-in for ${to}...`);
146-
for (const suffix of suffixes) {
147-
copyFileSync(`dist/${from}${suffix}`, `dist/${to}${suffix}`);
148-
}
149-
}
150143
function detectWasmOpt() {
151144
try {
152145
execFileSync("wasm-opt", ["--version"]);
@@ -176,6 +169,4 @@ buildWasm(
176169
);
177170
if (buildWasmMvp) {
178171
buildWasm("web-vanilla-wasm", "ruffle_web", hasWasmOpt, false, wasmSource);
179-
} else {
180-
copyStandIn("ruffle_web-wasm_extensions", "ruffle_web");
181172
}

web/packages/core/tools/set_version.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ if (process.env["ENABLE_VERSION_SEAL"] === "true") {
6464
}
6565
}
6666

67+
const fallbackWasmName =
68+
process.env["BUILD_WASM_MVP"] === "true"
69+
? "ruffle_web"
70+
: "ruffle_web-wasm_extensions";
71+
6772
const options = {
6873
files: "dist/**",
6974
from: [
@@ -72,8 +77,16 @@ const options = {
7277
/%VERSION_CHANNEL%/g,
7378
/%BUILD_DATE%/g,
7479
/%COMMIT_HASH%/g,
80+
/%FALLBACK_WASM%/g,
81+
],
82+
to: [
83+
versionNumber,
84+
versionName,
85+
versionChannel,
86+
buildDate,
87+
commitHash,
88+
fallbackWasmName,
7589
],
76-
to: [versionNumber, versionName, versionChannel, buildDate, commitHash],
7790
};
7891

7992
replaceInFileSync(options);

0 commit comments

Comments
 (0)