@@ -8,6 +8,7 @@ import { Client } from "../client";
88// Use this to get around Webpack inserting our fills.
99// TODO: is there a better way?
1010declare var _require : typeof require ;
11+ declare var _Buffer : typeof Buffer ;
1112
1213/**
1314 * Implements the native fs module
@@ -121,7 +122,7 @@ export class FS {
121122 const ae = this . client . run ( ( ae , path , options ) => {
122123 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
123124 const str = fs . createWriteStream ( path , options ) ;
124- ae . on ( "write" , ( d , e ) => str . write ( Buffer . from ( d , e ) ) ) ;
125+ ae . on ( "write" , ( d , e ) => str . write ( _Buffer . from ( d , "utf8" ) ) ) ;
125126 ae . on ( "close" , ( ) => str . close ( ) ) ;
126127 str . on ( "close" , ( ) => ae . emit ( "close" ) ) ;
127128 str . on ( "open" , ( fd ) => ae . emit ( "open" , fd ) ) ;
@@ -216,18 +217,18 @@ export class FS {
216217 this . client . evaluate ( ( fd ) => {
217218 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
218219 const util = _require ( "util" ) as typeof import ( "util" ) ;
220+ const tslib = _require ( "tslib" ) as typeof import ( "tslib" ) ;
219221
220222 return util . promisify ( fs . fstat ) ( fd ) . then ( ( stats ) => {
221- return {
222- ...stats ,
223- _isBlockDevice : stats . isBlockDevice ( ) ,
224- _isCharacterDevice : stats . isCharacterDevice ( ) ,
223+ return tslib . __assign ( stats , {
224+ _isBlockDevice : stats . isBlockDevice ? stats . isBlockDevice ( ) : false ,
225+ _isCharacterDevice : stats . isCharacterDevice ? stats . isCharacterDevice ( ) : false ,
225226 _isDirectory : stats . isDirectory ( ) ,
226- _isFIFO : stats . isFIFO ( ) ,
227+ _isFIFO : stats . isFIFO ? stats . isFIFO ( ) : false ,
227228 _isFile : stats . isFile ( ) ,
228- _isSocket : stats . isSocket ( ) ,
229- _isSymbolicLink : stats . isSymbolicLink ( ) ,
230- } ;
229+ _isSocket : stats . isSocket ? stats . isSocket ( ) : false ,
230+ _isSymbolicLink : stats . isSymbolicLink ? stats . isSymbolicLink ( ) : false ,
231+ } ) ;
231232 } ) ;
232233 } , fd ) . then ( ( stats ) => {
233234 callback ( undefined ! , new Stats ( stats ) ) ;
@@ -322,18 +323,18 @@ export class FS {
322323 this . client . evaluate ( ( path ) => {
323324 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
324325 const util = _require ( "util" ) as typeof import ( "util" ) ;
326+ const tslib = _require ( "tslib" ) as typeof import ( "tslib" ) ;
325327
326328 return util . promisify ( fs . lstat ) ( path ) . then ( ( stats ) => {
327- return {
328- ...stats ,
329- _isBlockDevice : stats . isBlockDevice ( ) ,
330- _isCharacterDevice : stats . isCharacterDevice ( ) ,
329+ return tslib . __assign ( stats , {
330+ _isBlockDevice : stats . isBlockDevice ? stats . isBlockDevice ( ) : false ,
331+ _isCharacterDevice : stats . isCharacterDevice ? stats . isCharacterDevice ( ) : false ,
331332 _isDirectory : stats . isDirectory ( ) ,
332- _isFIFO : stats . isFIFO ( ) ,
333+ _isFIFO : stats . isFIFO ? stats . isFIFO ( ) : false ,
333334 _isFile : stats . isFile ( ) ,
334- _isSocket : stats . isSocket ( ) ,
335- _isSymbolicLink : stats . isSymbolicLink ( ) ,
336- } ;
335+ _isSocket : stats . isSocket ? stats . isSocket ( ) : false ,
336+ _isSymbolicLink : stats . isSymbolicLink ? stats . isSymbolicLink ( ) : false ,
337+ } ) ;
337338 } ) ;
338339 } , path ) . then ( ( stats ) => {
339340 callback ( undefined ! , new Stats ( stats ) ) ;
@@ -397,7 +398,7 @@ export class FS {
397398 this . client . evaluate ( ( fd , length , position ) => {
398399 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
399400 const util = _require ( "util" ) as typeof import ( "util" ) ;
400- const buffer = new Buffer ( length ) ;
401+ const buffer = new _Buffer ( length ) ;
401402
402403 return util . promisify ( fs . read ) ( fd , buffer , 0 , length , position ) . then ( ( resp ) => {
403404 return {
@@ -513,18 +514,22 @@ export class FS {
513514 this . client . evaluate ( ( path ) => {
514515 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
515516 const util = _require ( "util" ) as typeof import ( "util" ) ;
517+ const tslib = _require ( "tslib" ) as typeof import ( "tslib" ) ;
516518
517519 return util . promisify ( fs . stat ) ( path ) . then ( ( stats ) => {
518- return {
519- ...stats ,
520- _isBlockDevice : stats . isBlockDevice ( ) ,
521- _isCharacterDevice : stats . isCharacterDevice ( ) ,
520+ return tslib . __assign ( stats , {
521+ /**
522+ * We need to check if functions exist because nexe's implemented FS
523+ * lib doesnt implement fs.stats properly
524+ */
525+ _isBlockDevice : stats . isBlockDevice ? stats . isBlockDevice ( ) : false ,
526+ _isCharacterDevice : stats . isCharacterDevice ? stats . isCharacterDevice ( ) : false ,
522527 _isDirectory : stats . isDirectory ( ) ,
523- _isFIFO : stats . isFIFO ( ) ,
528+ _isFIFO : stats . isFIFO ? stats . isFIFO ( ) : false ,
524529 _isFile : stats . isFile ( ) ,
525- _isSocket : stats . isSocket ( ) ,
526- _isSymbolicLink : stats . isSymbolicLink ( ) ,
527- } ;
530+ _isSocket : stats . isSocket ? stats . isSocket ( ) : false ,
531+ _isSymbolicLink : stats . isSymbolicLink ? stats . isSymbolicLink ( ) : false ,
532+ } ) ;
528533 } ) ;
529534 } , path ) . then ( ( stats ) => {
530535 callback ( undefined ! , new Stats ( stats ) ) ;
@@ -602,7 +607,7 @@ export class FS {
602607 const fs = _require ( "fs" ) as typeof import ( "fs" ) ;
603608 const util = _require ( "util" ) as typeof import ( "util" ) ;
604609
605- return util . promisify ( fs . write ) ( fd , Buffer . from ( buffer , "utf8" ) , offset , length , position ) . then ( ( resp ) => {
610+ return util . promisify ( fs . write ) ( fd , _Buffer . from ( buffer , "utf8" ) , offset , length , position ) . then ( ( resp ) => {
606611 return {
607612 bytesWritten : resp . bytesWritten ,
608613 content : resp . buffer . toString ( "utf8" ) ,
0 commit comments