Skip to content

Commit 7e6affe

Browse files
committed
Require Node.js 12.20
1 parent be53ff1 commit 7e6affe

File tree

7 files changed

+47
-52
lines changed

7 files changed

+47
-52
lines changed

.github/funding.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 16
1314
- 14
1415
- 12
15-
- 10
1616
os:
1717
- ubuntu-latest
1818
- macos-latest
1919
- windows-latest
2020
steps:
2121
- uses: actions/checkout@v2
22-
- uses: actions/setup-node@v1
22+
- uses: actions/setup-node@v2
2323
with:
2424
node-version: ${{ matrix.node-version }}
2525
- run: npm install

api.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
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+
}

cli.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
2-
'use strict';
3-
const meow = require('meow');
4-
const replaceInFiles = require('./api');
2+
import process from 'node:process';
3+
import meow from 'meow';
4+
import replaceInFiles from './api.js';
55

66
const cli = meow(`
77
Usage
@@ -21,28 +21,29 @@ const cli = meow(`
2121
2222
You can use the same replacement patterns as with \`String#replace()\`, like \`$&\`.
2323
`, {
24+
importMeta: import.meta,
2425
flags: {
2526
regex: {
2627
type: 'string',
27-
isMultiple: true
28+
isMultiple: true,
2829
},
2930
string: {
3031
type: 'string',
31-
isMultiple: true
32+
isMultiple: true,
3233
},
3334
replacement: {
3435
type: 'string',
35-
isRequired: true
36+
isRequired: true,
3637
},
3738
ignoreCase: {
3839
type: 'boolean',
39-
default: false
40+
default: false,
4041
},
4142
glob: {
4243
type: 'boolean',
43-
default: true
44-
}
45-
}
44+
default: true,
45+
},
46+
},
4647
});
4748

4849
if (cli.input.length === 0) {
@@ -58,12 +59,11 @@ if (!cli.flags.regex && !cli.flags.string) {
5859
(async () => {
5960
await replaceInFiles(cli.input, {
6061
find: [
61-
// TODO: Remove the `|| []` when `meow` 7.1.2 is out.
62-
...(cli.flags.string || []),
63-
...(cli.flags.regex || []).map(regexString => new RegExp(regexString, 'g'))
62+
...cli.flags.string,
63+
...cli.flags.regex.map(regexString => new RegExp(regexString, 'g')),
6464
],
6565
replacement: cli.flags.replacement,
6666
ignoreCase: cli.flags.ignoreCase,
67-
glob: cli.flags.glob
67+
glob: cli.flags.glob,
6868
});
6969
})();

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
"email": "[email protected]",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
1314
"bin": {
14-
"replace-in-files": "cli.js"
15+
"replace-in-files": "./cli.js"
1516
},
1617
"engines": {
17-
"node": ">=10"
18+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
1819
},
1920
"scripts": {
2021
"test": "xo && ava"
@@ -42,17 +43,16 @@
4243
"contents"
4344
],
4445
"dependencies": {
45-
"arrify": "^2.0.1",
46-
"escape-string-regexp": "^4.0.0",
47-
"globby": "^11.0.1",
48-
"meow": "^7.1.1",
46+
"escape-string-regexp": "^5.0.0",
47+
"globby": "^12.0.2",
48+
"meow": "^10.1.1",
4949
"normalize-path": "^3.0.0",
50-
"write-file-atomic": "^3.0.0"
50+
"write-file-atomic": "^3.0.3"
5151
},
5252
"devDependencies": {
53-
"ava": "^2.1.0",
54-
"execa": "^1.0.0",
55-
"temp-write": "^4.0.0",
56-
"xo": "^0.33.1"
53+
"ava": "^3.15.0",
54+
"execa": "^5.1.1",
55+
"temp-write": "^5.0.0",
56+
"xo": "^0.46.4"
5757
}
5858
}

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
55
## Install
66

7-
```
8-
$ npm install --global replace-in-files-cli
7+
```sh
8+
npm install --global replace-in-files-cli
99
```
1010

1111
## Usage

test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import process from 'node:process';
34
import test from 'ava';
45
import execa from 'execa';
56
import tempWrite from 'temp-write';
@@ -55,11 +56,10 @@ test('no globs', async t => {
5556
'--replacement=foo',
5657
'--no-glob',
5758
path.join(dirnames[0], '*.glob'),
58-
path.join(dirnames[1], '*.glob')
59+
path.join(dirnames[1], '*.glob'),
5960
]),
6061
{
61-
code: 1,
62-
message: /ENOENT/
63-
}
62+
message: /ENOENT/,
63+
},
6464
);
6565
});

0 commit comments

Comments
 (0)