Skip to content

Commit b6c64ba

Browse files
committed
Require Node.js 20
1 parent b5d18fc commit b6c64ba

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 24
1314
- 20
14-
- 18
1515
os:
1616
- ubuntu-latest
1717
- macos-latest
18-
- windows-latest
18+
# - windows-latest
1919
steps:
20-
- uses: actions/checkout@v4
21-
- uses: actions/setup-node@v4
20+
- uses: actions/checkout@v5
21+
- uses: actions/setup-node@v5
2222
with:
2323
node-version: ${{ matrix.node-version }}
2424
- run: npm install

api.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ const normalizeRegex = (pattern, forceIgnoreCase) => {
3535
};
3636

3737
/**
38-
* Replace matching strings and regexes in files.
39-
* - If `find` is provided, `replacement` must be a string.
40-
* - If `transform` is provided, it runs after all find/replace operations.
41-
* - When `dryRun` is true, returns a list of proposed changes.
42-
*/
38+
Replace matching strings and regexes in files.
39+
40+
- If `find` is provided, `replacement` must be a string.
41+
- If `transform` is provided, it runs after all find/replace operations.
42+
- When `dryRun` is true, returns a list of proposed changes.
43+
*/
4344
export default async function replaceInFiles(
4445
inputPaths,
4546
{
@@ -72,6 +73,7 @@ export default async function replaceInFiles(
7273
let filePaths;
7374
if (glob) {
7475
const patterns = filePathPatterns.map(p => normalizePath(p));
76+
// TODO: Look into using built-in glob when targeting Node.js 24.
7577
filePaths = await globby(patterns, {dot: true, absolute: true, expandDirectories: false});
7678
} else {
7779
filePaths = filePathPatterns.map(p => path.resolve(String(p)));
@@ -83,9 +85,9 @@ export default async function replaceInFiles(
8385
// Replace escape sequences in replacement if we have find patterns
8486
if (hasFind && typeof replacement === 'string') {
8587
replacement = replacement
86-
.replaceAll('\\n', '\n')
87-
.replaceAll('\\r', '\r')
88-
.replaceAll('\\t', '\t');
88+
.replaceAll(String.raw`\n`, '\n')
89+
.replaceAll(String.raw`\r`, '\r')
90+
.replaceAll(String.raw`\t`, '\t');
8991
}
9092

9193
// Prepare replacers

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"sideEffects": false,
2222
"engines": {
23-
"node": ">=18"
23+
"node": ">=20"
2424
},
2525
"scripts": {
2626
"test": "xo && ava"
@@ -50,15 +50,15 @@
5050
],
5151
"dependencies": {
5252
"escape-string-regexp": "^5.0.0",
53-
"globby": "^14.0.1",
53+
"globby": "^14.1.0",
5454
"meow": "^13.2.0",
5555
"normalize-path": "^3.0.0",
56-
"write-file-atomic": "^5.0.1"
56+
"write-file-atomic": "^6.0.0"
5757
},
5858
"devDependencies": {
59-
"ava": "^6.1.3",
60-
"execa": "^9.3.0",
61-
"temp-write": "^5.0.0",
62-
"xo": "^0.58.0"
59+
"ava": "^6.4.1",
60+
"execa": "^9.6.0",
61+
"temp-write": "^6.0.0",
62+
"xo": "^1.2.2"
6363
}
6464
}

readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Real-world use-case: [Bumping version number in a file when publishing to npm](h
4040

4141
The regex should be [JavaScript flavor](https://www.regular-expressions.info/javascript.html).
4242

43-
## Programmatic API
43+
## API
4444

4545
You can also use this package programmatically:
4646

@@ -66,8 +66,6 @@ await replaceInFiles('*.js', {
6666
});
6767
```
6868

69-
### Transform Option
70-
7169
The `transform` option provides full control over file content:
7270
- **Standalone**: Use alone for prepend, append, or complex transformations
7371
- **Combined**: Use with `find`/`replacement` - transform runs after find/replace operations

test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ test('--string', async t => {
1313

1414
test('--regex', async t => {
1515
const filePath = await tempWrite('foo bar foo');
16-
await execa('./cli.js', ['--regex=\\bb.*?\\b', '--replacement=foo', filePath]);
16+
await execa('./cli.js', [String.raw`--regex=\bb.*?\b`, '--replacement=foo', filePath]);
1717
t.is(fs.readFileSync(filePath, 'utf8'), 'foo foo foo');
1818
});
1919

2020
test('newlines and tabs', async t => {
2121
const filePath = await tempWrite('a,b,c');
22-
await execa('./cli.js', ['--string=,', '--replacement=\\n', filePath]);
22+
await execa('./cli.js', ['--string=,', String.raw`--replacement=\n`, filePath]);
2323
t.is(fs.readFileSync(filePath, 'utf8'), 'a\nb\nc');
2424

2525
const filePath2 = await tempWrite('a,b,c');
26-
await execa('./cli.js', ['--string=,', '--replacement=\\t', filePath2]);
26+
await execa('./cli.js', ['--string=,', String.raw`--replacement=\t`, filePath2]);
2727
t.is(fs.readFileSync(filePath2, 'utf8'), 'a\tb\tc');
2828

2929
const filePath3 = await tempWrite('a,b,c');
30-
await execa('./cli.js', ['--string=,', '--replacement=\\r', filePath3]);
30+
await execa('./cli.js', ['--string=,', String.raw`--replacement=\r`, filePath3]);
3131
t.is(fs.readFileSync(filePath3, 'utf8'), 'a\rb\rc');
3232
});
3333

3434
test('multiple newlines and tabs', async t => {
3535
const filePath = await tempWrite('a,b,c');
36-
await execa('./cli.js', ['--string=,', '--replacement=\\n\\n\\t\\r', filePath]);
36+
await execa('./cli.js', ['--string=,', String.raw`--replacement=\n\n\t\r`, filePath]);
3737
t.is(fs.readFileSync(filePath, 'utf8'), 'a\n\n\t\rb\n\n\t\rc');
3838
});
3939

@@ -84,7 +84,7 @@ test('--dry-run with no matches', async t => {
8484

8585
test('--dry-run with regex', async t => {
8686
const filePath = await tempWrite('version 1.2.3 here');
87-
const {stdout} = await execa('./cli.js', ['--dry-run', '--regex=\\d+\\.\\d+\\.\\d+', '--replacement=2.0.0', filePath]);
87+
const {stdout} = await execa('./cli.js', ['--dry-run', String.raw`--regex=\d+\.\d+\.\d+`, '--replacement=2.0.0', filePath]);
8888

8989
t.is(fs.readFileSync(filePath, 'utf8'), 'version 1.2.3 here');
9090
t.true(stdout.includes('version 1.2.3 here'));

0 commit comments

Comments
 (0)