11import _ from 'lodash' ;
22import path from 'node:path' ;
3- import { errors } from 'appium/driver' ;
4- import { fs , mkdirp , util , zip } from 'appium/support' ;
5- import { MODIFY_FS_FEATURE } from '../constants' ;
3+ import { errors } from 'appium/driver' ;
4+ import { fs , mkdirp , util , zip } from 'appium/support' ;
5+ import { MODIFY_FS_FEATURE } from '../constants' ;
66
77// List of env variables, that can be expanded in path
88const KNOWN_ENV_VARS = [
9- 'APPDATA' , 'LOCALAPPDATA' ,
10- 'PROGRAMFILES' , 'PROGRAMFILES(X86)' ,
11- 'PROGRAMDATA' , 'ALLUSERSPROFILE' ,
12- 'TEMP' , 'TMP' ,
13- 'HOMEPATH' , 'USERPROFILE' , 'PUBLIC'
9+ 'APPDATA' ,
10+ 'LOCALAPPDATA' ,
11+ 'PROGRAMFILES' ,
12+ 'PROGRAMFILES(X86)' ,
13+ 'PROGRAMDATA' ,
14+ 'ALLUSERSPROFILE' ,
15+ 'TEMP' ,
16+ 'TMP' ,
17+ 'HOMEPATH' ,
18+ 'USERPROFILE' ,
19+ 'PUBLIC' ,
1420] ;
1521
1622/**
@@ -20,12 +26,13 @@ const KNOWN_ENV_VARS = [
2026 * @param {string } base64Data
2127 * @returns {Promise<void> }
2228 */
23- export async function pushFile ( remotePath , base64Data ) {
29+ export async function pushFile ( remotePath , base64Data ) {
2430 this . assertFeatureEnabled ( MODIFY_FS_FEATURE ) ;
2531 if ( remotePath . endsWith ( path . sep ) ) {
2632 throw new errors . InvalidArgumentError (
2733 'It is expected that remote path points to a file rather than a folder. ' +
28- `'${ remotePath } ' is given instead` ) ;
34+ `'${ remotePath } ' is given instead` ,
35+ ) ;
2936 }
3037
3138 if ( _ . isArray ( base64Data ) ) {
@@ -46,7 +53,7 @@ export async function pushFile (remotePath, base64Data) {
4653 * @param {string } remotePath
4754 * @returns {Promise<string> }
4855 */
49- export async function pullFile ( remotePath ) {
56+ export async function pullFile ( remotePath ) {
5057 const fullPath = resolveToAbsolutePath ( remotePath ) ;
5158 await checkFileExists ( fullPath ) ;
5259 return ( await util . toInMemoryBase64 ( fullPath ) ) . toString ( ) ;
@@ -58,12 +65,14 @@ export async function pullFile (remotePath) {
5865 * @param {string } remotePath
5966 * @returns {Promise<string> }
6067 */
61- export async function pullFolder ( remotePath ) {
68+ export async function pullFolder ( remotePath ) {
6269 const fullPath = resolveToAbsolutePath ( remotePath ) ;
6370 await checkFolderExists ( fullPath ) ;
64- return ( await zip . toInMemoryZip ( fullPath , {
65- encodeToBase64 : true ,
66- } ) ) . toString ( ) ;
71+ return (
72+ await zip . toInMemoryZip ( fullPath , {
73+ encodeToBase64 : true ,
74+ } )
75+ ) . toString ( ) ;
6776}
6877
6978/**
@@ -78,7 +87,7 @@ export async function pullFolder (remotePath) {
7887 * @throws {InvalidArgumentError } If the file to be deleted does not exist or
7988 * remote path is not an absolute path.
8089 */
81- export async function windowsDeleteFile ( remotePath ) {
90+ export async function windowsDeleteFile ( remotePath ) {
8291 this . assertFeatureEnabled ( MODIFY_FS_FEATURE ) ;
8392 const fullPath = resolveToAbsolutePath ( remotePath ) ;
8493 await checkFileExists ( fullPath ) ;
@@ -97,7 +106,7 @@ export async function windowsDeleteFile (remotePath) {
97106 * @throws {InvalidArgumentError } If the folder to be deleted does not exist or
98107 * remote path is not an absolute path.
99108 */
100- export async function windowsDeleteFolder ( remotePath ) {
109+ export async function windowsDeleteFolder ( remotePath ) {
101110 this . assertFeatureEnabled ( MODIFY_FS_FEATURE ) ;
102111 const fullPath = resolveToAbsolutePath ( remotePath ) ;
103112 await checkFolderExists ( fullPath ) ;
@@ -109,17 +118,17 @@ export async function windowsDeleteFolder (remotePath) {
109118 * @param {string } remotePath
110119 * @returns {string }
111120 */
112- function resolveToAbsolutePath ( remotePath ) {
113- const resolvedPath = remotePath . replace (
114- / % ( [ ^ % ] + ) % / g,
115- ( _ , key ) => KNOWN_ENV_VARS . includes ( key . toUpperCase ( ) )
121+ function resolveToAbsolutePath ( remotePath ) {
122+ const resolvedPath = remotePath . replace ( / % ( [ ^ % ] + ) % / g, ( _ , key ) =>
123+ KNOWN_ENV_VARS . includes ( key . toUpperCase ( ) )
116124 ? /** @type {string } */ ( process . env [ key . toUpperCase ( ) ] )
117- : `%${ key } %`
125+ : `%${ key } %` ,
118126 ) ;
119127
120128 if ( ! path . isAbsolute ( resolvedPath ) ) {
121- throw new errors . InvalidArgumentError ( 'It is expected that remote path is absolute. ' +
122- `'${ resolvedPath } ' is given instead` ) ;
129+ throw new errors . InvalidArgumentError (
130+ 'It is expected that remote path is absolute. ' + `'${ resolvedPath } ' is given instead` ,
131+ ) ;
123132 }
124133 return resolvedPath ;
125134}
@@ -129,15 +138,16 @@ function resolveToAbsolutePath (remotePath) {
129138 * @param {string } remotePath
130139 * @returns {Promise<void> }
131140 */
132- async function checkFileExists ( remotePath ) {
133- if ( ! await fs . exists ( remotePath ) ) {
141+ async function checkFileExists ( remotePath ) {
142+ if ( ! ( await fs . exists ( remotePath ) ) ) {
134143 throw new errors . InvalidArgumentError ( `The remote file '${ remotePath } ' does not exist.` ) ;
135144 }
136145 const stat = await fs . stat ( remotePath ) ;
137146 if ( ! stat . isFile ( ) ) {
138147 throw new errors . InvalidArgumentError (
139148 'It is expected that remote path points to a file rather than a folder. ' +
140- `'${ remotePath } ' is given instead` ) ;
149+ `'${ remotePath } ' is given instead` ,
150+ ) ;
141151 }
142152}
143153
@@ -146,18 +156,19 @@ async function checkFileExists (remotePath) {
146156 * @param {string } remotePath
147157 * @returns {Promise<void> }
148158 */
149- async function checkFolderExists ( remotePath ) {
150- if ( ! await fs . exists ( remotePath ) ) {
159+ async function checkFolderExists ( remotePath ) {
160+ if ( ! ( await fs . exists ( remotePath ) ) ) {
151161 throw new errors . InvalidArgumentError ( `The remote folder '${ remotePath } ' does not exist.` ) ;
152162 }
153163 const stat = await fs . stat ( remotePath ) ;
154164 if ( ! stat . isDirectory ( ) ) {
155165 throw new errors . InvalidArgumentError (
156166 'It is expected that remote path points to a folder rather than a file. ' +
157- `'${ remotePath } ' is given instead` ) ;
167+ `'${ remotePath } ' is given instead` ,
168+ ) ;
158169 }
159170}
160171
161172/**
162173 * @typedef {import('../driver').WindowsDriver } WindowsDriver
163- */
174+ */
0 commit comments