Skip to content

Commit 3eb32ff

Browse files
chore: update required node version (#268)
BREAKING CHANGE: drops `node@12`
1 parent f8038a7 commit 3eb32ff

File tree

8 files changed

+48
-43
lines changed

8 files changed

+48
-43
lines changed

.circleci/config.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jobs:
22
lint:
33
docker:
4-
- image: circleci/node:12
4+
- image: circleci/node:14
55
steps:
66
- checkout
77
- restore_cache:
@@ -18,7 +18,7 @@ jobs:
1818

1919
release:
2020
docker:
21-
- image: circleci/node:12
21+
- image: circleci/node:14
2222
steps:
2323
- checkout
2424
- restore_cache:
@@ -31,11 +31,11 @@ jobs:
3131
- node_modules
3232
key: v1-dependencies-{{ checksum "package.json" }}
3333
- run: yarn build
34-
- run: npx semantic-release@17
34+
- run: npx semantic-release
3535

3636
test:
3737
docker:
38-
- image: circleci/node:12
38+
- image: circleci/node:14
3939
steps:
4040
- checkout
4141
- restore_cache:
@@ -52,7 +52,7 @@ jobs:
5252

5353
test-distribution:
5454
docker:
55-
- image: circleci/node:12
55+
- image: circleci/node:14
5656
steps:
5757
- checkout
5858
- restore_cache:

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
},
4646
},
4747
{
48-
files: ['__mocks__/*.ts', 'scripts/jest/*.js', '.eslintrc.js'],
48+
files: ['__mocks__/**/*.ts', 'scripts/jest/*.js', '.eslintrc.js'],
4949
rules: {
5050
// Mocks and some configuration files cannot be modules.
5151
'unicorn/prefer-module': 'off',

__mocks__/fs.ts

-20
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@ function _setFiles(newFiles: {[path: string]: Buffer}): void {
66
files = mapToMap(newFiles);
77
}
88

9-
const readFile = jest.fn(
10-
(
11-
path: string,
12-
encoding: BufferEncoding,
13-
// eslint-disable-next-line @rushstack/no-new-null
14-
callback: (error: Error | null, value?: string) => void,
15-
) => {
16-
const file = files.get(path);
17-
if (file && Buffer.isBuffer(file)) {
18-
const decodedFile = file.toString(encoding);
19-
// eslint-disable-next-line unicorn/no-null
20-
callback(null, decodedFile);
21-
} else {
22-
const error = new Error('File not found.');
23-
callback(error);
24-
}
25-
},
26-
);
27-
289
const readFileSync = jest.fn((path: string, encoding: BufferEncoding) => {
2910
const file = files.get(path);
3011
if (file && Buffer.isBuffer(file)) {
@@ -35,6 +16,5 @@ const readFileSync = jest.fn((path: string, encoding: BufferEncoding) => {
3516

3617
module.exports = {
3718
_setFiles,
38-
readFile,
3919
readFileSync,
4020
};

__mocks__/fs/promises.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import mapToMap from 'map-to-map';
2+
3+
let files: Map<string, Buffer> = new Map();
4+
5+
function _setFiles(newFiles: {[path: string]: Buffer}): void {
6+
files = mapToMap(newFiles);
7+
}
8+
9+
const readFile = jest.fn(async (path: string, encoding: BufferEncoding) => {
10+
const file = files.get(path);
11+
if (file && Buffer.isBuffer(file)) {
12+
return file.toString(encoding);
13+
}
14+
throw new Error('File not found.');
15+
});
16+
17+
module.exports = {
18+
_setFiles,
19+
readFile,
20+
};

__tests__/load-config.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
jest.mock('fs');
1+
jest.mock('fs/promises');
22

3-
import fs from 'fs';
3+
import fs from 'fs/promises';
44
import {ConfigError, loadConfig} from '../source';
55

66
describe('loadConfig', () => {

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
"@babel/core": "^7.15.0",
1111
"@babel/preset-env": "^7.15.0",
1212
"@babel/preset-typescript": "^7.15.0",
13-
"@commitlint/cli": "^16.0.0",
14-
"@commitlint/config-conventional": "^16.0.0",
13+
"@commitlint/cli": "^17.0.1",
14+
"@commitlint/config-conventional": "^17.0.0",
1515
"@rushstack/eslint-config": "^2.5.0",
1616
"@types/jest": "^27.4.1",
1717
"@types/node": "^16.6.1",
1818
"babel-jest": "^28.0.2",
19-
"builtin-modules": "^3.2.0",
2019
"eslint": "^8.4.1",
2120
"eslint-plugin-eslint-comments": "^3.2.0",
2221
"eslint-plugin-unicorn": "^42.0.0",
@@ -25,11 +24,11 @@
2524
"prettier": "2.6.2",
2625
"rimraf": "^3.0.2",
2726
"rollup": "^2.56.0",
28-
"rollup-plugin-ts": "^2.0.0",
29-
"typescript": "~4.6.0"
27+
"rollup-plugin-ts": "^3.0.1",
28+
"typescript": "~4.7.2"
3029
},
3130
"engines": {
32-
"node": ">=12"
31+
"node": ">=14"
3332
},
3433
"files": [
3534
"distribution",

rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import builtinModules from 'builtin-modules';
1+
import {builtinModules} from 'module';
22
import ts from 'rollup-plugin-ts';
33
import {fileURLToPath} from 'url';
44
import packageJson from './package.json';

source/load-file-property.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import {readFile} from 'fs';
1+
import {readFile} from 'fs/promises';
22
import formatProperty from './format-property';
33
import {FileConfig, PropertyResult} from './types';
44

5-
export default function loadFileProperty<Value>(
5+
async function tryToReadFile(
6+
propertyConfig: FileConfig<unknown>,
7+
): Promise<PropertyResult<string>> {
8+
const {encoding = 'utf8', filePath} = propertyConfig;
9+
try {
10+
return {error: false, value: await readFile(filePath, encoding)};
11+
} catch (error) {
12+
return {error: error as Error, value: undefined};
13+
}
14+
}
15+
16+
export default async function loadFileProperty<Value>(
617
propertyConfig: FileConfig<Value>,
718
): Promise<PropertyResult<string | Value>> {
8-
const {encoding = 'utf8', filePath} = propertyConfig;
9-
return new Promise((resolve) => {
10-
readFile(filePath, encoding, (error, value) => {
11-
resolve(formatProperty({error: error ?? false, value}, propertyConfig));
12-
});
13-
});
19+
return formatProperty(await tryToReadFile(propertyConfig), propertyConfig);
1420
}

0 commit comments

Comments
 (0)