Skip to content

Commit

Permalink
45ba302 fix(bun): Rewrite TextEncoderStream polyfill implementation f…
Browse files Browse the repository at this point in the history
…or Bun middleware (#6309)

QwikDev/qwik@c8de458
  • Loading branch information
octet-stream committed May 14, 2024
1 parent cca8831 commit 432e832
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
49 changes: 26 additions & 23 deletions middleware/bun/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,40 @@ var MIME_TYPES = {

// packages/qwik-city/middleware/bun/index.ts
import { join, extname } from "node:path";
var resolved = Promise.resolve();
var TextEncoderStream = class {
var TextEncoderStream_polyfill = class {
constructor() {
this._writer = null;
this.readable = {
pipeTo: (writableStream) => {
this._writer = writableStream.getWriter();
this._encoder = new TextEncoder();
this._reader = null;
this.ready = Promise.resolve();
this.closed = false;
this.readable = new ReadableStream({
start: (controller) => {
this._reader = controller;
}
};
this.writable = {
getWriter: () => {
if (!this._writer) {
throw new Error("No writable stream");
});
this.writable = new WritableStream({
write: async (chunk) => {
if (chunk != null && this._reader) {
const encoded = this._encoder.encode(chunk);
this._reader.enqueue(encoded);
}
const encoder = new TextEncoder();
return {
write: async (chunk) => {
if (chunk != null) {
await this._writer.write(encoder.encode(chunk));
}
},
close: () => this._writer.close(),
ready: resolved
};
},
close: () => {
var _a;
(_a = this._reader) == null ? void 0 : _a.close();
this.closed = true;
},
abort: (reason) => {
var _a;
(_a = this._reader) == null ? void 0 : _a.error(reason);
this.closed = true;
}
};
});
}
};
function createQwikCity(opts) {
var _a;
globalThis.TextEncoderStream ||= TextEncoderStream;
globalThis.TextEncoderStream = TextEncoderStream || TextEncoderStream_polyfill;
const qwikSerializer = {
_deserializeData,
_serializeData,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/qwik-city",
"description": "The meta-framework for Qwik.",
"version": "1.5.4-dev20240513151531",
"version": "1.5.4-dev20240514001418",
"bugs": "https://github.com/QwikDev/qwik/issues",
"dependencies": {
"@mdx-js/mdx": "^3.0.1",
Expand Down

0 comments on commit 432e832

Please sign in to comment.