Commit a7cad67
authored
[CLI] Fix __dirname not defined error in intl extension (#3094)
## Motivation for the change, related issues
Running `npx @wp-playground/cli server --debug` currently fails for
v3.0.38.
```
Unhandled rejection: ReferenceError: __dirname is not defined
at withIntl (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/node/index.js:485:20)
at async loadNodeRuntime (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/node/index.js:611:25)
at async Object.createPhpRuntime (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/cli/worker-thread-v1.js:138:48)
at async t (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:451:15)
at async PHPProcessManager.phpFactory (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2559:21)
at async PHPProcessManager.doSpawn (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2363:17)
at async PHPProcessManager.getPrimaryPhp (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2289:135)
at async PHPRequestHandler.getPrimaryPhp (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@php-wasm/universal/index.js:2585:12)
at async L (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:384:13)
at async V (file:///Users/brandon/.npm/_npx/8ab79f7a2a3f35a4/node_modules/@wp-playground/wordpress/index.js:380:10)
```
I think our tests for built npm packages should have caught this before
merging, so I would like to look into that before merging this fix.
cc @mho22
## Implementation details
Use conditional logic to determine the module directory: prefer
__dirname when available (CommonJS), fall back to import.meta.dirname
(ESM). Also switch to path.join for more robust path construction.
## Testing Instructions (or ideally a Blueprint)
- CI1 parent 5895ec4 commit a7cad67
File tree
2 files changed
+5
-2
lines changed- packages
- php-wasm/node/src/lib/extensions/intl
- playground/test-built-npm-packages/es-modules-and-vitest
2 files changed
+5
-2
lines changedLines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
0 commit comments