Skip to content

Commit 8ba3c2c

Browse files
[PHP-wasm Node] Add support for resolving wasm paths in Windows (#129)
## Motivation for the change, related issues Playground CLI can't run in Windows because it can't resolve the `wasm` file path. To fix the issue, this PR uses `path.join` and a Windows-compatible way of creating `__dirname`. ## Testing Instructions (or ideally a Blueprint) - Boot Windows 😅 - Checkout this branck - Run `bun ~packages/playground/cli/src/cli.ts server` - Confirm that WordPress works - Repeat on MacOS --------- Co-authored-by: Brandon Payton <[email protected]>
1 parent 2a3d28e commit 8ba3c2c

File tree

18 files changed

+136
-34
lines changed

18 files changed

+136
-34
lines changed

packages/php-wasm/compile/php/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ RUN set -euxo pipefail; \
12051205
# Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
12061206
# which pollutes the global namespace and does not play well with import() mechanics.
12071207
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
1208-
echo "const dependencyFilename = __dirname + '/${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
1208+
echo "const dependencyFilename = path.join(__dirname, '${PHP_VERSION_ESCAPED}', '$WASM_FILENAME');" >> /root/output/php-module.js; \
12091209
else \
12101210
echo "import dependencyFilename from './${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
12111211
fi; \

packages/php-wasm/compile/php/esm-node-boilerplate.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';

packages/php-wasm/node/asyncify/php_7_2.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_2_34/php_7_2.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_2_34', 'php_7_2.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15174064;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_7_3.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_3_33/php_7_3.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_3_33', 'php_7_3.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15264356;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_7_4.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_4_33/php_7_4.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_4_33', 'php_7_4.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15767571;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_8_0.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_0_30/php_8_0.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_0_30', 'php_8_0.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14885873;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_8_1.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_1_23/php_8_1.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_1_23', 'php_8_1.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14866086;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_8_2.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_2_10/php_8_2.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_2_10', 'php_8_2.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15123547;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_8_3.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_3_0/php_8_3.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_3_0', 'php_8_3.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15504351;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/asyncify/php_8_4.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_4_0/php_8_4.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_4_0', 'php_8_4.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 18827718;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_7_2.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_2_34/php_7_2.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_2_34', 'php_7_2.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14902784;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_7_3.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_3_33/php_7_3.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_3_33', 'php_7_3.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14999493;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_7_4.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/7_4_33/php_7_4.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '7_4_33', 'php_7_4.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15481719;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_8_0.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_0_30/php_8_0.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_0_30', 'php_8_0.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14670932;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_8_1.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_1_23/php_8_1.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_1_23', 'php_8_1.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14677997;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_8_2.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_2_10/php_8_2.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_2_10', 'php_8_2.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 14936153;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_8_3.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_3_0/php_8_3.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_3_0', 'php_8_3.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 15318281;
1016
export function init(RuntimeName, PHPLoader) {

packages/php-wasm/node/jspi/php_8_4.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
// this code in Node.js as an ES module.
44
import { createRequire } from 'module';
55
const require = createRequire(import.meta.url);
6-
const __dirname = new URL('.', import.meta.url).pathname;
7-
const dependencyFilename = __dirname + '/8_4_0/php_8_4.wasm';
6+
import { fileURLToPath } from 'url';
7+
import { dirname } from 'path';
8+
9+
const __filename = fileURLToPath(import.meta.url);
10+
const __dirname = dirname(__filename);
11+
12+
import path from 'path';
13+
const dependencyFilename = path.join(__dirname, '8_4_0', 'php_8_4.wasm');
814
export { dependencyFilename };
915
export const dependenciesTotalSize = 18644334;
1016
export function init(RuntimeName, PHPLoader) {

0 commit comments

Comments
 (0)