Skip to content

Commit fc24cb0

Browse files
bgrgicakadamziel
andauthored
[PHP-wasm Node] Fix Identifier '__filename' has already been declared (#143)
## Motivation for the change, related issues `__filename` and `__dirname` are available in CommonJS but unavailable in ES modules. ([Node.js docs](https://nodejs.org/api/esm.html#no-__filename-or-__dirname)). In Automattic/wordpress-playground-private#129 we made sure `__filename` and `__dirname` are available, but this broke ES module support and the latest version of PHP-wasm (1.0.36) can't initialize the PHP environment because of errors like `The "path" argument must be of type string or an instance of URL. Received undefined` and `SyntaxError: Identifier '__filename' has already been declared` ## Implementation details This PR addresses the issue by creating only the `__dirname` and `__filename` constants only if they weren't previously defined. The downside is that we need to define them as vars and not consts. The PR also adds package install tests to CI, and the test creates temporary packages from the current commit, installs them into an ESM and CJS project,t and runs simple tests that boot WordPress using `runCLI`. ## Testing Instructions (or ideally a Blueprint) I tested this by manually updating PHP-wasm and Playground packages in Studio and a personal project. I also tested that we can run Playground CLI using `npx PACKAGE_URL server`, and that we can use the CLI in Windows and MacOS using Bun. - Run `npx nx debug playground-cli --php=8.3 server` and confirm it still works --------- Co-authored-by: Adam Zieliński <[email protected]>
1 parent ef8d3e3 commit fc24cb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+638
-237
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,55 @@ jobs:
234234
uses: geekyeggo/delete-artifact@v2
235235
with:
236236
name: playwright-dist
237+
test-built-npm-packages:
238+
runs-on: wordpress-playground-private
239+
needs: [lint-and-typecheck]
240+
steps:
241+
- uses: actions/checkout@v4
242+
with:
243+
submodules: true
244+
- uses: ./.github/actions/prepare-playground
245+
- name: Generate a mock version number (for releasing the packages in a local registry) and store it as a global variable
246+
run: |
247+
VERSION=$(date +%s)
248+
CURRENT_VERSION=$(jq -r '.version' lerna.json)
249+
PORT=9934
250+
PACKAGE_BASE_URL=http://127.0.0.1:$PORT/$VERSION
251+
echo "VERSION=$VERSION" >> $GITHUB_ENV
252+
echo "PORT=$PORT" >> $GITHUB_ENV
253+
echo "PACKAGE_BASE_URL=$PACKAGE_BASE_URL" >> $GITHUB_ENV
254+
echo "PACKAGE_URL=$PACKAGE_BASE_URL/v$CURRENT_VERSION/@wp-playground-cli-$CURRENT_VERSION.tar.gz" >> $GITHUB_ENV
255+
echo "HOST_PATH=./dist/packages-for-self-hosting/http%3A%2F%2F127.0.0.1%3A$PORT%2F$VERSION" >> $GITHUB_ENV
256+
- name: Package repository
257+
run: |
258+
npx nx run-many --all --target=package-for-self-hosting -- --hostingBaseUrl="$PACKAGE_BASE_URL"
259+
- name: Install Bun
260+
uses: oven-sh/setup-bun@v2
261+
- name: Start a local node package registry server
262+
run: RUNNER_TRACKING_ID="" && (nohup bun ./packages/playground/cli/src/cli.ts server --port=$PORT --mount="$HOST_PATH:/wordpress/$VERSION" --quiet&)
263+
- name: Wait for the package server to be ready
264+
run: |
265+
for i in {1..60}; do
266+
curl_output=$(curl -v $PACKAGE_URL 2>&1)
267+
if [ $? -eq 0 ]; then
268+
break
269+
fi
270+
sleep 1
271+
done
272+
- name: Run integration tests in an ES Modules project
273+
run: |
274+
cd packages/playground/test-built-npm-packages/es-modules-and-vitest
275+
jq --arg package_url "$PACKAGE_URL" '.devDependencies["@wp-playground/cli"] = $package_url' package.json > package.json.tmp
276+
mv package.json.tmp package.json
277+
npm install
278+
npm run test
279+
- name: Run integration tests in a CommonJS project
280+
run: |
281+
cd packages/playground/test-built-npm-packages/commonjs-and-jest
282+
jq --arg package_url "$PACKAGE_URL" '.devDependencies["@wp-playground/cli"] = $package_url' package.json > package.json.tmp
283+
mv package.json.tmp package.json
284+
npm install
285+
npm run test
237286
238287
build:
239288
runs-on: wordpress-playground-private

CHANGELOG.md

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,120 +4,111 @@ All notable changes to this project are documented in this file by a CI job
44
that runs on every NPM release. The file follows the [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
55
format.
66

7-
## [v1.0.37] (2025-05-15)
7+
## [v1.0.37] (2025-05-15)
88

99
### Various
1010

11-
- Define `DB_NAME` constant when it's missing. ([#140](https://github.com/Automattic/wordpress-playground-private/pull/140))
12-
- Support limiting files added to self-hosted packages. ([#149](https://github.com/Automattic/wordpress-playground-private/pull/149))
11+
- Define `DB_NAME` constant when it's missing. ([#140](https://github.com/Automattic/wordpress-playground-private/pull/140))
12+
- Support limiting files added to self-hosted packages. ([#149](https://github.com/Automattic/wordpress-playground-private/pull/149))
1313

1414
### Contributors
1515

1616
The following contributors merged PRs in this release:
1717

1818
@brandonpayton @JanJakes
1919

20-
21-
## [v1.0.36] (2025-05-08)
20+
## [v1.0.36] (2025-05-08)
2221

2322
### Various
2423

25-
- Document mounting OPFS storage *after* the boot. ([#141](https://github.com/Automattic/wordpress-playground-private/pull/141))
26-
- QUERY_STRING should default to empty string. ([#139](https://github.com/Automattic/wordpress-playground-private/pull/139))
27-
- Remove null steps that are added. ([#135](https://github.com/Automattic/wordpress-playground-private/pull/135))
28-
- [CLI] Fix package entry point path. ([#136](https://github.com/Automattic/wordpress-playground-private/pull/136))
24+
- Document mounting OPFS storage _after_ the boot. ([#141](https://github.com/Automattic/wordpress-playground-private/pull/141))
25+
- QUERY_STRING should default to empty string. ([#139](https://github.com/Automattic/wordpress-playground-private/pull/139))
26+
- Remove null steps that are added. ([#135](https://github.com/Automattic/wordpress-playground-private/pull/135))
27+
- [CLI] Fix package entry point path. ([#136](https://github.com/Automattic/wordpress-playground-private/pull/136))
2928

3029
### Contributors
3130

3231
The following contributors merged PRs in this release:
3332

3433
@ashfame @bgrgicak @sejas
3534

35+
## [v1.0.35] (2025-05-08)
3636

37-
## [v1.0.35] (2025-05-08)
38-
39-
40-
41-
42-
## [v1.0.34] (2025-05-08)
37+
## [v1.0.34] (2025-05-08)
4338

4439
### Various
4540

46-
- Document mounting OPFS storage *after* the boot. ([#141](https://github.com/Automattic/wordpress-playground-private/pull/141))
41+
- Document mounting OPFS storage _after_ the boot. ([#141](https://github.com/Automattic/wordpress-playground-private/pull/141))
4742

4843
### Contributors
4944

5045
The following contributors merged PRs in this release:
5146

5247
@ashfame
5348

54-
55-
## [v1.0.33] (2025-05-08)
49+
## [v1.0.33] (2025-05-08)
5650

5751
### Various
5852

59-
- Add MySQL network calls to Asyncify tests. ([#108](https://github.com/Automattic/wordpress-playground-private/pull/108))
60-
- Format the plugin-proxy file. ([#127](https://github.com/Automattic/wordpress-playground-private/pull/127))
61-
- Plugin proxy: Allow all repos from WordPress, Automattic and Woocommerce organizations. ([#128](https://github.com/Automattic/wordpress-playground-private/pull/128))
62-
- QUERY_STRING should default to empty string. ([#139](https://github.com/Automattic/wordpress-playground-private/pull/139))
63-
- Remove null steps that are added. ([#135](https://github.com/Automattic/wordpress-playground-private/pull/135))
64-
- Remove unused dependencies. ([#116](https://github.com/Automattic/wordpress-playground-private/pull/116))
65-
- [CLI] Fix package entry point path. ([#136](https://github.com/Automattic/wordpress-playground-private/pull/136))
66-
- [PHP-wasm Node] Add support for resolving wasm paths in Windows. ([#129](https://github.com/Automattic/wordpress-playground-private/pull/129))
67-
- [PHP-wasm Node] Dynamically mount symlinks. ([#125](https://github.com/Automattic/wordpress-playground-private/pull/125))
53+
- Add MySQL network calls to Asyncify tests. ([#108](https://github.com/Automattic/wordpress-playground-private/pull/108))
54+
- Format the plugin-proxy file. ([#127](https://github.com/Automattic/wordpress-playground-private/pull/127))
55+
- Plugin proxy: Allow all repos from WordPress, Automattic and Woocommerce organizations. ([#128](https://github.com/Automattic/wordpress-playground-private/pull/128))
56+
- QUERY_STRING should default to empty string. ([#139](https://github.com/Automattic/wordpress-playground-private/pull/139))
57+
- Remove null steps that are added. ([#135](https://github.com/Automattic/wordpress-playground-private/pull/135))
58+
- Remove unused dependencies. ([#116](https://github.com/Automattic/wordpress-playground-private/pull/116))
59+
- [CLI] Fix package entry point path. ([#136](https://github.com/Automattic/wordpress-playground-private/pull/136))
60+
- [PHP-wasm Node] Add support for resolving wasm paths in Windows. ([#129](https://github.com/Automattic/wordpress-playground-private/pull/129))
61+
- [PHP-wasm Node] Dynamically mount symlinks. ([#125](https://github.com/Automattic/wordpress-playground-private/pull/125))
6862

6963
### Contributors
7064

7165
The following contributors merged PRs in this release:
7266

7367
@adamziel @ashfame @bgrgicak @ingeniumed @sejas
7468

75-
76-
## [v1.0.32] (2025-05-06)
69+
## [v1.0.32] (2025-05-06)
7770

7871
### Various
7972

80-
- Add MySQL network calls to Asyncify tests. ([#108](https://github.com/Automattic/wordpress-playground-private/pull/108))
81-
- Format the plugin-proxy file. ([#127](https://github.com/Automattic/wordpress-playground-private/pull/127))
82-
- Plugin proxy: Allow all repos from WordPress, Automattic and Woocommerce organizations. ([#128](https://github.com/Automattic/wordpress-playground-private/pull/128))
83-
- Remove unused dependencies. ([#116](https://github.com/Automattic/wordpress-playground-private/pull/116))
84-
- [PHP-wasm Node] Add support for resolving wasm paths in Windows. ([#129](https://github.com/Automattic/wordpress-playground-private/pull/129))
85-
- [PHP-wasm Node] Dynamically mount symlinks. ([#125](https://github.com/Automattic/wordpress-playground-private/pull/125))
73+
- Add MySQL network calls to Asyncify tests. ([#108](https://github.com/Automattic/wordpress-playground-private/pull/108))
74+
- Format the plugin-proxy file. ([#127](https://github.com/Automattic/wordpress-playground-private/pull/127))
75+
- Plugin proxy: Allow all repos from WordPress, Automattic and Woocommerce organizations. ([#128](https://github.com/Automattic/wordpress-playground-private/pull/128))
76+
- Remove unused dependencies. ([#116](https://github.com/Automattic/wordpress-playground-private/pull/116))
77+
- [PHP-wasm Node] Add support for resolving wasm paths in Windows. ([#129](https://github.com/Automattic/wordpress-playground-private/pull/129))
78+
- [PHP-wasm Node] Dynamically mount symlinks. ([#125](https://github.com/Automattic/wordpress-playground-private/pull/125))
8679

8780
### Contributors
8881

8982
The following contributors merged PRs in this release:
9083

9184
@adamziel @bgrgicak @ingeniumed
9285

93-
94-
## [v1.0.31] (2025-04-29)
86+
## [v1.0.31] (2025-04-29)
9587

9688
### Bug Fixes
9789

98-
- Fix changelog version order. ([#100](https://github.com/Automattic/wordpress-playground-private/pull/100))
99-
- Fix openssl library paths in php-wasm build. ([#102](https://github.com/Automattic/wordpress-playground-private/pull/102))
90+
- Fix changelog version order. ([#100](https://github.com/Automattic/wordpress-playground-private/pull/100))
91+
- Fix openssl library paths in php-wasm build. ([#102](https://github.com/Automattic/wordpress-playground-private/pull/102))
10092

10193
### Various
10294

103-
- Add private fork links to the changelog. ([#98](https://github.com/Automattic/wordpress-playground-private/pull/98))
104-
- Allow public access to A8C Playground instance. ([#119](https://github.com/Automattic/wordpress-playground-private/pull/119))
105-
- Make php-wasm and Playground CLI's fast to run with Node.js. ([#107](https://github.com/Automattic/wordpress-playground-private/pull/107))
106-
- Playground CLI: Add `skipSqliteSetup` flag for MySQL support. ([#97](https://github.com/Automattic/wordpress-playground-private/pull/97))
107-
- Prep the WP update workflows to be re-enabled. ([#110](https://github.com/Automattic/wordpress-playground-private/pull/110))
108-
- Support building for additional remote origins. ([#122](https://github.com/Automattic/wordpress-playground-private/pull/122))
109-
- Tweak Blueprint test string to match WP 6.8. ([#117](https://github.com/Automattic/wordpress-playground-private/pull/117))
110-
- Update Nx, Vite, and ESLint dependencies. ([#35](https://github.com/Automattic/wordpress-playground-private/pull/35))
111-
- Upgrade octokit to 3.1.2 to fix vulnerability. ([#106](https://github.com/Automattic/wordpress-playground-private/pull/106))
112-
- Use Node as the Vitest environment. ([#96](https://github.com/Automattic/wordpress-playground-private/pull/96))
95+
- Add private fork links to the changelog. ([#98](https://github.com/Automattic/wordpress-playground-private/pull/98))
96+
- Allow public access to A8C Playground instance. ([#119](https://github.com/Automattic/wordpress-playground-private/pull/119))
97+
- Make php-wasm and Playground CLI's fast to run with Node.js. ([#107](https://github.com/Automattic/wordpress-playground-private/pull/107))
98+
- Playground CLI: Add `skipSqliteSetup` flag for MySQL support. ([#97](https://github.com/Automattic/wordpress-playground-private/pull/97))
99+
- Prep the WP update workflows to be re-enabled. ([#110](https://github.com/Automattic/wordpress-playground-private/pull/110))
100+
- Support building for additional remote origins. ([#122](https://github.com/Automattic/wordpress-playground-private/pull/122))
101+
- Tweak Blueprint test string to match WP 6.8. ([#117](https://github.com/Automattic/wordpress-playground-private/pull/117))
102+
- Update Nx, Vite, and ESLint dependencies. ([#35](https://github.com/Automattic/wordpress-playground-private/pull/35))
103+
- Upgrade octokit to 3.1.2 to fix vulnerability. ([#106](https://github.com/Automattic/wordpress-playground-private/pull/106))
104+
- Use Node as the Vitest environment. ([#96](https://github.com/Automattic/wordpress-playground-private/pull/96))
113105

114106
### Contributors
115107

116108
The following contributors merged PRs in this release:
117109

118110
@bgrgicak @brandonpayton @ivan-ottinger @wojtekn
119111

120-
121112
## [v1.0.30] (2025-04-07)
122113

123114
### Bug Fixes

0 commit comments

Comments
 (0)