diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 495ba52..087eb91 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,16 +10,15 @@ jobs: fail-fast: false matrix: node-version: - - 16 - - 14 - - 12 + - 20 + - 18 os: - ubuntu-latest - macos-latest - windows-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/api.d.ts b/api.d.ts index 7402095..c8c0555 100644 --- a/api.d.ts +++ b/api.d.ts @@ -1,9 +1,9 @@ export default function replaceInFiles( path: string | string[], options: { - find: Array, - replacement: string, - ignoreCase?: boolean, - glob?: boolean + find: Array; + replacement: string; + ignoreCase?: boolean; + glob?: boolean; }, ): Promise; diff --git a/api.js b/api.js index 0153b86..2284b2d 100644 --- a/api.js +++ b/api.js @@ -28,11 +28,11 @@ export default async function replaceInFiler(filePaths, {find, replacement, igno // Replace the replacement string with the string unescaped (only one backslash) if it's escaped replacement = replacement - .replace(/\\n/g, '\n') - .replace(/\\r/g, '\r') - .replace(/\\t/g, '\t'); + .replaceAll('\\n', '\n') + .replaceAll('\\r', '\r') + .replaceAll('\\t', '\t'); - // TODO: Drop the `normalizePath` call when https://github.com/mrmlnc/fast-glob/issues/240 is fixed. + // TODO: Drop the `normalizePath` call when `convertPathToPattern` from `fast-glob` is added to globby. filePaths = glob ? await globby(filePaths.map(filePath => normalizePath(filePath))) : [...new Set(filePaths.map(filePath => normalizePath(path.resolve(filePath))))]; find = find.map(element => { diff --git a/cli.js b/cli.js index 5178c81..95aafec 100755 --- a/cli.js +++ b/cli.js @@ -56,14 +56,12 @@ if (!cli.flags.regex && !cli.flags.string) { process.exit(1); } -(async () => { - await replaceInFiles(cli.input, { - find: [ - ...cli.flags.string, - ...cli.flags.regex.map(regexString => new RegExp(regexString, 'g')), - ], - replacement: cli.flags.replacement, - ignoreCase: cli.flags.ignoreCase, - glob: cli.flags.glob, - }); -})(); +await replaceInFiles(cli.input, { + find: [ + ...cli.flags.string, + ...cli.flags.regex.map(regexString => new RegExp(regexString, 'g')), + ], + replacement: cli.flags.replacement, + ignoreCase: cli.flags.ignoreCase, + glob: cli.flags.glob, +}); diff --git a/package.json b/package.json index 9a0f235..6f7574a 100644 --- a/package.json +++ b/package.json @@ -18,12 +18,12 @@ "bin": { "replace-in-files": "./cli.js" }, + "sideEffects": false, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=18" }, "scripts": { - "//test": "xo && ava", - "test": "ava" + "test": "xo && ava" }, "files": [ "cli.js", @@ -50,15 +50,15 @@ ], "dependencies": { "escape-string-regexp": "^5.0.0", - "globby": "^12.0.2", - "meow": "^10.1.1", + "globby": "^14.0.1", + "meow": "^13.2.0", "normalize-path": "^3.0.0", - "write-file-atomic": "^3.0.3" + "write-file-atomic": "^5.0.1" }, "devDependencies": { - "ava": "^3.15.0", - "execa": "^5.1.1", + "ava": "^6.1.3", + "execa": "^9.3.0", "temp-write": "^5.0.0", - "xo": "^0.46.4" + "xo": "^0.58.0" } } diff --git a/test.js b/test.js index d21d477..c0cbde0 100644 --- a/test.js +++ b/test.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import test from 'ava'; -import execa from 'execa'; +import {execa} from 'execa'; import tempWrite from 'temp-write'; test('--string', async t => {