@php-wasm/universal 3.1.22 → 3.1.26
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/README.md +6 -5
- package/index.cjs +16 -15
- package/index.cjs.map +1 -1
- package/index.js +983 -396
- package/index.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/load-extension.d.ts +117 -145
- package/package.json +7 -6
- package/php-extension-manifest-schema-validator.d.ts +10 -0
- package/php-extension-manifest-schema-validator.js +1467 -0
- package/php-extension-manifest-schema.json +83 -0
package/lib/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export { rotatePHPRuntime } from './rotate-php-runtime';
|
|
|
36
36
|
export { writeFiles } from './write-files';
|
|
37
37
|
export type { FileTree } from './write-files';
|
|
38
38
|
export { withResolvedPHPExtensions, installPHPExtensionFilesSync, PHP_EXTENSIONS_DIR, resolvePHPExtension, } from './load-extension';
|
|
39
|
-
export type { InstallPHPExtensionFilesOptions,
|
|
39
|
+
export type { InstallPHPExtensionFilesOptions, PHPExtensionIniDirective, ResolvedInstallOptions, ResolvedPHPExtension, PHPExtensionManifest, PHPExtensionManifestExtraFiles, PHPExtensionSource, } from './load-extension';
|
|
40
40
|
export { DEFAULT_BASE_URL, ensurePathPrefix, removePathPrefix, toRelativeUrl, } from './urls';
|
|
41
41
|
export { isExitCode } from './is-exit-code';
|
|
42
42
|
export { proxyFileSystem, isPathToSharedFS } from './proxy-file-system';
|
package/lib/load-extension.d.ts
CHANGED
|
@@ -1,156 +1,100 @@
|
|
|
1
1
|
import type { Emscripten } from './emscripten-types';
|
|
2
2
|
import type { EmscriptenOptions } from './load-php-runtime';
|
|
3
|
-
import type { FileTree } from './write-files';
|
|
4
3
|
/**
|
|
5
4
|
* Default VFS directory where PHP.wasm stages extension `.so` files and
|
|
6
5
|
* writes their per-extension ini files.
|
|
7
6
|
*/
|
|
8
7
|
export declare const PHP_EXTENSIONS_DIR = "/internal/shared/extensions";
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Extension side modules must be compiled for the same mode as the main PHP
|
|
13
|
-
* module.
|
|
14
|
-
*/
|
|
15
|
-
export type PHPWasmAsyncMode = 'jspi' | 'asyncify';
|
|
16
|
-
/**
|
|
17
|
-
* The php.ini directive used to load the extension.
|
|
18
|
-
*
|
|
19
|
-
* Use `extension` for regular PHP extensions and `zend_extension` for Zend
|
|
20
|
-
* extensions such as Xdebug.
|
|
9
|
+
* The php.ini directive used to load the extension. Use `extension` for
|
|
10
|
+
* regular PHP extensions and `zend_extension` for Zend extensions like Xdebug.
|
|
21
11
|
*/
|
|
22
12
|
export type PHPExtensionIniDirective = 'extension' | 'zend_extension';
|
|
23
13
|
/**
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* PHP major/minor version the artifact was compiled against, e.g. `8.4`.
|
|
29
|
-
*/
|
|
30
|
-
phpVersion: string;
|
|
31
|
-
/**
|
|
32
|
-
* PHP.wasm async mode the artifact was compiled against.
|
|
33
|
-
*/
|
|
34
|
-
asyncMode: PHPWasmAsyncMode;
|
|
35
|
-
/**
|
|
36
|
-
* Relative to the manifest URL/base URL, or an absolute URL.
|
|
37
|
-
*/
|
|
38
|
-
file: string;
|
|
39
|
-
/**
|
|
40
|
-
* Optional SHA-256 checksum for the fetched `.so` artifact.
|
|
41
|
-
*/
|
|
42
|
-
sha256?: string;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Extension artifact manifest.
|
|
46
|
-
*
|
|
47
|
-
* A manifest lets callers publish a matrix of `.so` files and lets
|
|
48
|
-
* `resolvePHPExtension()` select the artifact that matches the current PHP
|
|
49
|
-
* version and async mode.
|
|
14
|
+
* Extension artifact manifest. Lets callers publish a matrix of `.so` files
|
|
15
|
+
* and lets `resolvePHPExtension()` select the artifact matching the current
|
|
16
|
+
* PHP version. External extension artifacts are JSPI-only.
|
|
50
17
|
*/
|
|
51
18
|
export interface PHPExtensionManifest {
|
|
52
19
|
name: string;
|
|
53
20
|
version?: string;
|
|
54
21
|
mode?: 'php-extension';
|
|
55
|
-
artifacts:
|
|
22
|
+
artifacts: Array<{
|
|
23
|
+
/** PHP major/minor version, e.g. `8.4`. */
|
|
24
|
+
phpVersion: string;
|
|
25
|
+
/** Relative to the manifest URL/base URL, or an absolute URL. */
|
|
26
|
+
sourcePath: string;
|
|
27
|
+
/** URL-backed files needed only by this artifact. */
|
|
28
|
+
extraFiles?: PHPExtensionManifestExtraFiles;
|
|
29
|
+
}>;
|
|
30
|
+
/** URL-backed files shared by every artifact in this manifest. */
|
|
31
|
+
extraFiles?: PHPExtensionManifestExtraFiles;
|
|
32
|
+
}
|
|
33
|
+
export interface PHPExtensionManifestExtraFiles {
|
|
34
|
+
/**
|
|
35
|
+
* Absolute VFS path where files and directories are written. When a
|
|
36
|
+
* manifest declares both top-level and per-artifact `extraFiles`, the
|
|
37
|
+
* first declared `targetPath` wins. Defaults to
|
|
38
|
+
* `<extensionDir>/<name>-assets`.
|
|
39
|
+
*/
|
|
40
|
+
vfsRoot?: string;
|
|
41
|
+
nodes?: Array<{
|
|
42
|
+
/** Joined with the group's `vfsRoot` to form the final VFS path. */
|
|
43
|
+
vfsPath: string;
|
|
44
|
+
/** Defaults to "file". Only file nodes need a `sourcePath`. */
|
|
45
|
+
type?: 'file' | 'directory';
|
|
46
|
+
/** Relative to the manifest URL/base URL, or an absolute URL. */
|
|
47
|
+
sourcePath?: string;
|
|
48
|
+
}>;
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
58
|
-
* Source for a PHP extension `.so`.
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* direct artifact URL, and `format: 'manifest'` when PHP.wasm should select
|
|
62
|
-
* the right artifact from a manifest.
|
|
51
|
+
* Source for a PHP extension `.so`. Use `format: 'so'` when the caller has
|
|
52
|
+
* bytes, `format: 'url'` for a direct artifact URL, and `format: 'manifest'`
|
|
53
|
+
* when PHP.wasm should select the right artifact from a manifest.
|
|
63
54
|
*/
|
|
64
55
|
export type PHPExtensionSource = {
|
|
65
56
|
format: 'so';
|
|
66
|
-
/**
|
|
67
|
-
* Required when `PHPExtensionInstallOptions.name` is not set.
|
|
68
|
-
*/
|
|
69
57
|
name?: string;
|
|
70
58
|
bytes: Uint8Array | ArrayBuffer;
|
|
71
|
-
sha256?: string;
|
|
72
59
|
} | {
|
|
73
60
|
format: 'url';
|
|
74
|
-
/**
|
|
75
|
-
* Optional extension name. If omitted, PHP.wasm infers the name
|
|
76
|
-
* from a `.so` filename in the URL.
|
|
77
|
-
*/
|
|
78
61
|
name?: string;
|
|
79
62
|
url: string | URL;
|
|
80
|
-
sha256?: string;
|
|
81
63
|
} | {
|
|
82
64
|
format: 'manifest';
|
|
83
65
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* In `@php-wasm/universal`, string values must be absolute URLs.
|
|
87
|
-
* In `@php-wasm/node`, this may also be a filesystem path or a
|
|
88
|
-
* `file:` URL; `@php-wasm/node` resolves local paths before fetching.
|
|
66
|
+
* In `@php-wasm/universal`, must be an absolute URL. `@php-wasm/node`
|
|
67
|
+
* also accepts filesystem paths and `file:` URLs.
|
|
89
68
|
*/
|
|
90
69
|
manifestUrl: string | URL;
|
|
91
70
|
} | {
|
|
92
71
|
format: 'manifest';
|
|
93
72
|
manifest: PHPExtensionManifest;
|
|
94
|
-
/**
|
|
95
|
-
* Base URL used to resolve relative artifact paths in an inline
|
|
96
|
-
* manifest.
|
|
97
|
-
*/
|
|
73
|
+
/** Base URL for resolving relative artifact paths. */
|
|
98
74
|
baseUrl?: string | URL;
|
|
99
75
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* that the extension expects to find at runtime.
|
|
105
|
-
*/
|
|
106
|
-
export interface PHPExtensionExtraFiles {
|
|
107
|
-
/**
|
|
108
|
-
* Files are written here. Defaults to
|
|
109
|
-
* `/internal/shared/extensions/<name>-assets`.
|
|
110
|
-
*/
|
|
111
|
-
targetPath?: string;
|
|
112
|
-
files: FileTree;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Options for staging a PHP extension before startup.
|
|
116
|
-
*/
|
|
117
|
-
export interface PHPExtensionInstallOptions {
|
|
118
|
-
/**
|
|
119
|
-
* The extension artifact bytes, URL, or manifest.
|
|
120
|
-
*/
|
|
76
|
+
export type DataToResolvePhpExtension = ResolvedInstallOptions;
|
|
77
|
+
export interface ResolvedInstallOptions {
|
|
78
|
+
/** PHP major/minor version the active runtime is initializing for. */
|
|
79
|
+
phpVersion: string;
|
|
121
80
|
source: PHPExtensionSource;
|
|
122
|
-
/**
|
|
123
|
-
* Extension name used for staged file names and the first ini directive.
|
|
124
|
-
*
|
|
125
|
-
* This overrides a name inferred from `source`.
|
|
126
|
-
*/
|
|
81
|
+
/** Overrides the name inferred from `source`. */
|
|
127
82
|
name?: string;
|
|
128
83
|
/**
|
|
129
|
-
* The directive
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* Regular PHP extensions need `extension=/path/to/name.so`. Zend
|
|
133
|
-
* extensions, such as Xdebug, need `zend_extension=/path/to/name.so`.
|
|
134
|
-
* This does not edit the main `php.ini`; it controls the generated
|
|
135
|
-
* per-extension `.ini` file PHP reads while starting.
|
|
84
|
+
* The first directive of the generated startup `.ini` file. Regular
|
|
85
|
+
* extensions need `extension=...`; Zend extensions like Xdebug need
|
|
86
|
+
* `zend_extension=...`.
|
|
136
87
|
*/
|
|
137
88
|
loadWithIniDirective?: PHPExtensionIniDirective;
|
|
138
|
-
/**
|
|
139
|
-
* Additional `key=value` lines written to the generated startup `.ini`
|
|
140
|
-
* file after the `extension=` or `zend_extension=` directive.
|
|
141
|
-
*/
|
|
89
|
+
/** Additional `key=value` lines for the generated startup `.ini` file. */
|
|
142
90
|
iniEntries?: Record<string, string>;
|
|
143
91
|
/**
|
|
144
92
|
* Sidecar files to write into the PHP VFS before the extension is loaded.
|
|
145
|
-
*
|
|
146
93
|
* Use this for data files or dependency assets the extension expects at
|
|
147
94
|
* runtime.
|
|
148
95
|
*/
|
|
149
|
-
extraFiles?:
|
|
150
|
-
/**
|
|
151
|
-
* Environment variables to add to the PHP runtime before the extension is
|
|
152
|
-
* loaded.
|
|
153
|
-
*/
|
|
96
|
+
extraFiles?: ResolvedExtraFiles;
|
|
97
|
+
/** Environment variables added before the extension is loaded. */
|
|
154
98
|
env?: Record<string, string>;
|
|
155
99
|
/**
|
|
156
100
|
* VFS directory where PHP.wasm writes the extension `.so` file and its
|
|
@@ -158,70 +102,98 @@ export interface PHPExtensionInstallOptions {
|
|
|
158
102
|
*/
|
|
159
103
|
extensionDir?: string;
|
|
160
104
|
/**
|
|
161
|
-
* Fetch implementation used for
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* Runtimes may provide environment-specific defaults. For example,
|
|
165
|
-
* `@php-wasm/node` provides local file support for extension manifests and
|
|
166
|
-
* artifacts.
|
|
105
|
+
* Fetch implementation used for URL and manifest sources. Runtimes may
|
|
106
|
+
* provide environment-specific defaults; for example, `@php-wasm/node`
|
|
107
|
+
* adds local file support.
|
|
167
108
|
*/
|
|
168
109
|
fetch?: typeof fetch;
|
|
169
110
|
}
|
|
170
111
|
/**
|
|
171
|
-
*
|
|
112
|
+
* Fully resolved files and settings needed to install one extension. Produced
|
|
113
|
+
* by `resolvePHPExtension`; consumed by `withResolvedPHPExtensions` and
|
|
114
|
+
* `installPHPExtensionFilesSync`.
|
|
172
115
|
*/
|
|
173
|
-
export
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
116
|
+
export interface ResolvedPHPExtension {
|
|
117
|
+
/** Absolute VFS path the `.so` file is staged at. */
|
|
118
|
+
soPath: string;
|
|
119
|
+
/** Compiled extension bytes to write at `soPath`. */
|
|
120
|
+
soBytes: Uint8Array;
|
|
121
|
+
/** Absolute VFS path the generated per-extension ini file is staged at. */
|
|
122
|
+
iniPath: string;
|
|
123
|
+
/**
|
|
124
|
+
* Contents of the generated per-extension ini file. The first line is the
|
|
125
|
+
* `extension=` or `zend_extension=` directive; remaining lines are the
|
|
126
|
+
* caller-supplied `iniEntries`.
|
|
127
|
+
*/
|
|
128
|
+
iniContent: string;
|
|
129
|
+
/** Sidecar files staged alongside the extension. Optional. */
|
|
130
|
+
extraFiles?: ResolvedExtraFiles;
|
|
131
|
+
/** Environment variables added before PHP startup. */
|
|
132
|
+
env?: Record<string, string>;
|
|
133
|
+
/** VFS directory the `.so` and ini file live in. */
|
|
134
|
+
extensionDir: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sidecar files to stage next to an extension. Use this for data files or
|
|
138
|
+
* native-library assets the extension expects at runtime. All paths are
|
|
139
|
+
* absolute VFS paths.
|
|
140
|
+
*/
|
|
141
|
+
export interface ResolvedExtraFiles {
|
|
142
|
+
/** Absolute VFS paths to create as empty directories. */
|
|
143
|
+
directories?: string[];
|
|
144
|
+
/** Map of absolute VFS paths to file contents. */
|
|
145
|
+
files: Record<string, Uint8Array | string>;
|
|
146
|
+
}
|
|
177
147
|
/**
|
|
178
|
-
* Inputs used to build the staged `.so` path and per-extension ini file
|
|
148
|
+
* Inputs used to build the staged `.so` path and per-extension ini file when
|
|
149
|
+
* `installPHPExtensionFilesSync` is called with raw install options instead of
|
|
150
|
+
* a `ResolvedPHPExtension`.
|
|
179
151
|
*/
|
|
180
152
|
export interface InstallPHPExtensionFilesOptions {
|
|
153
|
+
/** Extension name used for staged file names and the ini directive. */
|
|
181
154
|
name: string;
|
|
155
|
+
/** Compiled extension bytes. */
|
|
182
156
|
soBytes: Uint8Array | ArrayBuffer;
|
|
157
|
+
/**
|
|
158
|
+
* The first directive of the generated startup `.ini` file. Regular
|
|
159
|
+
* extensions need `extension=...`; Zend extensions like Xdebug need
|
|
160
|
+
* `zend_extension=...`.
|
|
161
|
+
*/
|
|
183
162
|
loadWithIniDirective?: PHPExtensionIniDirective;
|
|
163
|
+
/** Additional `key=value` lines for the generated startup `.ini` file. */
|
|
184
164
|
iniEntries?: Record<string, string>;
|
|
185
|
-
|
|
165
|
+
/** Sidecar files to write into the PHP VFS before the extension is loaded. */
|
|
166
|
+
extraFiles?: ResolvedExtraFiles;
|
|
167
|
+
/** Environment variables added before the extension is loaded. */
|
|
186
168
|
env?: Record<string, string>;
|
|
169
|
+
/**
|
|
170
|
+
* VFS directory where PHP.wasm writes the extension `.so` file and its
|
|
171
|
+
* per-extension ini file. Defaults to `PHP_EXTENSIONS_DIR`.
|
|
172
|
+
*/
|
|
187
173
|
extensionDir?: string;
|
|
188
174
|
}
|
|
189
175
|
/**
|
|
190
|
-
*
|
|
176
|
+
* Resolves an extension source without mutating a PHP instance. Use this from
|
|
177
|
+
* runtimes that need to fetch extension bytes and compute `iniPath`/`iniContent`
|
|
178
|
+
* before Emscripten initializes PHP.
|
|
191
179
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*/
|
|
195
|
-
export interface ResolvedPHPExtension {
|
|
196
|
-
soPath: string;
|
|
197
|
-
soBytes: Uint8Array;
|
|
198
|
-
iniPath: string;
|
|
199
|
-
iniContent: string;
|
|
200
|
-
extraFiles?: PHPExtensionExtraFiles & {
|
|
201
|
-
targetPath: string;
|
|
202
|
-
};
|
|
203
|
-
env?: Record<string, string>;
|
|
204
|
-
extensionDir: string;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Resolves an extension source without mutating a PHP instance.
|
|
180
|
+
* Manifest-declared extra files are joined with their group's `vfsRoot` so the
|
|
181
|
+
* returned `extraFiles` always uses absolute VFS paths.
|
|
208
182
|
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
183
|
+
* TODO: Remove the remote manifest.json resolution and move it to Blueprints
|
|
184
|
+
* where the paths can be validated and downloads scheduled using the
|
|
185
|
+
* same code paths as we do for all other paths and URLs.
|
|
211
186
|
*/
|
|
212
|
-
export declare function resolvePHPExtension(options:
|
|
187
|
+
export declare function resolvePHPExtension(options: DataToResolvePhpExtension): Promise<ResolvedPHPExtension>;
|
|
213
188
|
/**
|
|
214
|
-
* Adds resolved extensions to Emscripten options.
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* and update `PHP_INI_SCAN_DIR` before PHP startup.
|
|
189
|
+
* Adds resolved extensions to Emscripten options. The returned options install
|
|
190
|
+
* extension files during `onRuntimeInitialized` and update `PHP_INI_SCAN_DIR`
|
|
191
|
+
* before PHP startup.
|
|
218
192
|
*/
|
|
219
193
|
export declare function withResolvedPHPExtensions(options: EmscriptenOptions, extensions: ResolvedPHPExtension[]): EmscriptenOptions;
|
|
220
194
|
/**
|
|
221
195
|
* Installs extension files through Emscripten's synchronous filesystem API.
|
|
222
|
-
*
|
|
223
196
|
* Use this while the PHP runtime is initializing and only the raw Emscripten
|
|
224
|
-
* `FS` object is available.
|
|
225
|
-
* file to their resolved VFS paths.
|
|
197
|
+
* `FS` object is available.
|
|
226
198
|
*/
|
|
227
199
|
export declare function installPHPExtensionFilesSync(fs: Emscripten.RootFS, options: InstallPHPExtensionFilesOptions | ResolvedPHPExtension): ResolvedPHPExtension;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/universal",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.26",
|
|
4
4
|
"description": "PHP.wasm – emscripten bindings for PHP",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,17 +37,18 @@
|
|
|
37
37
|
"module": "./index.js",
|
|
38
38
|
"types": "index.d.ts",
|
|
39
39
|
"license": "GPL-2.0-or-later",
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "6acfccb8e79f4e664429e3f729f04dbf2ff55303",
|
|
41
41
|
"engines": {
|
|
42
42
|
"node": ">=20.10.0",
|
|
43
43
|
"npm": ">=10.2.3"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"ajv": "8.12.0",
|
|
46
47
|
"ini": "4.1.2",
|
|
47
|
-
"@php-wasm/logger": "3.1.
|
|
48
|
-
"@php-wasm/util": "3.1.
|
|
49
|
-
"@php-wasm/stream-compression": "3.1.
|
|
50
|
-
"@php-wasm/progress": "3.1.
|
|
48
|
+
"@php-wasm/logger": "3.1.26",
|
|
49
|
+
"@php-wasm/util": "3.1.26",
|
|
50
|
+
"@php-wasm/stream-compression": "3.1.26",
|
|
51
|
+
"@php-wasm/progress": "3.1.26"
|
|
51
52
|
},
|
|
52
53
|
"packageManager": "npm@10.9.2",
|
|
53
54
|
"overrides": {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type ValidationError = {
|
|
2
|
+
instancePath?: string;
|
|
3
|
+
message?: string;
|
|
4
|
+
params?: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
type ValidateFunction = ((data: unknown) => boolean) & {
|
|
7
|
+
errors?: ValidationError[] | null;
|
|
8
|
+
};
|
|
9
|
+
declare const validatePHPExtensionManifest: ValidateFunction;
|
|
10
|
+
export default validatePHPExtensionManifest;
|