1- import { readFile , access } from 'fs' ;
1+ import fs , { promises as fsPromises } from 'fs' ;
22import { resolve , dirname } from 'path' ;
33
44import type { PreprocessorArgs } from '../types' ;
55import { getLanguage } from './language' ;
66import { isValidLocalPath } from './utils' ;
77
8+ const { access, readFile } = fsPromises ;
9+
810const resolveSrc = ( importerFile : string , srcPath : string ) =>
911 resolve ( dirname ( importerFile ) , srcPath ) ;
1012
11- const getSrcContent = ( file : string ) : Promise < string > => {
12- return new Promise ( ( resolve , reject ) => {
13- readFile ( file , ( error : Error , data : unknown ) => {
14- // istanbul ignore if
15- if ( error ) reject ( error ) ;
16- else resolve ( data . toString ( ) ) ;
17- } ) ;
18- } ) ;
19- } ;
20-
2113async function doesFileExist ( file : string ) {
22- return new Promise ( ( resolve ) => access ( file , 0 , ( err ) => resolve ( ! err ) ) ) ;
14+ return access ( file , fs . constants . F_OK )
15+ . then ( ( ) => true )
16+ . catch ( ( ) => false ) ;
2317}
2418
2519export const getTagInfo = async ( {
@@ -44,10 +38,10 @@ export const getTagInfo = async ({
4438 if ( isValidLocalPath ( path ) ) {
4539 path = resolveSrc ( filename , path ) ;
4640 if ( await doesFileExist ( path ) ) {
47- content = await getSrcContent ( path ) ;
41+ content = ( await readFile ( path ) ) . toString ( ) ;
4842 dependencies . push ( path ) ;
4943 } else {
50- console . warn ( `[svelte-preprocess] The file "${ path } " was not found.` ) ;
44+ console . warn ( `[svelte-preprocess] The file "${ path } " was not found.` ) ;
5145 }
5246 }
5347 }
0 commit comments