66 */
77import fs = require( 'fs' ) ;
88import { parentPort , workerData } from 'worker_threads' ;
9- import { createCopyBoundary , isCopyContainmentError , resolveCopyPath } from './copy-containment' ;
9+ import {
10+ copyErrorCode ,
11+ createCopyBoundary ,
12+ isCopyContainmentError ,
13+ isCopyRecord ,
14+ resolveCopyPath ,
15+ } from './copy-containment' ;
1016import type { CopyBoundary } from './copy-containment' ;
1117interface CopyWorkerData {
1218 files : string [ ] ;
@@ -22,27 +28,17 @@ interface CopyError {
2228 relativePath : unknown ;
2329}
2430function isCopyWorkerData ( value : unknown ) : value is CopyWorkerData {
31+ if ( ! isCopyRecord ( value ) ) {
32+ return false ;
33+ }
2534 return (
26- typeof value === 'object' &&
27- value !== null &&
28- 'files' in value &&
2935 Array . isArray ( value . files ) &&
3036 value . files . every ( ( entry : unknown ) => typeof entry === 'string' ) &&
31- 'sourceBase' in value &&
3237 typeof value . sourceBase === 'string' &&
33- 'destBase' in value &&
3438 typeof value . destBase === 'string' &&
35- 'expectedBoundary' in value &&
36- typeof value . expectedBoundary === 'object' &&
37- value . expectedBoundary !== null
39+ isCopyRecord ( value . expectedBoundary )
3840 ) ;
3941}
40- function errorCode ( error : unknown ) : string | null {
41- if ( typeof error === 'object' && error !== null && 'code' in error ) {
42- return typeof error . code === 'string' ? error . code : null ;
43- }
44- return null ;
45- }
4642function errorMessage ( error : unknown ) : string {
4743 return error instanceof Error ? error . message : String ( error ) ;
4844}
@@ -64,7 +60,7 @@ for (const relativePath of files) {
6460 copied ++ ;
6561 } catch ( caughtError : unknown ) {
6662 // Skip files we can't copy (permission denied, broken symlinks, etc.)
67- const code = errorCode ( caughtError ) ;
63+ const code = copyErrorCode ( caughtError ) ;
6864 if (
6965 ! isCopyContainmentError ( caughtError ) &&
7066 ( code === 'EACCES' || code === 'EPERM' || code === 'ENOENT' )
@@ -78,7 +74,7 @@ for (const relativePath of files) {
7874 code,
7975 message : errorMessage ( caughtError ) ,
8076 relativePath :
81- typeof caughtError === 'object' && caughtError !== null && 'relativePath' in caughtError
77+ isCopyRecord ( caughtError ) && 'relativePath' in caughtError
8278 ? caughtError . relativePath
8379 : relativePath ,
8480 } ;
0 commit comments