From 0a3ef1eb1a99569921e8238c43314fea8704a174 Mon Sep 17 00:00:00 2001 From: Sean Morris <640101+seanmorris@users.noreply.github.com> Date: Fri, 15 Dec 2023 23:36:09 -0500 Subject: [PATCH] Options object. --- packages/php-wasm/universal/src/lib/base-php.ts | 11 ++++------- packages/php-wasm/universal/src/lib/universal-php.ts | 10 +++++++++- packages/php-wasm/web/src/lib/web-php-endpoint.ts | 5 +++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/php-wasm/universal/src/lib/base-php.ts b/packages/php-wasm/universal/src/lib/base-php.ts index cf3f78a252..f12aa6663b 100644 --- a/packages/php-wasm/universal/src/lib/base-php.ts +++ b/packages/php-wasm/universal/src/lib/base-php.ts @@ -19,6 +19,7 @@ import { SpawnHandler, PHPEventListener, PHPEvent, + CpOptions, } from './universal-php'; import { getFunctionsMaybeMissingFromAsyncify, @@ -618,7 +619,7 @@ export abstract class BasePHP implements IsomorphicLocalPHP { /** @inheritDoc */ @rethrowFileSystemError('Could not copy "{path}"') - cp(fromPath: string, toPath: string, recursive = false) { + cp(fromPath: string, toPath: string, options: CpOptions) { const FS = this[__private__dont__use].FS; const fromStat = FS.stat(fromPath); @@ -642,7 +643,7 @@ export abstract class BasePHP implements IsomorphicLocalPHP { return; } - if (!recursive) { + if (!options.recursive) { throw new Error( `Cannot use non-recurive copy on directory: ${fromPath}` ); @@ -655,11 +656,7 @@ export abstract class BasePHP implements IsomorphicLocalPHP { const files = this.listFiles(fromPath); files.forEach((file: string) => - this.cp( - joinPaths(fromPath, file), - joinPaths(toPath, file), - recursive - ) + this.cp(joinPaths(fromPath, file), joinPaths(toPath, file), options) ); } diff --git a/packages/php-wasm/universal/src/lib/universal-php.ts b/packages/php-wasm/universal/src/lib/universal-php.ts index 94329aba62..14a5e7dbaa 100644 --- a/packages/php-wasm/universal/src/lib/universal-php.ts +++ b/packages/php-wasm/universal/src/lib/universal-php.ts @@ -263,7 +263,7 @@ export interface IsomorphicLocalPHP extends RequestHandler { * @param oldPath The file or directory to be copied. * @param newPath The new, full path to copy the file or directory to. */ - cp(oldPath: string, newPath: string, recurive: boolean): void; + cp(oldPath: string, newPath: string, options: CpOptions): void; /** * Removes a directory from the PHP filesystem. @@ -551,6 +551,14 @@ export interface FileInfo { data: Uint8Array; } +export interface CpOptions { + /** + * If true, recursively copies the directory and all its contents. + * Default: false. + */ + recursive?: boolean; +} + export interface RmDirOptions { /** * If true, recursively removes the directory and all its contents. diff --git a/packages/php-wasm/web/src/lib/web-php-endpoint.ts b/packages/php-wasm/web/src/lib/web-php-endpoint.ts index 42620356c8..4cff3aaa23 100644 --- a/packages/php-wasm/web/src/lib/web-php-endpoint.ts +++ b/packages/php-wasm/web/src/lib/web-php-endpoint.ts @@ -12,6 +12,7 @@ import type { PHPEvent, } from '@php-wasm/universal'; import { EmscriptenDownloadMonitor } from '@php-wasm/progress'; +import { CpOptions } from 'packages/php-wasm/universal/src/lib/universal-php'; const _private = new WeakMap< WebPHPEndpoint, @@ -90,8 +91,8 @@ export class WebPHPEndpoint implements IsomorphicLocalPHP { } /** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.cp */ - cp(fromPath: string, toPath: string, recursive = false) { - return _private.get(this)!.php.cp(fromPath, toPath, recursive); + cp(fromPath: string, toPath: string, options: CpOptions) { + return _private.get(this)!.php.cp(fromPath, toPath, options); } /** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */