@php-wasm/universal 3.1.25 → 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/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, PHPExtensionExtraFiles, PHPExtensionIniDirective, PHPExtensionInstallOptions, ResolvedPHPExtension, PHPExtensionManifest, PHPExtensionManifestArtifact, PHPExtensionSource, ResolvePHPExtensionOptions, } from './load-extension';
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';
@@ -1,145 +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
- * The php.ini directive used to load the extension.
11
- *
12
- * Use `extension` for regular PHP extensions and `zend_extension` for Zend
13
- * 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.
14
11
  */
15
12
  export type PHPExtensionIniDirective = 'extension' | 'zend_extension';
16
13
  /**
17
- * One compiled extension artifact in a manifest.
18
- */
19
- export interface PHPExtensionManifestArtifact {
20
- /**
21
- * PHP major/minor version the artifact was compiled against, e.g. `8.4`.
22
- */
23
- phpVersion: string;
24
- /**
25
- * Relative to the manifest URL/base URL, or an absolute URL.
26
- */
27
- file: string;
28
- /**
29
- * Optional SHA-256 checksum for the fetched `.so` artifact.
30
- */
31
- sha256?: string;
32
- }
33
- /**
34
- * Extension artifact manifest.
35
- *
36
- * A manifest lets callers publish a matrix of `.so` files and lets
37
- * `resolvePHPExtension()` select the artifact that matches the current PHP
38
- * version. External extension artifacts are JSPI-only.
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.
39
17
  */
40
18
  export interface PHPExtensionManifest {
41
19
  name: string;
42
20
  version?: string;
43
21
  mode?: 'php-extension';
44
- artifacts: PHPExtensionManifestArtifact[];
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
+ }>;
45
49
  }
46
50
  /**
47
- * Source for a PHP extension `.so`.
48
- *
49
- * Use `format: 'so'` when the caller already has bytes, `format: 'url'` for a
50
- * direct artifact URL, and `format: 'manifest'` when PHP.wasm should select
51
- * 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.
52
54
  */
53
55
  export type PHPExtensionSource = {
54
56
  format: 'so';
55
- /**
56
- * Required when `PHPExtensionInstallOptions.name` is not set.
57
- */
58
57
  name?: string;
59
58
  bytes: Uint8Array | ArrayBuffer;
60
- sha256?: string;
61
59
  } | {
62
60
  format: 'url';
63
- /**
64
- * Optional extension name. If omitted, PHP.wasm infers the name
65
- * from a `.so` filename in the URL.
66
- */
67
61
  name?: string;
68
62
  url: string | URL;
69
- sha256?: string;
70
63
  } | {
71
64
  format: 'manifest';
72
65
  /**
73
- * URL of the extension manifest.
74
- *
75
- * In `@php-wasm/universal`, string values must be absolute URLs.
76
- * In `@php-wasm/node`, this may also be a filesystem path or a
77
- * `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.
78
68
  */
79
69
  manifestUrl: string | URL;
80
70
  } | {
81
71
  format: 'manifest';
82
72
  manifest: PHPExtensionManifest;
83
- /**
84
- * Base URL used to resolve relative artifact paths in an inline
85
- * manifest.
86
- */
73
+ /** Base URL for resolving relative artifact paths. */
87
74
  baseUrl?: string | URL;
88
75
  };
