From 91de8ac01903b060671c9be5e0ac8f76399715c5 Mon Sep 17 00:00:00 2001 From: Davri <42148912+Davr1@users.noreply.github.com> Date: Sat, 1 Aug 2026 21:57:17 +0200 Subject: [PATCH] Fix stuff --- packages/extendify-api/src/esperanto.ts | 20 +++++++++---- .../extendify-entrypoint/src/globals.d.ts | 8 ++--- .../extendify-scripts/src/build/config.ts | 6 ++-- packages/extendify-scripts/src/build/index.ts | 4 +-- packages/extendify-webpack/src/exporter.ts | 17 ----------- packages/extendify-webpack/src/interceptor.ts | 30 ++++++++++--------- packages/extendify-webpack/src/patcher.ts | 7 ++++- 7 files changed, 44 insertions(+), 48 deletions(-) diff --git a/packages/extendify-api/src/esperanto.ts b/packages/extendify-api/src/esperanto.ts index fae2c07..20d89a4 100644 --- a/packages/extendify-api/src/esperanto.ts +++ b/packages/extendify-api/src/esperanto.ts @@ -37,8 +37,8 @@ const { context, logger } = registerContext({ registerPatch(context, { find: "EsperantoTransport", replacement: { - match: /(\i\.executeEsperantoCall),(\i\.cancelEsperantoCall),!1/, - replace: "$1,$2,true" + match: /(\i\.executeEsperantoCall),(\i\.cancelEsperantoCall),/, + replace: "$1,$2,true||" } }); @@ -55,10 +55,12 @@ registerEventListener(context, "platformLoaded", async () => { const transport = await findModuleExport<{ subscribeToTraffic( callback: (e: { - type: "request" | "response"; + type: "request" | "response" | "stream_response" | "error" | "cancel"; id: string; - payload: Uint8Array; timestamp: number; + code?: number; + message?: string; + payload?: Uint8Array; method?: string; service?: string; isStreaming?: boolean; @@ -67,14 +69,20 @@ registerEventListener(context, "platformLoaded", async () => { }>(exportFilters.byProps("subscribeToTraffic")); transport.subscribeToTraffic(e => { - const payload = e.payload.length === 0 ? "Empty payload" : e.payload.join(" "); + const payload = !e.payload?.length ? "Empty payload" : e.payload.join(" "); - if (e.type === "response") { + if (e.type === "response" || e.type === "stream_response") { logger.debug(`Response to ${e.id}:\n${payload}`); } else if (e.type === "request") { logger.debug( `Sending request from ${e.service ?? "UnknownService"}#${e.method ?? "UnknownMethod"} (${e.id}):\n${payload}` ); + } else if (e.type === "error") { + logger.debug( + `${e.message}: ${e.service ?? "UnknownService"}#${e.method ?? "UnknownMethod"} has encountered an error (${e.id}):\n${payload}` + ); + } else if (e.type === "cancel") { + logger.debug(`Request with id ${e.id} was cancelled.`); } else { logger.warn(`Unknown traffic type ${e.type} (${e.id}):\n${payload}`); } diff --git a/packages/extendify-entrypoint/src/globals.d.ts b/packages/extendify-entrypoint/src/globals.d.ts index 6948d71..b182c79 100644 --- a/packages/extendify-entrypoint/src/globals.d.ts +++ b/packages/extendify-entrypoint/src/globals.d.ts @@ -13,12 +13,10 @@ declare global { export const PLATFORM: TargetPlatform; /** The urls of the possible entrypoint bundles */ export const ENTRYPOINTS: string[]; - /** The name of the webpack chunk in the global window object */ - export const WEBPACK_CHUNK: string; - - interface Window { - [WEBPACK_CHUNK]?: WebpackChunkGlobal; + /** The name of the webpack chunks in the global window object */ + export const WEBPACK_CHUNKS: string[]; + interface Window extends Record { ExtendifyFragment: symbol; ExtendifyCreateElement: typeof React.createElement | (() => any); diff --git a/packages/extendify-scripts/src/build/config.ts b/packages/extendify-scripts/src/build/config.ts index 69a9fb2..8b67d42 100644 --- a/packages/extendify-scripts/src/build/config.ts +++ b/packages/extendify-scripts/src/build/config.ts @@ -5,7 +5,7 @@ export const entrypoints: Record = { desktop: ["xpui-snapshot.js", "xpui.js"] }; -export const webpackChunkName: Record = { - browser: "webpackChunkclient_web", - desktop: "webpackChunkclient_web" +export const webpackChunkNames: Record = { + browser: ["webpackChunkclient_web", "rspackChunkclient_web"], + desktop: ["webpackChunkclient_web", "rspackChunkclient_web"] }; diff --git a/packages/extendify-scripts/src/build/index.ts b/packages/extendify-scripts/src/build/index.ts index d8b5067..35fd2fe 100644 --- a/packages/extendify-scripts/src/build/index.ts +++ b/packages/extendify-scripts/src/build/index.ts @@ -1,5 +1,5 @@ import { getKwarg, hasArg } from "@extendify/scripts/args"; -import { entrypoints, webpackChunkName } from "@extendify/scripts/build/config"; +import { entrypoints, webpackChunkNames } from "@extendify/scripts/build/config"; import { globPlugins } from "@extendify/scripts/build/plugins"; import { getTimeDifference, stringify } from "@extendify/scripts/utils"; import type { TargetPlatform } from "@extendify/shared/types"; @@ -40,7 +40,7 @@ await Bun.build({ DEVELOPMENT: DEVELOPMENT, ENTRYPOINTS: entrypoints[PLATFORM], PLATFORM: PLATFORM, - WEBPACK_CHUNK: webpackChunkName[PLATFORM] + WEBPACK_CHUNKS: webpackChunkNames[PLATFORM] }), entrypoints: [ENTRYPOINT], format: "iife", diff --git a/packages/extendify-webpack/src/exporter.ts b/packages/extendify-webpack/src/exporter.ts index dc67381..4bc7ad3 100644 --- a/packages/extendify-webpack/src/exporter.ts +++ b/packages/extendify-webpack/src/exporter.ts @@ -15,23 +15,6 @@ const { context, logger } = registerContext({ registerPatch(context, { all: true, replacement: [ - { - /** - * Turn every module into a function instead of an arrow function: - * 1111: (a, b, c) => {} -> 1111: function(a, b, c) {} - * 2222: (a, b) => {} -> 2222: function(a, b) {} - * 3333: a => {} -> 3333: function(a) {} - * 4444: module => {} -> 4444: function(module) {} - * 5555(a, b, c) {} -> 5555: function(a, b, c) {} - * ^ there's one of these that exists where there is only one argument which has a full name (module) - * If the module is already a function, which there is at least one example of, this patch will not apply - */ - match: /(function)?(?:\((.*?)\)(?:=>)?|(.|module)=>){/, - noWarn: true, - replace(match, func, args1, args2) { - return func ? match : `function(${args1 ?? args2}){`; - } - }, { // Inject the exporter at the very end of the function match: /}$/, diff --git a/packages/extendify-webpack/src/interceptor.ts b/packages/extendify-webpack/src/interceptor.ts index 393ee71..04cfebe 100644 --- a/packages/extendify-webpack/src/interceptor.ts +++ b/packages/extendify-webpack/src/interceptor.ts @@ -7,21 +7,23 @@ const logger = createLogger({ name: "WebpackInterceptor" }); let webpackChunk: any[] | undefined; -Object.defineProperty(window, WEBPACK_CHUNK, { - configurable: true, - get: () => webpackChunk, - set(chunk) { - if (chunk?.push && !chunk.push.$$) { - patchPush(chunk); - logger.info(`Patched ${WEBPACK_CHUNK}.push`); - - delete window[WEBPACK_CHUNK]; - window[WEBPACK_CHUNK] = chunk; - } +for (const chunkName of WEBPACK_CHUNKS) { + Object.defineProperty(window, chunkName, { + configurable: true, + get: () => webpackChunk, + set(chunk) { + if (chunk?.push && !chunk.push.$$) { + patchPush(chunk); + logger.info(`Patched ${chunkName}.push`); + + delete window[chunkName]; + window[chunkName] = chunk; + } - webpackChunk = chunk; - } -}); + webpackChunk = chunk; + } + }); +} Object.defineProperty(Function.prototype, "m", { configurable: true, diff --git a/packages/extendify-webpack/src/patcher.ts b/packages/extendify-webpack/src/patcher.ts index c8a3dbe..677db6a 100644 --- a/packages/extendify-webpack/src/patcher.ts +++ b/packages/extendify-webpack/src/patcher.ts @@ -86,12 +86,17 @@ export function patchFactories(factories: Record | Webpac } } +// Spotify only uses modules with deterministic or natural module ids and a modern ES target, +// removing the need for manually converting each factory function type separately in a patch. +// This simple text replacement already handles both cases: +// { 96879(e,t,i){...} } -> function(e,t,i){...} +// [ function(e,t,i){...} ] -> function(e,t,i){...} (unchanged) function sanitizeSrc(src: string) { const firstBlock = src.indexOf("{"); const firstParenth = src.indexOf("("); if (firstParenth < firstBlock && firstParenth !== 0) { - src = src.substring(firstParenth); + src = `function${src.substring(firstParenth)}`; } return src.replaceAll("\n", "");