From 4bee655f67b9b5161ee22adcc196325a92ab2bdd Mon Sep 17 00:00:00 2001 From: Krasilnikov Roman Date: Sun, 16 Jun 2024 01:47:35 +0300 Subject: [PATCH] Fix php runtime --- packages/testing-php/src/php-runtime-factory.ts | 9 ++++++++- packages/testing-php/vite.config.js | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/testing-php/src/php-runtime-factory.ts b/packages/testing-php/src/php-runtime-factory.ts index eaab303..8ee961a 100644 --- a/packages/testing-php/src/php-runtime-factory.ts +++ b/packages/testing-php/src/php-runtime-factory.ts @@ -1,5 +1,12 @@ import { WebPHP } from "@php-wasm/web"; +// @ts-expect-error hack +import * as phpModule from "@php-wasm/web/light/php_8_3.js"; import { version } from "./version"; -export const phpRuntimeFactory = () => WebPHP.loadRuntime(version); +export const phpRuntimeFactory = () => + WebPHP.loadRuntime(version, { + onPhpLoaderModuleLoaded(loader) { + Object.assign(loader, phpModule) + }, + }); diff --git a/packages/testing-php/vite.config.js b/packages/testing-php/vite.config.js index cd1e3f3..ad97fe4 100644 --- a/packages/testing-php/vite.config.js +++ b/packages/testing-php/vite.config.js @@ -39,6 +39,16 @@ export default defineConfig({ } }, }, + { + name: "transform-php-imports", + transform(code, id) { + if (id.includes("@php-wasm/web/index.js")) { + return { + code: code.replace(/await import\(".*php_\d_\d\.js"\)/g, "{}"), + }; + } + }, + }, dts({ rollupTypes: true, }),