php-wasm-xmlwriter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/8.0.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.0-xmlwriter.so', url: new URL('./php8.0-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/8.1.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.1-xmlwriter.so', url: new URL('./php8.1-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/8.2.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.2-xmlwriter.so', url: new URL('./php8.2-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/8.3.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.3-xmlwriter.so', url: new URL('./php8.3-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/8.4.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.4-xmlwriter.so', url: new URL('./php8.4-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/8.5.mjs ADDED
@@ -0,0 +1,13 @@
1
+ const importMeta = import.meta;
2
+ const url = new URL(importMeta.url ?? 'http://example.com#this-is-an-error-supression-hack');
3
+ const ini = !!(Number(url.searchParams.get('ini') ?? true));
4
+
5
+ /**
6
+ * Returns the shared library definitions for this package build.
7
+ * @returns {Array<object>} Shared library definitions for the current package version.
8
+ */
9
+ export const getLibs = () => [
10
+ {name: 'php8.5-xmlwriter.so', url: new URL('./php8.5-xmlwriter.so', import.meta.url), ini}
11
+ ];
12
+
13
+ export default {getLibs};
package/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # php-wasm-xmlwriter
2
+
3
+ `php-wasm-xmlwriter` provides the `xmlwriter` extension for `php-wasm`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install php-wasm php-wasm-libxml php-wasm-xmlwriter
9
+ ```
10
+
11
+ ## What It Loads
12
+
13
+ The package resolves the active runtime version to `php8.x-xmlwriter.so`.
14
+ Load `php-wasm-libxml` alongside it when you are using XMLWriter as a shared or dynamic extension.
15
+
16
+ ## Usage
17
+
18
+ ```js
19
+ import { PhpWeb } from 'php-wasm/PhpWeb.mjs';
20
+ import libxml from 'php-wasm-libxml';
21
+ import xmlwriter from 'php-wasm-xmlwriter';
22
+
23
+ const php = new PhpWeb({
24
+ version: '8.4',
25
+ sharedLibs: [libxml, xmlwriter],
26
+ });
27
+
28
+ await php.run(`<?php var_dump(extension_loaded('xmlwriter'));`);
29
+ ```
30
+
31
+ ## Custom Builds
32
+
33
+ Enable `WITH_XMLWRITER` in `.php-wasm-rc`.
34
+ Shared and dynamic XMLWriter builds also need `WITH_LIBXML` enabled.
35
+
36
+ ## Build Options
37
+
38
+ - `WITH_XMLWRITER`: defaults to `dynamic`. Allowed values: `0`, `1`, `static`, `dynamic`.
39
+ - `WITH_LIBXML`: `WITH_XMLWRITER=static` requires `WITH_LIBXML=static`. `WITH_XMLWRITER=dynamic` requires libxml to be enabled in the build.
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export type PhpRuntimeVersion = '8.0' | '8.1' | '8.2' | '8.3' | '8.4' | '8.5';
2
+ export interface PhpVersionedRuntime { phpVersion?: PhpRuntimeVersion; }
3
+ export interface PhpPreloadFile { url: string | URL; path?: string; parent?: string; name?: string; }
4
+ export interface PhpSharedLibrary { name?: string; url: string | URL; ini?: boolean; getLibs?: () => PhpSharedLibrary[]; getFiles?: () => PhpPreloadFile[]; }
5
+ export function getLibs(php: PhpVersionedRuntime): PhpSharedLibrary[];
6
+ declare const _default: { getLibs: typeof getLibs };
7
+ export default _default;
package/index.mjs ADDED
@@ -0,0 +1,24 @@
1
+ import xmlwriter8_5 from './8.5.mjs';
2
+ import xmlwriter8_4 from './8.4.mjs';
3
+ import xmlwriter8_3 from './8.3.mjs';
4
+ import xmlwriter8_2 from './8.2.mjs';
5
+ import xmlwriter8_1 from './8.1.mjs';
6
+ import xmlwriter8_0 from './8.0.mjs';
7
+
8
+ const versionTable = {
9
+ '8.5': xmlwriter8_5,
10
+ '8.4': xmlwriter8_4,
11
+ '8.3': xmlwriter8_3,
12
+ '8.2': xmlwriter8_2,
13
+ '8.1': xmlwriter8_1,
14
+ '8.0': xmlwriter8_0
15
+ };
16
+
17
+ /**
18
+ * Returns the shared library definitions for the active PHP version.
19
+ * @param {object} php PHP runtime wrapper used to select the versioned package build.
20
+ * @returns {Array<object>} Shared library definitions for the active PHP version.
21
+ */
22
+ export const getLibs = php => versionTable[php.phpVersion].getLibs();
23
+
24
+ export default {getLibs};
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "php-wasm-xmlwriter",
3
+ "description": "xmlwriter for php-wasm.",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "git+https://github.com/seanmorris/php-wasm.git"
7
+ },
8
+ "author": "Sean Morris <php-wasm@seanmorr.is>",
9
+ "version": "0.1.0",
10
+ "main": "index.mjs",
11
+ "types": "index.d.ts",
12
+ "files": [
13
+ "*.mjs",
14
+ "index.d.ts",
15
+ "test/basic.mjs",
16
+ "README.md",
17
+ "static.mak",
18
+ "*.so"
19
+ ]
20
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/static.mak ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env make
2
+
3
+ DOCKER_RUN_IN_EXT_XMLWRITER =${DOCKER_ENV} -e NOCONFIGURE=1 -e EMCC_CFLAGS='-fPIC -flto -O${SUB_OPTIMIZE}' -w /src/third_party/php${PHP_VERSION}-xmlwriter/ emscripten-builder
4
+
5
+ WITH_XMLWRITER?=dynamic
6
+
7
+ ifeq ($(filter ${WITH_XMLWRITER},0 1 static dynamic),)
8
+ $(error WITH_XMLWRITER MUST BE 0, 1, static, OR dynamic. WITH_XMLWRITER: '${WITH_XMLWRITER}' PLEASE CHECK YOUR SETTINGS FILE: $(abspath ${ENV_FILE}))
9
+ endif
10
+
11
+ ifeq (${WITH_XMLWRITER},1)
12
+ WITH_XMLWRITER=dynamic
13
+ endif
14
+
15
+ ifeq (${WITH_XMLWRITER},static)
16
+ ifeq ($(filter ${WITH_LIBXML},static),)
17
+ $(error WITH_XMLWRITER=static REQUIRES WITH_LIBXML=static. WITH_LIBXML: '${WITH_LIBXML}' WITH_XMLWRITER: '${WITH_XMLWRITER}' PLEASE CHECK YOUR SETTINGS FILE: $(abspath ${ENV_FILE}))
18
+ endif
19
+ CONFIGURE_FLAGS+= --enable-xmlwriter
20
+ TEST_LIST+=$(shell ls packages/xmlwriter/test/*.mjs)
21
+ endif
22
+
23
+ ifeq (${WITH_XMLWRITER},dynamic)
24
+ ifeq ($(filter ${WITH_LIBXML},1 static shared dynamic),)
25
+ $(error WITH_XMLWRITER=dynamic REQUIRES WITH_LIBXML=[static|shared]. WITH_LIBXML: '${WITH_LIBXML}' WITH_XMLWRITER: '${WITH_XMLWRITER}' PLEASE CHECK YOUR SETTINGS FILE: $(abspath ${ENV_FILE}))
26
+ endif
27
+ TEST_LIST+=$(shell ls packages/xmlwriter/test/*.mjs)
28
+ EXTRA_MODULES+= packages/xmlwriter/php${PHP_VERSION}-xmlwriter.so
29
+ endif
30
+
31
+ third_party/php${PHP_VERSION}-xmlwriter/config.m4: third_party/php${PHP_VERSION}-src/patched
32
+ ${DOCKER_RUN} cp -Lprf /src/third_party/php${PHP_VERSION}-src/ext/xmlwriter /src/third_party/php${PHP_VERSION}-xmlwriter
33
+
34
+ packages/xmlwriter/php${PHP_VERSION}-xmlwriter.so: ${PHPIZE} third_party/php${PHP_VERSION}-xmlwriter/config.m4
35
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} chmod +x /src/third_party/php${PHP_VERSION}-src/scripts/phpize;
36
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} /src/third_party/php${PHP_VERSION}-src/scripts/phpize;
37
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} emconfigure ./configure PKG_CONFIG_PATH=${PKG_CONFIG_PATH} --prefix='/src/lib/php${PHP_VERSION}' --with-php-config=/src/lib/php${PHP_VERSION}/bin/php-config;
38
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} sed -i 's#-shared#-static#g' Makefile;
39
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} sed -i 's#-export-dynamic##g' Makefile;
40
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} emmake make -j${CPU_COUNT} EXTRA_INCLUDES='-I/src/third_party/php${PHP_VERSION}-src';
41
+ ${DOCKER_RUN_IN_EXT_XMLWRITER} emcc -shared -o /src/$@ -fPIC -flto -sSIDE_MODULE=1 -O${SUB_OPTIMIZE} -Wl,--whole-archive .libs/xmlwriter.a /src/packages/libxml/libxml2.so
package/test/basic.mjs ADDED
@@ -0,0 +1,48 @@
1
+ import { test } from 'node:test';
2
+ import { strict as assert } from 'node:assert';
3
+ import { PhpNode } from '../../../test/lib/PhpNode.mjs';
4
+ import { env } from 'node:process';
5
+
6
+ import libxml from 'php-wasm-libxml';
7
+ import xmlwriter from 'php-wasm-xmlwriter';
8
+
9
+ test('XMLWriter Extension is enabled. (loaded via strings)', async () => {
10
+ const php = env.WITH_XMLWRITER === 'dynamic'
11
+ ? new PhpNode({sharedLibs:[
12
+ { url: './packages/libxml/libxml2.so', ini: false },
13
+ `./packages/xmlwriter/php${process.env.PHP_VERSION ?? '8.4'}-xmlwriter.so`
14
+ ]})
15
+ : new PhpNode;
16
+
17
+ let stdOut = '', stdErr = '';
18
+
19
+ php.addEventListener('output', event => event.detail.forEach(line => void (stdOut += line)));
20
+ php.addEventListener('error', event => event.detail.forEach(line => void (stdErr += line)));
21
+
22
+ await php.binary;
23
+
24
+ const exitCode = await php.run(`<?php var_dump(extension_loaded('xmlwriter'));`);
25
+
26
+ assert.equal(exitCode, 0);
27
+ assert.equal(stdOut, `bool(true)\n`);
28
+ assert.equal(stdErr, '');
29
+ });
30
+
31
+ test('XMLWriter Extension is enabled. (loaded via module)', async () => {
32
+ const php = env.WITH_XMLWRITER === 'dynamic'
33
+ ? new PhpNode({sharedLibs:[libxml, xmlwriter]})
34
+ : new PhpNode;
35
+
36
+ let stdOut = '', stdErr = '';
37
+
38
+ php.addEventListener('output', event => event.detail.forEach(line => void (stdOut += line)));
39
+ php.addEventListener('error', event => event.detail.forEach(line => void (stdErr += line)));
40
+
41
+ await php.binary;
42
+
43
+ const exitCode = await php.run(`<?php var_dump(extension_loaded('xmlwriter'));`);
44
+
45
+ assert.equal(exitCode, 0);
46
+ assert.equal(stdOut, `bool(true)\n`);
47
+ assert.equal(stdErr, '');
48
+ });