Skip to content

Commit

Permalink
PHP.wasm Node: Revert a part of #1289, do not import a .wasm file (#1348
Browse files Browse the repository at this point in the history
)

#1289 shipped a
PHP.wasm building logic that used an import statement instead of
composing a path of __dirname. It did that to support Bun bundling, as
Bun needs those static imports to include the .wasm files in the single
executable. Unfortunately, that change broke npm bundling and
publishing, resulting in a broken package that doesn't ship the correct
paths and builds a broken index.cjs file.
  • Loading branch information
adamziel authored Apr 30, 2024
1 parent ec6b478 commit 2f28635
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 27 deletions.
6 changes: 5 additions & 1 deletion packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,11 @@ RUN set -euxo pipefail; \
# Turn the php.js file into an ES module
# Manually turn the output into a esm module instead of relying on -s MODULARIZE=1.
# which pollutes the global namespace and does not play well with import() mechanics.
echo "import dependencyFilename from './${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
if [ "$EMSCRIPTEN_ENVIRONMENT" = "node" ]; then \
echo "const dependencyFilename = __dirname + '/${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
else \
echo "import dependencyFilename from './${PHP_VERSION_ESCAPED}/$WASM_FILENAME'; " >> /root/output/php-module.js; \
fi; \
echo "export { dependencyFilename }; " >> /root/output/php-module.js && \
echo "export const dependenciesTotalSize = $FILE_SIZE; " >> /root/output/php-module.js && \
cat /root/esm-prefix.js >> /root/output/php-module.js && \
Expand Down
5 changes: 0 additions & 5 deletions packages/php-wasm/fs-journal/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import { join } from 'path';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteTsConfigPaths } from '../../vite-ts-config-paths';

// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteWasmLoader } from '../../vite-wasm-loader';

export default defineConfig({
cacheDir: '../../../node_modules/.vite/php-wasm-fs-journal',

Expand All @@ -22,8 +19,6 @@ export default defineConfig({
viteTsConfigPaths({
root: '../../../',
}),

viteWasmLoader,
],

// Configuration for building your library.
Expand Down
4 changes: 1 addition & 3 deletions packages/php-wasm/node/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"cp -rf packages/php-wasm/node/public/* dist/packages/php-wasm/node",
"node packages/php-wasm/node/bin/postprocess-php-modules.cjs dist/packages/php-wasm/node",
"rm -rf dist/packages/php-wasm/node/*.wasm"
"cp -rf packages/php-wasm/node/public/* dist/packages/php-wasm/node"
],
"parallel": false
},
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './7_0_33/php_7_0.wasm';
const dependencyFilename = __dirname + '/7_0_33/php_7_0.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13118939;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './7_1_30/php_7_1.wasm';
const dependencyFilename = __dirname + '/7_1_30/php_7_1.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13643181;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './7_2_34/php_7_2.wasm';
const dependencyFilename = __dirname + '/7_2_34/php_7_2.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14335706;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './7_3_33/php_7_3.wasm';
const dependencyFilename = __dirname + '/7_3_33/php_7_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14441796;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_7_4.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './7_4_33/php_7_4.wasm';
const dependencyFilename = __dirname + '/7_4_33/php_7_4.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14675209;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_0.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './8_0_30/php_8_0.wasm';
const dependencyFilename = __dirname + '/8_0_30/php_8_0.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13904218;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './8_1_23/php_8_1.wasm';
const dependencyFilename = __dirname + '/8_1_23/php_8_1.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 13884035;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './8_2_10/php_8_2.wasm';
const dependencyFilename = __dirname + '/8_2_10/php_8_2.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14143340;
export function init(RuntimeName, PHPLoader) {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/node/public/php_8_3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dependencyFilename from './8_3_0/php_8_3.wasm';
const dependencyFilename = __dirname + '/8_3_0/php_8_3.wasm';
export { dependencyFilename };
export const dependenciesTotalSize = 14523141;
export function init(RuntimeName, PHPLoader) {
Expand Down
3 changes: 0 additions & 3 deletions packages/php-wasm/node/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import viteTsConfigPaths from 'vite-tsconfig-paths';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteWasmLoader } from '../../vite-wasm-loader';

export default defineConfig(function () {
return {
Expand All @@ -16,7 +14,6 @@ export default defineConfig(function () {
viteTsConfigPaths({
root: '../../../',
}),
viteWasmLoader,
],

// Configuration for building your library.
Expand Down
4 changes: 0 additions & 4 deletions packages/playground/blueprints/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { join } from 'path';

// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteTsConfigPaths } from '../../vite-ts-config-paths';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteWasmLoader } from '../../vite-wasm-loader';

export default defineConfig({
cacheDir: '../../../node_modules/.vite/playground-blueprints',
Expand All @@ -21,8 +19,6 @@ export default defineConfig({
viteTsConfigPaths({
root: '../../../',
}),

viteWasmLoader,
],

// Uncomment this if you are using workers.
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/sync/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { viteTsConfigPaths } from '../../vite-ts-config-paths';

// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteWasmLoader } from '../../vite-wasm-loader';
import ignoreWasmImports from '../ignore-wasm-imports';

export default {
base: '/',
Expand All @@ -20,7 +20,7 @@ export default {
viteTsConfigPaths({
root: '../../../',
}),
viteWasmLoader,
ignoreWasmImports,
],

// Configuration for building your library.
Expand Down

0 comments on commit 2f28635

Please sign in to comment.