-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathwith-wp-mysql-parser.ts
More file actions
65 lines (59 loc) · 1.74 KB
/
Copy pathwith-wp-mysql-parser.ts
File metadata and controls
65 lines (59 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
type EmscriptenOptions,
type PHPRuntime,
type SupportedPHPVersion,
installPHPExtensionFilesSync,
PHP_EXTENSIONS_DIR,
} from '@php-wasm/universal';
import fs from 'fs';
export interface WpMysqlParserOptions {
/**
* Absolute path on the host filesystem to a `wp_mysql_parser.so` side
* module compiled for the target PHP version and async mode.
*
* The extension itself lives at
* https://github.com/WordPress/sqlite-database-integration/pull/381
* and is not yet packaged with Playground; users build it themselves
* (or fetch it from a release artifact) and pass the path via
* `--wp-mysql-parser-so=<path>` on the CLI.
*/
soPath: string;
}
/*
* The PR #381 build hasn't been validated against earlier PHP versions
* yet, so this run only wires it up for PHP 8.4. Widening to other
* versions is a one-line change once we have artifacts to test against.
*/
const SUPPORTED_VERSIONS: ReadonlyArray<SupportedPHPVersion> = ['8.4'];
export async function withWpMysqlParser(
version: SupportedPHPVersion,
options: EmscriptenOptions,
wpMysqlParserOptions: WpMysqlParserOptions
): Promise<EmscriptenOptions> {
if (!SUPPORTED_VERSIONS.includes(version)) {
throw new Error(
`withWpMysqlParser: only PHP ${SUPPORTED_VERSIONS.join(
', '
)} are supported in this build; got ${version}.`
);
}
const soBytes = new Uint8Array(
fs.readFileSync(wpMysqlParserOptions.soPath)
);
return {
...options,
ENV: {
...options.ENV,
PHP_INI_SCAN_DIR: PHP_EXTENSIONS_DIR,
},
onRuntimeInitialized: (phpRuntime: PHPRuntime) => {
if (options.onRuntimeInitialized) {
options.onRuntimeInitialized(phpRuntime);
}
installPHPExtensionFilesSync(phpRuntime.FS, {
name: 'wp_mysql_parser',
soBytes,
});
},
};
}