From a33d84487074845e06bb6cd19f1a6fcda1757889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 30 Apr 2024 22:43:35 +0200 Subject: [PATCH] Playground CLI: ship as ESM --- packages/playground/cli/public/wp-playground.js | 2 +- packages/playground/cli/src/setup-php.ts | 14 ++++++++++---- packages/playground/cli/vite.config.ts | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/playground/cli/public/wp-playground.js b/packages/playground/cli/public/wp-playground.js index 3381c80e65..cf80c624bb 100644 --- a/packages/playground/cli/public/wp-playground.js +++ b/packages/playground/cli/public/wp-playground.js @@ -1,2 +1,2 @@ #!/usr/bin/env node -import './cli.cjs'; +import './cli.js'; diff --git a/packages/playground/cli/src/setup-php.ts b/packages/playground/cli/src/setup-php.ts index 4c23e34fd3..dcf36eedf6 100644 --- a/packages/playground/cli/src/setup-php.ts +++ b/packages/playground/cli/src/setup-php.ts @@ -3,7 +3,6 @@ import { BasePHP, PHPRequestHandler, SupportedPHPVersion, - __private__dont__use, rotatePHPRuntime, } from '@php-wasm/universal'; import { rootCertificates } from 'tls'; @@ -82,6 +81,10 @@ export function proxyFileSystem( replica: BasePHP, documentRoot: string ) { + // We can't just import the symbol from the library because + // Playground CLI is built as ESM and php-wasm-node is built as + // CJS and the imported symbols will different in the production build. + const __private__symbol = Object.getOwnPropertySymbols(sourceOfTruth)[0]; for (const path of [documentRoot, '/tmp']) { if (!replica.fileExists(path)) { replica.mkdir(path); @@ -89,11 +92,14 @@ export function proxyFileSystem( if (!sourceOfTruth.fileExists(path)) { sourceOfTruth.mkdir(path); } - replica[__private__dont__use].FS.mount( - replica[__private__dont__use].PROXYFS, + // @ts-ignore + replica[__private__symbol].FS.mount( + // @ts-ignore + replica[__private__symbol].PROXYFS, { root: path, - fs: sourceOfTruth[__private__dont__use].FS, + // @ts-ignore + fs: sourceOfTruth[__private__symbol].FS, }, path ); diff --git a/packages/playground/cli/vite.config.ts b/packages/playground/cli/vite.config.ts index 4872894c25..6f585a41cc 100644 --- a/packages/playground/cli/vite.config.ts +++ b/packages/playground/cli/vite.config.ts @@ -39,8 +39,8 @@ export default defineConfig({ ], input: 'packages/playground/cli/src/cli.ts', output: { - format: 'cjs', - entryFileNames: '[name].cjs', + format: 'es', + entryFileNames: '[name].js', }, }, },