@php-wasm/util 0.9.32 → 0.9.33
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/index.d.ts +1 -0
- package/lib/create-spawn-handler.d.ts +48 -0
- package/lib/index.d.ts +9 -0
- package/lib/paths.d.ts +76 -0
- package/lib/php-vars.d.ts +2 -0
- package/lib/php-wasm-error.d.ts +4 -0
- package/lib/random-filename.d.ts +1 -0
- package/lib/random-string.d.ts +1 -0
- package/lib/semaphore.d.ts +24 -0
- package/lib/sleep.d.ts +2 -0
- package/lib/split-shell-command.d.ts +10 -0
- package/package.json +2 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type Listener = (...args: any[]) => any;
|
|
2
|
+
export interface ProcessOptions {
|
|
3
|
+
cwd?: string;
|
|
4
|
+
env?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```ts
|
|
9
|
+
* php.setSpawnHandler(
|
|
10
|
+
* createSpawnHandler(function (command, processApi) {
|
|
11
|
+
* console.log(processApi.flushStdin());
|
|
12
|
+
* processApi.stdout('/\n/tmp\n/home');
|
|
13
|
+
* processApi.exit(0);
|
|
14
|
+
* })
|
|
15
|
+
* );
|
|
16
|
+
* ```
|
|
17
|
+
* @param program
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function createSpawnHandler(program: (command: string[], processApi: ProcessApi, options: ProcessOptions) => void | Promise<void>): any;
|
|
21
|
+
declare class EventEmitter {
|
|
22
|
+
listeners: Record<string, Listener[]>;
|
|
23
|
+
emit(eventName: string, data: any): void;
|
|
24
|
+
on(eventName: string, listener: Listener): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class ProcessApi extends EventEmitter {
|
|
27
|
+
private childProcess;
|
|
28
|
+
private exited;
|
|
29
|
+
private stdinData;
|
|
30
|
+
constructor(childProcess: ChildProcess);
|
|
31
|
+
stdout(data: string | ArrayBuffer): void;
|
|
32
|
+
stdoutEnd(): void;
|
|
33
|
+
stderr(data: string | ArrayBuffer): void;
|
|
34
|
+
stderrEnd(): void;
|
|
35
|
+
exit(code: number): void;
|
|
36
|
+
flushStdin(): void;
|
|
37
|
+
}
|
|
38
|
+
export type StdIn = {
|
|
39
|
+
write: (data: string) => void;
|
|
40
|
+
};
|
|
41
|
+
export declare class ChildProcess extends EventEmitter {
|
|
42
|
+
pid: number;
|
|
43
|
+
stdout: EventEmitter;
|
|
44
|
+
stderr: EventEmitter;
|
|
45
|
+
stdin: StdIn;
|
|
46
|
+
constructor(pid?: number);
|
|
47
|
+
}
|
|
48
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import Semaphore, { AcquireTimeoutError } from './semaphore';
|
|
2
|
+
export { Semaphore, AcquireTimeoutError };
|
|
3
|
+
export { PhpWasmError } from './php-wasm-error';
|
|
4
|
+
export type { SemaphoreOptions } from './semaphore';
|
|
5
|
+
export { dirname, joinPaths, basename, normalizePath, isParentOf, } from './paths';
|
|
6
|
+
export { createSpawnHandler } from './create-spawn-handler';
|
|
7
|
+
export { randomString } from './random-string';
|
|
8
|
+
export { randomFilename } from './random-filename';
|
|
9
|
+
export * from './php-vars';
|
package/lib/paths.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The functions in this module are mostly copied from the generated
|
|
3
|
+
* Emscripten PHP module. This enables features like filesystem journaling,
|
|
4
|
+
* which use some low-level Emscripten APIs and need access to the
|
|
5
|
+
* same path helpers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Joins paths together.
|
|
9
|
+
*
|
|
10
|
+
* For example:
|
|
11
|
+
*
|
|
12
|
+
* > joinPaths('wordpress', 'wp-content')
|
|
13
|
+
* 'wordpress/wp-content'
|
|
14
|
+
*
|
|
15
|
+
* Use this for all PHP paths and **do not** use path.join().
|
|
16
|
+
* This is important because Emscripten paths are **always**
|
|
17
|
+
* POSIX-style paths. Imagine joining paths on Windows:
|
|
18
|
+
*
|
|
19
|
+
* > path.join('wordpress', 'wp-content')
|
|
20
|
+
* '\\wordpress\\wp-content' // invalid in PHP.wasm
|
|
21
|
+
*
|
|
22
|
+
* See the path.join issue for more details:
|
|
23
|
+
*
|
|
24
|
+
* https://github.com/WordPress/playground-tools/issues/11#issuecomment-1579074763
|
|
25
|
+
*
|
|
26
|
+
* @param paths Paths segments to join
|
|
27
|
+
* @returns A joined path
|
|
28
|
+
*/
|
|
29
|
+
export declare function joinPaths(...paths: string[]): string;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the directory name of a path.
|
|
32
|
+
*
|
|
33
|
+
* @param path
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function dirname(path: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the last portion of a path.
|
|
39
|
+
*
|
|
40
|
+
* @param path - The path to extract the basename from.
|
|
41
|
+
* @returns The basename of the path.
|
|
42
|
+
*/
|
|
43
|
+
export declare function basename(path: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Normalizes a path.
|
|
46
|
+
*
|
|
47
|
+
* For example:
|
|
48
|
+
*
|
|
49
|
+
* > normalizePath('wordpress/wp-content/../')
|
|
50
|
+
* 'wordpress'
|
|
51
|
+
*
|
|
52
|
+
* @param path
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizePath(path: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Normalizes paths.
|
|
58
|
+
*
|
|
59
|
+
* For example:
|
|
60
|
+
*
|
|
61
|
+
* > normalizePathsArray(['wordpress', 'wp-content', '..', '', '.',
|
|
62
|
+
* 'wp-includes']) ['wordpress', 'wp-includes']
|
|
63
|
+
*
|
|
64
|
+
* @param parts parts of the path to normalize
|
|
65
|
+
* @param allowAboveRoot allow paths above the root
|
|
66
|
+
* @returns normalized paths
|
|
67
|
+
*/
|
|
68
|
+
export declare function normalizePathsArray(parts: string[], allowAboveRoot: boolean): string[];
|
|
69
|
+
/**
|
|
70
|
+
* Checks if the given parent path is an ancestor of the given child path.
|
|
71
|
+
*
|
|
72
|
+
* @param parent The parent path to check.
|
|
73
|
+
* @param child The child path to verify against the parent.
|
|
74
|
+
* @returns Whether the `parent` path is an ancestor of the `child` path.
|
|
75
|
+
*/
|
|
76
|
+
export declare function isParentOf(parent: string, child: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomFilename(): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomString(length?: number, specialChars?: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface SemaphoreOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The maximum number of concurrent locks.
|
|
4
|
+
*/
|
|
5
|
+
concurrency: number;
|
|
6
|
+
/**
|
|
7
|
+
* The maximum time to wait for a lock to become available.
|
|
8
|
+
*/
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class AcquireTimeoutError extends Error {
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
14
|
+
export default class Semaphore {
|
|
15
|
+
private _running;
|
|
16
|
+
private concurrency;
|
|
17
|
+
private timeout?;
|
|
18
|
+
private queue;
|
|
19
|
+
constructor({ concurrency, timeout }: SemaphoreOptions);
|
|
20
|
+
get remaining(): number;
|
|
21
|
+
get running(): number;
|
|
22
|
+
acquire(): Promise<() => void>;
|
|
23
|
+
run<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
24
|
+
}
|
package/lib/sleep.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naive shell command parser.
|
|
3
|
+
* Ensures that commands like `wp option set blogname "My blog name"` are split
|
|
4
|
+
* into `['wp', 'option', 'set', 'blogname', 'My blog name']` instead of
|
|
5
|
+
* `['wp', 'option', 'set', 'blogname', 'My', 'blog', 'name']`.
|
|
6
|
+
*
|
|
7
|
+
* @param command
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function splitShellCommand(command: string): string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/util",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.33",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"typedoc": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"access": "public",
|
|
14
14
|
"directory": "../../../dist/packages/php-wasm/util"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "bcfaa019188a6a6e381338704151566eb050638a",
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">=18.18.0",
|
|
19
19
|
"npm": ">=8.11.0"
|