Skip to content

Commit

Permalink
Options object.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmorris committed Dec 16, 2023
1 parent cd3902f commit 0a3ef1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
11 changes: 4 additions & 7 deletions packages/php-wasm/universal/src/lib/base-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SpawnHandler,
PHPEventListener,
PHPEvent,
CpOptions,
} from './universal-php';
import {
getFunctionsMaybeMissingFromAsyncify,
Expand Down Expand Up @@ -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);
Expand All @@ -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}`
);
Expand All @@ -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)
);
}

Expand Down
10 changes: 9 additions & 1 deletion packages/php-wasm/universal/src/lib/universal-php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions packages/php-wasm/web/src/lib/web-php-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 15 in packages/php-wasm/web/src/lib/web-php-endpoint.ts

View workflow job for this annotation

GitHub Actions / Lint and typecheck

Projects cannot be imported by a relative or absolute path, and must begin with a npm scope

const _private = new WeakMap<
WebPHPEndpoint,
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 0a3ef1e

Please sign in to comment.