Skip to content

Commit b7e3352

Browse files
committed
text_blobs/Text module support for service worker format in local mode
This adds support for `text_blobs`/Text module support in local mode. Now that cloudflare/miniflare#228 has landed in miniflare (thanks @caass!), we can use that in wrangler as well. Fixes #416
1 parent 942e9f1 commit b7e3352

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/wrangler/src/__tests__/configuration.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe("normalizeAndValidateConfig()", () => {
354354
expect(diagnostics.hasWarnings()).toBe(false);
355355
});
356356

357-
it("should error on invalid `wasm_module` paths", () => {
357+
it("should error on invalid `wasm_modules` paths", () => {
358358
const expectedConfig = {
359359
wasm_modules: {
360360
MODULE_1: 111,

packages/wrangler/src/dev/local.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function useLocalWorker({
8282
const scriptPath = realpathSync(bundle.path);
8383

8484
const wasmBindings = { ...bindings.wasm_modules };
85+
const textBlobBindings = { ...bindings.text_blobs };
8586
if (format === "service-worker") {
8687
for (const { type, name } of bundle.modules) {
8788
if (type === "compiled-wasm") {
@@ -91,6 +92,13 @@ function useLocalWorker({
9192
// characters with an underscore.
9293
const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
9394
wasmBindings[identifier] = name;
95+
} else if (type === "text") {
96+
// In service-worker format, text modules are referenced by global identifiers,
97+
// so we convert it here.
98+
// This identifier has to be a valid JS identifier, so we replace all non alphanumeric
99+
// characters with an underscore.
100+
const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
101+
textBlobBindings[identifier] = name;
94102
}
95103
}
96104
}
@@ -130,6 +138,7 @@ function useLocalWorker({
130138
: undefined,
131139
bindings: bindings.vars,
132140
wasmBindings,
141+
textBlobBindings,
133142
sourceMap: true,
134143
logUnhandledRejections: true,
135144
};
@@ -227,6 +236,7 @@ function useLocalWorker({
227236
publicDirectory,
228237
rules,
229238
bindings.wasm_modules,
239+
bindings.text_blobs,
230240
]);
231241
return { inspectorUrl };
232242
}

packages/wrangler/src/module-collection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export default function createModuleCollector(props: {
102102
modules.splice(0);
103103
});
104104

105-
// ~ start legacy module specifier support ~
105+
// ~ start legacy module specifier support ~
106106

107107
// This section detects usage of "legacy" 1.x style module specifiers
108108
// and modifies them so they "work" in wrangler v2, but with a warning

0 commit comments

Comments
 (0)