Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
Fixes #22
  • Loading branch information
sindresorhus committed Jun 26, 2024
1 parent f74c53f commit dc6c964
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 34 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions api.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default function replaceInFiles(
path: string | string[],
options: {
find: Array<string | RegExp>,
replacement: string,
ignoreCase?: boolean,
glob?: boolean
find: Array<string | RegExp>;
replacement: string;
ignoreCase?: boolean;
glob?: boolean;
},
): Promise<void>;
8 changes: 4 additions & 4 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
20 changes: 9 additions & 11 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit dc6c964

Please sign in to comment.