@php-wasm/universal 3.1.21 → 3.1.22

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/lib/index.d.ts CHANGED
@@ -35,6 +35,8 @@ export type { FileNotFoundGetActionCallback, FileNotFoundToInternalRedirect, Fil
35
35
  export { rotatePHPRuntime } from './rotate-php-runtime';
36
36
  export { writeFiles } from './write-files';
37
37
  export type { FileTree } from './write-files';
38
+ export { withResolvedPHPExtensions, installPHPExtensionFilesSync, PHP_EXTENSIONS_DIR, resolvePHPExtension, } from './load-extension';
39
+ export type { InstallPHPExtensionFilesOptions, PHPExtensionExtraFiles, PHPExtensionIniDirective, PHPExtensionInstallOptions, ResolvedPHPExtension, PHPExtensionManifest, PHPExtensionManifestArtifact, PHPExtensionSource, PHPWasmAsyncMode, ResolvePHPExtensionOptions, } from './load-extension';
38
40
  export { DEFAULT_BASE_URL, ensurePathPrefix, removePathPrefix, toRelativeUrl, } from './urls';
39
41
  export { isExitCode } from './is-exit-code';
40
42
  export { proxyFileSystem, isPathToSharedFS } from './proxy-file-system';
@@ -0,0 +1,227 @@
1
+ import type { Emscripten } from './emscripten-types';
2
+ import type { EmscriptenOptions } from './load-php-runtime';
3
+ import type { FileTree } from './write-files';
4
+ /**
5
+ * Default VFS directory where PHP.wasm stages extension `.so` files and
6
+ * writes their per-extension ini files.
7
+ */
8
+ export declare const PHP_EXTENSIONS_DIR = "/internal/shared/extensions";
9
+ /**
10
+ * Async mode used by the PHP.wasm build that will load the extension.
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.
21
+ */
22
+ export type PHPExtensionIniDirective = 'extension' | 'zend_extension';
23
+ /**
24
+ * One compiled extension artifact in a manifest.
25
+ */
26
+ export interface PHPExtensionManifestArtifact {
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.
50
+ */
51
+ export interface PHPExtensionManifest {
52
+ name: string;
53
+ version?: string;
54
+ mode?: 'php-extension';
55
+ artifacts: PHPExtensionManifestArtifact[];
56
+ }
57
+ /**
58
+ * Source for a PHP extension `.so`.
59
+ *
60
+ * Use `format: 'so'` when the caller already has bytes, `format: 'url'` for a
61
+ * direct artifact URL, and `format: 'manifest'` when PHP.wasm should select
62
+ * the right artifact from a manifest.
63
+ */
64
+ export type PHPExtensionSource = {
65
+ format: 'so';
66
+ /**
67
+ * Required when `PHPExtensionInstallOptions.name` is not set.
68
+ */
69
+ name?: string;
70
+ bytes: Uint8Array | ArrayBuffer;
71
+ sha256?: string;
72
+ } | {
73
+ format: 'url';
74
+ /**
75
+ * Optional extension name. If omitted, PHP.wasm infers the name
76
+ * from a `.so` filename in the URL.
77
+ */
78
+ name?: string;
79
+ url: string | URL;
80
+ sha256?: string;
81
+ } | {
82
+ format: 'manifest';
83
+ /**
84
+ * URL of the extension manifest.
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.
89
+ */
90
+ manifestUrl: string | URL;
91
+ } | {
92
+ format: 'manifest';
93
+ manifest: PHPExtensionManifest;
94
+ /**
95
+ * Base URL used to resolve relative artifact paths in an inline
96
+ * manifest.
97
+ */
98
+ baseUrl?: string | URL;
99
+ };
100
+ /**
101
+ * Extra files to stage next to an extension.
102
+ *
103
+ * Use this for sidecar data files such as ICU data or native-library assets
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
+ */
121
+ 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
+ */
127
+ name?: string;
128
+ /**
129
+ * The directive PHP.wasm writes as the first line of the generated
130
+ * startup `.ini` file for this extension.
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.
136
+ */
137
+ loadWithIniDirective?: PHPExtensionIniDirective;
138
+ /**
139
+ * Additional `key=value` lines written to the generated startup `.ini`
140
+ * file after the `extension=` or `zend_extension=` directive.
141
+ */
142
+ iniEntries?: Record<string, string>;
143
+ /**
144
+ * Sidecar files to write into the PHP VFS before the extension is loaded.
145
+ *
146
+ * Use this for data files or dependency assets the extension expects at
147
+ * runtime.
148
+ */
149
+ extraFiles?: PHPExtensionExtraFiles;
150
+ /**
151
+ * Environment variables to add to the PHP runtime before the extension is
152
+ * loaded.
153
+ */
154
+ env?: Record<string, string>;
155
+ /**
156
+ * VFS directory where PHP.wasm writes the extension `.so` file and its
157
+ * per-extension ini file. Defaults to `PHP_EXTENSIONS_DIR`.
158
+ */
159
+ extensionDir?: string;
160
+ /**
161
+ * Fetch implementation used for `format: 'url'`, `manifestUrl`, and
162
+ * manifest artifacts.
163
+ *
164
+ * Runtimes may provide environment-specific defaults. For example,
165
+ * `@php-wasm/node` provides local file support for extension manifests and
166
+ * artifacts.
167
+ */
168
+ fetch?: typeof fetch;
169
+ }
170
+ /**
171
+ * Options for resolving an extension before a PHP instance exists.
172
+ */
173
+ export type ResolvePHPExtensionOptions = PHPExtensionInstallOptions & {
174
+ phpVersion: string;
175
+ asyncMode: PHPWasmAsyncMode;
176
+ };
177
+ /**
178
+ * Inputs used to build the staged `.so` path and per-extension ini file.
179
+ */
180
+ export interface InstallPHPExtensionFilesOptions {
181
+ name: string;
182
+ soBytes: Uint8Array | ArrayBuffer;
183
+ loadWithIniDirective?: PHPExtensionIniDirective;
184
+ iniEntries?: Record<string, string>;
185
+ extraFiles?: PHPExtensionExtraFiles;
186
+ env?: Record<string, string>;
187
+ extensionDir?: string;
188
+ }
189
+ /**
190
+ * Fully resolved files and settings needed to install one extension.
191
+ *
192
+ * `iniPath` and `iniContent` describe the per-extension ini file PHP.wasm
193
+ * writes into the PHP VFS.
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.
208
+ *
209
+ * Use this from runtimes that need to fetch extension bytes and compute
210
+ * `iniPath`/`iniContent` before Emscripten initializes PHP.
211
+ */
212
+ export declare function resolvePHPExtension(options: ResolvePHPExtensionOptions): Promise<ResolvedPHPExtension>;
213
+ /**
214
+ * Adds resolved extensions to Emscripten options.
215
+ *
216
+ * The returned options install extension files during `onRuntimeInitialized`
217
+ * and update `PHP_INI_SCAN_DIR` before PHP startup.
218
+ */
219
+ export declare function withResolvedPHPExtensions(options: EmscriptenOptions, extensions: ResolvedPHPExtension[]): EmscriptenOptions;
220
+ /**
221
+ * Installs extension files through Emscripten's synchronous filesystem API.
222
+ *
223
+ * Use this while the PHP runtime is initializing and only the raw Emscripten
224
+ * `FS` object is available. This writes the `.so` file and generated `.ini`
225
+ * file to their resolved VFS paths.
226
+ */
227
+ export declare function installPHPExtensionFilesSync(fs: Emscripten.RootFS, options: InstallPHPExtensionFilesOptions | ResolvedPHPExtension): ResolvedPHPExtension;
@@ -161,6 +161,7 @@ export type PHPRuntime = any;
161
161
  export type PHPLoaderModule = {
162
162
  dependencyFilename: string;
163
163
  dependenciesTotalSize: number;
164
+ phpWasmAsyncMode?: 'jspi' | 'asyncify';
164
165
  init: (jsRuntime: string, options: EmscriptenOptions) => PHPRuntime;
165
166
  };
166
167
  export type DataModule = {
@@ -25,6 +25,11 @@ export type Pooled<T extends object> = Omit<Promisified<T>, typeof Symbol.dispos
25
25
  *
26
26
  * The returned proxy provides a promisified version of the original
27
27
  * interface: method calls and property accesses all return promises.
28
+ *
29
+ * Methods may return streamed response objects whose work continues
30
+ * after the method promise resolves. When a returned value exposes a
31
+ * `finished` promise, the pool keeps the instance checked out until
32
+ * that promise settles.
28
33
  */
29
34
  export declare function createObjectPoolProxy<T extends object>(instances: T[]): Pooled<T>;
30
35
  export {};
@@ -43,7 +43,7 @@ export declare class PHPWorker implements LimitedPHPApi, AsyncDisposable {
43
43
  * the web API. It will change or even be removed without
44
44
  * a warning.
45
45
  */
46
- protected __internal_getRequestHandler(): PHPRequestHandler | undefined;
46
+ protected __internal_getRequestHandler(): PHPRequestHandler;
47
47
  setPrimaryPHP(php: PHP): Promise<void>;
48
48
  /** @inheritDoc @php-wasm/universal!PHPRequestHandler.pathToInternalUrl */
49
49
  pathToInternalUrl(path: string): string;
@@ -121,4 +121,6 @@ export declare class PHPWorker implements LimitedPHPApi, AsyncDisposable {
121
121
  protected dispatchEvent<Event extends PHPWorkerEvent>(event: Event): void;
122
122
  protected registerWorkerListeners(php: PHP): void;
123
123
  [Symbol.asyncDispose](): Promise<void>;
124
+ protected getRequestHandler(required?: true): PHPRequestHandler;
125
+ protected getRequestHandler(required: false): PHPRequestHandler | undefined;
124
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/universal",
3
- "version": "3.1.21",
3
+ "version": "3.1.22",
4
4
  "description": "PHP.wasm – emscripten bindings for PHP",
5
5
  "repository": {
6
6
  "type": "git",
@@ -37,17 +37,17 @@
37
37
  "module": "./index.js",
38
38
  "types": "index.d.ts",
39
39
  "license": "GPL-2.0-or-later",
40
- "gitHead": "5864051cbf4c2a55656112d99a3f1b076bcd67cd",
40
+ "gitHead": "04c986b63dd56fe74e4ed0cf04d00cae7ac050bf",
41
41
  "engines": {
42
42
  "node": ">=20.10.0",
43
43
  "npm": ">=10.2.3"
44
44
  },
45
45
  "dependencies": {
46
46
  "ini": "4.1.2",
47
- "@php-wasm/logger": "3.1.21",
48
- "@php-wasm/util": "3.1.21",
49
- "@php-wasm/stream-compression": "3.1.21",
50
- "@php-wasm/progress": "3.1.21"
47
+ "@php-wasm/logger": "3.1.22",
48
+ "@php-wasm/util": "3.1.22",
49
+ "@php-wasm/stream-compression": "3.1.22",
50
+ "@php-wasm/progress": "3.1.22"
51
51
  },
52
52
  "packageManager": "npm@10.9.2",
53
53
  "overrides": {