Skip to content

Commit

Permalink
Playground CLI: ship as ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Apr 30, 2024
1 parent bbe15f8 commit a33d844
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/playground/cli/public/wp-playground.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
import './cli.cjs';
import './cli.js';
14 changes: 10 additions & 4 deletions packages/playground/cli/src/setup-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
BasePHP,
PHPRequestHandler,
SupportedPHPVersion,
__private__dont__use,
rotatePHPRuntime,
} from '@php-wasm/universal';
import { rootCertificates } from 'tls';
Expand Down Expand Up @@ -82,18 +81,25 @@ 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);
}
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
);
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/cli/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},
Expand Down

0 comments on commit a33d844

Please sign in to comment.