@@ -16,6 +16,7 @@ import Status from 'polykey/status/Status.js';
1616import * as clientUtils from 'polykey/client/utils.js' ;
1717import { arrayZip , promise } from 'polykey/utils/index.js' ;
1818import config from 'polykey/config.js' ;
19+ import * as utils from './utils.js' ;
1920import * as errors from '../errors.js' ;
2021
2122/**
@@ -175,9 +176,10 @@ async function processPassword(
175176 */
176177async function processNewPassword (
177178 passwordNewFile ?: string ,
178- fs : FileSystem = require ( 'fs' ) ,
179+ fs ? : FileSystem ,
179180 existing : boolean = false ,
180181) : Promise < string > {
182+ fs = await utils . importFS ( fs ) ;
181183 let passwordNew : string | undefined ;
182184 if ( passwordNewFile != null ) {
183185 try {
@@ -217,8 +219,9 @@ async function processNewPassword(
217219 */
218220async function processRecoveryCode (
219221 recoveryCodeFile ?: string ,
220- fs : FileSystem = require ( 'fs' ) ,
222+ fs ? : FileSystem ,
221223) : Promise < RecoveryCode | undefined > {
224+ fs = await utils . importFS ( fs ) ;
222225 let recoveryCode : string | undefined ;
223226 if ( recoveryCodeFile != null ) {
224227 try {
@@ -258,13 +261,14 @@ async function processClientOptions(
258261 nodeId ?: NodeId ,
259262 clientHost ?: string ,
260263 clientPort ?: number ,
261- fs = require ( 'fs' ) ,
264+ fs ?: FileSystem ,
262265 logger = new Logger ( processClientOptions . name ) ,
263266) : Promise < {
264267 nodeId : NodeId ;
265268 clientHost : string ;
266269 clientPort : number ;
267270} > {
271+ fs = await utils . importFS ( fs ) ;
268272 if ( nodeId != null && clientHost != null && clientPort != null ) {
269273 return {
270274 nodeId,
@@ -321,7 +325,7 @@ async function processClientStatus(
321325 nodeId ?: NodeId ,
322326 clientHost ?: string ,
323327 clientPort ?: number ,
324- fs = require ( 'fs' ) ,
328+ fs ?: FileSystem ,
325329 logger = new Logger ( processClientStatus . name ) ,
326330) : Promise <
327331 | {
@@ -346,6 +350,7 @@ async function processClientStatus(
346350 clientPort : number ;
347351 }
348352> {
353+ fs = await utils . importFS ( fs ) ;
349354 if ( nodeId != null && clientHost != null && clientPort != null ) {
350355 return {
351356 statusInfo : undefined ,
@@ -426,8 +431,9 @@ async function processClientStatus(
426431 */
427432async function processAuthentication (
428433 passwordFile ?: string ,
429- fs : FileSystem = require ( 'fs' ) ,
434+ fs ? : FileSystem ,
430435) : Promise < { authorization ?: string } > {
436+ fs = await utils . importFS ( fs ) ;
431437 if ( passwordFile != null ) {
432438 let password ;
433439 try {
0 commit comments