1- 'use strict' ;
2- const { promisify} = require ( 'util' ) ;
3- const path = require ( 'path' ) ;
4- const fs = require ( 'fs' ) ;
5- const normalizePath = process . platform === 'win32' ? require ( 'normalize-path' ) : x => x ;
6- const writeFileAtomic = require ( 'write-file-atomic' ) ;
7- const escapeStringRegexp = require ( 'escape-string-regexp' ) ;
8- const arrify = require ( 'arrify' ) ;
9- const globby = require ( 'globby' ) ;
1+ import process from 'node:process' ;
2+ import path from 'node:path' ;
3+ import { promises as fsPromises } from 'node:fs' ;
4+ import normalizePath_ from 'normalize-path' ;
5+ import writeFileAtomic from 'write-file-atomic' ;
6+ import escapeStringRegexp from 'escape-string-regexp' ;
7+ import { globby } from 'globby' ;
108
11- const readFile = promisify ( fs . readFile ) ;
9+ const normalizePath = process . platform === 'win32' ? normalizePath_ : x => x ;
1210
1311// TODO(sindresorhus): I will extract this to a separate module at some point when it's more mature.
1412// `find` is expected to be `Array<string | RegExp>`
1513// The `ignoreCase` option overrides the `i` flag for regexes in `find`
16- module . exports = async ( filePaths , { find, replacement, ignoreCase, glob} = { } ) => {
17- filePaths = arrify ( filePaths ) ;
14+ export default async function replaceInFiler ( filePaths , { find, replacement, ignoreCase, glob} = { } ) {
15+ filePaths = [ filePaths ] . flat ( ) ;
1816
1917 if ( filePaths . length === 0 ) {
2018 return ;
@@ -48,7 +46,7 @@ module.exports = async (filePaths, {find, replacement, ignoreCase, glob} = {}) =
4846 } ) ;
4947
5048 await Promise . all ( filePaths . map ( async filePath => {
51- const string = await readFile ( filePath , 'utf8' ) ;
49+ const string = await fsPromises . readFile ( filePath , 'utf8' ) ;
5250
5351 let newString = string ;
5452 for ( const pattern of find ) {
@@ -61,4 +59,4 @@ module.exports = async (filePaths, {find, replacement, ignoreCase, glob} = {}) =
6159
6260 await writeFileAtomic ( filePath , newString ) ;
6361 } ) ) ;
64- } ;
62+ }
0 commit comments