89
- /**
90
- * Extra files to stage next to an extension.
91
- *
92
- * Use this for sidecar data files such as ICU data or native-library assets
93
- * that the extension expects to find at runtime.
94
- */
95
- export interface PHPExtensionExtraFiles {
96
- /**
97
- * Files are written here. Defaults to
98
- * `/internal/shared/extensions/<name>-assets`.
99
- */
100
- targetPath?: string;
101
- files: FileTree;
102
- }
103
- /**
104
- * Options for staging a PHP extension before startup.
105
- */
106
- export interface PHPExtensionInstallOptions {
107
- /**
108
- * The extension artifact bytes, URL, or manifest.
109
- */
76
+ export type DataToResolvePhpExtension = ResolvedInstallOptions;
77
+ export interface ResolvedInstallOptions {
78
+ /** PHP major/minor version the active runtime is initializing for. */
79
+ phpVersion: string;
110
80
  source: PHPExtensionSource;
111
- /**
112
- * Extension name used for staged file names and the first ini directive.
113
- *
114
- * This overrides a name inferred from `source`.
115
- */
81
+ /** Overrides the name inferred from `source`. */
116
82
  name?: string;
117
83
  /**
118
- * The directive PHP.wasm writes as the first line of the generated
119
- * startup `.ini` file for this extension.
120
- *
121
- * Regular PHP extensions need `extension=/path/to/name.so`. Zend
122
- * extensions, such as Xdebug, need `zend_extension=/path/to/name.so`.
123
- * This does not edit the main `php.ini`; it controls the generated
124
- * 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=...`.
125
87
  */
126
88
  loadWithIniDirective?: PHPExtensionIniDirective;
127
- /**
128
- * Additional `key=value` lines written to the generated startup `.ini`
129
- * file after the `extension=` or `zend_extension=` directive.
130
- */
89
+ /** Additional `key=value` lines for the generated startup `.ini` file. */
131
90
  iniEntries?: Record<string, string>;
132
91
  /**
133
92
  * Sidecar files to write into the PHP VFS before the extension is loaded.
134
- *
135
93
  * Use this for data files or dependency assets the extension expects at
136
94
  * runtime.
137
95
  */
138
- extraFiles?: PHPExtensionExtraFiles;
139
- /**
140
- * Environment variables to add to the PHP runtime before the extension is
141
- * loaded.
142
- */
96
+ extraFiles?: ResolvedExtraFiles;
97
+ /** Environment variables added before the extension is loaded. */
143
98
  env?: Record<string, string>;
144
99
  /**
145
100
  * VFS directory where PHP.wasm writes the extension `.so` file and its
@@ -147,69 +102,98 @@ export interface PHPExtensionInstallOptions {
147
102
  */
148
103
  extensionDir?: string;
149
104
  /**
150
- * Fetch implementation used for `format: 'url'`, `manifestUrl`, and
151
- * manifest artifacts.
152
- *
153
- * Runtimes may provide environment-specific defaults. For example,
154
- * `@php-wasm/node` provides local file support for extension manifests and
155
- * 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.
156
108
  */
157
109
  fetch?: typeof fetch;
158
110
  }
159
111
  /**
160
- * Options for resolving an extension before a PHP instance exists.
112
+ * Fully resolved files and settings needed to install one extension. Produced
113
+ * by `resolvePHPExtension`; consumed by `withResolvedPHPExtensions` and
114
+ * `installPHPExtensionFilesSync`.
161
115
  */
162
- export type ResolvePHPExtensionOptions = PHPExtensionInstallOptions & {
163
- phpVersion: string;
164
- };
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
+ }
165
136
  /**
166
- * Inputs used to build the staged `.so` path and per-extension ini file.
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
+ }
147
+ /**
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`.
167
151
  */
168
152
  export interface InstallPHPExtensionFilesOptions {
153
+ /** Extension name used for staged file names and the ini directive. */
169
154
  name: string;
155
+ /** Compiled extension bytes. */
170
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
+ */
171
162
  loadWithIniDirective?: PHPExtensionIniDirective;
163
+ /** Additional `key=value` lines for the generated startup `.ini` file. */
172
164
  iniEntries?: Record<string, string>;
173
- extraFiles?: PHPExtensionExtraFiles;
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. */
174
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
+ */
175
173
  extensionDir?: string;
176
174
  }
177
175
  /**
178
- * Fully resolved files and settings needed to install one extension.
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.
179
179
  *
180
- * `iniPath` and `iniContent` describe the per-extension ini file PHP.wasm
181
- * writes into the PHP VFS.
182
- */
183
- export interface ResolvedPHPExtension {
184
- soPath: string;
185
- soBytes: Uint8Array;
186
- iniPath: string;
187
- iniContent: string;
188
- extraFiles?: PHPExtensionExtraFiles & {
189
- targetPath: string;
190
- };
191
- env?: Record<string, string>;
192
- extensionDir: string;
193
- }
194
- /**
195
- * 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.
196
182
  *
197
- * Use this from runtimes that need to fetch extension bytes and compute
198
- * `iniPath`/`iniContent` before Emscripten initializes PHP.
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.
199
186
  */
200
- export declare function resolvePHPExtension(options: ResolvePHPExtensionOptions): Promise<ResolvedPHPExtension>;
187
+ export declare function resolvePHPExtension(options: DataToResolvePhpExtension): Promise<ResolvedPHPExtension>;
201
188
  /**
202
- * Adds resolved extensions to Emscripten options.
203
- *
204
- * The returned options install extension files during `onRuntimeInitialized`
205
- * 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.
206
192
  */
207
193
  export declare function withResolvedPHPExtensions(options: EmscriptenOptions, extensions: ResolvedPHPExtension[]): EmscriptenOptions;
208
194
  /**
209
195
  * Installs extension files through Emscripten's synchronous filesystem API.
210
- *
211
196
  * Use this while the PHP runtime is initializing and only the raw Emscripten
212
- * `FS` object is available. This writes the `.so` file and generated `.ini`
213
- * file to their resolved VFS paths.
197
+ * `FS` object is available.
214
198
  */
215
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.25",
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": "e662afdd9a3b6dad3e194ad34d80421c539b7386",
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.25",
48
- "@php-wasm/util": "3.1.25",
49
- "@php-wasm/stream-compression": "3.1.25",
50
- "@php-wasm/progress": "3.1.25"
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;